help mouse coordinates
when i click the mouse on my opengl window , and then converts the mouse coordinates in to the opengl coordinates, the converted coordinates are lying on a place which is above the place where i have clicked
i.e the changed coordinates y value is more.....................
why is it so?
and how to correct it
thanks
Quote:Original post by asdfwe
why is it so?
and how to correct it
How you you performing the conversion?
i am doing the conversion like this:::::::::::
xPos = LOWORD(lParam); // horizontal position of cursor
yPos = HIWORD(lParam); // vertical position of cursor
//////// changes windows coordinates to opengl coordinates
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)xPos;
winY = (float)viewport[3] - (float)yPos;
glReadPixels( xPos, int(winY), 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &winZ );
gluUnProject( winX, winY, winZ, modelview, projection, viewport, &posX, &posY, &posZ);
/// posX, posY, posZ now are the changed coorcinates
// i am not using posZ in my code
xPos = LOWORD(lParam); // horizontal position of cursor
yPos = HIWORD(lParam); // vertical position of cursor
//////// changes windows coordinates to opengl coordinates
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)xPos;
winY = (float)viewport[3] - (float)yPos;
glReadPixels( xPos, int(winY), 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &winZ );
gluUnProject( winX, winY, winZ, modelview, projection, viewport, &posX, &posY, &posZ);
/// posX, posY, posZ now are the changed coorcinates
// i am not using posZ in my code
i dont know whether this has an effect::
the height and width of my opengl window are not in ration 1:1
the height and width of my opengl window are not in ration 1:1
I haven't used windows messages to receive mouse x,y (because windows messages are crap, you should be using GetCursorPos(&mouse);
http://www.gamedev.net/community/forums/topic.asp?topic_id=459259
But in either case, if your in window'd mode (which causes the problem)
Move the window to the top left corner of the screen/desktop, then your mouse should align with your window, to understand what it's doing.
or make it full screen or same resolution as your windows desktop.
but the link I provided you gives you the ScreenToClient function which will solve your problem.
http://www.gamedev.net/community/forums/topic.asp?topic_id=459259
But in either case, if your in window'd mode (which causes the problem)
Move the window to the top left corner of the screen/desktop, then your mouse should align with your window, to understand what it's doing.
or make it full screen or same resolution as your windows desktop.
but the link I provided you gives you the ScreenToClient function which will solve your problem.
thanks for the link ........but i cant understand how to use it(ScreenToClient)
can u just provide an example ......it will be a great favour
thanks
can u just provide an example ......it will be a great favour
thanks
short x = (short)LOWORD(lParam);
short y = (short)HIWORD(lParam);
POINT pt = {x, y};
ClientToScreen(hWnd, &pt);
gluUnProject( winX, winY, winZ, modelview, projection, viewport, &pt[0], &pt[1], &posZ);
short y = (short)HIWORD(lParam);
POINT pt = {x, y};
ClientToScreen(hWnd, &pt);
gluUnProject( winX, winY, winZ, modelview, projection, viewport, &pt[0], &pt[1], &posZ);
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement