grodslukaren

07-04-2001, 04:57 AM

What might be the error if I get really strange convertions with the use of gluUnproject??

I have a OpenGL window with the dimensions 250*250 and a coordinate sytem in my OpenGL space defined as:

// create the coordinate system

glOrtho(-180.0,180,-180.0,180.0,-256.0,256.0);

When I use the screen coordinates I get from a mouse click, I receive the "un"-projected coordinates as:

screenX = 96 => objectX = -72

screenY = 182 => objectY = 357

screenZ = 0.36 => objectZ = 103

Itīs strange, because I make a mouse click at an object placed almost in the center of my coordinate system that has the radius of 130 and is not rotated. After the projection my "clicked" point is outside my coordintae system and my object... ????

Is there anything wrong to do gluUnProject with the use of glOrtho??

some code when converting:

// get the mouse coordinates

event.GetPosition(&x,&y);

winx = (GLdouble) x;

winy = (GLdouble) 250-y; // window height - y

glReadPixels(x,y,1,1,GL_DEPTH_COMPONENT,GL_FLOAT,&depth);

winz = (GLdouble) depth;

// here we get the object coordinates from the screen coordinates

glMatrixMode(GL_MODELVIEW);

glGetDoublev(GL_MODELVIEW_MATRIX, modelviewMatrix);

glMatrixMode(GL_PROJECTION);

glGetDoublev(GL_PROJECTION_MATRIX , projectionMatrix);

glGetIntegerv(GL_VIEWPORT,viewport);

gluUnProject(winx,winy,winz,modelviewMatrix,projec tionMatrix,viewport,&objx,&objy,&objz);

I have a OpenGL window with the dimensions 250*250 and a coordinate sytem in my OpenGL space defined as:

// create the coordinate system

glOrtho(-180.0,180,-180.0,180.0,-256.0,256.0);

When I use the screen coordinates I get from a mouse click, I receive the "un"-projected coordinates as:

screenX = 96 => objectX = -72

screenY = 182 => objectY = 357

screenZ = 0.36 => objectZ = 103

Itīs strange, because I make a mouse click at an object placed almost in the center of my coordinate system that has the radius of 130 and is not rotated. After the projection my "clicked" point is outside my coordintae system and my object... ????

Is there anything wrong to do gluUnProject with the use of glOrtho??

some code when converting:

// get the mouse coordinates

event.GetPosition(&x,&y);

winx = (GLdouble) x;

winy = (GLdouble) 250-y; // window height - y

glReadPixels(x,y,1,1,GL_DEPTH_COMPONENT,GL_FLOAT,&depth);

winz = (GLdouble) depth;

// here we get the object coordinates from the screen coordinates

glMatrixMode(GL_MODELVIEW);

glGetDoublev(GL_MODELVIEW_MATRIX, modelviewMatrix);

glMatrixMode(GL_PROJECTION);

glGetDoublev(GL_PROJECTION_MATRIX , projectionMatrix);

glGetIntegerv(GL_VIEWPORT,viewport);

gluUnProject(winx,winy,winz,modelviewMatrix,projec tionMatrix,viewport,&objx,&objy,&objz);