Java Reference
In-Depth Information
Figure 16. Second code segment and result for SensorBehavior.java
1.
public BranchGroup createSceneGraph(SimpleUniverse universe, Canvas3D c)
2.
{
3.
TransformGroup viewTrans = new TransformGroup();
4.
viewTrans = universe.getViewingPlatform().getViewPlatformTransform();
5.
setPosition(viewTrans, initviewpoint);
6.
setPosition(holdBody, initviewpoint);
7.
holdBody.addChild(body);
8.
setPosition(body, new Point3f(0.0f, -0.2f, -1.5f));
9.
10.
joyDevice = new JoystickInputDevice(viewTrans, body.getShape(), holdBody, initviewpoint);
11.
joyDevice.initialize();
12.
universe.getViewer().getPhysicalEnvironment().addInputDevice(joyDevice);
13.
14.
Sensor joystick = joyDevice.getSensor(0);
15.
SensorBehavior s = new SensorBehavior(joystick);
16.
s.setSchedulingBounds(new BoundingSphere(new Point3d(0.0,0.0,0.0), Float.MAX_VALUE));
17.
root.addChild(s);
18.
Translational movement
Rotational movement
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.
collIsIons
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 ::




Custom Search