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".

Reply via email to