Game Development Reference
In-Depth Information
2D Transformations: Fun with the Model-View Matrix
All we've done so far is define static geometries in the form of triangle lists. There was nothing
moving, rotating, or scaling. Also, even when the vertex data itself stayed the same (for example,
where the width and height stayed the same for the rectangle composed of two triangles along
with texture coordinates and color), we still had to duplicate the vertices if we wanted to draw
the same rectangle at different places. Look back at Listing 7-11 and ignore the color attributes
of the vertices for now. The two rectangles only differ in their y coordinates by 200 units. If we
had a way to move those vertices without actually changing their values, we could get away with
defining the rectangle of Bob only once and simply drawing him at different locations—and that's
exactly how we can use the model-view matrix.
World and Model Space
To understand how world and model work, we literally have to think outside of our little
orthographic view frustum box. Our view frustum is in a special coordinate system called the
world space . This is the space where all our vertices are going to end up eventually.
Up until now, we have specified all vertex positions in absolute coordinates relative to the origin
of this world space (compare with Figure 7-5 ). What we really want is to make the definition
of the positions of our vertices independent from this world space coordinate system. We can
achieve this by giving each of our models (for example, Bob's rectangle, a spaceship, and
so forth) its own coordinate system. This is what we usually call model space , the coordinate
system within which we define the positions of our model's vertices. Figure 7-19 illustrates this
concept in 2D, and the same rules apply to 3D as well (just add a z axis).
Figure 7-19. Defining our model in model space, reusing it, and rendering it at different locations in the world space
 
Search WWH ::




Custom Search