PDA

View Full Version : my tangents?



Lurking
01-22-2004, 12:48 PM
It seems that my tangents and binormals are wrong from what i understand. The vertex part of the light seems to work (ie the triangle is shaded correctly when moved through the lights) but the bumps arn't shading correctly. They seem almost static. Bumps show but the lighting doesn't seem to be updating itself on the bumps. If you could see if there is a problem with the way i generate my tangents and binormals that would help me out alot.




void md2::calcTB(int frame){
for(int verts = 0; verts < theHeader->iNumVerts;verts++){
vector a,b,c;
vector temp3,temp4;
vector temp1,temp2;
float deltaA,deltaB;
for(int k = 0; k < lShared[verts].num;k++){

a.setStruct(theFrames[frame].verts[theTriangles[lShared[verts].index[k]].usVertIndices[0]].vert);
b.setStruct(theFrames[frame].verts[theTriangles[lShared[verts].index[k]].usVertIndices[1]].vert);
c.setStruct(theFrames[frame].verts[theTriangles[lShared[verts].index[k]].usVertIndices[2]].vert);

temp1 = b - a;
temp2 = c - a;

deltaA = (theTexCoords[theTriangles[lShared[verts].index[k]].usTexIndices[1]].coord[0] -
theTexCoords[theTriangles[lShared[verts].index[k]].usTexIndices[0]].coord[0]);
deltaB = (theTexCoords[theTriangles[lShared[verts].index[k]].usTexIndices[2]].coord[0] -
theTexCoords[theTriangles[lShared[verts].index[k]].usTexIndices[0]].coord[0]);
}
tangents[verts].setX((deltaA * temp1.getX())-(deltaB * temp2.getX()));
tangents[verts].setY((deltaA * temp1.getY())-(deltaB * temp2.getY()));
tangents[verts].setZ((deltaA * temp1.getZ())-(deltaB * temp2.getZ()));

binormals[verts] = tangents[verts].cross(normals[verts]);

}

}


Im using a md2 for the model. Thanks!

[This message has been edited by dorbie (edited 01-22-2004).]

SirKnight
01-22-2004, 02:56 PM
Take a look at this discussion, it may help: http://www.opengl.org/discussion_boards/ubb/Forum3/HTML/011349.html

In particular, look at the second to last post by Eric.


BTW Eric if you read this, I just got your book (second editon math for 3d games/gfx prog.)! http://www.opengl.org/discussion_boards/ubb/biggrin.gif Should be here in a few days, can't wait! http://www.opengl.org/discussion_boards/ubb/smile.gif


-SirKnight

Eric Lengyel
01-22-2004, 04:33 PM
Great!

Lurking
01-22-2004, 06:05 PM
Thanks that looks like it should help me out alot. When i get home ill have to mess with it.