我如何使用 glUnProject 计算 openGL 上的 Touch [英] how do i calculate the Touch on openGL using glUnProject
问题描述
我找到了近程和远程计划..然后如何使用我在物体上触摸的这个来识别..任何人都可以帮助我..这是我的代码..
Hi i found upto near plan and far plan.. then how to identify using this i touched on the object.. could anyone pls help me.. Here is My code..
-(Boolean) checkCollission:(CGPoint)winPos
{
winPos.y = (float)__viewport[3] - winPos.y;
Point3D nearPoint;
Point3D farPoint;
Point3D rayVector;
//Retreiving position projected on near plan
gluUnProject( winPos.x, winPos.y , 0, __modelview, __projection, __viewport, &nearPoint.x, &nearPoint.y, &nearPoint.z);
//Retreiving position projected on far plan
gluUnProject( winPos.x, winPos.y, 1, __modelview, __projection, __viewport, &farPoint.x, &farPoint.y, &farPoint.z);
}
推荐答案
and…
rayVector.x = farPoint.x - nearPoint.x
rayVector.y = farPoint.y - nearPoint.y
rayVector.z = farPoint.z - nearPoint.z
既然您已经确定了通过鼠标位置投射到场景中的光线,您必须测试光线是否与任何对象相交.OpenGL 在这方面帮不了你,因为 OpenGL 就是在屏幕上画东西.
Now that you've determined the ray that's cast into the scene by the mouse position, you have to test if the ray intersects with any of the objects. OpenGL can not help you there, since all that OpenGL is about is drawing things on the screen.
选择,这就是您要问的问题,是 OpenGL 之外的问题.在互联网上搜索选择射线交叉测试"这个词应该会给你很多结果.
Picking, that's the problem you're asking about, is a problem outside of OpenGL. A internet search on the terms "Picking ray intersection test" should give you plenty of results.
这篇关于我如何使用 glUnProject 计算 openGL 上的 Touch的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!