Picking Order Patterns

Hi i’m firing a pick ray at a chess board and need to get the first shape3d object it hits. I presumed that the first object hit is always the last in the PickRenderResults array, but from a few tests i found that sometimes it’s the first element and sometimes it’s the last element.

I cannot see any pattern to the results can anyone suggest any reasons as to why its inverting sometimes???

Currently I do it this way. It returns the picked Shape3D. Checkpos is the xy-position on the screen you want to check for hits:


View mYourview = ... this is your view object.

public Node pickit(Point checkpos)
{
  PickRenderResult[] result = mYourview.pick(mYourview.getCanvas3D(0), checkpos.x, checkpos.y, 2, 2);
  if (result == null) {
    return null;
  }
  
  Node node = null;
  int zbest = 0;
  for (int i = 0; i < result.length; i++) {
    PickRenderResult restmp = result[i];
    int zmin = restmp.getZMin();
    if (zmin < zbest) {
      zbest = zmin;
      node = restmp.getNodes()[0];
    }
  }
  System.out.println(result.length + " hit objects.");
  return node;
}

All good, i’ll give tyhat a try thanks v much Bombadil