It is currently Fri May 31, 2024 6:15 am





Gary wrote:You could look at the HL2 beta leak code. I would assume it hasn't changed since then.

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:
- Code: Select all
u = tv0,0 * x + tv0,1 * y + tv0,2 * z + tv0,3
v = tv1,0 * x + tv1,1 * y + tv1,2 * z + tv1,3
(ie. The dot product of the vectors with the vertex plus the offset in that direction. Where tvA,B is textureVecs[A][B].
Furthermore, after calculating (u, v), to convert them to texture coordinates which you would send to your graphics card, divide u and v by the width and height of the texture respectively.


point 0 - (0,0,0)
point 1 - (1,0,0)
point 2 - (0,0,1)
point 3 - (1,0,1)float tv[2][4]; // textureVecs
tv[0][0] = 1f; // s
tv[0][1] = 0f; // x
tv[0][2] = 0f; // y
tv[0][3] = 0f; // z
tv[1][0] = 1f; // t
tv[1][1] = 0f; // x
tv[1][2] = 0f; // y
tv[1][3] = 0f; // z
float x = 0f, y = 0f, z = 0f;
u = tv[0][0] * x + tv[0][1] * y + tv[0][2] * z + tv[0][3];
v = tv[1][0] * x + tv[1][1] * y + tv[1][2] * z + tv[1][3];

Users browsing this forum: No registered users