problem with window coords--- world coords

Started by
0 comments, last by Chire 16 years, 4 months ago
hi, i've read the tutorial about transforming window coordinates to Opengl coordinates. in the last step, when i transform my window mouse coordinates to new opengl world coordinates x,y,z.... i have a problem because they are just the same as my old window coordinates, and z reads -1 all the time. heres the code:

//variables
GLint viewPort[4];
GLdouble modelView[16];
GLdouble projection[16];
GLfloat winX, winY, winZ;
GLdouble mouseWorldCoordX, mouseWorldCoordY, mouseWorldCoordZ;	


winX = (float)mousePos.x;		//Reading mouse coords x			
winY = (float)mousePos.y;	        //Reading mouse coords y
glGetIntegerv(GL_VIEWPORT, viewPort);   //getting viewport
winY = (float)viewPort[3] - winY;       //changey to increase from bottom to up 
glGetDoublev(GL_MODELVIEW_MATRIX, modelView);	//getting modelView matrix
glGetDoublev(GL_PROJECTION_MATRIX, projection); //getting projection Matrix
glReadPixels(winX, winY, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &winZ); // ???
gluUnProject( winX, winY, winZ, modelView, projection, viewPort, &mouseWorldCoordX, &mouseWorldCoordY, &mouseWorldCoordZ); //get world values
those final variables mouseWorldCoordX mouseWorldCoordY mouseWorldCoordZ have just the same values as my winX winY winZ coords. any suggestion? thanks
Advertisement
problem solved with google

my mistake was that i was obtaining the matrix data in a wrong part of the drawing function, and also is recommended to use this method in orthogonal projection.

This topic is closed to new replies.

Advertisement