Sivakumar
Sivakumar

Reputation: 11

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

Upvotes: 0

Views: 535

Answers (1)

datenwolf
datenwolf

Reputation: 162164

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.

Upvotes: 2

Related Questions