Here are some simplified code fragments showing how LightWave computes UV coordinates from X, Y, and Z. If the resulting UV coordinates are not in the range from 0 to 1, the appropriate integer should be added to them to bring them into that range (the fract function should have accomplished this by subtracting the floor of each number from itself). Then they can be multiplied by the width and height (in pixels) of an image map to determine which pixel to look up. The texture size, center, and tiling parameters are taken right off the texture control panel. x -= xTextureCenter; y -= yTextureCenter; z -= zTextureCenter; if (textureType == TT_PLANAR) { s = (textureAxis == TA_X) ? z / zTextureSize + .5 : x / xTextureSize + .5; t = (textureAxis == TA_Y) ? -z / zTextureSize + .5 : -y / yTextureSize + .5; u = fract(s); v = fract(t); } else if (type == TT_CYLINDRICAL) { if (textureAxis == TA_X) { xyztoh(z,x,-y,&lon); t = -x / xTextureSize + .5; } else if (textureAxis == TA_Y) { xyztoh(-x,y,z,&lon); t = -y / yTextureSize + .5; } else { xyztoh(-x,z,-y,&lon); t = -z / zTextureSize + .5; } lon = 1.0 - lon / TWOPI; if (widthTiling != 1.0) lon = fract(lon) * widthTiling; u = fract(lon); v = fract(t); } else if (type == TT_SPHERICAL) { if (textureAxis == TA_X) xyztohp(z,x,-y,&lon,&lat); else if (textureAxis == TA_Y) xyztohp(-x,y,z,&lon,&lat); else xyztohp(-x,z,-y,&lon,&lat); lon = 1.0 - lon / TWOPI; lat = .5 - lat / PI; if (widthTiling != 1.0) lon = fract(lon) * widthTiling; if (heightTiling != 1.0) lat = fract(lat) * heightTiling; u = fract(lon); v = fract(lat); } support functions: void xyztoh(float x,float y,float z,float *h) { if (x == 0.0 && z == 0.0) *h = 0.0; else { if (z == 0.0) *h = (x < 0.0) ? HALFPI : -HALFPI; else if (z < 0.0) *h = -atan(x / z) + PI; else *h = -atan(x / z); } } void xyztohp(float x,float y,float z,float *h,float *p) { if (x == 0.0 && z == 0.0) { *h = 0.0; if (y != 0.0) *p = (y < 0.0) ? -HALFPI : HALFPI; else *p = 0.0; } else { if (z == 0.0) *h = (x < 0.0) ? HALFPI : -HALFPI; else if (z < 0.0) *h = -atan(x / z) + PI; else *h = -atan(x / z); x = sqrt(x * x + z * z); if (x == 0.0) *p = (y < 0.0) ? -HALFPI : HALFPI; else *p = atan(y / x); } }