Adding Prebuilt Behaviors to the Scene Graph

We digress from this chapter's main topic for a moment to introduce some standard Behaviors that we can add to our scene graph. For most projects, it is worthwhile to add these standard Behaviors to the application early in the development. The reason for this is some type of basic 3D user interaction (e.g. navigation, picking) is useful for debugging the scene when it is first created. Often, you might run a program only to discover that what appears to be an empty scene is actually not empty because the ViewPlatform is not properly oriented and positioned or the lighting too soft.

The following Behaviors are part of the Java 3D utilities package: MouseRotate, MouseTranslate, and MouseZoom. They are often attached to the highest level TransformGroup in the content or view subgraphs. Another useful Behavior included in the Java 3D utilities is the OrbitBehavior. Not included in the Java 3D utilities is a basic utility for navigating via the keyboard. Therefore, we develop the NavigatorBehavior class as part of Chapter 12.

Behaviors are typically added to the scene graph or view graph by attaching to the desired TransformGroup as follows:

TransformGroup tg = new TransformGroup();
Bounds bounds = new BoundingSphere(0.f,100.f);
MouseRotate mrotate = new MouseRotate();
mrotate.setTransformGroup(tg);
mrotate.setSchedulingBounds(bounds);
objRoot.addChild(mrotate);

The preceding section of code allows the user to rotate all elements that are added to the TransformGroup tg and is useful for examining a model.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset