Sign in to follow this  
rogerdv

click to coord question

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this