예제 #1
0
 public FMat4(FVec4 x, FVec4 y, FVec4 z, FVec4 w)
 {
     this.x = x;
     this.y = y;
     this.z = z;
     this.w = w;
 }
예제 #2
0
        public static FMat4 FromQuaternion(FQuat quaternion)
        {
            FVec4 squared = new FVec4(quaternion.x * quaternion.x, quaternion.y * quaternion.y, quaternion.z * quaternion.z,
                                      quaternion.w * quaternion.w);
            Fix64 invSqLength = Fix64.One / (squared.x + squared.y + squared.z + squared.w);

            Fix64 temp1 = quaternion.x * quaternion.y;
            Fix64 temp2 = quaternion.z * quaternion.w;
            Fix64 temp3 = quaternion.x * quaternion.z;
            Fix64 temp4 = quaternion.y * quaternion.w;
            Fix64 temp5 = quaternion.y * quaternion.z;
            Fix64 temp6 = quaternion.x * quaternion.w;

            return(new FMat4
                   (
                       new FVec4((squared.x - squared.y - squared.z + squared.w) * invSqLength,
                                 Fix64.Two * (temp1 + temp2) * invSqLength,
                                 Fix64.Two * (temp3 - temp4) * invSqLength,
                                 Fix64.Zero),
                       new FVec4(Fix64.Two * (temp1 - temp2) * invSqLength,
                                 (-squared.x + squared.y - squared.z + squared.w) * invSqLength,
                                 Fix64.Two * (temp5 + temp6) * invSqLength,
                                 Fix64.Zero),
                       new FVec4(Fix64.Two * (temp3 + temp4) * invSqLength,
                                 Fix64.Two * (temp5 - temp6) * invSqLength,
                                 (-squared.x - squared.y + squared.z + squared.w) * invSqLength,
                                 Fix64.Zero),
                       new FVec4(Fix64.Zero, Fix64.Zero, Fix64.Zero, Fix64.One)
                   ));
        }
예제 #3
0
 public static void SetFVec4(this Hashtable ht, string key, FVec4 v)
 {
     float[] al = new float[3];
     al[0]   = ( float )v.x;
     al[1]   = ( float )v.y;
     al[2]   = ( float )v.z;
     al[3]   = ( float )v.w;
     ht[key] = al;
 }
