Exemplo n.º 1
0
        public static void Invert(ref Fixed64Matrix matrix, out Fixed64Matrix result)
        {
            Fixed64 determinantInverse = 1 / matrix.Determinant();
            Fixed64 m11 = (matrix.M22 * matrix.M33 - matrix.M23 * matrix.M32) * determinantInverse;
            Fixed64 m12 = (matrix.M13 * matrix.M32 - matrix.M33 * matrix.M12) * determinantInverse;
            Fixed64 m13 = (matrix.M12 * matrix.M23 - matrix.M22 * matrix.M13) * determinantInverse;

            Fixed64 m21 = (matrix.M23 * matrix.M31 - matrix.M21 * matrix.M33) * determinantInverse;
            Fixed64 m22 = (matrix.M11 * matrix.M33 - matrix.M13 * matrix.M31) * determinantInverse;
            Fixed64 m23 = (matrix.M13 * matrix.M21 - matrix.M11 * matrix.M23) * determinantInverse;

            Fixed64 m31 = (matrix.M21 * matrix.M32 - matrix.M22 * matrix.M31) * determinantInverse;
            Fixed64 m32 = (matrix.M12 * matrix.M31 - matrix.M11 * matrix.M32) * determinantInverse;
            Fixed64 m33 = (matrix.M11 * matrix.M22 - matrix.M12 * matrix.M21) * determinantInverse;

            result.M11 = m11;
            result.M12 = m12;
            result.M13 = m13;

            result.M21 = m21;
            result.M22 = m22;
            result.M23 = m23;

            result.M31 = m31;
            result.M32 = m32;
            result.M33 = m33;
        }
Exemplo n.º 2
0
 /// <summary>
 /// Matrices are added.
 /// </summary>
 /// <param name="matrix1">The first matrix.</param>
 /// <param name="matrix2">The second matrix.</param>
 /// <param name="result">The sum of both matrices.</param>
 public static void Add(ref Fixed64Matrix matrix1, ref Fixed64Matrix matrix2, out Fixed64Matrix result)
 {
     result.M11 = matrix1.M11 + matrix2.M11;
     result.M12 = matrix1.M12 + matrix2.M12;
     result.M13 = matrix1.M13 + matrix2.M13;
     result.M21 = matrix1.M21 + matrix2.M21;
     result.M22 = matrix1.M22 + matrix2.M22;
     result.M23 = matrix1.M23 + matrix2.M23;
     result.M31 = matrix1.M31 + matrix2.M31;
     result.M32 = matrix1.M32 + matrix2.M32;
     result.M33 = matrix1.M33 + matrix2.M33;
 }
Exemplo n.º 3
0
 /// <summary>
 /// Creates the transposed matrix.
 /// </summary>
 /// <param name="matrix">The matrix which should be transposed.</param>
 /// <param name="result">The transposed JMatrix.</param>
 public static void Transpose(ref Fixed64Matrix matrix, out Fixed64Matrix result)
 {
     result.M11 = matrix.M11;
     result.M12 = matrix.M21;
     result.M13 = matrix.M31;
     result.M21 = matrix.M12;
     result.M22 = matrix.M22;
     result.M23 = matrix.M32;
     result.M31 = matrix.M13;
     result.M32 = matrix.M23;
     result.M33 = matrix.M33;
 }
Exemplo n.º 4
0
 /// <summary>
 /// Changes every sign of the matrix entry to '+'
 /// </summary>
 /// <param name="matrix">The matrix.</param>
 /// <param name="result">The absolute matrix.</param>
 public static void Absolute(ref Fixed64Matrix matrix, out Fixed64Matrix result)
 {
     result.M11 = Fixed64.Abs(matrix.M11);
     result.M12 = Fixed64.Abs(matrix.M12);
     result.M13 = Fixed64.Abs(matrix.M13);
     result.M21 = Fixed64.Abs(matrix.M21);
     result.M22 = Fixed64.Abs(matrix.M22);
     result.M23 = Fixed64.Abs(matrix.M23);
     result.M31 = Fixed64.Abs(matrix.M31);
     result.M32 = Fixed64.Abs(matrix.M32);
     result.M33 = Fixed64.Abs(matrix.M33);
 }
Exemplo n.º 5
0
        static Fixed64Matrix()
        {
            Zero = new Fixed64Matrix();

            Identity = new Fixed64Matrix
            {
                M11 = Fixed64.One,
                M22 = Fixed64.One,
                M33 = Fixed64.One
            };

            InternalIdentity = Identity;
        }
Exemplo n.º 6
0
        /// <summary>
        /// Multiply a matrix by a scalefactor.
        /// </summary>
        /// <param name="matrix1">The matrix.</param>
        /// <param name="scaleFactor">The scale factor.</param>
        /// <param name="result">A JMatrix multiplied by the scale factor.</param>
        public static void Multiply(ref Fixed64Matrix matrix1, Fixed64 scaleFactor, out Fixed64Matrix result)
        {
            Fixed64 num = scaleFactor;

            result.M11 = matrix1.M11 * num;
            result.M12 = matrix1.M12 * num;
            result.M13 = matrix1.M13 * num;
            result.M21 = matrix1.M21 * num;
            result.M22 = matrix1.M22 * num;
            result.M23 = matrix1.M23 * num;
            result.M31 = matrix1.M31 * num;
            result.M32 = matrix1.M32 * num;
            result.M33 = matrix1.M33 * num;
        }
Exemplo n.º 7
0
        public static void CreateRotationZ(Fixed64 radians, out Fixed64Matrix result)
        {
            Fixed64 num2 = Fixed64.Cos(radians);
            Fixed64 num  = Fixed64.Sin(radians);

            result.M11 = num2;
            result.M12 = num;
            result.M13 = Fixed64.Zero;
            result.M21 = -num;
            result.M22 = num2;
            result.M23 = Fixed64.Zero;
            result.M31 = Fixed64.Zero;
            result.M32 = Fixed64.Zero;
            result.M33 = Fixed64.One;
        }
Exemplo n.º 8
0
        public static void LookAt(Fixed64Vector3 forward, Fixed64Vector3 upwards, out Fixed64Matrix result)
        {
            Fixed64Vector3 zaxis = forward; zaxis.Normalize();
            Fixed64Vector3 xaxis = Fixed64Vector3.Cross(upwards, zaxis); xaxis.Normalize();
            Fixed64Vector3 yaxis = Fixed64Vector3.Cross(zaxis, xaxis);

            result.M11 = xaxis.x;
            result.M21 = yaxis.x;
            result.M31 = zaxis.x;
            result.M12 = xaxis.y;
            result.M22 = yaxis.y;
            result.M32 = zaxis.y;
            result.M13 = xaxis.z;
            result.M23 = yaxis.z;
            result.M33 = zaxis.z;
        }
Exemplo n.º 9
0
        /// <summary>
        /// Calculates the inverse of a give matrix.
        /// </summary>
        /// <param name="matrix">The matrix to invert.</param>
        /// <param name="result">The inverted JMatrix.</param>
        public static void Inverse(ref Fixed64Matrix matrix, out Fixed64Matrix result)
        {
            Fixed64 det = 1024 * matrix.M11 * matrix.M22 * matrix.M33 -
                          1024 * matrix.M11 * matrix.M23 * matrix.M32 -
                          1024 * matrix.M12 * matrix.M21 * matrix.M33 +
                          1024 * matrix.M12 * matrix.M23 * matrix.M31 +
                          1024 * matrix.M13 * matrix.M21 * matrix.M32 -
                          1024 * matrix.M13 * matrix.M22 * matrix.M31;

            Fixed64 num11 = 1024 * matrix.M22 * matrix.M33 - 1024 * matrix.M23 * matrix.M32;
            Fixed64 num12 = 1024 * matrix.M13 * matrix.M32 - 1024 * matrix.M12 * matrix.M33;
            Fixed64 num13 = 1024 * matrix.M12 * matrix.M23 - 1024 * matrix.M22 * matrix.M13;

            Fixed64 num21 = 1024 * matrix.M23 * matrix.M31 - 1024 * matrix.M33 * matrix.M21;
            Fixed64 num22 = 1024 * matrix.M11 * matrix.M33 - 1024 * matrix.M31 * matrix.M13;
            Fixed64 num23 = 1024 * matrix.M13 * matrix.M21 - 1024 * matrix.M23 * matrix.M11;

            Fixed64 num31 = 1024 * matrix.M21 * matrix.M32 - 1024 * matrix.M31 * matrix.M22;
            Fixed64 num32 = 1024 * matrix.M12 * matrix.M31 - 1024 * matrix.M32 * matrix.M11;
            Fixed64 num33 = 1024 * matrix.M11 * matrix.M22 - 1024 * matrix.M21 * matrix.M12;

            if (det == 0)
            {
                result.M11 = Fixed64.PositiveInfinity;
                result.M12 = Fixed64.PositiveInfinity;
                result.M13 = Fixed64.PositiveInfinity;
                result.M21 = Fixed64.PositiveInfinity;
                result.M22 = Fixed64.PositiveInfinity;
                result.M23 = Fixed64.PositiveInfinity;
                result.M31 = Fixed64.PositiveInfinity;
                result.M32 = Fixed64.PositiveInfinity;
                result.M33 = Fixed64.PositiveInfinity;
            }
            else
            {
                result.M11 = num11 / det;
                result.M12 = num12 / det;
                result.M13 = num13 / det;
                result.M21 = num21 / det;
                result.M22 = num22 / det;
                result.M23 = num23 / det;
                result.M31 = num31 / det;
                result.M32 = num32 / det;
                result.M33 = num33 / det;
            }
        }
Exemplo n.º 10
0
        public override bool Equals(object obj)
        {
            if (!(obj is Fixed64Matrix))
            {
                return(false);
            }
            Fixed64Matrix other = (Fixed64Matrix)obj;

            return(M11 == other.M11 &&
                   M12 == other.M12 &&
                   M13 == other.M13 &&
                   M21 == other.M21 &&
                   M22 == other.M22 &&
                   M23 == other.M23 &&
                   M31 == other.M31 &&
                   M32 == other.M32 &&
                   M33 == other.M33);
        }
Exemplo n.º 11
0
        /// <summary>
        /// Multiply two matrices. Notice: matrix multiplication is not commutative.
        /// </summary>
        /// <param name="matrix1">The first matrix.</param>
        /// <param name="matrix2">The second matrix.</param>
        /// <param name="result">The product of both matrices.</param>
        public static void Multiply(ref Fixed64Matrix matrix1, ref Fixed64Matrix matrix2, out Fixed64Matrix result)
        {
            Fixed64 num0 = ((matrix1.M11 * matrix2.M11) + (matrix1.M12 * matrix2.M21)) + (matrix1.M13 * matrix2.M31);
            Fixed64 num1 = ((matrix1.M11 * matrix2.M12) + (matrix1.M12 * matrix2.M22)) + (matrix1.M13 * matrix2.M32);
            Fixed64 num2 = ((matrix1.M11 * matrix2.M13) + (matrix1.M12 * matrix2.M23)) + (matrix1.M13 * matrix2.M33);
            Fixed64 num3 = ((matrix1.M21 * matrix2.M11) + (matrix1.M22 * matrix2.M21)) + (matrix1.M23 * matrix2.M31);
            Fixed64 num4 = ((matrix1.M21 * matrix2.M12) + (matrix1.M22 * matrix2.M22)) + (matrix1.M23 * matrix2.M32);
            Fixed64 num5 = ((matrix1.M21 * matrix2.M13) + (matrix1.M22 * matrix2.M23)) + (matrix1.M23 * matrix2.M33);
            Fixed64 num6 = ((matrix1.M31 * matrix2.M11) + (matrix1.M32 * matrix2.M21)) + (matrix1.M33 * matrix2.M31);
            Fixed64 num7 = ((matrix1.M31 * matrix2.M12) + (matrix1.M32 * matrix2.M22)) + (matrix1.M33 * matrix2.M32);
            Fixed64 num8 = ((matrix1.M31 * matrix2.M13) + (matrix1.M32 * matrix2.M23)) + (matrix1.M33 * matrix2.M33);

            result.M11 = num0;
            result.M12 = num1;
            result.M13 = num2;
            result.M21 = num3;
            result.M22 = num4;
            result.M23 = num5;
            result.M31 = num6;
            result.M32 = num7;
            result.M33 = num8;
        }
Exemplo n.º 12
0
        /// <summary>
        /// Creates a JMatrix representing an orientation from a quaternion.
        /// </summary>
        /// <param name="quaternion">The quaternion the matrix should be created from.</param>
        /// <param name="result">JMatrix representing an orientation.</param>
        public static void CreateFromQuaternion(ref Fixed64Quaternion quaternion, out Fixed64Matrix result)
        {
            Fixed64 num9 = quaternion.x * quaternion.x;
            Fixed64 num8 = quaternion.y * quaternion.y;
            Fixed64 num7 = quaternion.z * quaternion.z;
            Fixed64 num6 = quaternion.x * quaternion.y;
            Fixed64 num5 = quaternion.z * quaternion.w;
            Fixed64 num4 = quaternion.z * quaternion.x;
            Fixed64 num3 = quaternion.y * quaternion.w;
            Fixed64 num2 = quaternion.y * quaternion.z;
            Fixed64 num  = quaternion.x * quaternion.w;

            result.M11 = Fixed64.One - (2 * (num8 + num7));
            result.M12 = 2 * (num6 + num5);
            result.M13 = 2 * (num4 - num3);
            result.M21 = 2 * (num6 - num5);
            result.M22 = Fixed64.One - (2 * (num7 + num9));
            result.M23 = 2 * (num2 + num);
            result.M31 = 2 * (num4 + num3);
            result.M32 = 2 * (num2 - num);
            result.M33 = Fixed64.One - (2 * (num8 + num9));
        }
