Exemple #1
0
        /// <summary>
        /// Create a rotation and scale.
        /// </summary>
        static public Matrix4x4d RotateScale(Quaternion3d r, Vector3d s)
        {
            Matrix4x4d R = r.ToMatrix4x4d();
            Matrix4x4d S = Scale(s);

            return(R * S);
        }
Exemple #2
0
        /// <summary>
        /// Create a translation and rotation.
        /// </summary>
        static public Matrix4x4d TranslateRotate(Vector3d t, Quaternion3d r)
        {
            Matrix4x4d T = Translate(t);
            Matrix4x4d R = r.ToMatrix4x4d();

            return(T * R);
        }
Exemple #3
0
        /// <summary>
        /// Create a translation and scale.
        /// </summary>
        static public Matrix4x4d TranslateScale(Vector3d t, Vector3d s)
        {
            Matrix4x4d T = Translate(t);
            Matrix4x4d S = Scale(s);

            return(T * S);
        }
Exemple #4
0
        /// <summary>
        /// Multiply a matrix by a scalar.
        /// </summary>
        public static Matrix4x4d operator *(double s, Matrix4x4d m1)
        {
            Matrix4x4d kProd = new Matrix4x4d();

            kProd.m00 = m1.m00 * s;
            kProd.m01 = m1.m01 * s;
            kProd.m02 = m1.m02 * s;
            kProd.m03 = m1.m03 * s;

            kProd.m10 = m1.m10 * s;
            kProd.m11 = m1.m11 * s;
            kProd.m12 = m1.m12 * s;
            kProd.m13 = m1.m13 * s;

            kProd.m20 = m1.m20 * s;
            kProd.m21 = m1.m21 * s;
            kProd.m22 = m1.m22 * s;
            kProd.m23 = m1.m23 * s;

            kProd.m30 = m1.m30 * s;
            kProd.m31 = m1.m31 * s;
            kProd.m32 = m1.m32 * s;
            kProd.m33 = m1.m33 * s;
            return(kProd);
        }
Exemple #5
0
        /// <summary>
        /// Multiply two matrices.
        /// </summary>
        public static Matrix4x4d operator *(Matrix4x4d m1, Matrix4x4d m2)
        {
            Matrix4x4d kProd = new Matrix4x4d();

            kProd.m00 = m1.m00 * m2.m00 + m1.m01 * m2.m10 + m1.m02 * m2.m20 + m1.m03 * m2.m30;
            kProd.m01 = m1.m00 * m2.m01 + m1.m01 * m2.m11 + m1.m02 * m2.m21 + m1.m03 * m2.m31;
            kProd.m02 = m1.m00 * m2.m02 + m1.m01 * m2.m12 + m1.m02 * m2.m22 + m1.m03 * m2.m32;
            kProd.m03 = m1.m00 * m2.m03 + m1.m01 * m2.m13 + m1.m02 * m2.m23 + m1.m03 * m2.m33;

            kProd.m10 = m1.m10 * m2.m00 + m1.m11 * m2.m10 + m1.m12 * m2.m20 + m1.m13 * m2.m30;
            kProd.m11 = m1.m10 * m2.m01 + m1.m11 * m2.m11 + m1.m12 * m2.m21 + m1.m13 * m2.m31;
            kProd.m12 = m1.m10 * m2.m02 + m1.m11 * m2.m12 + m1.m12 * m2.m22 + m1.m13 * m2.m32;
            kProd.m13 = m1.m10 * m2.m03 + m1.m11 * m2.m13 + m1.m12 * m2.m23 + m1.m13 * m2.m33;

            kProd.m20 = m1.m20 * m2.m00 + m1.m21 * m2.m10 + m1.m22 * m2.m20 + m1.m23 * m2.m30;
            kProd.m21 = m1.m20 * m2.m01 + m1.m21 * m2.m11 + m1.m22 * m2.m21 + m1.m23 * m2.m31;
            kProd.m22 = m1.m20 * m2.m02 + m1.m21 * m2.m12 + m1.m22 * m2.m22 + m1.m23 * m2.m32;
            kProd.m23 = m1.m20 * m2.m03 + m1.m21 * m2.m13 + m1.m22 * m2.m23 + m1.m23 * m2.m33;

            kProd.m30 = m1.m30 * m2.m00 + m1.m31 * m2.m10 + m1.m32 * m2.m20 + m1.m33 * m2.m30;
            kProd.m31 = m1.m30 * m2.m01 + m1.m31 * m2.m11 + m1.m32 * m2.m21 + m1.m33 * m2.m31;
            kProd.m32 = m1.m30 * m2.m02 + m1.m31 * m2.m12 + m1.m32 * m2.m22 + m1.m33 * m2.m32;
            kProd.m33 = m1.m30 * m2.m03 + m1.m31 * m2.m13 + m1.m32 * m2.m23 + m1.m33 * m2.m33;
            return(kProd);
        }
