how do i calculate the Touch on openGL using glUnP

2019-08-29 02:36发布

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);
}

1条回答
兄弟一词,经得起流年.
2楼-- · 2019-08-29 02:51

and…

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

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.

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.

查看更多
登录 后发表回答