Game Development Reference

In-Depth Information

Figure 6.3 Calculating the u values for a cylindrical texture map.

2

radians are equivalent to 360°. The distance across the texture map

is given by the product of the width wrap and the current angle,

,

divided by 2

. This is capped to between 0 and 1.0 using a while

loop.

Calculating the v value is the same as planar mapping, although in

this sample we use the centre of the texture as the origin point not the

minimum vector, so we need to add 0.5 back to the
v
value to centre the

result. Here is a code snippet that shows how to generate the

coordinates for a cylindrical image mapping around the
y
-axis:

for (i=0; i<ply->numverts; i++){

pt=&oi->pts[ply->p[i]];

vec.x = pt->x - tex->centre.x;

vec.y = pt->y - tex->centre.y;

vec.z = pt->z - tex->centre.z;

//Calculate the u coordinate

u = (float)(atan2(vec.x,vec.z)/PI2);

u *= tex->widthwrap;

//Cap to 0 < u < 1

while (u>=1.0) u-=1.0;

while (u<0) u+=1.0;

Search Nedrilad ::

Custom Search