• 关于normal,binormal,tangent的计算


    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     }

               

      

  • 相关阅读:
    PHP编程基础学习(一)——数据类型
    6-6 带头结点的链式表操作集(20 分)
    6-5 链式表操作集(20 分)
    6-4 链式表的按序号查找(10 分)
    6-3 求链式表的表长(10 分)
    6-2 顺序表操作集(20 分)
    6-1 单链表逆转(20 分)
    学生成绩管理系统(六):项目总结
    学生成绩管理系统(五):系统的完善与数据库的链接
    学生成绩管理系统(四)
  • 原文地址:https://www.cnblogs.com/ThreeThousandBigWorld/p/2593892.html
Copyright © 2020-2023  润新知