Original Post
I'm importing LightWave LWO files into my OpenGL 3D viewer. As texture coordinates themselves are not stored in the LWO file, I need to generate texture coordinates manually (using planar mapping) for every vertex of a polygon, given axis of projection (either X, Y or Z), texture width/height and texture u/v offsets. These are the only information found in the LWO file. Is there good simple algorithm for this?
I tried using following code but soon realized that it is only ideal for those who are writing their own rasterizer from scratch, as it only returns U/V values in range [0..1[, ie. for every texel on polygon's surface, but never 1.0.
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);
}
[edited by - Arkion on February 3, 2004 11:26:47 AM]