Here is today quiz.
Suppose you have a triangle in perspective projection and that you want to select it in two ways:
- clicking inside of it
- crossing one of its sides with a selection box
When you look to it far enough, you can easily project vertices on screen and do PointInTriangle with the mouse coords as 2D problem, the same applies for box crossing selection: project everything on screen and check for intersections between triangles sides and box sides.
Troubles arise when you zoom very close to one vertex the other two are probably behind the viewer point and the projection returns wild coordinates.
- Why we are still able to see the triangle correctly on screen? I belived that if you get wild coordinates from gluProject even the display should be wild.
- How can we skip the triangle in this case? Checking if the screen Z (depth) is Z < 0 or Z > 1 ?