Java Reference
In-Depth Information
Figure 24. Second code segment for PickBoundsBehavior.java
1.
case MouseEvent.MOUSE_CLICKED:
2.
3.
// getting the mouse position on the 2D viewing plane
4.
x_m = ((MouseEvent)event[i]).getX(); y_m = ((MouseEvent)event[i]).getY();
5.
6.
// transforming the 2D local coordinates to virtual world coordinates
7.
canvas.getPixelLocationInImagePlate( x_m, y_m, pt_m );
8.
canvas.getImagePlateToVworld( trans );
9.
trans.transform( pt_m );
10.
11. // getting the direction for the picking shape
12. canvas.getCenterEyeInImagePlate( start_pt );
13. trans.transform( start_pt );
14. pt_m.sub( start_pt );
15. dirn.set( pt_m );
16. dirn.normalize();
17. dirn.scale( 2.5 );
18. end_pt.add( start_pt, dirn );
19.
20. BoundingSphere bounding = new BoundingSphere ( end_pt, 0.5 );
21. picktool.setShapeBounds( bounding, start_pt );
22.
23. result = picktool.pickAllSorted();
24.
25. if( result != null )
26. {
27.
Primitive[] picked_node = new Primitive[result.length];
28.
for ( int j=0; j < result.length && result[j] != null; j++ )
29.
{
30.
picked_node[j] = (Primitive)result[j].getNode( PickResult.PRIMITIVE );
31.
current_attr = picked_node[j].getAppearance().getColoringAttributes();
32.
current_attr.getColor( current_clr );
33.
if ( current_clr.equals( yellow ) ) current_attr.setColor( red );
34.
else current_attr.setColor( yellow );
35.
}
36. }
37.
38. break;
obtain the corresponding 3D coordinate in the same way as other examples in previous
sections, and a spherical bound with a certain radius is specified to pick up objects within
the sphere. The color attributes of the objects picked are then changed.
Search WWH ::




Custom Search