예제 #4
0
        public void Invert()
        {
            Fix64 determinant = Fix64.One / this.Determinant();

            Fix64 m00 = (this.y.y * this.z.z * this.w.w + this.y.z * this.z.w * this.w.y + this.y.w * this.z.y * this.w.z -
                         this.y.y * this.z.w * this.w.z - this.y.z * this.z.y * this.w.w - this.y.w * this.z.z * this.w.y) * determinant;
            Fix64 m01 = (this.x.y * this.z.w * this.w.z + this.x.z * this.z.y * this.w.w + this.x.w * this.z.z * this.w.y -
                         this.x.y * this.z.z * this.w.w - this.x.z * this.z.w * this.w.y - this.x.w * this.z.y * this.w.z) * determinant;
            Fix64 m02 = (this.x.y * this.y.z * this.w.w + this.x.z * this.y.w * this.w.y + this.x.w * this.y.y * this.w.z -
                         this.x.y * this.y.w * this.w.z - this.x.z * this.y.y * this.w.w - this.x.w * this.y.z * this.w.y) * determinant;
            Fix64 m03 = (this.x.y * this.y.w * this.z.z + this.x.z * this.y.y * this.z.w + this.x.w * this.y.z * this.z.y -
                         this.x.y * this.y.z * this.z.w - this.x.z * this.y.w * this.z.y - this.x.w * this.y.y * this.z.z) * determinant;

            Fix64 m10 = (this.y.x * this.z.w * this.w.z + this.y.z * this.z.x * this.w.w + this.y.w * this.z.z * this.w.x -
                         this.y.x * this.z.z * this.w.w - this.y.z * this.z.w * this.w.x - this.y.w * this.z.x * this.w.z) * determinant;
            Fix64 m11 = (this.x.x * this.z.z * this.w.w + this.x.z * this.z.w * this.w.x + this.x.w * this.z.x * this.w.z -
                         this.x.x * this.z.w * this.w.z - this.x.z * this.z.x * this.w.w - this.x.w * this.z.z * this.w.x) * determinant;
            Fix64 m12 = (this.x.x * this.y.w * this.w.z + this.x.z * this.y.x * this.w.w + this.x.w * this.y.z * this.w.x -
                         this.x.x * this.y.z * this.w.w - this.x.z * this.y.w * this.w.x - this.x.w * this.y.x * this.w.z) * determinant;
            Fix64 m13 = (this.x.x * this.y.z * this.z.w + this.x.z * this.y.w * this.z.x + this.x.w * this.y.x * this.z.z -
                         this.x.x * this.y.w * this.z.z - this.x.z * this.y.x * this.z.w - this.x.w * this.y.z * this.z.x) * determinant;

            Fix64 m20 = (this.y.x * this.z.y * this.w.w + this.y.y * this.z.w * this.w.x + this.y.w * this.z.x * this.w.y -
                         this.y.x * this.z.w * this.w.y - this.y.y * this.z.x * this.w.w - this.y.w * this.z.y * this.w.x) * determinant;
            Fix64 m21 = (this.x.x * this.z.w * this.w.y + this.x.y * this.z.x * this.w.w + this.x.w * this.z.y * this.w.x -
                         this.x.x * this.z.y * this.w.w - this.x.y * this.z.w * this.w.x - this.x.w * this.z.x * this.w.y) * determinant;
            Fix64 m22 = (this.x.x * this.y.y * this.w.w + this.x.y * this.y.w * this.w.x + this.x.w * this.y.x * this.w.y -
                         this.x.x * this.y.w * this.w.y - this.x.y * this.y.x * this.w.w - this.x.w * this.y.y * this.w.x) * determinant;
            Fix64 m23 = (this.x.x * this.y.w * this.z.y + this.x.y * this.y.x * this.z.w + this.x.w * this.y.y * this.z.x -
                         this.x.x * this.y.y * this.z.w - this.x.y * this.y.w * this.z.x - this.x.w * this.y.x * this.z.y) * determinant;

            Fix64 m30 = (this.y.x * this.z.z * this.w.y + this.y.y * this.z.x * this.w.z + this.y.z * this.z.y * this.w.x -
                         this.y.x * this.z.y * this.w.z - this.y.y * this.z.z * this.w.x - this.y.z * this.z.x * this.w.y) * determinant;
            Fix64 m31 = (this.x.x * this.z.y * this.w.z + this.x.y * this.z.z * this.w.x + this.x.z * this.z.x * this.w.y -
                         this.x.x * this.z.z * this.w.y - this.x.y * this.z.x * this.w.z - this.x.z * this.z.y * this.w.x) * determinant;
            Fix64 m32 = (this.x.x * this.y.z * this.w.y + this.x.y * this.y.x * this.w.z + this.x.z * this.y.y * this.w.x -
                         this.x.x * this.y.y * this.w.z - this.x.y * this.y.z * this.w.x - this.x.z * this.y.x * this.w.y) * determinant;
            Fix64 m33 = (this.x.x * this.y.y * this.z.z + this.x.y * this.y.z * this.z.x + this.x.z * this.y.x * this.z.y -
                         this.x.x * this.y.z * this.z.y - this.x.y * this.y.x * this.z.z - this.x.z * this.y.y * this.z.x) * determinant;

            this.x.x = m00;
            this.x.y = m01;
            this.x.z = m02;
            this.x.w = m03;
            this.y.x = m10;
            this.y.y = m11;
            this.y.z = m12;
            this.y.w = m13;
            this.z.x = m20;
            this.z.y = m21;
            this.z.z = m22;
            this.z.w = m23;
            this.w.x = m30;
            this.w.y = m31;
            this.w.z = m32;
            this.w.w = m33;
        }
