devdept

11-11-2009, 04:09 AM

Hi All,

Here is today quiz.

Suppose you have a triangle in perspective projection and that you want to select it in two ways:

1) clicking inside of it

2) 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.

Two questions:

1) 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.

2) How can we skip the triangle in this case? Checking if the screen Z (depth) is Z < 0 or Z > 1 ?

Thanks,

Alberto

Here is today quiz.

Suppose you have a triangle in perspective projection and that you want to select it in two ways:

1) clicking inside of it

2) 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.

Two questions:

1) 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.

2) How can we skip the triangle in this case? Checking if the screen Z (depth) is Z < 0 or Z > 1 ?

Thanks,

Alberto