PDA

View Full Version : Depth Test



Rong Yao
03-06-2002, 10:30 AM
Is there any way for the programmer to know which plane is in front of another one if there are two planes in the view? OpenGL knows that with Z Buffer, however, how can I know this?

Our project: we need to retrieve some information from planes in the view. We only try to get information from the front most plane. So we need to know which plane is the front most one. Is there any way to do that?

Omaha
03-07-2002, 01:32 PM
Just make your own state variable that keeps track of it.

mmm
03-07-2002, 06:48 PM
Rong Yao,
there is an extremelly fast way to do what you want. Please dont use any gl command to do that (like rendering the planes with different colors or using the stencil buffer). If you choose that method you will have to draw a lot of overlapping geometry what will cost a lot of rendering time and will speed down your scene. To find the nearest plane at the mouse point use 3d math.
Follow these steps:

1) convert the mouse screen coordinates to a camera space segment starting at the near view plane and ending at the far view plane;
2) transform that segment to view space (multiply it by the inverted view matrix);
3) uses a segment-plane intersection routine to find which planes are intersected and the intersection distance;
4) get the smallest distance.

Althought that seems to be computationally expensive it isn't and will run thousands of times faster than any rendering approach.
If you aren't able to do the involved computation tasks i can send you a demo of mouse picking.

marcio