• Advertisement
Sign in to follow this  

click to coord question

This topic is 3705 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have a problem converting mouse coordinates to 3d world coordinates. I implemented a basic tile test: I draw quads, starting at x=0,z=0, keeping y constant for the moment. I use the following code I found in Berlioz to convert the mouse coords:
vector3f GetOGLPos(int x, int y)
{
    GLint viewport[4];
    GLdouble modelview[16];
    GLdouble projection[16];
    GLfloat winX, winY, winZ;
    GLdouble posX, posY, posZ;
    //float v[3];

    glGetDoublev( GL_MODELVIEW_MATRIX, modelview );
    glGetDoublev( GL_PROJECTION_MATRIX, projection );
    glGetIntegerv( GL_VIEWPORT, viewport );

    winX = (float)x;
    winY = (float)viewport[3] - (float)y;
    glReadPixels( x, int(winY), 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &winZ );

    gluUnProject( winX, winY, winZ, modelview, projection, viewport, &posX, &posY, &posZ);
    
    return vector3f(posX,posY,posZ);
}

But, when I scroll the tiles by translating the world I start getting wrong results. Can somebody give me an idea about how to do this?

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement