- if (svector3f)
- for (i = 0;i < 3;i++)
- VectorAdd(svector3f + e[i]*3, sdir, svector3f + e[i]*3);
- if (tvector3f)
- for (i = 0;i < 3;i++)
- VectorAdd(tvector3f + e[i]*3, tdir, tvector3f + e[i]*3);
- if (normal3f)
- for (i = 0;i < 3;i++)
- VectorAdd(normal3f + e[i]*3, normal, normal3f + e[i]*3);
+ for (i = 0;i < 3;i++)
+ {
+ VectorAdd(svector3f + e[i]*3, sdir, svector3f + e[i]*3);
+ VectorAdd(tvector3f + e[i]*3, tdir, tvector3f + e[i]*3);
+ }
+ }
+ // make the tangents completely perpendicular to the surface normal, and
+ // then normalize them
+ // 16 assignments, 2 divide, 2 sqrt, 2 negates, 14 adds, 24 multiplies
+ for (i = 0, sv = svector3f + 3 * firstvertex, tv = tvector3f + 3 * firstvertex, n = normal3f + 3 * firstvertex;i < numvertices;i++, sv += 3, tv += 3, n += 3)
+ {
+ f = -DotProduct(sv, n);
+ VectorMA(sv, f, n, sv);
+ VectorNormalize(sv);
+ f = -DotProduct(tv, n);
+ VectorMA(tv, f, n, tv);
+ VectorNormalize(tv);