Java Reference
In-Depth Information
Input devIce
Since the mouse and keyboard are basically 2D devices with a third dimension in terms of
button clicking and key pressing, it is sometimes more convenient to carry out 3D navigation
and object manipulation using more sophisticated devices such as a joystick, head tracker,
motion capture suit, and space ball.
For this purpose, Java 3D provides an InputDevice interface for adding a device into
an application. The runtime environment will support the device in the same manner as
for a mouse. In Java 3D, any source that provides information with six degrees of freedom
can be taken as an input device (Sowizral & Deering, 1999). The input devices may also
have an unlimited number of buttons. As an example, a 6-button joystick will be a valid
input device.
When the mouse and keyboard are used to capture user interactions, standard AWT
event mechanisms are available and we have discussed how these events can be captured and
processed for object manipulation and navigation in the 3D world. However, the capturing
of events and getting information from other devices for processing in Java 3D require both
the InputDevice interface and a Sensor class. The former encompasses the entire object
interface, while the latter corresponds to one element of input from the device.
Figure 12. Specifying joystick device driver
40.
public class Joystick
41.
{
42.
public static final int BUTTON1 = 0x0001, BUTTON2 = 0x0002, BUTTON3 = 0x0004,
43.
BUTTON4 = 0x0008;
44.
static { System.loadLibrary("joystick"); }
45.
private int joyID = 0;
46.
public native int getNumDevs(),getButtons(int id);
47.
public native float getXPos(int id), getYPos(int id), getZPos(int id);
48.
49.
public Joystick(int id) { joyID = id; }
50.
51.
public float getXPos() { return getXPos(joyID); }
52.
53.
public float getYPos() { return getYPos(joyID); }
54.
55.
public float getZPos() { return getZPos(joyID); }
56.
57.
public int getButtons() { return getButtons(joyID); }
58.
59.
public String toString() { return "Joystick"; }
60. }
Search WWH ::




Custom Search