• (转)Ogre中计算Tangent, 感觉很不错!


    代码
    Vector3 Math::calculateTangentSpaceVector(
     
    const Vector3& position1, const Vector3& position2, const Vector3& position3,
     Real u1, Real v1, Real u2, Real v2, Real u3, Real v3)
     {
       
    //side0 is the vector along one side of the triangle of vertices passed in, 
       
    //and side1 is the vector along another side. Taking the cross product of these returns the normal.
       Vector3 side0 = position1 - position2;
       Vector3 side1 
    = position3 - position1;
       
    //Calculate face normal
       Vector3 normal = side1.crossProduct(side0);
       normal.normalise();
       
    //Now we use a formula to calculate the tangent. 
       Real deltaV0 = v1 - v2;
       Real deltaV1 
    = v3 - v1;
       Vector3 tangent 
    = deltaV1 * side0 - deltaV0 * side1;
       tangent.normalise();
       
    //Calculate binormal
       Real deltaU0 = u1 - u2;
       Real deltaU1 
    = u3 - u1;
       Vector3 binormal 
    = deltaU1 * side0 - deltaU0 * side1;
       binormal.normalise();
       
    //Now, we take the cross product of the tangents to get a vector which 
       
    //should point in the same direction as our normal calculated above. 
       
    //If it points in the opposite direction (the dot product between the normals is less than zero), 
       
    //then we need to reverse the s and t tangents. 
       
    //This is because the triangle has been mirrored when going from tangent space to object space.
       
    //reverse tangents if necessary
       Vector3 tangentCross = tangent.crossProduct(binormal);
       
    if (tangentCross.dotProduct(normal) < 0.0f)
       {
         tangent 
    = -tangent;
         binormal 
    = -binormal;
       }

     
    return tangent;

     }
  • 相关阅读:
    我说AOP(面向切面编程)--藏在苹果里的五角星
    mysql workbench 一个‘愚蠢’的设计
    .Net MVC Json 日期格式
    es6 import
    asp.net mvc 模型绑定太糙淡了
    asp.net mvc 报错 CS1617: Invalid option ‘6’ for /langversion; must be ISO-1, ISO-2, 3, 4, 5 or Default
    撸代码时到底用var好还是强类型变量好
    iphone5 从ios7升级到最新9.2
    修复win7 只有IE64 能上网 其他浏览器及应用都无法联网
    使用Teleri 导出实体类数组到Excel
  • 原文地址:https://www.cnblogs.com/lancidie/p/1846442.html
Copyright © 2020-2023  润新知