This is a copy of an e-mail sent to the newsgroup comp.lang.java.3d. Thank you for
your attention.
Hello,
I am confronted with the following issue using the class set for picking
(PickResult, PickTool and PickIntersection).
I have a square created using GeometryInfo and a segment which I am sure
crosses the square, and I'm trying to determinate their intersection, but I
always get a null-pointer exception corresponding to the fact that my
pickTool.pickClosest() returns a null pointer. What am I doing wrong?
Here are some pieces of the code, I hope they're enough.
There I create my square:
GeometryInfo geom=new GeometryInfo(GeometryInfo.QUAD_ARRAY);
geom.setCoordinates(new Point3d[] {new Point3d(0.1,-0.3,-0.3),new
Point3d(0.1,-0.3,0.3),new Point3d(0.1,0.3,0.3),new Point3d(0.1,0.3,-0.3)});
geom.setColors(new Color3f[] {new Color3f(1.0f,0.0f,0.0f),new
Color3f(1.0f,0.0f,0.0f),new Color3f(1.0f,0.0f,0.0f),new
Color3f(1.0f,0.0f,0.0f)});
Appearance app=new Appearance();
PolygonAttributes poly=new PolygonAttributes();
poly.setPolygonMode(poly.POLYGON_FILL);
app.setPolygonAttributes(poly);
Shape3D cube=new Shape3D(geom.getGeometryArray(),app);
cube.setCapability(cube.ENABLE_PICK_REPORTING);
PickTool.setCapabilities(cube,PickTool.INTERSECT_FULL);
cube.setBoundsAutoCompute(true);
root.addChild(cube);
(...) I don't write everything here, the scene tree is built since I can see
the filled squared on the screen - I would see the problem elsewhere, some
flag I would not have set to true or something in this direction (...)
There I try to pick:
PickTool pickTool=new PickTool(scene);
pickTool.setMode(PickTool.GEOMETRY_INTERSECT_INFO);
pickTool.setShapeSegment(new Point3d(-1.0,0.0,0.0),new
Point3d(1.0,0.0,0.0));
PickResult pickResult=pickTool.pickClosest();
System.out.println(pickResult); (Here is a null pointer causing
the exception at the next line)
PickIntersection pickIntersection=pickResult.getIntersection(0);
System.out.println(pickIntersection.getClosestVertexCoordinates());
What am I doing wrong? I would be so glad if someone could help me. Thanks
for your help, this is making me crazy and I am sure it's so small an error!
Roland
===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA3D-INTEREST". For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".