|
G.3.21 PickTest
Directory: demo/java3d/PickTest
The PickTest program displays several 3D objects and a control panel. The control
panel allows the user to change the pick mode, the pick tolerance, and the view
mode. You can pick and rotate objects with the mouse. The PickTest program demonstrates
the use of the PickMouseBehavior utility classes.
The IntersectTest program demonstrates the ability to get geometric intersection
information from a picked object. Use the mouse to pick a point on one of the
objects in the window. The program illuminates the picked location and the vertices
of the primitive with tiny spheres. Information about the picked primitive and
the point of intersection is printed. The IntersectTest program uses a mouse-based
behavior, IntersectInfoBehavior, to control the picking. The relevant source
code fragments from IntersectInfoBehavior.java follow:
------------------------------------------------------------------------
PickCanvas pickCanvas;
PickResult[] pickResult;
public IntersectInfoBehavior(Canvas3D canvas3D,
BranchGroup branchGroup,
float size) {
pickCanvas = new PickCanvas(canvas3D, branchGroup);
pickCanvas.setTolerance(5.0f);
pickCanvas.setMode(PickCanvas.GEOMETRY_INTERSECT_INFO);
...
------------------------------------------------------------------------
The IntersectInfoBehavior class constructor creates a new PickCanvas object,
initializes the PickCanvas with the desired tolerance, and sets the mode to
allow geometry intersection information to be retrieved.
http://java.sun.com/products/java-media/3D/forDevelopers/J3D_1_2_API/j3dguide/AppendixExamples.html
public void processStimulus(Enumeration criteria) {
...
<check for mouse event> if (eventId == MouseEvent.MOUSE_PRESSED) {
int x = ((MouseEvent)event[i]).getX();
int y = ((MouseEvent)event[i]).getY();
pickCanvas.setShapeLocation(x, y);
Point3d eyePos = pickCanvas.getStartPosition();
pickResult = pickCanvas.pickAllSorted();
if (pickResult != null) {
// Get node info
Node curNode = pickResult[0].getObject();
Geometry curGeom = ((Shape3D)curNode).getGeometry();
GeometryArray curGeomArray = (GeometryArray) curGeom;
// Get closest intersection results
PickIntersection pi =
pickResult[0].getClosestIntersection(eyePos);
<get specific info from PickIntersection>
}
}
...
|
| See the "Links" link above to find out the sources of the proposed informations Pascal Vuylsteker / eScience / Computer Science / ANU |
Last modified: 2/4/2002
TOC - Print |
Send your comments at : <Hugh.Fisher@anu.edu.au> |