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
provided.
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 SensorBehavior.java
1.
public class SensorBehavior extends Behavior
2.
{
3.
private WakeupOnElapsedFrames conditions = new WakeupOnElapsedFrames(0);
4.
private TransformGroup transformGroup;
5.
private Sensor sensor;
6.
private Transform3D transform = new Transform3D();
7.
8.
public SensorBehavior(Sensor sensor ) { this.sensor = sensor; }
9.
10.
public void initialize() { wakeupOn(conditions); }
11.
12.
public void processStimulus(Enumeration criteria) {
13.
sensor.getRead(transform);
14.
wakeupOn(conditions); }
15. }
Search WWH ::




Custom Search