Game Development Reference
In-Depth Information
a bitmap. The simplest mapping between a polygon and a bitmap is to use
a four-vertex polygon where the corners of the bitmap map directly to the
vertices of the polygon. The challenge then becomes one of determining,
for each on-screen pixel from the polygon, which texture pixel ( u , v ) to
choose for the display.
There are many approaches to this and there are several references to
further information for the interested reader in the bibliography. In
essence, we need a function that goes from screen space to texture
space, via world space. In other words, an inverse function of the mapping
we use to transform a vertex in world space to screen space.
Figure 2.8 Overview of position P and vectors M and N.
First we define vectors P , M and N . P is simply a vertex one. For
simplicity, P does not need to be on the polygon. It is, however, a point in
world space. Vectors M and N define the orientation of the texture in world
space. For simplicity here, we define them as vertices 0 and 2 of our
polygon. So vertex 0 is P + N , vertex 2 is P + M and vertex 3 is P + M +
N . This will stretch the texture over the whole polygon. Using different
values for P , M and N could stretch the texture over several polygons.
If we consider a point a on the plane defined by P , M and N , it can be
defined as
a = P + u M + v N
where u and v are values between 0 and 1.
We need functions that define u and v from screen coordinates. When
going from world space to screen space ( sx , sy ), we perform a mapping;
at its simplest this perspective transform is
Search Nedrilad ::

Custom Search