|
Using the custom behavior class |
|
|
Finding or writing the appropriate behavior class for your application is the
beginning of writing an interactive Java 3D program. This tip covers the
programming issues in adding behavior objects to programs.
The next list summarizes the steps for using a behavior object in a recipe.
- prepare the scene graph (by adding a TransformGroup or other necessary objects)
- insert behavior object in the scene graph, referencing the object of change
- specify a scheduling bounds (or SchedulingBoundingLeaf)
- set write (and read) capabilities for the target object (as appropriate)
The sample illustrates this recipe,it renders a single ColorCube that rotates
when any key is pressed.
public BranchGroup createSceneGraph() {
BranchGroup objRoot = new BranchGroup();
TransformGroup objRotate = new TransformGroup();
objRotate.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
objRoot.addChild(objRotate);
objRotate.addChild(new ColorCube(0.4));
// Create the SimpleBehavior object
SimpleBehavior myRotationBehavior = new SimpleBehavior(objRotate);
myRotationBehavior.setSchedulingBounds(new BoundingSphere());
// Add it into the scene
objRoot.addChild(myRotationBehavior);
objRoot.compile();
return objRoot;
}
|
Related Tips
|
Page 1 of 0 ( 0 comments )
You can share your information about this topic using the form below!
Please do not post your questions with this form! Thanks.