• Advertisement
Sign in to follow this  

help mouse coordinates

This topic is 3657 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
Yeah sorry my bad, it's a structure not an array doh!

so pt.x and pt.y

Share this post


Link to post
Share on other sites
even then it is giving an error
cannot convert `LONG*' to `GLdouble*' for argument `7' to `GLint gluUnProject(GLdouble, GLdouble, GLdouble, const GLdouble*, const GLdouble*, const GLint*, GLdouble*, GLdouble*, GLdouble*)'



how to correct it

thanks

Share this post


Link to post
Share on other sites
winX=pt.x;
winY=pt.y;

gluUnProject( winX, winY, winZ, modelview, projection, viewport, &posX, &posY, &posZ);

Share this post


Link to post
Share on other sites
thanks that error is removed

but my basic problem has become even more
now mouse clicks are not being captured at all
help please

Share this post


Link to post
Share on other sites
Quote:
Original post by ViperG
I haven't used windows messages to receive mouse x,y (because windows messages are crap, you should be using GetCursorPos(&mouse);
No, quite the opposite. If you click somewhere and then move the mouse, the WM_LBUTTONDOWN message will have the coordinates of the click in it, but GetCursorPos() could return a completely different position, which will make the mouse feel laggy.

Also, window messages contain the cursor position in client space, not in screen space - which means you don't need to use ScreenToClient().

As for the actual problem, I forget - which way is "up" in OpenGL? Is that +y or +z? (I'm a D3D guy). And have you tried initialising WinZ to something (Like 0.0)?

Share this post


Link to post
Share on other sites
____________________________________
| line drawn here |
| |
| clicked here |
|___________________________________|


this was my original problem

Share this post


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

  • Advertisement