Exemplo n.º 1
0
        public static FMat3 Invert(FMat3 m)
        {
            Fix64 determinant = Fix64.One / m.Determinant();

            return(new FMat3
                   (
                       new FVec3
                       (
                           (m.y.y * m.z.z - m.y.z * m.z.y) * determinant,
                           (m.x.z * m.z.y - m.z.z * m.x.y) * determinant,
                           (m.x.y * m.y.z - m.y.y * m.x.z) * determinant
                       ),
                       new FVec3
                       (
                           (m.y.z * m.z.x - m.y.x * m.z.z) * determinant,
                           (m.x.x * m.z.z - m.x.z * m.z.x) * determinant,
                           (m.x.z * m.y.x - m.x.x * m.y.z) * determinant
                       ),
                       new FVec3
                       (
                           (m.y.x * m.z.y - m.y.y * m.z.x) * determinant,
                           (m.x.y * m.z.x - m.x.x * m.z.y) * determinant,
                           (m.x.x * m.y.y - m.x.y * m.y.x) * determinant
                       )
                   ));
        }
Exemplo n.º 2
0
 public static FMat3 Transpose(FMat3 m)
 {
     return(new FMat3
            (
                new FVec3(m.x.x, m.y.x, m.z.x),
                new FVec3(m.x.y, m.y.y, m.z.y),
                new FVec3(m.x.z, m.y.z, m.z.z)
            ));
 }
Exemplo n.º 3
0
        public static FMat3 NonhomogeneousInverse(FMat3 m)
        {
            FMat2 m2 = m;

            m2.Invert();
            FMat3 o = m2;
            FVec3 v = m2 * m.z;

            o.z.x = -v.x;
            o.z.y = -v.y;
            return(o);
        }
Exemplo n.º 4
0
        public void Matrix3()
        {
            FMat3 fm  = FMat3.FromQuaternion(FQuat.Euler(( Fix64 )30, ( Fix64 )(-20), ( Fix64 )49.342f));
            Mat3  m   = Mat3.FromQuaternion(Quat.Euler(30, -20, 49.342f));
            FVec3 fv  = new FVec3(12.5f, 9, 8);
            FVec3 fv2 = new FVec3(4, 6, 9);
            Vec3  v   = new Vec3(12.5f, 9, 8);
            Vec3  v2  = new Vec3(4, 6, 9);

            fv  = fm.TransformPoint(fv);
            fv2 = fm.TransformVector(fv2);
            v   = m.TransformPoint(v);
            v2  = m.TransformVector(v2);
            this._output.WriteLine(fm.ToString());
            this._output.WriteLine(m.ToString());
            this._output.WriteLine(fv.ToString());
            this._output.WriteLine(fv2.ToString());
            this._output.WriteLine(v.ToString());
            this._output.WriteLine(v2.ToString());
            fm = FMat3.LookAt(fv, fv2);
            m  = Mat3.LookAt(v, v2);
            this._output.WriteLine(fm.ToString());
            this._output.WriteLine(m.ToString());
            fv = fm.Euler();
            v  = m.Euler();
            this._output.WriteLine(fv.ToString());
            this._output.WriteLine(v.ToString());
            fm = FMat3.FromEuler(fv);
            m  = Mat3.FromEuler(v);
            this._output.WriteLine(fm.ToString());
            this._output.WriteLine(m.ToString());
            fm = FMat3.FromScale(fv);
            m  = Mat3.FromScale(v);
            this._output.WriteLine(fm.ToString());
            this._output.WriteLine(m.ToString());
            fm = FMat3.FromCross(fv);
            m  = Mat3.FromCross(v);
            this._output.WriteLine(fm.ToString());
            this._output.WriteLine(m.ToString());
            fm = FMat3.FromOuterProduct(fv, fv2);
            m  = Mat3.FromOuterProduct(v, v2);
            this._output.WriteLine(fm.ToString());
            this._output.WriteLine(m.ToString());
            fm = FMat3.FromRotationAxis(( Fix64 )35, fv);
            m  = Mat3.FromRotationAxis(35, v);
            this._output.WriteLine(fm.ToString());
            this._output.WriteLine(m.ToString());
            fm = FMat3.NonhomogeneousInverse(fm);
            m  = Mat3.NonhomogeneousInvert(m);
            this._output.WriteLine(fm.ToString());
            this._output.WriteLine(m.ToString());
        }
Exemplo n.º 5
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);
        }
Exemplo n.º 6
0
        public FMat3 RotateAround(Fix64 angle, FVec3 axis)
        {
            // rotate into world space
            FQuat quaternion       = FQuat.AngleAxis(Fix64.Zero, axis).Conjugate();
            FMat3 worldSpaceMatrix = FromQuaternion(quaternion) * this;

            // rotate back to matrix space
            quaternion = FQuat.AngleAxis(angle, axis);
            FMat3 qMat = FromQuaternion(quaternion);

            worldSpaceMatrix = qMat * worldSpaceMatrix;
            return(worldSpaceMatrix);
        }
Exemplo n.º 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;
        }
Exemplo n.º 8
0
 public FMat3 MultiplyTransposed(FMat3 matrix)
 {
     return(new FMat3
            (
                new FVec3
                (
                    this.x.x * matrix.x.x + this.y.x * matrix.y.x + this.z.x * matrix.z.x,
                    this.x.x * matrix.x.y + this.y.x * matrix.y.y + this.z.x * matrix.z.y,
                    this.x.x * matrix.x.z + this.y.x * matrix.y.z + this.z.x * matrix.z.z
                ),
                new FVec3
                (
                    this.x.y * matrix.x.x + this.y.y * matrix.y.x + this.z.y * matrix.z.x,
                    this.x.y * matrix.x.y + this.y.y * matrix.y.y + this.z.y * matrix.z.y,
                    this.x.y * matrix.x.z + this.y.y * matrix.y.z + this.z.y * matrix.z.z
                ),
                new FVec3
                (
                    this.x.z * matrix.x.x + this.y.z * matrix.y.x + this.z.z * matrix.z.x,
                    this.x.z * matrix.x.y + this.y.z * matrix.y.y + this.z.z * matrix.z.y,
                    this.x.z * matrix.x.z + this.y.z * matrix.y.z + this.z.z * matrix.z.z
                )
            ));
 }
Exemplo n.º 9
0
 public FLine3 Transform(FMat3 matrix)
 {
     return(new FLine3(this.point1.Transform(matrix), this.point2.Transform(matrix)));
 }