Re: Jasoco's 3D Model Extravaganza.. NOTHING IS "NORMAL" ANYMORE
Posted: Sat Mar 13, 2010 7:38 am
If I read your code correctly, you are calculating the cross product from the point coordinates of the triangles. You should instead calculate them from the coordinates of the vectors you get from subtracting the triangles' corner coordinates. These are the edge vectors of the triangle.
You can pick any two edges of the triangle for this, as long as they are not the same. You may get the negation of the normal vector that the format uses if you pick a different order to do the calculations in, but you can easily see if that happens by comparing the expected values with the ones you get.
Actually, it seems the values I got from some experiments differ slightly from the NORM values in the model file. The difference is on the order of a few hundreths of a coordinate unit.
So, to sum up: You have three points defining a triangle--p1 p2 and p3. Calculate the vectors (p2-p1) and (p3-p1) and do their cross product. That is the normal you are looking for. Or if it is not, then using them in the order (p3-p1) and (p2-p1) should be.
You can pick any two edges of the triangle for this, as long as they are not the same. You may get the negation of the normal vector that the format uses if you pick a different order to do the calculations in, but you can easily see if that happens by comparing the expected values with the ones you get.
Actually, it seems the values I got from some experiments differ slightly from the NORM values in the model file. The difference is on the order of a few hundreths of a coordinate unit.
So, to sum up: You have three points defining a triangle--p1 p2 and p3. Calculate the vectors (p2-p1) and (p3-p1) and do their cross product. That is the normal you are looking for. Or if it is not, then using them in the order (p3-p1) and (p2-p1) should be.