normal:
三角面normal:
v0,v1,v2三个顶点
vN = normal((v1-v0)corss(v2-v1));叉乘的顺序决定了vN的z
定点normal:
v1 = normalize(a-b);
v2 = normalize(a-c);
normalWeight = acos(dot(v1,v2));
normal = 0,0,0
totalWeight = 0
for:所有共定点的面的法线和
normal += trangleNormal * normalWeight;
totalWeight += normalWeight
finalNormal = normal/totalWeight;
binormal abd tangent:
来自OGRE的函数
1 Vector3 Math::calculateTangentSpaceVector( 2 const Vector3& position1, const Vector3& position2, const Vector3& position3, 3 Real u1, Real v1, Real u2, Real v2, Real u3, Real v3) 4 { 5 //side0 is the vector along one side of the triangle of vertices passed in, 6 //and side1 is the vector along another side. Taking the cross product of these returns the normal. 7 Vector3 side0 = position1 - position2; 8 Vector3 side1 = position3 - position1; 9 //Calculate face normal 10 Vector3 normal = side1.crossProduct(side0); 11 normal.normalise(); 12 //Now we use a formula to calculate the tangent. 13 Real deltaV0 = v1 - v2; 14 Real deltaV1 = v3 - v1; 15 Vector3 tangent = deltaV1 * side0 - deltaV0 * side1; 16 tangent.normalise(); 17 //Calculate binormal 18 Real deltaU0 = u1 - u2; 19 Real deltaU1 = u3 - u1; 20 Vector3 binormal = deltaU1 * side0 - deltaU0 * side1; 21 binormal.normalise(); 22 //Now, we take the cross product of the tangents to get a vector which 23 //should point in the same direction as our normal calculated above. 24 //If it points in the opposite direction (the dot product between the normals is less than zero), 25 //then we need to reverse the s and t tangents. 26 //This is because the triangle has been mirrored when going from tangent space to object space. 27 //reverse tangents if necessary 28 Vector3 tangentCross = tangent.crossProduct(binormal); 29 if (tangentCross.dotProduct(normal) < 0.0f) 30 { 31 tangent = -tangent; 32 binormal = -binormal; 33 } 34 35 return tangent; 36 37 }