View more

View more

View more

Image of the Day Submit

IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.

Pixel to world coords for asymmetrical ortho projection

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

No replies to this topic

#1pondwater  Members

Posted 17 January 2013 - 05:34 PM

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, 17 January 2013 - 05:54 PM.

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.