Hi, I’m having trouble figuring out the tangent vector for bsp code in the project I’m working in. I’m trying to rewrite my Simple Tangent Calculation using the following verts. I need help on how to write a CalculateTangent function with this vert array to get a tangent vector. I’m only 17 so please be patient with me
// Simple Tangent Calculation Example
// v[0...2] vertex position
// t[0...2] texcoords
// tan.xyz = (v1-v0).xyz * (t2-t0).y - (v2-v0).xyz * (t1-t0).y;
// Write above into a CalculateTangent() func using
// Variables described below:
// #define VERTEXSIZE 9 //xyz s1t1 s2t2 s3t3
// where xyz = vert coords; s1t1 = normal tex coords;
// s2t2 = lightmap tex coords; s3t2 = detail tex coords
// s->polys->verts (float verts[4][9]) - variable sized (xyz s1t1 s2t2)
// Additional Variables of Interest:
// s->texinfo->vecs (float vecs[2][4]) - [s/t][xyz offset]
// s->plane->normal (float normal[3]) - plane normal
// Pass the Tangent to the Vertex Shader using an attribute 3fv:
// attribute3fv("tangent", tan);
// BSP Render Code:
for ( ; s; s = s->texturechain) {
v = s->polys->verts[0];
glBegin(GL_POLYGON);
for (k = 0; k < s->polys->numverts; k++, v += VERTEXSIZE) {
glMultiTexCoord2fARB (GL_TEXTURE0_ARB, v[3], v[4]);
if (s->flags & SURF_PLANEBACK)
glNormal3fv(-s->plane->normal);
else
glNormal3fv(s->plane->normal);
glVertex3fv (v);
}
glEnd ();
}
This is the best I could come up with so far. Part of the problem I see with this method is there is often more than 3 verts per polygon of which I’m not sure how I account for. Can anyone give me some direction or let me know if I’m on the right track please.