hittest / glupickmatrix / selectionbuffer

Hello

  1. I have a scene with a lot of polygons.
  2. I am sucessfully getting a selectionbuffer.
  3. The selection buffer is working correctly if I select all the polygons that are “hit”.
  4. The problem is to pick/select only the nearest polygon.

I am playing with the z1 and z2 values that are in the selectionbuffer but the problem is that sometimes the nearest polygon has the greatest max(z1,z2) and sometimes it is the opposite being the nearest polygon the one with min(z1,z2).

What am i missing here?