Game Development Reference

In-Depth Information

//Calculate the v coordinate

v = vec.y/tex->size.y + 0.5;

ply->tc[i].u = u;

ply->tc[i].v = v;

}

Figure 6.4 shows the result of wrapping the texture shown in Figure 6.2

twice around a cylinder in the
y
-axis.

Figure 6.4 Example of cylindrical image mapping.

Spherical mapping

The final type of basic mapping is spherical. In this type of mapping we

need to wrap the image in two directions. Calculations for the principal

axis are exactly the same as for cylindrical mapping. Wrapping around

towards the poles of the sphere is handled differently. We need to

consider another angle. Using the vector we have created from the

texture centre to the current vertex, we normalize this vector to unit length.

We now effectively have a hypotenuse that is of length 1. That means the

y
value is the sine of the angle

. Using the inverse function arcsin will

return the angle from the
y
value of the vector.

Search Nedrilad ::

Custom Search