List of usage examples for javax.media.j3d Alpha INCREASING_ENABLE
int INCREASING_ENABLE
To view the source code for javax.media.j3d Alpha INCREASING_ENABLE.
Click Source Link
From source file:GearTest.java
public BranchGroup createSceneGraph(int toothCount) { // 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(0.4);/*w w w .jav a 2 s . c o m*/ objScale.setTransform(t3d); objRoot.addChild(objScale); // Create a bounds for the background and lights BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0); // Set up the background Color3f bgColor = new Color3f(0.05f, 0.05f, 0.2f); Background bgNode = new Background(bgColor); bgNode.setApplicationBounds(bounds); objScale.addChild(bgNode); // Set up the global lights Color3f light1Color = new Color3f(1.0f, 1.0f, 0.9f); Vector3f light1Direction = new Vector3f(4.0f, -7.0f, -12.0f); Color3f light2Color = new Color3f(0.3f, 0.3f, 0.4f); Vector3f light2Direction = new Vector3f(-6.0f, -2.0f, -1.0f); Color3f ambientColor = new Color3f(0.1f, 0.1f, 0.1f); AmbientLight ambientLightNode = new AmbientLight(ambientColor); ambientLightNode.setInfluencingBounds(bounds); objScale.addChild(ambientLightNode); DirectionalLight light1 = new DirectionalLight(light1Color, light1Direction); light1.setInfluencingBounds(bounds); objScale.addChild(light1); DirectionalLight light2 = new DirectionalLight(light2Color, light2Direction); light2.setInfluencingBounds(bounds); objScale.addChild(light2); // Create the transform group node and initialize it to the // identity. Enable the TRANSFORM_WRITE capability so that // our behavior code can modify it at runtime. Add it to the // root of the subgraph. TransformGroup objTrans = new TransformGroup(); objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); objScale.addChild(objTrans); // Create an Appearance. Appearance look = new Appearance(); Color3f objColor = new Color3f(0.5f, 0.5f, 0.6f); Color3f black = new Color3f(0.0f, 0.0f, 0.0f); Color3f white = new Color3f(1.0f, 1.0f, 1.0f); look.setMaterial(new Material(objColor, black, objColor, white, 100.0f)); // Create a gear, add it to the scene graph. // SpurGear gear = new SpurGear(toothCount, 1.0f, 0.2f, SpurGear gear = new SpurGearThinBody(toothCount, 1.0f, 0.2f, 0.05f, 0.05f, 0.3f, 0.28f, look); objTrans.addChild(gear); // Create a new Behavior object that will rotate the object and // add it into the scene graph. Transform3D yAxis = new Transform3D(); Alpha rotationAlpha = new Alpha(-1, Alpha.INCREASING_ENABLE, 0, 0, 8000, 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); // Have Java 3D perform optimizations on this scene graph. objRoot.compile(); return objRoot; }
From source file:ScenegraphTest.java
private TransformGroup addLimb(Group parentGroup, String szName, double radius, double length, double rotMin, double rotMax) { // create the rotator TransformGroup tgJoint = new TransformGroup(); tgJoint.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); tgJoint.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); // add a rotator if necessary if (rotMin != rotMax) { Transform3D xAxis = new Transform3D(); xAxis.rotX(Math.PI / 2.0); Alpha rotationAlpha = new Alpha(-1, Alpha.INCREASING_ENABLE, 0, 0, 4000, 0, 0, 0, 0, 0); RotationInterpolator rotator = new RotationInterpolator(rotationAlpha, tgJoint, xAxis, (float) rotMin, (float) rotMax); rotator.setSchedulingBounds(createApplicationBounds()); tgJoint.addChild(rotator);//from w ww .j av a 2 s .c o m } // create a cylinder using length and radius tgJoint.addChild(createLimb(radius, length)); // create the joint (the *next* TG should // be offset by the length of this limb) TransformGroup tgOffset = new TransformGroup(); Transform3D t3d = new Transform3D(); t3d.setTranslation(new Vector3d(0, length, 0)); tgOffset.setTransform(t3d); tgJoint.addChild(tgOffset); parentGroup.addChild(tgJoint); // return the offset TG, so any child TG's will be added // in the correct position. return tgOffset; }
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());/* w ww.j av a2 s . c o m*/ 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:PolygonOffset.java
public BranchGroup createSceneGraph() { // Create the root of the branch graph BranchGroup objRoot = new BranchGroup(); // Create the transform group node and initialize it to the // identity. Enable the TRANSFORM_WRITE capability so that // our behavior code can modify it at runtime. Add it to the // root of the subgraph. TransformGroup objTrans = new TransformGroup(); objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); objRoot.addChild(objTrans);//ww w .j a v a 2 s . co m // Create a Sphere. We will display this as both wireframe and // solid to make a hidden line display // wireframe Appearance wireApp = new Appearance(); ColoringAttributes wireCa = new ColoringAttributes(); wireCa.setColor(black); wireApp.setColoringAttributes(wireCa); wirePa = new PolygonAttributes(PolygonAttributes.POLYGON_LINE, PolygonAttributes.CULL_BACK, 0.0f); wireApp.setPolygonAttributes(wirePa); Sphere outWireSphere = new Sphere(sphereRadius, 0, 15, wireApp); objTrans.addChild(outWireSphere); // solid ColoringAttributes outCa = new ColoringAttributes(red, ColoringAttributes.SHADE_FLAT); Appearance outSolid = new Appearance(); outSolid.setColoringAttributes(outCa); solidPa = new PolygonAttributes(PolygonAttributes.POLYGON_FILL, PolygonAttributes.CULL_BACK, 0.0f); solidPa.setPolygonOffsetFactor(dynamicOffset); solidPa.setPolygonOffset(staticOffset); solidPa.setCapability(PolygonAttributes.ALLOW_OFFSET_WRITE); outSolid.setPolygonAttributes(solidPa); Sphere outSolidSphere = new Sphere(sphereRadius, 0, 15, outSolid); objTrans.addChild(outSolidSphere); innerTG = new TransformGroup(); innerTG.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); scale = new Transform3D(); updateInnerScale(); objTrans.addChild(innerTG); // Create a smaller sphere to go inside. This sphere has a different // tesselation and color Sphere inWireSphere = new Sphere(sphereRadius, 0, 10, wireApp); innerTG.addChild(inWireSphere); // inside solid ColoringAttributes inCa = new ColoringAttributes(blue, ColoringAttributes.SHADE_FLAT); Appearance inSolid = new Appearance(); inSolid.setColoringAttributes(inCa); inSolid.setPolygonAttributes(solidPa); Sphere inSolidSphere = new Sphere(sphereRadius, 0, 10, inSolid); innerTG.addChild(inSolidSphere); // Create a new Behavior object that will perform the desired // operation on the specified transform object and add it into // the scene graph. AxisAngle4f axisAngle = new AxisAngle4f(0.0f, 0.0f, 1.0f, -(float) Math.PI / 2.0f); Transform3D yAxis = new Transform3D(); Alpha rotationAlpha = new Alpha(-1, Alpha.INCREASING_ENABLE, 0, 0, 80000, 0, 0, 0, 0, 0); RotationInterpolator rotator = new RotationInterpolator(rotationAlpha, objTrans, yAxis, 0.0f, (float) Math.PI * 2.0f); BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0); rotator.setSchedulingBounds(bounds); objTrans.addChild(rotator); // set up a white background Background bgWhite = new Background(new Color3f(1.0f, 1.0f, 1.0f)); bgWhite.setApplicationBounds(bounds); objTrans.addChild(bgWhite); // Have Java 3D perform optimizations on this scene graph. objRoot.compile(); return objRoot; }
From source file:AvatarTest.java
public TransformGroup addBehaviors(Group bgRoot) { // Create the transform group node and initialize it to the // identity. Enable the TRANSFORM_WRITE capability so that // our behavior code can modify it at runtime. Add it to the // root of the subgraph. TransformGroup objTrans = new TransformGroup(); objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); Transform3D zAxis = new Transform3D(); zAxis.rotY(Math.toRadians(90.0)); Alpha zoomAlpha = new Alpha(-1, Alpha.INCREASING_ENABLE, 0, 0, 20000, 0, 0, 0, 0, 0); PositionInterpolator posInt = new PositionInterpolator(zoomAlpha, objTrans, zAxis, 0, -160); posInt.setSchedulingBounds(getBoundingSphere()); objTrans.addChild(posInt);//ww w . j a v a 2 s . c o m bgRoot.addChild(objTrans); return objTrans; }
From source file:SphereMotion.java
public BranchGroup createSceneGraph(SimpleUniverse u) { Color3f eColor = new Color3f(0.0f, 0.0f, 0.0f); Color3f sColor = new Color3f(1.0f, 1.0f, 1.0f); Color3f objColor = new Color3f(0.6f, 0.6f, 0.6f); Color3f lColor1 = new Color3f(1.0f, 0.0f, 0.0f); Color3f lColor2 = new Color3f(0.0f, 1.0f, 0.0f); Color3f alColor = new Color3f(0.2f, 0.2f, 0.2f); Color3f bgColor = new Color3f(0.05f, 0.05f, 0.2f); Transform3D t;//from w w w. j a va 2 s . c o m // 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(0.4); objScale.setTransform(t3d); objRoot.addChild(objScale); // Create a bounds for the background and lights BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0); // Set up the background Background bg = new Background(bgColor); bg.setApplicationBounds(bounds); objScale.addChild(bg); // Create a Sphere object, generate one copy of the sphere, // and add it into the scene graph. Material m = new Material(objColor, eColor, objColor, sColor, 100.0f); Appearance a = new Appearance(); m.setLightingEnable(true); a.setMaterial(m); Sphere sph = new Sphere(1.0f, Sphere.GENERATE_NORMALS, 80, a); objScale.addChild(sph); // Create the transform group node for the each light and initialize // it to the identity. Enable the TRANSFORM_WRITE capability so that // our behavior code can modify it at runtime. Add them to the root // of the subgraph. TransformGroup l1RotTrans = new TransformGroup(); l1RotTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); objScale.addChild(l1RotTrans); TransformGroup l2RotTrans = new TransformGroup(); l2RotTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); objScale.addChild(l2RotTrans); // Create transformations for the positional lights t = new Transform3D(); Vector3d lPos1 = new Vector3d(0.0, 0.0, 2.0); t.set(lPos1); TransformGroup l1Trans = new TransformGroup(t); l1RotTrans.addChild(l1Trans); t = new Transform3D(); Vector3d lPos2 = new Vector3d(0.5, 0.8, 2.0); t.set(lPos2); TransformGroup l2Trans = new TransformGroup(t); l2RotTrans.addChild(l2Trans); // Create Geometry for point lights ColoringAttributes caL1 = new ColoringAttributes(); ColoringAttributes caL2 = new ColoringAttributes(); caL1.setColor(lColor1); caL2.setColor(lColor2); Appearance appL1 = new Appearance(); Appearance appL2 = new Appearance(); appL1.setColoringAttributes(caL1); appL2.setColoringAttributes(caL2); l1Trans.addChild(new Sphere(0.05f, appL1)); l2Trans.addChild(new Sphere(0.05f, appL2)); // Create lights AmbientLight aLgt = new AmbientLight(alColor); Light lgt1 = null; Light lgt2 = null; Point3f lPoint = new Point3f(0.0f, 0.0f, 0.0f); Point3f atten = new Point3f(1.0f, 0.0f, 0.0f); Vector3f lDirect1 = new Vector3f(lPos1); Vector3f lDirect2 = new Vector3f(lPos2); lDirect1.negate(); lDirect2.negate(); switch (lightType) { case DIRECTIONAL_LIGHT: lgt1 = new DirectionalLight(lColor1, lDirect1); lgt2 = new DirectionalLight(lColor2, lDirect2); break; case POINT_LIGHT: lgt1 = new PointLight(lColor1, lPoint, atten); lgt2 = new PointLight(lColor2, lPoint, atten); break; case SPOT_LIGHT: lgt1 = new SpotLight(lColor1, lPoint, atten, lDirect1, 25.0f * (float) Math.PI / 180.0f, 10.0f); lgt2 = new SpotLight(lColor2, lPoint, atten, lDirect2, 25.0f * (float) Math.PI / 180.0f, 10.0f); break; } // Set the influencing bounds aLgt.setInfluencingBounds(bounds); lgt1.setInfluencingBounds(bounds); lgt2.setInfluencingBounds(bounds); // Add the lights into the scene graph objScale.addChild(aLgt); l1Trans.addChild(lgt1); l2Trans.addChild(lgt2); // Create a new Behavior object that will perform the desired // operation on the specified transform object and add it into the // scene graph. Transform3D yAxis = new Transform3D(); Alpha rotor1Alpha = new Alpha(-1, Alpha.INCREASING_ENABLE, 0, 0, 4000, 0, 0, 0, 0, 0); RotationInterpolator rotator1 = new RotationInterpolator(rotor1Alpha, l1RotTrans, yAxis, 0.0f, (float) Math.PI * 2.0f); rotator1.setSchedulingBounds(bounds); l1RotTrans.addChild(rotator1); // Create a new Behavior object that will perform the desired // operation on the specified transform object and add it into the // scene graph. Alpha rotor2Alpha = new Alpha(-1, Alpha.INCREASING_ENABLE, 0, 0, 1000, 0, 0, 0, 0, 0); RotationInterpolator rotator2 = new RotationInterpolator(rotor2Alpha, l2RotTrans, yAxis, 0.0f, 0.0f); bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0); rotator2.setSchedulingBounds(bounds); l2RotTrans.addChild(rotator2); // Create a position interpolator and attach it to the view // platform TransformGroup vpTrans = u.getViewingPlatform().getViewPlatformTransform(); Transform3D axisOfTranslation = new Transform3D(); Alpha transAlpha = new Alpha(-1, Alpha.INCREASING_ENABLE | Alpha.DECREASING_ENABLE, 0, 0, 5000, 0, 0, 5000, 0, 0); axisOfTranslation.rotY(-Math.PI / 2.0); PositionInterpolator translator = new PositionInterpolator(transAlpha, vpTrans, axisOfTranslation, 2.0f, 3.5f); translator.setSchedulingBounds(bounds); objScale.addChild(translator); // Let Java 3D perform optimizations on this scene graph. objRoot.compile(); 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);//w w w . j a v a 2 s . com 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: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);//from w ww . j a v a 2 s. com 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:ConicWorld.java
private Group createObject(int i, int j, Appearance app, double scale, double xpos, double ypos) { // Create a transform group node to scale and position the object. Transform3D t = new Transform3D(); t.set(scale, new Vector3d(xpos, ypos, 0.0)); TransformGroup objTrans = new TransformGroup(t); // Create a second transform group node and initialize it to the // identity. Enable the TRANSFORM_WRITE capability so that // our behavior code can modify it at runtime. TransformGroup spinTg = new TransformGroup(); spinTg.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); spinTg.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); Primitive obj = null;//from www . j a v a 2 s.c om if (i % 3 == 2) { obj = (Primitive) new Sphere(1.0f, Sphere.GENERATE_NORMALS | Sphere.GENERATE_TEXTURE_COORDS, j * 8 + 4, app); } else if (i % 3 == 1) { obj = (Primitive) new Cylinder(1.0f, 2.0f, Cylinder.GENERATE_TEXTURE_COORDS | Cylinder.GENERATE_NORMALS, j * 8 + 4, j * 8 + 4, app); } else if (i % 3 == 0) { obj = (Primitive) new Cone(1.0f, 2.0f, Cone.GENERATE_NORMALS | Cone.GENERATE_TEXTURE_COORDS, j * 8 + 4, j * 8 + 4, app); } // add it to the scene graph. spinTg.addChild(obj); // Create a new Behavior object that will perform the desired // operation on the specified transform object and add it into // the scene graph. Transform3D yAxis = new Transform3D(); Alpha rotationAlpha = new Alpha(-1, Alpha.INCREASING_ENABLE, 0, 0, 5000, 0, 0, 0, 0, 0); RotationInterpolator rotator = new RotationInterpolator(rotationAlpha, spinTg, yAxis, 0.0f, (float) Math.PI * 2.0f); BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0); rotator.setSchedulingBounds(bounds); // Add the behavior and the transform group to the object objTrans.addChild(rotator); objTrans.addChild(spinTg); return objTrans; }
From source file:SimpleTest.java
public TransformGroup createBehaviors(BranchGroup bg) { // create a TransformGroup. ////from www .ja v a 2s.c o m // 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; }