Fichier texte en cours : TNB.txt
[code language="cpp"]
void ComputeTangentBasis(const D3DXVECTOR3& P1, const D3DXVECTOR3& P2,
const D3DXVECTOR3& P3, const D3DXVECTOR2& UV1,
const D3DXVECTOR2& UV2, const D3DXVECTOR2& UV3,
D3DXVECTOR3 &tangent, D3DXVECTOR3 &bitangent)
{
D3DXVECTOR3 Edge1 = P2 - P1;
D3DXVECTOR3 Edge2 = P3 - P1;
D3DXVECTOR2 Edge1uv = UV2 - UV1;
D3DXVECTOR2 Edge2uv = UV3 - UV1;
float cp = Edge1uv.y * Edge2uv.x - Edge1uv.x * Edge2uv.y;
if ( cp != 0.0f )
{
float mul = 1.0f / cp;
Tangent = (Edge1 * -Edge2uv.y + Edge2 * Edge1uv.y) * mul;
Bitangent = (Edge1 * -Edge2uv.x + Edge2 * Edge1uv.x) * mul;
D3DXVEC3Normalize(&Tangent, &Tangent);
D3DXVEC3Normalize(&Bitangent, &Bitangent);
}
}
[/code]