Figure 16. Second code segment and result for SensorBehavior.java
public BranchGroup createSceneGraph(SimpleUniverse universe, Canvas3D c)
TransformGroup viewTrans = new TransformGroup();
viewTrans = universe.getViewingPlatform().getViewPlatformTransform();
setPosition(body, new Point3f(0.0f, -0.2f, -1.5f));
joyDevice = new JoystickInputDevice(viewTrans, body.getShape(), holdBody, initviewpoint);
Sensor joystick = joyDevice.getSensor(0);
SensorBehavior s = new SensorBehavior(joystick);
s.setSchedulingBounds(new BoundingSphere(new Point3d(0.0,0.0,0.0), Float.MAX_VALUE));
the sensor class assigned to the created joyDevice in line 14, the joystick will become fully
functional and will allow the user to navigate in the 3D world as shown.
In addition to a change of view, another important issue in 3D navigation is collision of the
viewer with other visual objects (Bishop, Hembruch, & Trudeau, 1999). Obviously, this has
to be properly taken care of if the 3D world built is to be as realistic as possible.
As discussed in earlier chapters, object collisions can be detected through setting up
the proper wakeup criteria. Specifically, WakeupOnCollisionEntry, WakeupOnCollision-
Movement and WakeupOnCollisionExit can be used. The first criterion will generate a
trigger when an object first collides with another, the second one will be triggered while
the two objects are still in collision and there is relative movement, and the third will give
a stimulus when collisions no longer exist.
Search WWH ::