Game Development Reference
In-Depth Information
texture coordinates involves checking the mapping type and using the flag
member of the surface variable to switch to the appropriate axis. Let's
look at the principle texturing methods.
Planar mapping
As we know from Chapter 6, planar mapping takes an image and projects it
parallel down one of the axes. If the axis is z , for a planar texture then the
coordinates are applied with the x -axis running left to right and the y -axis
running up and down. For each polygon we loop through the vertices. The
actual texture coordinates are found by subtracting the texture centre from
the current point, then dividing by the size of the texture. This will result in
texture coordinates that run from -0.5 to 0.5 assuming that automatic sizing
was used in Lightwave to determine the texture size and centre. When
automatic sizing is used, Lightwave loops through all the polygons in a
scene that uses the current surface; for each vertex in a polygon it stores
the maximum and minimum values. Then it subtracts the minimum from the
maximum to get the size, divides this by 2 and adds back the minimum to
define the centre. OpenGL uses texture coordinates that run from 0.0 to
1.0, so we add 0.5 to the calculation to re-centre the texture suitable for
switch (tex->flag & 0x07){
//Only axis bits are supported. Flag bits are
//7 NU
//6 AntiAlias
//5 PixelBlend
//4 Negative Image
//3 World Coord
//2 Z axis
//1 Y axis
//0 X axis
case 1://X axis
for (i=0; i<ply->numverts; i++){
ply->tc[i].u = ((float)pt->z - tex->centre.z)/
tex->size.z + 0.5f;
ply->tc[i].v = ((float)pt->y - tex->centre.y)/
tex->size.y + 0.5f;
case 2://Y axis
Search Nedrilad ::

Custom Search