Java Reference
In-Depth Information
Instrument buttons, sliders, and connectors have geometries constructed using
QuadArray, while knobs are built using TriangleStripArray.
In the standard Java 3D API, an object in a 3D virtual scene cannot be identified
directly using mouse events. To create a picking function that can be used for the
various types of control, we assign to each control a unique identity number based
on its position.
For the instrument to behave as realistically as possible, controls on the instrument
panel should not be adjustable unless the mouse is on their front face. Thus, when the
side of a button is pressed, it should not be activated or deactivated. This is different
from the basic picking behavior from Java 3D, where picking from other faces may
also be possible. To obtain the intended behavior, the origin of the local coordinate
system for a 3D button, slider, and knob is taken to be the geometric center of the
front face of the control, while that for a 2D connector is the center of its left edge.
To obtain the identity number of a control, the coordinates of all the controls, which
may have changed depending on how the user has used the instruments, have to be
Figure 27. Second code segment for Oscilloscope.java
1.
public boolean isObject(Point3f object, float x, float y)
2.
{
3.
float d;
4.
d = (object.x-x)*(object.x-x)+(object.y-y)*(object.y-y);
5.
System.out.println(d);
6.
if (d < 0.00001f) return true;
7.
else return false;
8.
}
9.
10. public int whichObject(float x, float y)
11. {
12.
if (isObject(osci_knobposi[0], x, y)) return 1101;
13.
14.
if (isObject(osci_knobposi[9], x, y)) return 1110;
15.
if (isObject(osci_buttonposi[0], x, y)) return 1201;
16.
if (isObject(osci_slideposi[0], x, y)) return 1301;
17.
18.
if (isObject(osci_slideposi[4], x, y)) return 1305;
19.
if (isObject(sg_knobposi[0], x-0.47f, y+0.075f)) return 2101;
20.
if (isObject(sg_buttonposi[0], x-0.47f, y+0.075f)) return 2201;
21.
22.
if (isObject(sg_buttonposi[5], x-0.47f, y+0.075f)) return 2206;
23.
return 0;
24. }
Search WWH ::




Custom Search