World and Model Space

To understand how this works we have to literally 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 (e.g., Bob's rectangle, a spaceship, etc.) 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).

Eye/World Space

Figure 7-19. Defining our model in model space, reusing it, and rendering it at different locations in the world space

In Figure 7-19 we have a single model, defined via a Vertices instance—for example, like this:

Vertices vertices = new Vertices(glGraphics, 4, 12, false, false); vertices.setVertices(new float[] { -50, -50,

50, -50, 50, 50, -50, 50 }, 0, 8); vertices.setIndices(new short[] {0, 1, 2, 2, 3, 0}, 0, 6);

For our discussion we just leave out any vertex colors or texture coordinates. Now, when we render this model without any further modifications, it will be placed around the origin in the world space in our final image. If we want to render it at a different position — say, its center being at (200,300) in world space—we could redefine the vertex positions like this:

vertices.setVertices(new float[] { -50 + 200, -50 + 300,

On the next call to vertices.draw(), the model would be rendered with its center at (200,300). But this is a tad bit tedious isn't it?

0 0

Post a comment