Java Reference
In-Depth Information
the virtual world. While it is possible that a single device may have many sensors, a sensor
can provide information corresponding to six degrees of freedom and some buttons, and
is usually associated with a single device.
A typical joystick with forwards/backwards and left/right movements has two degrees
of freedom and at least two buttons. The inputs these provide are thus well within what
can be provided for by a single sensor.
In java 3D, the creation of an input device will require the construction of all the associ-
ated sensors that will be needed. This is usually done during initialization and is carried
out in line 25 in the example in Figure 13, where reference to the specific input device is
Retrieving data and information from a sensor can be carried out through the use
of SensorRead, which can provide information such as a timestamp, a transform, and
optional button values. Note, however, that the short time gap between two consecutive
SensorRead invocations may give different values depending on how much and how fast
the input device has changed.
Figure 15 shows the skeleton code segment for a customized behavior class for getting
data from the sensor and calling the Sensor.getRead method to update the new position of
the view platform in the virtual world.
After specifying and creating the input device interface and the associated sensor
class, new input device can be added into the environment. As can be seen in the example
in Figure 16, the addInputDevice method is used. This passes an existing instance of the
created InputDevice and registers it with the system at runtime. Then, with an instance of
Figure 15. First Code segment for
public class SensorBehavior extends Behavior
private WakeupOnElapsedFrames conditions = new WakeupOnElapsedFrames(0);
private TransformGroup transformGroup;
private Sensor sensor;
private Transform3D transform = new Transform3D();
public SensorBehavior(Sensor sensor ) { this.sensor = sensor; }
public void initialize() { wakeupOn(conditions); }
public void processStimulus(Enumeration criteria) {
wakeupOn(conditions); }
15. }
Search WWH ::

Custom Search