Exemplo n.º 13
0
        /// <summary>
        /// Creates a matrix which rotates around the given axis by the given angle.
        /// </summary>
        /// <param name="axis">The axis.</param>
        /// <param name="angle">The angle.</param>
        /// <param name="result">The resulting rotation matrix</param>
        public static void CreateFromAxisAngle(ref Fixed64Vector3 axis, Fixed64 angle, out Fixed64Matrix result)
        {
            Fixed64 x     = axis.x;
            Fixed64 y     = axis.y;
            Fixed64 z     = axis.z;
            Fixed64 num2  = Fixed64.Sin(angle);
            Fixed64 num   = Fixed64.Cos(angle);
            Fixed64 num11 = x * x;
            Fixed64 num10 = y * y;
            Fixed64 num9  = z * z;
            Fixed64 num8  = x * y;
            Fixed64 num7  = x * z;
            Fixed64 num6  = y * z;

            result.M11 = num11 + (num * (Fixed64.One - num11));
            result.M12 = (num8 - (num * num8)) + (num2 * z);
            result.M13 = (num7 - (num * num7)) - (num2 * y);
            result.M21 = (num8 - (num * num8)) - (num2 * z);
            result.M22 = num10 + (num * (Fixed64.One - num10));
            result.M23 = (num6 - (num * num6)) + (num2 * x);
            result.M31 = (num7 - (num * num7)) + (num2 * y);
            result.M32 = (num6 - (num * num6)) - (num2 * x);
            result.M33 = num9 + (num * (Fixed64.One - num9));
        }
Exemplo n.º 14
0
 /// <summary>
 /// Matrices are added.
 /// </summary>
 /// <param name="matrix1">The first matrix.</param>
 /// <param name="matrix2">The second matrix.</param>
 /// <returns>The sum of both matrices.</returns>
 public static Fixed64Matrix Add(Fixed64Matrix matrix1, Fixed64Matrix matrix2)
 {
     Add(ref matrix1, ref matrix2, out Fixed64Matrix result);
     return(result);
 }
Exemplo n.º 15
0
 /// <summary>
 /// Creates the transposed matrix.
 /// </summary>
 /// <param name="matrix">The matrix which should be transposed.</param>
 /// <returns>The transposed JMatrix.</returns>
 public static Fixed64Matrix Transpose(Fixed64Matrix matrix)
 {
     Transpose(ref matrix, out Fixed64Matrix result);
     return(result);
 }
Exemplo n.º 16
0
 /// <summary>
 /// Multiply two matrices. Notice: matrix multiplication is not commutative.
 /// </summary>
 /// <param name="matrix1">The first matrix.</param>
 /// <param name="matrix2">The second matrix.</param>
 /// <returns>The product of both matrices.</returns>
 public static Fixed64Matrix Multiply(Fixed64Matrix matrix1, Fixed64Matrix matrix2)
 {
     Multiply(ref matrix1, ref matrix2, out Fixed64Matrix result);
     return(result);
 }
Exemplo n.º 17
0
 /// <summary>
 /// Multiply a matrix by a scalefactor.
 /// </summary>
 /// <param name="matrix1">The matrix.</param>
 /// <param name="scaleFactor">The scale factor.</param>
 /// <returns>A JMatrix multiplied by the scale factor.</returns>
 public static Fixed64Matrix Multiply(Fixed64Matrix matrix1, Fixed64 scaleFactor)
 {
     Multiply(ref matrix1, scaleFactor, out Fixed64Matrix result);
     return(result);
 }
Exemplo n.º 18
0
 /// <summary>
 /// Calculates the inverse of a give matrix.
 /// </summary>
 /// <param name="matrix">The matrix to invert.</param>
 /// <returns>The inverted JMatrix.</returns>
 public static Fixed64Matrix Inverse(Fixed64Matrix matrix)
 {
     Inverse(ref matrix, out Fixed64Matrix result);
     return(result);
 }