help mouse coordinates

Started by
14 comments, last by asdfwe 16 years, 1 month ago
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
Advertisement
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










i dont know whether this has an effect::

the height and width of my opengl window are not in ration 1:1
can anyone help
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.
Black Sky A Star Control 2/Elite like game
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
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);
Black Sky A Star Control 2/Elite like game
it is giving an error

no match for 'operator[]' in 'pt[0]'

and more of same type
how to correct them

do i have to use pt.x in place of pt[0]

thanks
Yeah sorry my bad, it's a structure not an array doh!

so pt.x and pt.y
Black Sky A Star Control 2/Elite like game

This topic is closed to new replies.

Advertisement