Recommended: Sing it, brah! 5 fabulous songs for developers
JW's Top 5
Optimize with a SATA RAID Storage Solution
Range of capacities as low as $1250 per TB. Ideal if you currently rely on servers/disks/JBODs
Page 2 of 6
Behaviors can be keyed to any number of Java events or user interactions. When a user hovers near a certain object, for instance, you can cause the object to move, change color, or otherwise exhibit behavior. (In this case, the stimuli would be the user's presence inside of a specified bounds, or region, of space.)
Many behaviors can be controlled using interpolators, objects that accept a range of values to provide a time-varying behavior. You can build your own interpolators if you like, but Java 3D's built-in interpolators and Sun's utilities should suffice for most of your needs. In this month's Example 4, we modify last month's Example 3 to make the word JavaWorld rotate.
001 /**
002 * constructContentBranch() is where we specify the 3D graphics
003 * content to be rendered. We return the content branch group
004 * for use with our SimpleUniverse. We have added a RotationInterpolator
005 * to Example03 so that in this case, our "JavaWorld" text rotates
006 * about the origin. We have also removed the scaling and static
007 * rotation from the text, and the scaling from our ColorCube.
008 **/
009 private BranchGroup constructContentBranch() {
010 Font myFont = new Font("TimesRoman",Font.PLAIN,10);
011 Font3D myFont3D = new Font3D(myFont,new FontExtrusion());
012 Text3D myText3D = new Text3D(myFont3D, "JavaWorld");
013 Shape3D myShape3D = new Shape3D(myText3D, new Appearance());
014 Shape3D myCube = new ColorCube();
015
016 BranchGroup contentBranchGroup = new BranchGroup();
017 Transform3D myTransform3D = new Transform3D();
018 TransformGroup contentTransformGroup = new TransformGroup(myTransform3D);
019 contentTransformGroup.addChild(myShape3D);
020
021 Alpha myAlpha = new Alpha();
022 myAlpha.setIncreasingAlphaDuration(10000);
023 myAlpha.setLoopCount(-1);
024 RotationInterpolator myRotater =
025 new RotationInterpolator(myAlpha,contentTransformGroup);
026 myRotater.setAxisOfRotation(myTransform3D);
027 myRotater.setMinimumAngle(0.0f);
028 myRotater.setMaximumAngle((float)(Math.PI*2.0));
029 BoundingSphere myBounds = new BoundingSphere();
030 myRotater.setSchedulingBounds(myBounds);
031 contentTransformGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
032 contentTransformGroup.addChild(myRotater);
033
034 contentBranchGroup.addChild(contentTransformGroup);
035
036 myTransform3D.setTranslation(new Vector3f(-0.5f,-0.5f,-2.3f));
037 TransformGroup cubeTransformGroup = new TransformGroup(myTransform3D);
038 cubeTransformGroup.addChild(myCube);
039 contentBranchGroup.addChild(cubeTransformGroup);
040
041 return(contentBranchGroup);
042 }

Rotating 'JavaWorld' in the 3D world using RotationInterpolator -- Part 1

Rotating 'JavaWorld' again in the 3D world using RotationInterpolator -- Part 2
By default, behaviors have no scheduling bounds and are never scheduled. You must set scheduling bounds yourself to execute behaviors in Java 3D. It's also important to remember that even with nondefault bounds specified, your behaviors may not be executed if the view platform isn't within the bounded region. This is, of course, by design, but it can make for frustrating debugging experiences if you're not careful.