Java Reference
In-Depth Information
Figure 8. Code segment and result for PickRayBehaviour.java
1.
case MouseEvent.MOUSE_CLICKED:
2.
int x = ((MouseEvent)event[i]).getX(); int y = ((MouseEvent)event[i]).getY();
3.
Point3d point3d = new Point3d(); canvas.getPixelLocationInImagePlate(x,y,point3d);
4.
Point3d center = new Point3d(); canvas.getCenterEyeInImagePlate(center);
5.
Transform3D transform3D = new Transform3D(); canvas.getImagePlateToVworld(transform3D);
6.
transform3D.transform(point3d); transform3D.transform(center);
7.
8.
Vector3d mouseVec; mouseVec = new Vector3d(); mouseVec.sub(point3d, center);
9.
mouseVec.normalize();
10.
11.
picktool.setShapeRay(point3d, mouseVec);
12.
13.
if ( picktool.pickClosest() != null )
14.
{
15.
System.out.println( "Object picked " + picktool.getPickShape() );
16.
System.out.println("Direction vector =" + mouseVec);
17.
pickresult = picktool.pickClosest();
18.
19.
PickIntersection pickint = pickresult.getClosestIntersection(center);
20.
shape3d = (Shape3D) pickresult.getNode(PickResult.SHAPE3D);
21.
IndexedGeometryArray quadarray = (IndexedGeometryArray) shape3d.getGeometry();
22.
23.
quadarray.getColor( 0, temp);
24.
if ( temp.equals( red ) ) quadarray.setColor(0,blue);
else quadarray.setColor(0,red);
25.
}
26.
else
27.
System.out.println( "Target not aacquired !!" );
28. break;
have inherent system inaccuracies. Nevertheless, PickPoint can be used in BranchGroup
and Locale pick testing as well as for picking package classes.
ray seGment pIckInG shape
As discussed, the use of PickRay will pick all objects that intersect a ray of infinite extent.
Obviously, in a scene with many objects, this may give to problems in determining the exact
object that the user is trying to pick. PickSegment attends to overcome this to a certain
degree by using only a ray with appropriate starting and ending points
We will now illustrate how PickSegment can be used to change the transparency values
of a few rows of trapezoidal objects and will discuss the important program segments in
greater details. Specifically, we will discuss the overall structure, variable declaration,
constructor, initialize(), and processStimulus() methods one after another.
Search WWH ::




Custom Search