List of usage examples for javax.media.j3d PositionInterpolator setSchedulingBounds
public void setSchedulingBounds(Bounds region)
From source file:SimpleTest.java
public TransformGroup createBehaviors(BranchGroup bg) { // create a TransformGroup. ///*from w w w. j ava 2s. co 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; }
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 . ja v a 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:SimpleGame.java
/** * Creates the duck. This loads the two duck geometries from the files * 'duck.obj' and 'deadduck.obj' and loads these into a switch. The access * rights to the switch are then set so we can write to this switch to swap * between the two duck models. It also creates a transform group and an * interpolator to move the duck./*from w ww . j a v a 2s .c o m*/ * * @return BranchGroup with content attached. */ protected BranchGroup buildDuck() { BranchGroup theDuck = new BranchGroup(); duckSwitch = new Switch(0); duckSwitch.setCapability(Switch.ALLOW_SWITCH_WRITE); ObjectFile f1 = new ObjectFile(); ObjectFile f2 = new ObjectFile(); Scene s1 = null; Scene s2 = null; try { s1 = f1.load("duck.obj"); s2 = f2.load("deadduck.obj"); } catch (Exception e) { System.exit(1); } TransformGroup duckRotXfmGrp = new TransformGroup(); Transform3D duckRotXfm = new Transform3D(); Matrix3d duckRotMat = new Matrix3d(); duckRotMat.rotY(Math.PI / 2); duckRotXfm.set(duckRotMat, new Vector3d(0.0, 0.0, -30.0), 1.0); duckRotXfmGrp.setTransform(duckRotXfm); duckRotXfmGrp.addChild(duckSwitch); duckSwitch.addChild(s1.getSceneGroup()); duckSwitch.addChild(s2.getSceneGroup()); TransformGroup duckMovXfmGrp = new TransformGroup(); duckMovXfmGrp.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); duckMovXfmGrp.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); duckMovXfmGrp.addChild(duckRotXfmGrp); duckAlpha = new Alpha(-1, 0, 0, 3000, 0, 0); Transform3D axis = new Transform3D(); PositionInterpolator moveDuck = new PositionInterpolator(duckAlpha, duckMovXfmGrp, axis, -30.0f, 30.0f); moveDuck.setSchedulingBounds(bounds); theDuck.addChild(moveDuck); theDuck.addChild(duckMovXfmGrp); return theDuck; }
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);//from w w w. j a v a 2s . c o m bgRoot.addChild(objTrans); return objTrans; }
From source file:CustomAlphaTest.java
protected BranchGroup createSceneBranchGroup() { BranchGroup objRoot = super.createSceneBranchGroup(); TransformGroup objTrans = new TransformGroup(); objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE); objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_READ); ColorCube cube = new ColorCube(2); objTrans.addChild(cube);//from www . j ava 2 s.c om FileAlpha fileAlpha = null; try { fileAlpha = new FileAlpha(new URL(getWorkingDirectory(), "values.xls"), this); } catch (Exception e) { e.toString(); } PositionInterpolator posInterpolator = new PositionInterpolator(fileAlpha, objTrans, new Transform3D(), -6, 6); posInterpolator.setSchedulingBounds(getApplicationBounds()); objTrans.addChild(posInterpolator); objRoot.addChild(objTrans); return objRoot; }