Results 1 to 4 of 4

Thread: Java 3d HELP needed

  1. #1
    Join Date
    Oct 2011
    Location
    Chicago
    Posts
    3,352
    Mentioned
    21 Post(s)
    Quoted
    437 Post(s)

    Default Java 3d HELP needed

    java Code:
    /*

     */


    import java.applet.Applet;
    import java.awt.*;
    import com.sun.j3d.utils.applet.MainFrame;
    import com.sun.j3d.utils.geometry.*;
    import com.sun.j3d.utils.universe.*;
    import javax.media.j3d.*;
    import javax.vecmath.*;
    import com.sun.j3d.utils.behaviors.keyboard.*;

    public class Assignment8 extends Applet {
           
         SimpleUniverse simpleU=null;

         public BranchGroup createSceneGraph() {
            // Create the root of the branch graph
            BranchGroup objRoot = new BranchGroup();
           
            AmbientLight lightA = new AmbientLight();
            BoundingSphere bs = new BoundingSphere(new Point3d(0.0,0.0,0.0),1000.0);
            lightA.setInfluencingBounds(bs);
            objRoot.addChild(lightA);
           
           
            // The Sea Floor.
            Color3f black = new Color3f(0.0f, 0.0f, 0.0f);
            Color3f white = new Color3f(1.0f, 1.0f, 1.0f);
            Appearance appX = new Appearance();
            Color3f colorX = new Color3f(0.1f, 0.9f, 0.9f);
            appX.setMaterial(new Material(colorX, black, colorX, white, 80.0f));
            Box xaxis = new Box(20.0f, 1.0f, 20.0f, appX);
            objRoot.addChild(xaxis);
           
           
            // The trendy roof's.
            Appearance appS = new Appearance();
            Color3f colorS = new Color3f(0.02f, 0.02f, 0.7f);
            appS.setMaterial(new Material(colorS, black, colorS, white, 80.0f));
            Sphere s1 = new Sphere(1.0f, appS);
            Sphere s2 = new Sphere(0.9f, appS);
            Transform3D tS = new Transform3D();
            Transform3D tG = new Transform3D();
            tS.setTranslation(new Vector3f(4.0f, 3.0f, 1.5f));
            tG.setTranslation(new Vector3f(-4.0f, 3.0f, 1.5f));
            TransformGroup tgS = new TransformGroup(tG);
            TransformGroup tgs2 = new TransformGroup(tS);
            tgS.addChild(s2);
            tgs2.addChild(s1);
            objRoot.addChild(tgS);
            objRoot.addChild(tgs2);
           
           
            // Green Homes.
            Appearance appB = new Appearance();
            Color3f colorB = new Color3f(0.02f, 0.7f, 0.02f);
            appB.setMaterial(new Material(colorB, black, colorB, white, 80.0f));
            Box b1 = new Box(0.7f, 0.7f, 0.7f, appB);
            Transform3D tB = new Transform3D();
            tB.setTranslation(new Vector3f(4.0f, 2.0f, 1.5f));
            TransformGroup tgB = new TransformGroup(tB);
            tgB.addChild(b1);
            objRoot.addChild(tgB);
           
            Appearance appC = new Appearance();
            Color3f colorC = new Color3f(0.05f, 0.12f, 0.12f);
            appC.setMaterial(new Material(colorC, black, colorC, black, 80.0f));
            Box b2 = new Box(0.7f, 0.7f, 0.7f, appB);
            Transform3D tC = new Transform3D();
            tC.setTranslation(new Vector3f(-4.0f, 2.0f, 1.5f));
            TransformGroup tgC = new TransformGroup(tC);
            tgC.addChild(b2);
            objRoot.addChild(tgC);

            return objRoot;
        } // end of CreateSceneGraph method of assignment8

        public Assignment8() {
            setLayout(new BorderLayout());
            Canvas3D canvas3D = new Canvas3D(SimpleUniverse.getPreferredConfiguration());
            add("Center", canvas3D);
            //Zoom out a little bit to see the entire landscape

            // SimpleUniverse is a Convenience Utility class
            simpleU = new SimpleUniverse(canvas3D);

            BranchGroup scene = createSceneGraph();
           
            //...and, set up a KeyNavigator to let us move about
            //
            TransformGroup vpTrans = simpleU.getViewingPlatform().getViewPlatformTransform();
       
            KeyNavigatorBehavior keyNav = new KeyNavigatorBehavior(vpTrans);
            keyNav.setSchedulingBounds(new BoundingSphere(new Point3d(), 1000.0));
            scene.addChild(keyNav);
           
            scene.compile();

            simpleU.addBranchGraph(scene);
        }

        //  The following allows this to be run as an application
        //  as well as an applet

        public static void main(String[] args) {
            Frame frame = new MainFrame(new Assignment8(), 256, 256);
        }

    }

    I am trying to add this cube to it, smaller and above the boxes and circles
    http://www.java2s.com/Code/Java/3D/SimpleRotation.htm


    Anyone able to do this? I took a few stabs, but I keep getting errors when it runs.
    Last edited by masterBB; 04-24-2015 at 06:26 AM. Reason: java tags




    Anti-Leech Movement Prevent Leeching Spread the word
    Insanity 60 Days (Killer workout)
    XoL Blog (Workouts/RS/Misc)

  2. #2
    Join Date
    Sep 2010
    Posts
    5,762
    Mentioned
    136 Post(s)
    Quoted
    2739 Post(s)

    Default

    That example looks like it is pretty old judging off the windows XP UI, maybe the code and or library no longer compiles and needs to be updated with the newer version of Java? Beyond that IDK

  3. #3
    Join Date
    Oct 2011
    Location
    Chicago
    Posts
    3,352
    Mentioned
    21 Post(s)
    Quoted
    437 Post(s)

    Default

    Its Java3d, it requires a different eclipse/java source I think




    Anti-Leech Movement Prevent Leeching Spread the word
    Insanity 60 Days (Killer workout)
    XoL Blog (Workouts/RS/Misc)

  4. #4
    Join Date
    Jan 2012
    Location
    Long Island, NY
    Posts
    413
    Mentioned
    5 Post(s)
    Quoted
    95 Post(s)

    Default

    Quote Originally Posted by [XoL] View Post
    Its Java3d, it requires a different eclipse/java source I think
    Download j3d from https://java3d.java.net/binary-builds.html.

    I ran your code in NetBeans, just spawns a frame with a black background, but it does compile and run no issues.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •