0

I have a mesh that is stored as an array of Vertices with an Index array used to draw it. Four of the vertices are also redrawn with a shader to highlight the points, and the indices for these are stored in another array.

The user can rotate the model using touches, which affects the modelViewMatrix:

modelViewMatrix = GLKMatrix4Multiply(modelViewMatrix, _rotMatrix);

My problem is that I need to detect which of my four highlighted points is closest to the screen when the user makes a rotation.

I think the best method would be to calculate the distance from the near clip of the view frustum to the the point, but how to I calculate those points in the first place?

Dover8
  • 607
  • 3
  • 17

1 Answers1

1

You can do this easily from camera/eye space[1], where everything is relative to the camera (So, the camera will be at (0, 0, 0) and looking down the negative z axis).

Use your modelViewMatrix to transform the vertex to camera space, say vertex_cs. Then the distance of the vertex from the camera (plane) would simply be the -vertex_cs.z .

--
1. What exactly are eye space coordinates?

Community
  • 1
  • 1
radical
  • 4,364
  • 2
  • 25
  • 27