|
Using Behavior Utility Classes for Keyboard Navigation |
|
|
It is easy to use the KeyNavigatorBehavior utility class in a Java 3D program.
Here is the recipe:
- create a KeyNavigatorBehavior object, setting the transform group
- add the KeyNavigatorBehavior object to the scene graph
- provide a bounds (or BoundingLeaf) for the KeyNavigatorBehavior object
In this program you can see that the steps involved in using the KeyNavigatorBehavior
class are essentially identical to those of using any behavior class.
public BranchGroup createSceneGraph(SimpleUniverse su) {
TransformGroup vpTrans = null;
BranchGroup objRoot = new BranchGroup();
Vector3f translate = new Vector3f();
Transform3D T3D = new Transform3D();
TransformGroup TG = null;
objRoot.addChild(createLand());
SharedGroup share = new SharedGroup();
share.addChild(createPyramid());
float[][] position = { { 0.0f, 0.0f, -3.0f }, { 6.0f, 0.0f, 0.0f },
{ 6.0f, 0.0f, 6.0f }, { 3.0f, 0.0f, -10.0f },
{ 13.0f, 0.0f, -30.0f }, { -13.0f, 0.0f, 30.0f },
{ -13.0f, 0.0f, 23.0f }, { 13.0f, 0.0f, 3.0f } };
for (int i = 0; i < position.length; i++) {
translate.set(position[i]);
T3D.setTranslation(translate);
TG = new TransformGroup(T3D);
TG.addChild(new Link(share));
objRoot.addChild(TG);
}
vpTrans = su.getViewingPlatform().getViewPlatformTransform();
translate.set(0.0f, 0.3f, 0.0f);
T3D.setTranslation(translate);
vpTrans.setTransform(T3D);
KeyNavigatorBehavior keyNavBeh = new KeyNavigatorBehavior(vpTrans);
keyNavBeh
.setSchedulingBounds(new BoundingSphere(new Point3d(), 1000.0));
objRoot.addChild(keyNavBeh);
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.