Jump to content
  • Advertisement
Sign in to follow this  
litewarri

OpenGL Mouse Coords to Unit Coords math problem

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

Here is my algorithm for converting cursor coordinates Windows sends with WM_MOUSEMOVE, etc., into actual unit coordinates in the 3D world. window_x, window_y are my window sizes mouse_x, mouse_y are my incoming Windows cursor coordinates mx, my are those coordinates converted into "(0,0) in center" camera_distance is the distance between the camera and the 2D plane on which the unit coordinates will be mapped ("board") camera_x_offset, camera_y_offset are the relevant positions of the camera Here is my code: float mx = mouse_x - (window_x / 2); float my = mouse_y - (window_y / 2); mouse_ux = ((mx / window_x) * camera_distance) / ((window_y/window_x) * sin(DEGtoRAD(TGO_FIELDANGLE))) - camera_x_offset; mouse_uy = ((my / window_y) * camera_distance) / sin(DEGtoRAD(TGO_FIELDANGLE)) - camera_y_offset; Everything works great UNTIL you tilt the board a little bit (change the camera's angle around the X axis). Normally, when the camera's looking at the board straight-on, my cursor points to the center of the circle model that I'm moving around on the board. When I change the X angle of the board slightly, however, things get slightly messed up. On the top half, near the corners, the cursor gets a little farther out than the center of the circle. On the bottom half, near the corners, the cursor gets a little closer in than the center of the circle. This is clearly due to perspective, because units appear closer together up top, and father apart on bottom (but Windows cursor coordinates remain constant). So here's my variable: camera_x_angle Could anyone tell me how to insert that variable in the above code to make the Cursor-to-Unit conversion flawless? Here is a diagram of my dilemma: EDIT: Oops!! This isn't OpenGL specific. Sorry!

Share this post


Link to post
Share on other sites
Advertisement
>>Here is my algorithm for converting cursor coordinates Windows sends with WM_MOUSEMOVE, etc., into actual unit coordinates in the 3D world.<<

SEE GLUUNPROJECT(..)

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!