Tangent space calculation

Started by
1 comment, last by Ruggostein 14 years ago
I'm implementing tangent space calculation using the code from http://www.terathon.com/code/tangent.html However, for example, when applying the function to a cube, every tangent vector is (0,0,0). I found that this is because of this line tangent[a] = (t - n * Dot(n, t)).Normalize(); The tangent vector is perpendicular to the normal vector, and the dot product of both is zero, this nullifies all tangents in the mesh. Also for more complex meshes this also happens (but only for some triangles). Help?
Advertisement
Quote:
tangent[a] = (t - n * Dot(n, t)).Normalize();

The tangent vector is perpendicular to the normal vector, and the dot product of both is zero, this nullifies all tangents in the mesh.


Are you sure? If n and t are orthogonal then (n * Dot(n, t)) is 0, and you get:

(t - 0).Normalize() = t.Normalize() which should not be 0 unless t was 0 to begin with (which would be a bug somewhere else).


All that code does is orthogonalize n and t in case they aren't already orthogonal.
-----Quat
Ahh, thank you, I found the problem thanks to you.
I was messing up the order of the operations, doing the subtraction before the dot product!

This topic is closed to new replies.

Advertisement