Game Development Reference
In-Depth Information
Figure 6.5 Generating spherical coordinates.
Toon3D allows for the width wrapping and the height wrapping to be
set. In this way, a single texture can be tiled around the sphere's principal
and minor axes.
This code snippet shows how to generate spherical texture coordinates
having previously defined the texture centre and size as described for the
planar and cylindrical examples:
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;
while (u>=1.0) u-=1.0;
while (u<0) u+=1.0;
//Calculate the v coordinate
vec.y /= sqrt(vec.x*vec.x + vec.y*vec.y +
vec.z*vec.z);
v = (asin(vec.y)*tex->heightwrap)/PI + 0.5;
Search Nedrilad ::




Custom Search