开发者

How to select objects in OpenGL on iPhone without using glUnProject or GL_SELECT?

开发者 https://www.devze.com 2023-03-14 18:48 出处:网络
I have 3 OpenGL objects which are shown at the same time. If the user touches any one of them, the开发者_JAVA百科n that particular OpenGL object alone should display in screen.Just use gluUnProject to

I have 3 OpenGL objects which are shown at the same time. If the user touches any one of them, the开发者_JAVA百科n that particular OpenGL object alone should display in screen.


Just use gluUnProject to convert your touch point to a point on your near clipping plane and a point on your far clipping plane. Use the ray between those two points in a ray-triangle intersection algorithm. Figure out which triangle was closest, and whatever object that triangle is part of is your object. Another approach is to give each object a unique ID color. Then, whenever the user touches the screen, render using your unique ID colors with no lighting, but don't present the render buffer. Now you can just check the color of the pixel where the user touched and compare it against your list of object color ID's. Quick and easy, and it supports up to 16,581,375 unique objects.


You would have to parse every object of your scene and check the possible collision of each one of them with the ray you computed thanks to gluUnProject.

Depending on whether you want to select a face or an object, you could test the collision of the ray with bounding volumes (e.g. bounding box) of your objects for efficiency purposes.

0

精彩评论

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