Transformations
The shapes that we've rendered so far have been stationary, always stuck to their original coordinates. If we want our renderers to feel interactive or to tell stories, we need some way of making our objects move.
Operations that change the spatial properties of an object are called transformations. Most graphical applications support just three fundamental transformations:
- rotation, which spins an object around a pivot point
- scaling, which enlarges or shrinks an object around a pivot point
- translation, which shifts an object
We transform models not by permanently altering their positions in the vertex buffer, but rather by applying mathematical operations on the fly in the vertex shader. Before we learn the mathematics behind them, first develop a visceral feel for their behaviors and parameters by fiddling with this renderer:
Ask yourself some questions as you explore. Here are a few to get you started:
- What happens if a translated triangle goes offscreen?
- In what direction does a positive rotation spin the object?
- What happens when you scale by a negative factor?
In this renderer, only one type of transformation may be applied at a time. Soon our shapes will run through a gauntlet of scales, rotations, and translations before they are drawn in the framebuffer. Additionally, these transformations are for now restricted to the \(z = 0\) plane because the mathematics behind rotation is simpler in 2D. Soon we'll extend them into 3D.