gluUnProject gives wrong positions(opengl)

Started by
-1 comments, last by marti901 11 years, 11 months ago
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?

This topic is closed to new replies.

Advertisement