Jump to content
  • Advertisement
Sign in to follow this  

Pixel to world coords for asymmetrical ortho projection

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

I am modifying some existing code that has a 2D orthographic projection set as:


glOrtho(-0.02, 1.02, -0.02, 0.68, -1, 1);


I have never had an issue with transfering pixel coords (mouse clicks specifically) into world space when the left/right, top/bottom values of the frustum are symmetrical.


I simply convert the pixel values to a normalize -1 to 1 'window coord' centered in the middle of the window and then scale those values by the right/top values given to my frustum.


But for some reason I am getting really confused when converting to this asymmetrical frustum.


This should be simple, but I can't for the life of me figure it out!




I feel silly now, I figured it out:

// normalized window coords centered on bottom left of window
float x = (pixel_x / window_width);
float y = (window_height - pixel_y)/(window_height);

// world coords by scaling and translating
x = x*(frustum_right - frustum_left ) - frustum_left;
y = y*(frustum_top - frustum_bottom) - frustum_bottom;
Edited by pondwater

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.

GameDev.net 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!