# [SOLVED]Translating Mouse Co-ords to GL-Space

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

## Recommended Posts

This is in OpenGL, and I have been posting under someone elses thread about this, however no one has responded and I know it's just a stupid problem. This is with a set Z value. here's what I have so far:

double aspect = pwidth / pheight;
ymax = ((double)CameraZ) * Math.tan(45.0 * M_PI / 360.0);
xmax = ymax * aspect;
ymin = (-1 * ymax);
xmin = (ymin * aspect) + CameraX;
ymin = ymin + CameraY;
ymax = ymax + CameraY;
xmax = xmax + CameraX;
//THE ABOVE CODE WORKS FINE

realmouseX = (mousex / pwidth  * xmax);
//^^^this works it's a little off but it's fine.
realmouseY = (mousey / pwidth) * (ymax);

The bold line is were I need help. I can't figure out how to translate the Y values captured to the GL canvas. So when my mouse is over half of the the screen(On Y Axis) it returns it's opposite. Meaning the point returned will be the under half the screen the same distance from the center and vice versa. Anyone got a helping hand on how to do this? [Edited by - Cakey on January 25, 2009 1:16:35 PM]

##### Share on other sites
Wow.. never mind the correct line for the bold statement is:
realmouseY = ((pheight - imy)/pheight) * ymax;

• 10
• 13
• 14
• 18
• 15