Java Reference
In-Depth Information
Figure 17. Third code segment for PickConeRayBehavior.java
1.
public class PickingBehaviour extends Behavior
2.
{
3.
private WakeupCriterion[] allEvents;
4.
private PickTool picktool;
5.
private PickResult result;
6.
private Point3d pt_m = new Point3d();
7.
private Transform3D trans = new Transform3D();
8.
private Point3d start_pt = new Point3d();
9.
private Vector3d dirn = new Vector3d( );
10.
private int x_m;
11.
private int y_m;
12.
private TransformGroup picked_tg = new TransformGroup();
13.
int mouse_button;
14.
private PointLight lighting = new PointLight();
15.
private Color3f light_colour = new Color3f();
16.
private Color3f red = new Color3f( 1.0f, 0.0f, 0.0f );
17.
private Color3f white = new Color3f( 1.0f, 1.0f, 1.0f );
18.
19.
public PickingBehaviour( BranchGroup branch ) // constructor for behavior class
20.
{
21.
picktool = new PickTool( branch );
22.
picktool.setMode( PickTool.BOUNDS );
23.
}
24.
25.
public void initialize() // initialize method
26.
{
27.
allEvents = new WakeupCriterion[1];
28.
allEvents[0] = new WakeupOnAWTEvent( MouseEvent.MOUSE_CLICKED );
29.
wakeupOn ( new WakeupOr( allEvents ) );
30.
}
31.
32.
public void processStimulus(Enumeration criteria)
33.
{
// actions to be taken by this behavior class when triggered }
34. }
Figures 18 and 19 show the important code segment in the processStimulus method
which will be invoked for carrying out the necessary processing when a mouse click event
has occurred. Essentially, the method checks that a mouse click event has indeed happened
before finding the local mouse position on the 2D image plane, transforming this to 3D
world coordinators, and calculating the principal 3D pick shape direction.
A cone ray is then selected as the picking shape to detect the sphere that the user is
trying to pick or select. As mentioned, the use of cone ray is crucial in this application
Search WWH ::




Custom Search