Exemple #6
0
        /// <summary>
        /// Subtract two matrices.
        /// </summary>
        public static Matrix4x4d operator -(Matrix4x4d m1, Matrix4x4d m2)
        {
            Matrix4x4d kSum = new Matrix4x4d();

            kSum.m00 = m1.m00 - m2.m00;
            kSum.m01 = m1.m01 - m2.m01;
            kSum.m02 = m1.m02 - m2.m02;
            kSum.m03 = m1.m03 - m2.m03;

            kSum.m10 = m1.m10 - m2.m10;
            kSum.m11 = m1.m11 - m2.m11;
            kSum.m12 = m1.m12 - m2.m12;
            kSum.m13 = m1.m13 - m2.m13;

            kSum.m20 = m1.m20 - m2.m20;
            kSum.m21 = m1.m21 - m2.m21;
            kSum.m22 = m1.m22 - m2.m22;
            kSum.m23 = m1.m23 - m2.m23;

            kSum.m30 = m1.m30 - m2.m30;
            kSum.m31 = m1.m31 - m2.m31;
            kSum.m32 = m1.m32 - m2.m32;
            kSum.m33 = m1.m33 - m2.m33;
            return(kSum);
        }
Exemple #7
0
        /// <summary>
        /// Add two matrices.
        /// </summary>
        public static Matrix4x4d operator +(Matrix4x4d m1, Matrix4x4d m2)
        {
            Matrix4x4d kSum = new Matrix4x4d();

            kSum.m00 = m1.m00 + m2.m00;
            kSum.m01 = m1.m01 + m2.m01;
            kSum.m02 = m1.m02 + m2.m02;
            kSum.m03 = m1.m03 + m2.m03;

            kSum.m10 = m1.m10 + m2.m10;
            kSum.m11 = m1.m11 + m2.m11;
            kSum.m12 = m1.m12 + m2.m12;
            kSum.m13 = m1.m13 + m2.m13;

            kSum.m20 = m1.m20 + m2.m20;
            kSum.m21 = m1.m21 + m2.m21;
            kSum.m22 = m1.m22 + m2.m22;
            kSum.m23 = m1.m23 + m2.m23;

            kSum.m30 = m1.m30 + m2.m30;
            kSum.m31 = m1.m31 + m2.m31;
            kSum.m32 = m1.m32 + m2.m32;
            kSum.m33 = m1.m33 + m2.m33;

            return(kSum);
        }
Exemple #8
0
        /// <summary>
        /// Create a translation, rotation and scale.
        /// </summary>
        static public Matrix4x4d TranslateRotateScale(Vector3d t, Quaternion3d r, Vector3d s)
        {
            Matrix4x4d T = Translate(t);
            Matrix4x4d R = r.ToMatrix4x4d();
            Matrix4x4d S = Scale(s);

            return(T * R * S);
        }
Exemple #9
0
        /// <summary>
        /// Are these matrices equal.
        /// </summary>
        public override bool Equals(object obj)
        {
            if (!(obj is Matrix4x4d))
            {
                return(false);
            }

            Matrix4x4d mat = (Matrix4x4d)obj;

            return(this == mat);
        }
Exemple #10
0
        /// <summary>
        /// The inverse of the matrix.
        /// A matrix multipled by its inverse is the idenity.
        /// </summary>
        public bool TryInverse(ref Matrix4x4d mInv)
        {
            double det = Determinant;

            if (DMath.IsZero(det))
            {
                return(false);
            }

            mInv = Adjoint * (1.0 / det);
            return(true);
        }
Exemple #11
0
        /// <summary>
        /// Are these matrices equal.
        /// </summary>
        public bool EqualsWithError(Matrix4x4d m, double eps)
        {
            if (Math.Abs(m00 - m.m00) > eps)
            {
                return(false);
            }
            if (Math.Abs(m10 - m.m10) > eps)
            {
                return(false);
            }
            if (Math.Abs(m20 - m.m20) > eps)
            {
                return(false);
            }
            if (Math.Abs(m30 - m.m30) > eps)
            {
                return(false);
            }

            if (Math.Abs(m01 - m.m01) > eps)
            {
                return(false);
            }
            if (Math.Abs(m11 - m.m11) > eps)
            {
                return(false);
            }
            if (Math.Abs(m21 - m.m21) > eps)
            {
                return(false);
            }
            if (Math.Abs(m31 - m.m31) > eps)
            {
                return(false);
            }

            if (Math.Abs(m02 - m.m02) > eps)
            {
                return(false);
            }
            if (Math.Abs(m12 - m.m12) > eps)
            {
                return(false);
            }
            if (Math.Abs(m22 - m.m22) > eps)
            {
                return(false);
            }
            if (Math.Abs(m32 - m.m32) > eps)
            {
                return(false);
            }

            if (Math.Abs(m03 - m.m03) > eps)
            {
                return(false);
            }
            if (Math.Abs(m13 - m.m13) > eps)
            {
                return(false);
            }
            if (Math.Abs(m23 - m.m23) > eps)
            {
                return(false);
            }
            if (Math.Abs(m33 - m.m33) > eps)
            {
                return(false);
            }

            return(true);
        }
Exemple #12
0
 /// <summary>
 /// Are these matrices equal.
 /// </summary>
 public bool Equals(Matrix4x4d mat)
 {
     return(this == mat);
 }