Java Reference
In-Depth Information
Figure 21. Second code segment for PickCylinderRayBehavior.java
42.
public void processStimulus(Enumeration criteria)
43.
{
44.
WakeupCriterion wakeup; AWTEvent[] event; int eventId;
45.
while ( criteria.hasMoreElements() )
46.
{
47.
wakeup = (WakeupCriterion) criteria.nextElement();
48.
if ( wakeup instanceof WakeupOnAWTEvent )
49.
{
50.
event = ((WakeupOnAWTEvent) wakeup).getAWTEvent();
51.
for ( int i=0; i<event.length; i++ )
52.
{
53.
eventId = event[i].getID();
54.
switch ( eventId )
55.
{
56.
case MouseEvent.MOUSE_PRESSED:
57.
case MouseEvent.MOUSE_DRAGGED:
58.
int x_m = ((MouseEvent)event[i]).getX();
59.
int y_m = ((MouseEvent)event[i]).getY();
60.
Point3d start_pt = new Point3d();
61.
Transform3D trans = new Transform3D();
62.
canvas.getPixelLocationInImagePlate( x_m, y_m, start_pt );
63.
canvas.getImagePlateToVworld( trans );
64.
trans.transform( start_pt );
65.
pickCanvas.setShapeCylinderRay( start_pt, new Vector3d( 0,0,-1),0.1);
66.
if ( pickCanvas.pickClosest() != null )
67.
{
68.
pickres = pickCanvas.pickClosest();
69.
PickIntersection pickint = pickres.getClosestIntersection(p_3d);
70.
shape3d = (Shape3D) pickres.getNode(PickResult.SHAPE3D);
71.
shape3d.addGeometry(new Square().getGeometry());
72.
shape3d.removeGeometry(0);
73.
}
74.
break;
75.
default: ;
76.
}
77.
}
78.
}
79.
this.wakeupOn( new WakeupOr( allEvents ) );
80.
}
81. }
tor and the initialize method for a customized picking behavior class for this application,
whereas Figure 21 shows the important code segment in the processStimulus method. Note
that the transformation of the visual object can be done through pressing or dragging the
Search WWH ::




Custom Search