Skip to content

Commit

Permalink
tangent vector fix
Browse files Browse the repository at this point in the history
git-svn-id: https://sauerbraten.svn.sourceforge.net/svnroot/sauerbraten@3660 ac1f7847-fce6-4368-a212-70e9bdee79d4
  • Loading branch information
eihrul committed Aug 16, 2011
1 parent abbabd2 commit ad516d0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
16 changes: 10 additions & 6 deletions src/engine/animmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -449,12 +449,16 @@ struct animmodel : model
&tc1 = tcverts[t.vert[1]],
&tc2 = tcverts[t.vert[2]];
float u1 = tc1.u - tc0.u, v1 = tc1.v - tc0.v,
u2 = tc2.u - tc0.u, v2 = tc2.v - tc0.v,
scale = u1*v2 - u2*v1;
if(scale!=0) scale = 1.0f / scale;
vec u(e1), v(e2);
u.mul(v2).sub(vec(e2).mul(v1)).mul(scale);
v.mul(u1).sub(vec(e1).mul(u2)).mul(scale);
u2 = tc2.u - tc0.u, v2 = tc2.v - tc0.v;
vec u(e2), v(e2);
u.mul(v1).sub(vec(e1).mul(v2));
v.mul(u1).sub(vec(e1).mul(u2));

if(vec().cross(e2, e1).dot(vec().cross(v, u)) < 0)
{
u.neg();
v.neg();
}

if(!areaweight)
{
Expand Down
3 changes: 1 addition & 2 deletions src/engine/iqm.h
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,7 @@ struct iqm : skelmodel, skelloader<iqm>
{
bumpvert &bv = m->bumpverts[j];
loopk(3) bv.tangent[k] = vtan[4*fj + k];
bv.tangent.x = -bv.tangent.x;
bv.tangent.z = -bv.tangent.z;
bv.tangent.y = -bv.tangent.y;
bv.bitangent = vtan[4*fj + 3];
}
}
Expand Down

0 comments on commit ad516d0

Please sign in to comment.