Chapter 3: Coordinate Mapping
To draw something, we need to transform from world to pixel!
Before transform, we must constrain the view into the world.
In general, transforms can look like this:
Where and are scales and and are shifts.
(it’s going to seem like we use these equations for this assignment and never again, but this is the basis for most of the transforms we will do this quarter)
We must constrain our world into a particular view. We will determine a mapping from four world space values to pixel/screen space values. On the left is world coordinates, on the right is pixel coordinates:
Where and are the width and height of the screen in pixels (e.g.
1024 x 768).
, , , and are the left, right, bottom, and top (respectively) of the viewport in world space. We will use for Left and Bottom, and for Right and Top.
Solve for and
So what about ?
Plug back in to our equation.
Let’s say our window is
320x240 and using the L/R/B/T values from above.
And now plugging in to our equation:
So our general transformation from world coordinates into pixel coordinates is:
The formulation for y will be quite similar.
To account for aspect ratio, we need to pick different L and R values.