• 13
• 15
• 19
• 27
• 9

# Pixel to world coords for asymmetrical ortho projection

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

## 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!

EDIT:

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