Hi John,
I'm assuming that you're using Java3D 1.3 release.
Try to check out the PickTool utilities source code
(bundle in the distribution) and see why the closest
Geometry is not return in your case. Note that there
is a limitation of utility PickTool
4351579 - APIs issue : Shape3D intersect method -- multiple geometry support
Also
But if you're not using mutliple geometry in the same shape that's fine.
The procedure that return closest distance in PickTool is
private PickResult pickGeomClosest(PickShape pickShape) {
PickResult[] pr = pickGeomAllSorted(pickShape);
if (pr == null) {
return null;
} else {
return pr[0];
}
}
where pickGeomAllSorted() will use core API
BranchGroup/Locale pickAll()
to get a list of intersecting Shape3D in SceneGraphPath
Then use core API Shape3D
public boolean intersect(SceneGraphPath path,
PickRay pickRay,
double[] dist)
to get the distance for each intersection and
return the smallest one.
I guess there may be bug in the above API.
Please let us know which type of Shape3D (Morph, OrientedShape)
and GeometryArray you are using since different combinations will
fall into different intersection routine. If you can identify
a set of Geometry which intersect() fail to return the correct
distance please send us the test case so we can fix it in time
for the next release.
Thanks.
- Kelvin
---------------------
Java 3D Team
Sun Microsystems Inc.
John Wright wrote:
> This is perhaps a bit of a vague report (and I'm sure Sun would request
> sample code), but in reviewing my terrain navigation code (because we
> were sometimes "falling through the ground") I noticed that
> PickTool.pickClosest doesn't always seem to pick the closest result.
>
> The documentation states:
> "When using pickAllSorted or pickClosest methods, the picks will be
> sorted by the distance from the start point of the pick shape to the
> intersection point."
>
> What defines the "intersection point"? If I hit a polygon (triangle)
> that is "sloped" it does seem to return the proper values for where I
> intersected that slope. (i.e. we can climb a "hill" that is a single
> polygon properly)
>
> Yet in writing some checking code I found that pickClosest sometimes
> returned more than one result and if I looked at the values of all
> results returned then SOMETIMES I found a value that was "closer" than
> the first (zero item) result returned.
>
> The relevant code is listed below.
>
> - John Wright
> Starfire Research
>
> Note: I'm picking straight "down" and thus hopefully the y value
> returned from the pick would actually correspond to the "closest"
> intersection.
>
> public float checkHeight(float nx, float nz) {
> pickTool = new PickTool(structureObjects);
> pickTool.setMode(PickTool.GEOMETRY);
> startRay = new Point3d((double) nx, (double) y+1.2+jumpHeight,
> (double) nz); // allow a 1.2 meter "climb"
> rayVector = new Vector3d(0,-1.0,0);
> pickTool.setShapeRay(startRay,rayVector);
> pr = pickTool.pickClosest(); // pick result
> if ( (pr != null) ) {
> if (pr.numIntersections() > 0) {
> for (int loop = 0; loop < pr.numIntersections(); loop++) {
> if ( pr.getIntersection(loop) != null ) {
> pickIntersection = pr.getIntersection(loop); // get the pick
> intersection
> iPoint = pickIntersection.getPointCoordinatesVW(); //
> definitely should be VW!
> tmpHeight = iPoint.y;
> if ( tmpHeight > highestHeight) {
> highestHeight = tmpHeight;
> } // highest check
> } // null check
> } // checking for
> return (float) highestHeight+jumpHeight;
> } // end of pr.numIntersections
> } // end if pr null
> return y; // nothing below us! Return what we came in with!
> } // end of checkHeight
>
> ===========================================================================
> 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".
===========================================================================
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".