Jump to content
  • Advertisement
Sign in to follow this  
marti901

OpenGL gluUnProject gives wrong positions(opengl)

This topic is 2355 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'm trying to make a flat plane with a sphere.

If i click on the plane is want the sphere to move to to positions of the mouse click.
But i'm getting wrong mouse positions.
If i click 5 pixels to the left of the sphere is moves around 10 to the left.
If i click 10 pixels to the left of the sphere is moves around 35 to the left.
If i click 50 pixels to the left of the sphere is moves around 250 to the left.

code


vertex3f getOGLPos(int xx, int yy){
GLint viewport[4];
GLdouble modelview[16];
GLdouble projection[16];
GLfloat winX, winY, winZ;
GLdouble posX, posY, posZ;
glGetDoublev( GL_MODELVIEW_MATRIX, modelview );
glGetDoublev( GL_PROJECTION_MATRIX, projection );
glGetIntegerv( GL_VIEWPORT, viewport );

winX = (float)xx;
winY = (float)viewport[3] - (float)yy;
glReadPixels( xx, int(winY), 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &winZ );
gluUnProject( xx, winY, winZ, modelview, projection, viewport, &posX, &posY, &posZ);
return vertex3f(posX, posY, posZ);
}


Can someone help me with the problem?

Share this post


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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!