I thought u,v are in world space and s,t are in texture coords.
Zitat: The texinfo lump (6) contains an array of texinfo_t structures:
typedef struct texinfo_s { float textureVecsTexelsPerWorldUnits[2][4]; // [s/t][xyz offset] float lightmapVecsLuxelsPerWorldUnits[2][4]; // [s/t][xyz offset] - length is in units of texels/area int flags; // miptex flags + overrides int texdata; // Pointer to texture name, size, etc. } texinfo_t;
Each texinfo is 72 bytes long.
The first array of floats is in essence two vectors that represent how the texture is orientated and scaled when rendered on the world geometry. The two vectors, s and t, are the mapping of the left-to-right and down-to-up directions in the texture pixel coordinate space, onto the world. Each vector has an x, y, and z component, plus an offset which is the "shift" of the texture in that direction relative to the world. The length of the vectors represent the scaling of the texture in each direction.
The 2D coordinates (u, v) of a texture pixel (or texel) are mapped to the world coordinates (x, y, z) of a point on a face by: u = tv0,0 . x + tv0,1 . y + tv0,2 . z + tv0,3 v = tv1,0 . x + tv1,1 . y + tv1,2 . z + tv1,3
where tvA,B is textureVecs[A][B].
The U,V calculation uses the Vertex's position which doesn't give s,t coords. (Insted of having a nice texture its basicaly one colour).
Code: P := {Normalize2}(RenderVerts[rendervertno].Position); RenderVerts[rendervertno].TextureCoord.X := (TexInfo[Faces[x].TexInfo].TextureVects[0][0] * P.X + TexInfo[Faces[x].TexInfo].TextureVects[0][1] * P.Y + TexInfo[Faces[x].TexInfo].TextureVects[0][2] * P.Z) + TexInfo[Faces[x].TexInfo].TextureVects[0][3]; RenderVerts[rendervertno].TextureCoord.Y := (TexInfo[Faces[x].TexInfo].TextureVects[1][0] * P.X + TexInfo[Faces[x].TexInfo].TextureVects[1][1] * P.Y + TexInfo[Faces[x].TexInfo].TextureVects[1][2] * P.Z) + TexInfo[Faces[x].TexInfo].TextureVects[1][3];
The above code gives the following result:

The best i can get it is with the following code:
Code: RenderVerts[rendervertno].TextureCoord.Y := (TexInfo[Faces[x].TexInfo].TextureVects[0][0] * P.X + TexInfo[Faces[x].TexInfo].TextureVects[0][1] * P.Y + TexInfo[Faces[x].TexInfo].TextureVects[0][2] * P.Z)/TexData[TexInfo[Faces[x].TexInfo].texdata].Height + TexInfo[Faces[x].TexInfo].TextureVects[0][3]; RenderVerts[rendervertno].TextureCoord.X := -(TexInfo[Faces[x].TexInfo].TextureVects[1][0] * P.X + TexInfo[Faces[x].TexInfo].TextureVects[1][1] * P.Y + TexInfo[Faces[x].TexInfo].TextureVects[1][2] * P.Z)/TexData[TexInfo[Faces[x].TexInfo].texdata].Width + TexInfo[Faces[x].TexInfo].TextureVects[1][3];
|