1

In this thread. The second answer suggest that :

Solution 2 call the gluUnproject two time, one with clipZ = -1 and another one with clipZ = 1, you get two point (in world space). With these two point you get a ray and you can use some raycast algorithm to compute the mouse coordinate.

But unfortunately it is not explained there after the suggestion. There is also this thread which explains a direction can be get by calling gluUnproject twice. Getting a direction makes sense to me but my question is how can I get the depth info by calling gluUnProject twice?

Community
  • 1
  • 1
Kadir Erdem Demir
  • 3,531
  • 3
  • 28
  • 39

1 Answers1

2

You don't get depth info. You only have a X and a Y, but to unproject you need a Z. And no magic is going to give it. Instead try to deduce it.

After you undo the viewport transform you have X,Y in NDC. What Z? Use z1= 1 and X, Y. Unproject. Now you have a point P1 in world coordinates. Repeat Unproject but this time with z2= -1. You get P2. Likely you have to deal with forth 'w' coordinate. Remember you can extract 3D coordinates after dividing by w. In homogeneous coordinates w is a scale factor.

With P1 and P2 perhaps you can find on your own the intersection between line P1P2 and your model.

z= -1, 1 are most separated coordinates in NDC, so more accurate the calculation results.

Ripi2
  • 7,031
  • 1
  • 17
  • 33
  • Ok that make sense. In the first link i feel like it was saying we can find the Z value just like readPixel. One more question if my model does not intersects? – Kadir Erdem Demir Feb 04 '17 at 06:57
  • If your model does not intersect then you are setting the mouse over an empty area. – Ripi2 Feb 04 '17 at 12:58
  • Ripl2 I hope you saw my other question you commented it as well. I am not looking for selection I am trying to determine zooming level instead. – Kadir Erdem Demir Feb 04 '17 at 18:03