Java Reference
In-Depth Information
Figure 18. Fourth code segment for PickConeRayBehavior.java
1.
if( wakeup instanceof WakeupOnAWTEvent )
2.
{
3.
event = ((WakeupOnAWTEvent) wakeup).getAWTEvent();
4.
for( int i=0; i<event.length; i++ )
5.
{
6.
eventId = event[i].getID();
7.
( eventId )
8.
{
9.
case MouseEvent.MOUSE_CLICKED:
10.
11.
// get mouse position on 2D viewing plane
12.
x_m = ((MouseEvent)event[i]).getX();
13.
y_m = ((MouseEvent)event[i]).getY();
14.
15.
// transform 2D local to virtual world coordinates
16.
canvas.getPixelLocationInImagePlate( x_m, y_m, pt_m );
17.
canvas.getImagePlateToVworld( trans );
18.
trans.transform( pt_m );
19.
20.
// get pick shape direction
21.
canvas.getCenterEyeInImagePlate( start_pt );
22.
trans.transform( start_pt );
23.
pt_m.sub( start_pt );
24.
dirn.set( pt_m );
25.
dirn.normalize();
26.
27.
// set pick shape to ConeRay
28.
picktool.setShapeConeRay( start_pt, dirn, 2*Math.PI/180 );
29.
as the smaller spheres that can be picked have very small sizes. If a simple ray with zero
thickness is used, the chance of intersecting the smaller spheres will be small and it will
be difficult for the user to pick the visual objects.
After specifying the pick shape, the nearest object that intersects with this shape is
retrieved. With ENABLE_PICK_REPORTING capability for transform group set, the
transform group of the picked object can also be retrieved. This in turns enables the light
node, the second child added to the transform group, to be retrieved using the getChild(int
x) method with x being equal to 1 (0 for the first child and 1 for the second child). The
light node can subsequently be changed to result in the visual effects in the live scene as
illustrated in Figure 14.
Search WWH ::




Custom Search