List of usage examples for javax.media.j3d BranchGroup addChild
public void addChild(Node child)
From source file:LightsNPlanesApp.java
public LightsNPlanesApp() { setLayout(new BorderLayout()); Canvas3D c = new Canvas3D(null); add("Center", c); BoundingSphere bounds = new BoundingSphere(new Point3d(), 0.1); Vector3f direction = new Vector3f(0.0f, -1.0f, 0.0f); Point3f position = new Point3f(0.0f, 0.5f, -0.3f); Color3f white = new Color3f(1.0f, 1.0f, 1.0f); Color3f red = new Color3f(1.0f, 0.0f, 0.0f); Color3f green = new Color3f(0.0f, 1.0f, 0.0f); Color3f blue = new Color3f(0.0f, 0.0f, 1.0f); BranchGroup scene = new BranchGroup(); IndexedQuadArray qa = new IndexedQuadArray(9, QuadArray.COORDINATES | QuadArray.NORMALS, 16); qa.setCoordinate(0, new Point3f(-0.3f, 0.3f, -0.3f)); qa.setCoordinate(1, new Point3f(0.0f, 0.3f, -0.3f)); qa.setCoordinate(2, new Point3f(0.3f, 0.3f, -0.3f)); qa.setCoordinate(3, new Point3f(-0.3f, 0.0f, 0.0f)); qa.setCoordinate(4, new Point3f(0.0f, 0.0f, 0.0f)); qa.setCoordinate(5, new Point3f(0.3f, 0.0f, 0.0f)); qa.setCoordinate(6, new Point3f(-0.3f, -0.3f, 0.3f)); qa.setCoordinate(7, new Point3f(0.0f, -0.3f, 0.3f)); qa.setCoordinate(8, new Point3f(0.3f, -0.3f, 0.3f)); Vector3f n = new Vector3f(0.0f, 0.6f, 0.8f); n.normalize();/* w ww . jav a 2 s . co m*/ qa.setNormal(0, n); qa.setNormal(1, n); qa.setNormal(2, n); qa.setNormal(3, n); qa.setNormal(4, n); qa.setNormal(5, n); qa.setNormal(6, n); qa.setNormal(7, n); qa.setNormal(8, n); qa.setCoordinateIndex(0, 0); qa.setCoordinateIndex(1, 3); qa.setCoordinateIndex(2, 4); qa.setCoordinateIndex(3, 1); qa.setCoordinateIndex(4, 1); qa.setCoordinateIndex(5, 4); qa.setCoordinateIndex(6, 5); qa.setCoordinateIndex(7, 2); qa.setCoordinateIndex(8, 3); qa.setCoordinateIndex(9, 6); qa.setCoordinateIndex(10, 7); qa.setCoordinateIndex(11, 4); qa.setCoordinateIndex(12, 4); qa.setCoordinateIndex(13, 7); qa.setCoordinateIndex(14, 8); qa.setCoordinateIndex(15, 5); TransformGroup trans1 = createTG(-0.7f, 0.0f, -0.5f); scene.addChild(trans1); TransformGroup trans2 = createTG(0.0f, 0.0f, -0.5f); scene.addChild(trans2); TransformGroup trans3 = createTG(0.7f, 0.0f, -0.5f); scene.addChild(trans3); Appearance qAppear = createMatAppear(white, white, 5.0f); Shape3D p1 = new Shape3D(qa, qAppear); // p1.setBoundsAutoCompute(false); p1.setBounds(bounds); p1.setCapability(Node.ALLOW_BOUNDS_READ); trans1.addChild(p1); Shape3D p2 = new Shape3D(qa, qAppear); p2.setBounds(bounds); p2.setCapability(Node.ALLOW_BOUNDS_READ); trans2.addChild(p2); Shape3D p3 = new Shape3D(qa, qAppear); p3.setBounds(bounds); p3.setCapability(Node.ALLOW_BOUNDS_READ); trans3.addChild(p3); AmbientLight lightA = new AmbientLight(); lightA.setInfluencingBounds(new BoundingSphere()); lightA.setCapability(Light.ALLOW_INFLUENCING_BOUNDS_READ); scene.addChild(lightA); DirectionalLight lightD = new DirectionalLight(); lightD.setInfluencingBounds(bounds); lightD.setBoundsAutoCompute(false); lightD.setCapability(Light.ALLOW_INFLUENCING_BOUNDS_READ); lightD.setDirection(direction); lightD.setColor(red); trans1.addChild(lightD); PointLight lightP = new PointLight(); lightP.setInfluencingBounds(bounds); lightP.setCapability(Light.ALLOW_INFLUENCING_BOUNDS_READ); lightP.setPosition(position); lightP.setColor(green); trans2.addChild(lightP); SpotLight lightS = new SpotLight(); lightS.setInfluencingBounds(bounds); lightS.setCapability(Light.ALLOW_INFLUENCING_BOUNDS_READ); lightS.setPosition(position); lightS.setDirection(direction); lightS.setSpreadAngle(0.3f); lightS.setConcentration(1.0f); lightS.setColor(blue); trans3.addChild(lightS); Background background = new Background(); background.setApplicationBounds(new BoundingSphere()); background.setColor(1.0f, 1.0f, 1.0f); scene.addChild(background); scene.compile(); System.out.print("bounds object: "); System.out.println(bounds); System.out.print("influencing bounds for lightA: "); System.out.println(lightA.getInfluencingBounds()); System.out.print("influencing bounds for lightD: "); System.out.println(lightD.getInfluencingBounds()); System.out.print("influencing bounds for lightP: "); System.out.println(lightP.getInfluencingBounds()); System.out.print("influencing bounds for lightS: "); System.out.println(lightS.getInfluencingBounds()); System.out.print("bounds for plane1: "); System.out.println(p1.getBounds()); System.out.print("bounds for plane2: "); System.out.println(p2.getBounds()); System.out.print("bounds for plane3: "); System.out.println(p3.getBounds()); BoundingSphere bs0 = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 0.2); BoundingSphere bs1 = new BoundingSphere(new Point3d(-0.1, 0.0, 0.0), 0.2); BoundingSphere bs2 = new BoundingSphere(new Point3d(-0.2, 0.0, 0.0), 0.2); BoundingSphere bs3 = new BoundingSphere(new Point3d(-0.3, 0.0, 0.0), 0.2); BoundingSphere bs4 = new BoundingSphere(new Point3d(-0.4, 0.0, 0.0), 0.2); BoundingSphere bs5 = new BoundingSphere(new Point3d(-0.5, 0.0, 0.0), 0.2); BoundingSphere bs6 = new BoundingSphere(new Point3d(-0.6, 0.0, 0.0), 0.2); BoundingSphere bs7 = new BoundingSphere(new Point3d(-0.7, 0.0, 0.0), 0.2); BoundingSphere bs8 = new BoundingSphere(new Point3d(-0.8, 0.0, 0.0), 0.2); BoundingBox bb1 = new BoundingBox(bs1); BoundingBox bb2 = new BoundingBox(bs2); BoundingBox bb3 = new BoundingBox(bs3); BoundingBox bb4 = new BoundingBox(bs4); BoundingBox bb5 = new BoundingBox(bs5); BoundingBox bb6 = new BoundingBox(bs6); BoundingBox bb7 = new BoundingBox(bs7); BoundingBox bb8 = new BoundingBox(bs8); if (bs0.intersect(bs1)) System.out.println("bs0 intersects bs1"); if (bs0.intersect(bs2)) System.out.println("bs0 intersects bs2"); if (bs0.intersect(bs3)) System.out.println("bs0 intersects bs3"); if (bs0.intersect(bs4)) System.out.println("bs0 intersects bs4"); if (bs0.intersect(bs5)) System.out.println("bs0 intersects bs5"); if (bs0.intersect(bs6)) System.out.println("bs0 intersects bs6"); if (bs0.intersect(bs7)) System.out.println("bs0 intersects bs7"); if (bs0.intersect(bs8)) System.out.println("bs0 intersects bs8"); if (bs0.intersect(bb1)) System.out.println("bs0 intersects bb1"); if (bs0.intersect(bb2)) System.out.println("bs0 intersects bb2"); if (bs0.intersect(bb3)) System.out.println("bs0 intersects bb3"); if (bs0.intersect(bb4)) System.out.println("bs0 intersects bb4"); if (bs0.intersect(bb5)) System.out.println("bs0 intersects bb5"); if (bs0.intersect(bb6)) System.out.println("bs0 intersects bb6"); if (bs0.intersect(bb7)) System.out.println("bs0 intersects bb7"); if (bs0.intersect(bb8)) System.out.println("bs0 intersects bb8"); SimpleUniverse u = new SimpleUniverse(c); // This will move the ViewPlatform back a bit so the // objects in the scene can be viewed. u.getViewingPlatform().setNominalViewingTransform(); u.addBranchGraph(scene); }
From source file:TexCoordTest.java
protected BranchGroup createSceneBranchGroup() { BranchGroup objRoot = super.createSceneBranchGroup(); TransformGroup objPosition = new TransformGroup(); objPosition.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); TransformGroup objRotate = new TransformGroup(); objRotate.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); Transform3D axisTranslate = new Transform3D(); axisTranslate.rotZ(Math.toRadians(90)); Alpha rotationAlpha = new Alpha(-1, Alpha.INCREASING_ENABLE, 0, 0, 6000, 0, 0, 0, 0, 0); m_PositionInterpolator = new PositionInterpolator(rotationAlpha, objPosition, axisTranslate, 0, 70); m_PositionInterpolator.setSchedulingBounds(createApplicationBounds()); objPosition.addChild(m_PositionInterpolator); m_PositionInterpolator.setEnable(false); m_RotationInterpolator = new RotationInterpolator(rotationAlpha, objRotate, new Transform3D(), 0.0f, (float) Math.PI * 2.0f); m_RotationInterpolator.setSchedulingBounds(getApplicationBounds()); objRotate.addChild(m_RotationInterpolator); m_RotationInterpolator.setEnable(true); TransformGroup tgLand = new TransformGroup(); Transform3D t3dLand = new Transform3D(); t3dLand.setTranslation(new Vector3d(0, -30, 0)); tgLand.setTransform(t3dLand);/* ww w . ja v a 2 s . c o m*/ tgLand.addChild(createDemLandscape()); objRotate.addChild(tgLand); objPosition.addChild(objRotate); objRoot.addChild(objPosition); // create some lights for the scene Color3f lColor1 = new Color3f(0.3f, 0.3f, 0.3f); Vector3f lDir1 = new Vector3f(-1.0f, -1.0f, -1.0f); Color3f alColor = new Color3f(0.1f, 0.1f, 0.1f); AmbientLight aLgt = new AmbientLight(alColor); aLgt.setInfluencingBounds(getApplicationBounds()); DirectionalLight lgt1 = new DirectionalLight(lColor1, lDir1); lgt1.setInfluencingBounds(getApplicationBounds()); // add the lights to the parent BranchGroup objRoot.addChild(aLgt); objRoot.addChild(lgt1); return objRoot; }
From source file:PickTest.java
public BranchGroup createSceneGraph(Canvas3D canvas) { // Create the root of the branch graph BranchGroup objRoot = new BranchGroup(); // Create a Transformgroup to scale all objects so they // appear in the scene. TransformGroup objScale = new TransformGroup(); Transform3D t3d = new Transform3D(); t3d.setScale(1.0);// ww w .ja v a2 s.c om objScale.setTransform(t3d); objRoot.addChild(objScale); // Create a bunch of objects with a behavior and add them // into the scene graph. int row, col; int numRows = 4, numCols = 4; for (int i = 0; i < numRows; i++) { double ypos = (double) (i - numRows / 2) * 0.45 + 0.25; for (int j = 0; j < numCols; j++) { double xpos = (double) (j - numCols / 2) * 0.45 + 0.25; objScale.addChild(createObject(i * numCols + j, 0.1, xpos, ypos)); } } BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0); // Add a light. Color3f lColor = new Color3f(1.0f, 1.0f, 1.0f); Vector3f lDir = new Vector3f(0.0f, 0.0f, -1.0f); DirectionalLight lgt = new DirectionalLight(lColor, lDir); lgt.setInfluencingBounds(bounds); objRoot.addChild(lgt); // Now create the Alpha object that controls the speed of the // morphing operation. Alpha morphAlpha = new Alpha(-1, Alpha.INCREASING_ENABLE | Alpha.DECREASING_ENABLE, 0, 0, 4000, 1000, 500, 4000, 1000, 500); // Finally, create the morphing behavior MorphingBehavior mBeh = new MorphingBehavior(morphAlpha, morph); mBeh.setSchedulingBounds(bounds); objRoot.addChild(mBeh); behavior1 = new PickRotateBehavior(objRoot, canvas, bounds); objRoot.addChild(behavior1); behavior2 = new PickZoomBehavior(objRoot, canvas, bounds); objRoot.addChild(behavior2); behavior3 = new PickTranslateBehavior(objRoot, canvas, bounds); objRoot.addChild(behavior3); // Let Java 3D perform optimizations on this scene graph. objRoot.compile(); return objRoot; }
From source file:KeyNavigateTest.java
protected BranchGroup createSceneBranchGroup() { BranchGroup objRoot = super.createSceneBranchGroup(); TransformGroup objTrans = new TransformGroup(); objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); createMap(objTrans);//from w ww .ja va2s . co m createFloor(objTrans); createCeiling(objTrans); objRoot.addChild(objTrans); return objRoot; }
From source file:PointTest.java
protected BranchGroup createSceneBranchGroup() { BranchGroup objRoot = super.createSceneBranchGroup(); TransformGroup objTrans = new TransformGroup(); objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); Transform3D yAxis = new Transform3D(); Alpha rotationAlpha = new Alpha(-1, Alpha.INCREASING_ENABLE, 0, 0, 14000, 0, 0, 0, 0, 0); RotationInterpolator rotator = new RotationInterpolator(rotationAlpha, objTrans, yAxis, 0.0f, (float) Math.PI * 2.0f); rotator.setSchedulingBounds(getApplicationBounds()); objTrans.addChild(rotator);/*from w ww .ja v a2 s .c om*/ Switch switchGroup = new Switch(); switchGroup.setCapability(Switch.ALLOW_SWITCH_WRITE); switchGroup.addChild(createPoints(1, 5, false)); switchGroup.addChild(createPoints(1, 5, true)); switchGroup.addChild(createPoints(8, 10, false)); switchGroup.addChild(createPoints(8, 10, true)); switchGroup.addChild(createPoints(2, 5, false)); switchGroup.addChild(createPoints(2, 5, true)); switchGroup.addChild(createPoints(2, 20, false)); switchGroup.addChild(createPoints(2, 20, true)); // create a SwitchValueInterpolator to // cycle through the child nodes in the Switch Node Alpha switchAlpha = new Alpha(-1, Alpha.INCREASING_ENABLE, 0, 0, 15000, 0, 0, 0, 0, 0); SwitchValueInterpolator switchInterpolator = new SwitchValueInterpolator(switchAlpha, switchGroup); switchInterpolator.setSchedulingBounds(getApplicationBounds()); switchInterpolator.setEnable(true); // WARNING: do not add the SwitchValueInterpolator to the Switch Node! objRoot.addChild(switchInterpolator); objTrans.addChild(switchGroup); objRoot.addChild(objTrans); return objRoot; }
From source file:SpotLightApp.java
public SpotLightApp() { BoundingSphere bound1 = new BoundingSphere(new Point3d(0.0, 0.9, 0.0), 0.5); BoundingSphere bound2 = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 0.5); BoundingSphere bound3 = new BoundingSphere(new Point3d(0.0, -0.9, 0.0), 0.5); Vector3f direction = new Vector3f(0.0f, 0.0f, -1.0f); Color3f white = new Color3f(1.0f, 1.0f, 1.0f); Color3f red = new Color3f(1.0f, 0.0f, 0.0f); Color3f green = new Color3f(0.0f, 1.0f, 0.0f); Color3f blue = new Color3f(0.0f, 0.0f, 1.0f); BranchGroup scene = new BranchGroup(); final int X = 101, Y = 102; final float dx = 0.01f, dy = -0.01f; final float epx = dx / 2.0f, epy = dy / 2.0f; final float top = 0.5f, left = -0.5f; final float right = left + dx * (X - 1); final float bottom = top + dy * (Y - 1); IndexedQuadArray qa = new IndexedQuadArray(X * Y, QuadArray.COORDINATES | QuadArray.NORMALS, (X - 1) * (Y - 1) * 4);//w w w . j av a 2 s .c o m float x, y; int i = 0; System.out.print("set " + X * Y + " coordiantes..... "); for (y = top; y >= bottom - epx; y += dy) for (x = left; x <= right + epx; x += dx) qa.setCoordinate(i++, new Point3f(x, y, 0.0f)); System.out.println(i + " coordiantes done"); int row, col; i = 0; Vector3f n = new Vector3f(0.0f, 0.0f, 1.0f); System.out.print("set " + (X - 1) * (Y - 1) * 4 + " coordinate indices..... "); for (row = 0; row < (Y - 1); row++) { for (col = 0; col < (X - 1); col++) { qa.setNormal(row * X + col, n); qa.setCoordinateIndex(i++, row * X + col); qa.setCoordinateIndex(i++, (row + 1) * X + col); qa.setCoordinateIndex(i++, (row + 1) * X + col + 1); qa.setCoordinateIndex(i++, row * X + col + 1); } qa.setNormal(row * X + col + 1, n); } System.out.println(i + " coordinate indices done"); for (col = 0; col < (X - 1); col++) { qa.setNormal(X * (Y - 1) + 1 + col, n); } System.out.println("coordinate normals done"); Appearance qAppear = createMatAppear(blue, white, 5.0f); Shape3D plane = new Shape3D(qa, qAppear); Transform3D translate = new Transform3D(); translate.set(new Vector3f(-0.5f, 0.5f, 0.0f)); TransformGroup tg1 = new TransformGroup(translate); scene.addChild(tg1); Shape3D plane1 = new Shape3D(qa, qAppear); plane1.setBounds(bound1); tg1.addChild(plane1); translate.set(new Vector3f(0.5f, 0.5f, 0.0f)); TransformGroup tg2 = new TransformGroup(translate); scene.addChild(tg2); Shape3D plane2 = new Shape3D(qa, qAppear); plane2.setBounds(bound1); tg2.addChild(plane2); translate.set(new Vector3f(-0.5f, -0.5f, 0.0f)); TransformGroup tg3 = new TransformGroup(translate); scene.addChild(tg3); Shape3D plane3 = new Shape3D(qa, qAppear); plane3.setBounds(bound3); tg3.addChild(plane3); translate.set(new Vector3f(0.5f, -0.5f, 0.0f)); TransformGroup tg4 = new TransformGroup(translate); scene.addChild(tg4); Shape3D plane4 = new Shape3D(qa, qAppear); plane4.setBounds(bound3); tg4.addChild(plane4); AmbientLight lightA = new AmbientLight(); lightA.setInfluencingBounds(new BoundingSphere()); scene.addChild(lightA); scene.addChild(newSpotLight(bound1, new Point3f(-0.7f, 0.7f, 0.5f), 0.1f, 5.0f)); scene.addChild(newSpotLight(bound1, new Point3f(0.0f, 0.7f, 0.5f), 0.1f, 50.0f)); scene.addChild(newSpotLight(bound1, new Point3f(0.7f, 0.7f, 0.5f), 0.1f, 100.0f)); scene.addChild(newSpotLight(bound2, new Point3f(-0.7f, 0.0f, 0.5f), 0.3f, 5.0f)); scene.addChild(newSpotLight(bound2, new Point3f(0.0f, 0.0f, 0.5f), 0.3f, 50.0f)); scene.addChild(newSpotLight(bound2, new Point3f(0.7f, 0.0f, 0.5f), 0.3f, 100.0f)); scene.addChild(newSpotLight(bound3, new Point3f(-0.7f, -0.7f, 0.5f), 0.5f, 5.0f)); scene.addChild(newSpotLight(bound3, new Point3f(0.0f, -0.7f, 0.5f), 0.5f, 50.0f)); scene.addChild(newSpotLight(bound3, new Point3f(0.7f, -0.7f, 0.5f), 0.5f, 100.0f)); Background background = new Background(); background.setApplicationBounds(new BoundingSphere()); background.setColor(1.0f, 1.0f, 1.0f); scene.addChild(background); scene.compile(); setLayout(new BorderLayout()); Canvas3D c = new Canvas3D(null); add("Center", c); SimpleUniverse u = new SimpleUniverse(c); // This will move the ViewPlatform back a bit so the // objects in the scene can be viewed. u.getViewingPlatform().setNominalViewingTransform(); u.addBranchGraph(scene); }
From source file:ConfigObjLoad.java
public void init() { if (filename == null) { try {/*from w w w . ja v a 2s . co m*/ filename = new URL("file:galleon.obj"); } catch (MalformedURLException e) { System.err.println(e); System.exit(1); } } // Get the config file URL from the j3d.configURL property or use the // default config file "j3d1x1-window" in the current directory. URL configURL = ConfiguredUniverse.getConfigURL("file:j3d1x1-window"); // Create a simple scene and attach it to the virtual universe BranchGroup scene = createSceneGraph(); u = new ConfiguredUniverse(configURL); // Get the ViewingPlatform. ViewingPlatform viewingPlatform = u.getViewingPlatform(); // This will move the ViewPlatform back a bit so the objects in the // scene can be viewed. This will only have an effect if the config // file sets the window eyepoint policy to something other than // RELATIVE_TO_COEXISTENCE, which is the default eyepoint policy // applied by ConfiguredUniverse. // // The default view attach policy for ConfiguredUniverse applications // is NOMINAL_SCREEN. This sets the view platform origin in the // physical world to the center of coexistence, which allows eye // positions expressed relative to coexistence to see the appropriate // field of view automatically. viewingPlatform.setNominalViewingTransform(); // Add a ViewPlatformBehavior if not specified in the config file. if (!spin && viewingPlatform.getViewPlatformBehavior() == null) { OrbitBehavior orbit = new OrbitBehavior(u.getCanvas(), OrbitBehavior.REVERSE_ALL); BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0); orbit.setSchedulingBounds(bounds); viewingPlatform.setViewPlatformBehavior(orbit); } // See if there's a 6 degree of freedom mouse in the environment. // We look for one named "mouse6d". Map sensorMap = null; sensorMap = u.getNamedSensors(); if (sensorMap != null) { Sensor mouse6d = (Sensor) sensorMap.get("mouse6d"); if (mouse6d != null) { Mouse6DPointerBehavior behavior = new Mouse6DPointerBehavior(mouse6d, 1.0, true); BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0); behavior.setSchedulingBounds(bounds); scene.addChild(behavior); scene.addChild(behavior.getEcho()); } } // Listen for a typed "q", "Q", or "Escape" key on each canvas to // allow a convenient exit from full screen configurations. Canvas3D[] canvases; canvases = u.getViewer().getCanvas3Ds(); class QuitListener extends KeyAdapter { public void keyTyped(KeyEvent e) { char c = e.getKeyChar(); if (c == 'q' || c == 'Q' || c == 27) System.exit(0); } } QuitListener quitListener = new QuitListener(); for (int i = 0; i < canvases.length; i++) canvases[i].addKeyListener(quitListener); // Make the scenegraph live. u.addBranchGraph(scene); }
From source file:SimpleTest.java
public TransformGroup createBehaviors(BranchGroup bg) { // create a TransformGroup. //// www . j a va2 s . c om // A TransformGroup is a Group node (can have children) // and contains a Transform3D member. // // The Transform3D member contains a 4x4 transformation matrix // that is applied during rendering to all the TransformGroup's // child nodes. The 4x4 matrix can describe: // scaling, translation and rotation in one neat package! // enable the TRANSFORM_WRITE capability so that // our behavior code can modify it at runtime TransformGroup objTrans = new TransformGroup(); objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); // create a new Transform3D that will describe // the direction we want to move. Transform3D xAxis = new Transform3D(); // create an Alpha object. // The Alpha object describes a function against time. // The Alpha will output a value that ranges between 0 and 1 // using the time parameters (in milliseconds). Alpha xAlpha = new Alpha(-1, Alpha.DECREASING_ENABLE | Alpha.INCREASING_ENABLE, 1000, 1000, 5000, 1000, 1000, 10000, 2000, 4000); // create a PositionInterpolator // The PositionInterpolator will modify the translation components // of a TransformGroup's Transform3D (objTrans) based on the output // from the Alpha. In this case the movement will range from // -0.8 along the X-axis with Alpha=0 to X=0.8 when Alpha=1. PositionInterpolator posInt = new PositionInterpolator(xAlpha, objTrans, xAxis, -0.8f, 0.8f); // set the range of influence of the PositionInterpolator posInt.setSchedulingBounds(getBoundingSphere()); // wire the PositionInterpolator into its parent // TransformGroup. Just like rendering nodes behaviors // must be added to the scenegraph. objTrans.addChild(posInt); // add the TransformGroup to its parent BranchGroup bg.addChild(objTrans); // we return the TransformGroup with the // behavior attached so that we can add nodes to it // (which will be effected by the PositionInterpolator). return objTrans; }
From source file:BehaviorTest.java
protected BranchGroup createSceneBranchGroup() { BranchGroup objRoot = super.createSceneBranchGroup(); // create a TransformGroup to rotate the hand TransformGroup objTrans = new TransformGroup(); objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); // create a RotationInterpolator behavior to rotate the hand Transform3D yAxis = new Transform3D(); Alpha rotationAlpha = new Alpha(-1, Alpha.INCREASING_ENABLE, 0, 0, 4000, 0, 0, 0, 0, 0); m_RotationInterpolator = new RotationInterpolator(rotationAlpha, objTrans, yAxis, 0.0f, (float) Math.PI * 2.0f); m_RotationInterpolator.setSchedulingBounds(createApplicationBounds()); objTrans.addChild(m_RotationInterpolator); // create an Appearance and Material Appearance app = new Appearance(); TextureLoader tex = new TextureLoader("earth.jpg", this); app.setTexture(tex.getTexture());/*from w w w .j a v a2 s. com*/ Sphere sphere = new Sphere(3, Primitive.GENERATE_NORMALS | Primitive.GENERATE_TEXTURE_COORDS, 32, app); // connect the scenegraph objTrans.addChild(sphere); objRoot.addChild(objTrans); m_FpsBehavior = new FpsBehavior(); m_FpsBehavior.setSchedulingBounds(getApplicationBounds()); objRoot.addChild(m_FpsBehavior); m_BoundsBehavior = new BoundsBehavior(sphere); m_BoundsBehavior.setSchedulingBounds(getApplicationBounds()); m_BoundsBehavior.addBehaviorToParentGroup(objTrans); m_StretchBehavior = new StretchBehavior((GeometryArray) sphere.getShape().getGeometry()); m_StretchBehavior.setSchedulingBounds(getApplicationBounds()); objRoot.addChild(m_StretchBehavior); m_StretchBehavior.setEnable(false); m_SizeBehavior = new ObjectSizeBehavior((GeometryArray) sphere.getShape().getGeometry()); m_SizeBehavior.setSchedulingBounds(getApplicationBounds()); objRoot.addChild(m_SizeBehavior); m_SizeBehavior.setEnable(false); m_ExplodeBehavior = new ExplodeBehavior(sphere.getShape(), 10000, 20, this); m_ExplodeBehavior.setSchedulingBounds(getApplicationBounds()); objRoot.addChild(m_ExplodeBehavior); return objRoot; }
From source file:CuboidTest.java
protected BranchGroup createSceneBranchGroup() { BranchGroup objRoot = super.createSceneBranchGroup(); TransformGroup objTrans = new TransformGroup(); objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0); Transform3D yAxis = new Transform3D(); Alpha rotationAlpha = new Alpha(-1, Alpha.INCREASING_ENABLE, 0, 0, 4000, 0, 0, 0, 0, 0); RotationInterpolator rotator = new RotationInterpolator(rotationAlpha, objTrans, yAxis, 0.0f, (float) Math.PI * 2.0f); rotator.setSchedulingBounds(bounds); objTrans.addChild(rotator);/*from ww w .j av a 2 s. c o m*/ // create an appearance Appearance ap = new Appearance(); // render as a wireframe PolygonAttributes polyAttrbutes = new PolygonAttributes(); polyAttrbutes.setPolygonMode(PolygonAttributes.POLYGON_LINE); polyAttrbutes.setCullFace(PolygonAttributes.CULL_NONE); ap.setPolygonAttributes(polyAttrbutes); objTrans.addChild(new Cuboid(50, 30, 20, ap)); objTrans.addChild(new Box(25, 15, 10, ap)); objRoot.addChild(objTrans); return objRoot; }