View Full Version : intesection test in 3D space.

02-10-2010, 09:30 AM
Hi, I have this 3D model loaded.Then on the same screen, I have many points draw on it.. how Can I determine whether the points are on the model or not.Only take the XY plane for consideration.

Anyone can teach me how to do a 3D intersection test only on the XY plane, because Im really clueless.

02-10-2010, 10:32 AM
Okay, so to be clear, you are rendering a 3D model to the screen and you want to know which points in (x pixels, y pixels) on your screen fall on your mesh and which don't? Are the points in screen space (x pixels, y pixels) or 3D space like your model?

One easy way to do it is using the stencil buffer.

1. make sure your stencil buffer is on and working
2. clear it to something like 0x0
3. render the mesh setting the stencil values to 0x1, where the mesh get's rasterized
4. render your points to the screen setting the stencil value back to 0x0
5. For each point, call glReadPixels() on your stencil buffer reading in a single pixel (width=1,height=1). If that value is 0x1, it lies inside the mesh. If it is 0x0, it doesn't.

This assuming your points are in 2D. It's very slightly more tricky with 3D points depending on what you're trying to do.