Jump to content
  • Advertisement
Sign in to follow this  
asdfwe

help mouse coordinates

This topic is 3773 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
Advertisement
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










Share this post


Link to post
Share on other sites
i dont know whether this has an effect::

the height and width of my opengl window are not in ration 1:1

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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);

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!