Advertisement Jump to content
Sign in to follow this  

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

This topic is 3648 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

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;

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 this post

Link to post
Share on other sites
Wow.. never mind the correct line for the bold statement is:
realmouseY = ((pheight - imy)/pheight) * ymax;
Thanks for reading, hopefully I save you a head-ache.

Share this post

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

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!