예제 #5
0
 public FVec4 Transform(FVec4 v)
 {
     return(new FVec4
            (
                v.x * this.x.x + v.y * this.y.x + v.z * this.z.x + v.w * this.w.x,
                v.x * this.x.y + v.y * this.y.y + v.z * this.z.y + v.w * this.w.y,
                v.x * this.x.z + v.y * this.y.z + v.z * this.z.z + v.w * this.w.z,
                v.x * this.x.w + v.y * this.y.w + v.z * this.z.w + v.w * this.w.w
            ));
 }
예제 #6
0
        public static FMat4 NonhomogeneousInverse(FMat4 m)
        {
            FMat3 m3 = m;

            m3.Invert();
            FMat4 o = m3;
            FVec4 v = m3 * m.w;

            o.w.x = -v.x;
            o.w.y = -v.y;
            o.w.z = -v.z;
            return(o);
        }
예제 #7
0
        public void NonhomogeneousInverse()
        {
            FMat3 m3 = this;

            m3.Invert();
            this.x = m3.x;
            this.y = m3.y;
            this.z = m3.z;
            FVec4 v = m3 * this.w;

            this.w.x = -v.x;
            this.w.y = -v.y;
            this.w.z = -v.z;
        }
예제 #8
0
 public void Identity()
 {
     this.x.x = Fix64.One;
     this.x.y = Fix64.Zero;
     this.x.z = Fix64.Zero;
     this.x.w = Fix64.Zero;
     this.y.x = Fix64.Zero;
     this.y.y = Fix64.One;
     this.y.z = Fix64.Zero;
     this.y.w = Fix64.Zero;
     this.z.x = Fix64.Zero;
     this.z.y = Fix64.Zero;
     this.z.z = Fix64.One;
     this.z.w = Fix64.Zero;
     this.w.x = Fix64.Zero;
     this.w.y = Fix64.Zero;
     this.w.z = Fix64.Zero;
     this.w.w = Fix64.One;
 }
예제 #9
0
        public void Transpose()
        {
            Fix64 m00 = this.x.x;
            Fix64 m01 = this.y.x;
            Fix64 m02 = this.z.x;
            Fix64 m03 = this.w.x;
            Fix64 m10 = this.x.y;
            Fix64 m11 = this.y.y;
            Fix64 m12 = this.z.y;
            Fix64 m13 = this.w.y;
            Fix64 m20 = this.x.z;
            Fix64 m21 = this.y.z;
            Fix64 m22 = this.z.z;
            Fix64 m23 = this.w.z;
            Fix64 m30 = this.x.w;
            Fix64 m31 = this.y.w;
            Fix64 m32 = this.z.w;
            Fix64 m33 = this.w.w;

            this.x.x = m00;
            this.x.y = m01;
            this.x.z = m02;
            this.x.w = m03;
            this.y.x = m10;
            this.y.y = m11;
            this.y.z = m12;
            this.y.w = m13;
            this.z.x = m20;
            this.z.y = m21;
            this.z.z = m22;
            this.z.w = m23;
            this.w.x = m30;
            this.w.y = m31;
            this.w.z = m32;
            this.w.w = m33;
        }
예제 #10
0
 public static FMat4 Abs(FMat4 m)
 {
     return(new FMat4(FVec4.Abs(m.x), FVec4.Abs(m.y), FVec4.Abs(m.z), FVec4.Abs(m.w)));
 }
예제 #11
0
 public static Vector4 ToVector4(this FVec4 v)
 {
     return(new Vector4(( float )v.x, ( float )v.y, ( float )v.z, ( float )v.w));
 }