如何使用glUnProject计算openGL上的Touch

问题描述 投票:0回答:1

嗨我发现了接近计划和远计划..然后如何识别使用这个我触摸对象..任何人都可以帮助我..这是我的代码..

-(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);
}
opengl 3d raycasting picking
1个回答
2
投票

和…

rayVector.x = farPoint.x - nearPoint.x
rayVector.y = farPoint.y - nearPoint.y
rayVector.z = farPoint.z - nearPoint.z

现在您已经确定了通过鼠标位置投射到场景中的光线,您必须测试光线是否与任何对象相交。 OpenGL无法帮助你,因为OpenGL的所有功能都是在屏幕上绘制内容。

挑选,这是你问的问题,是OpenGL以外的问题。对“挑选射线交叉点测试”这一术语进行互联网搜索应该会给你带来很多结果。

© www.soinside.com 2019 - 2024. All rights reserved.