开发者

3D intersection test

开发者 https://www.devze.com 2022-12-19 15:24 出处:网络
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 considerat

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.


There are several ways you could do this. Most practical options are probably:

a) Use a stencil buffer that you write to when you render your model and glReadPixels(...) to see if the stencil buffer is set for the particular (x,y) point on the screen.

b) Convert the (x,y) point into a line in 3D space from the camera position. Then do a line intersection test with your model (the simple but slow way would be to test against each polygon, you can clearly get faster results by using bounding volumes etc.)

c) Use glReadPixels(...) to read the colour of the (x,y) point on the screen. Obviously this will will only work if you are able to accurately distinguish which colours are part of the model or not.

If you are able to set up and use a stencil buffer for this purpose, then a) is probably the simplest to implement. Otherwise b) is probably the most useful general solution.

0

精彩评论

暂无评论...
验证码 换一张
取 消