Beispiel #1
0
 public static float3x3 GenValid3x3FromVectorWithLength(float3 facing)
 {
     float3 perp1, perp2;
     if (System.Math.Abs(facing.x) > System.Math.Abs(facing.z))
     {
         perp1 = facing.Cross(new float3(0, 0, 1));
     }
     else
     {
         perp1 = facing.Cross(new float3(1, 0, 0));
     }
     perp2 = perp1.Cross(facing);
     return new float3x3(facing, perp1.Normalize(), perp2.Normalize());
 }
Beispiel #2
0
        public float4x4 OrthogonalBasis(float3 zaxis)
        {
            // from PBRT p54
            float3 basisU;
            if( System.Math.Abs(zaxis.x) > System.Math.Abs(zaxis.y) )
            {
                float invLen = 1.0f / (float)System.Math.Sqrt((zaxis.x*zaxis.x) + (zaxis.z*zaxis.z));
                basisU = new float3(-zaxis.z * invLen, 0.0f, zaxis.x * invLen);
            }
            else
            {
                float invLen = 1.0f / (float)System.Math.Sqrt((zaxis.y*zaxis.y) + (zaxis.z*zaxis.z));
                basisU = new float3(0.0f, zaxis.z * invLen, -zaxis.y * invLen);
            }
            float3 basisV = zaxis.Cross(basisU);

            float4x4 ret = Identity();
            ret.m[0,0] = basisU.x;
            ret.m[0,1] = basisU.y;
            ret.m[0,2] = basisU.z;
            ret.m[1,0] = basisV.x;
            ret.m[1,1] = basisV.y;
            ret.m[1,2] = basisV.z;
            ret.m[2,0] = zaxis.x;
            ret.m[2,1] = zaxis.y;
            ret.m[2,2] = zaxis.z;

            return ret;
        }
Beispiel #3
0
 public static float3x3 Basis(float3 z)
 {
     // from PBRT p54
     float3 basisU;
     if (System.Math.Abs(z.x) > System.Math.Abs(z.y))
     {
         float invLen = 1.0f / (float)System.Math.Sqrt((z.x * z.x) + (z.z * z.z));
         basisU = new float3(-z.z * invLen, 0.0f, z.x * invLen);
     }
     else
     {
         float invLen = 1.0f / (float)System.Math.Sqrt((z.y * z.y) + (z.z * z.z));
         basisU = new float3(0.0f, z.z * invLen, -z.y * invLen);
     }
     float3 basisV = z.Cross(basisU);
     return new float3x3(basisU, basisV, z);
 }