diff --git a/licenses/microsoft.LICENSE b/licenses/microsoft.LICENSE new file mode 100644 index 00000000..5ae193c9 --- /dev/null +++ b/licenses/microsoft.LICENSE @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) Microsoft Corporation + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/src/Math/BoundingFrustum.cs b/src/Math/BoundingFrustum.cs index 48cb1724..7e40b888 100644 --- a/src/Math/BoundingFrustum.cs +++ b/src/Math/BoundingFrustum.cs @@ -33,7 +33,7 @@ namespace MoonWorks.Math /// /// Gets or sets the of the frustum. /// - public Matrix Matrix + public Matrix4x4 Matrix { get { @@ -148,7 +148,7 @@ namespace MoonWorks.Math #region Private Fields - private Matrix matrix; + private Matrix4x4 matrix; private readonly Vector3[] corners = new Vector3[CornerCount]; private readonly Plane[] planes = new Plane[PlaneCount]; @@ -165,7 +165,7 @@ namespace MoonWorks.Math /// Constructs the frustum by extracting the view planes from a matrix. /// /// Combined matrix which usually is (View * Projection). - public BoundingFrustum(Matrix value) + public BoundingFrustum(Matrix4x4 value) { this.matrix = value; this.CreatePlanes(); diff --git a/src/Math/BoundingSphere.cs b/src/Math/BoundingSphere.cs index c0c18704..d49db218 100644 --- a/src/Math/BoundingSphere.cs +++ b/src/Math/BoundingSphere.cs @@ -77,11 +77,11 @@ namespace MoonWorks.Math #region Public Methods /// - /// Creates a new that contains a transformation of translation and scale from this sphere by the specified . + /// Creates a new that contains a transformation of translation and scale from this sphere by the specified . /// - /// The transformation . + /// The transformation . /// Transformed . - public BoundingSphere Transform(Matrix matrix) + public BoundingSphere Transform(Matrix4x4 matrix) { BoundingSphere sphere = new BoundingSphere(); sphere.Center = Vector3.Transform(this.Center, matrix); @@ -99,11 +99,11 @@ namespace MoonWorks.Math } /// - /// Creates a new that contains a transformation of translation and scale from this sphere by the specified . + /// Creates a new that contains a transformation of translation and scale from this sphere by the specified . /// - /// The transformation . + /// The transformation . /// Transformed as an output parameter. - public void Transform(ref Matrix matrix, out BoundingSphere result) + public void Transform(ref Matrix4x4 matrix, out BoundingSphere result) { result.Center = Vector3.Transform(this.Center, matrix); result.Radius = this.Radius * diff --git a/src/Math/Matrix3x2.cs b/src/Math/Matrix3x2.cs new file mode 100644 index 00000000..b7e082d9 --- /dev/null +++ b/src/Math/Matrix3x2.cs @@ -0,0 +1,826 @@ +/* MoonWorks - Game Development Framework + * Copyright 2021 Evan Hemsley + */ + +/* Derived from code by Microsoft. + * Released under the MIT license. + * See microsoft.LICENSE for details. + */ + +using System; +using System.Globalization; + +namespace MoonWorks.Math +{ + /// + /// A structure encapsulating a 3x2 matrix. + /// + public struct Matrix3x2 : IEquatable + { + #region Public Fields + /// + /// The first element of the first row + /// + public float M11; + /// + /// The second element of the first row + /// + public float M12; + /// + /// The first element of the second row + /// + public float M21; + /// + /// The second element of the second row + /// + public float M22; + /// + /// The first element of the third row + /// + public float M31; + /// + /// The second element of the third row + /// + public float M32; + #endregion Public Fields + + private static readonly Matrix3x2 _identity = new Matrix3x2 + ( + 1f, 0f, + 0f, 1f, + 0f, 0f + ); + + /// + /// Returns the multiplicative identity matrix. + /// + public static Matrix3x2 Identity + { + get { return _identity; } + } + + /// + /// Returns whether the matrix is the identity matrix. + /// + public bool IsIdentity + { + get + { + return M11 == 1f && M22 == 1f && // Check diagonal element first for early out. + M12 == 0f && + M21 == 0f && + M31 == 0f && M32 == 0f; + } + } + + /// + /// Gets or sets the translation component of this matrix. + /// + public Vector2 Translation + { + get + { + return new Vector2(M31, M32); + } + + set + { + M31 = value.X; + M32 = value.Y; + } + } + + /// + /// Constructs a Matrix3x2 from the given components. + /// + public Matrix3x2(float m11, float m12, + float m21, float m22, + float m31, float m32) + { + this.M11 = m11; + this.M12 = m12; + this.M21 = m21; + this.M22 = m22; + this.M31 = m31; + this.M32 = m32; + } + + /// + /// Creates a translation matrix from the given vector. + /// + /// The translation position. + /// A translation matrix. + public static Matrix3x2 CreateTranslation(Vector2 position) + { + Matrix3x2 result; + + result.M11 = 1.0f; + result.M12 = 0.0f; + result.M21 = 0.0f; + result.M22 = 1.0f; + + result.M31 = position.X; + result.M32 = position.Y; + + return result; + } + + /// + /// Creates a translation matrix from the given X and Y components. + /// + /// The X position. + /// The Y position. + /// A translation matrix. + public static Matrix3x2 CreateTranslation(float xPosition, float yPosition) + { + Matrix3x2 result; + + result.M11 = 1.0f; + result.M12 = 0.0f; + result.M21 = 0.0f; + result.M22 = 1.0f; + + result.M31 = xPosition; + result.M32 = yPosition; + + return result; + } + + /// + /// Creates a scale matrix from the given X and Y components. + /// + /// Value to scale by on the X-axis. + /// Value to scale by on the Y-axis. + /// A scaling matrix. + public static Matrix3x2 CreateScale(float xScale, float yScale) + { + Matrix3x2 result; + + result.M11 = xScale; + result.M12 = 0.0f; + result.M21 = 0.0f; + result.M22 = yScale; + result.M31 = 0.0f; + result.M32 = 0.0f; + + return result; + } + + /// + /// Creates a scale matrix that is offset by a given center point. + /// + /// Value to scale by on the X-axis. + /// Value to scale by on the Y-axis. + /// The center point. + /// A scaling matrix. + public static Matrix3x2 CreateScale(float xScale, float yScale, Vector2 centerPoint) + { + Matrix3x2 result; + + float tx = centerPoint.X * (1 - xScale); + float ty = centerPoint.Y * (1 - yScale); + + result.M11 = xScale; + result.M12 = 0.0f; + result.M21 = 0.0f; + result.M22 = yScale; + result.M31 = tx; + result.M32 = ty; + + return result; + } + + /// + /// Creates a scale matrix from the given vector scale. + /// + /// The scale to use. + /// A scaling matrix. + public static Matrix3x2 CreateScale(Vector2 scales) + { + Matrix3x2 result; + + result.M11 = scales.X; + result.M12 = 0.0f; + result.M21 = 0.0f; + result.M22 = scales.Y; + result.M31 = 0.0f; + result.M32 = 0.0f; + + return result; + } + + /// + /// Creates a scale matrix from the given vector scale with an offset from the given center point. + /// + /// The scale to use. + /// The center offset. + /// A scaling matrix. + public static Matrix3x2 CreateScale(Vector2 scales, Vector2 centerPoint) + { + Matrix3x2 result; + + float tx = centerPoint.X * (1 - scales.X); + float ty = centerPoint.Y * (1 - scales.Y); + + result.M11 = scales.X; + result.M12 = 0.0f; + result.M21 = 0.0f; + result.M22 = scales.Y; + result.M31 = tx; + result.M32 = ty; + + return result; + } + + /// + /// Creates a scale matrix that scales uniformly with the given scale. + /// + /// The uniform scale to use. + /// A scaling matrix. + public static Matrix3x2 CreateScale(float scale) + { + Matrix3x2 result; + + result.M11 = scale; + result.M12 = 0.0f; + result.M21 = 0.0f; + result.M22 = scale; + result.M31 = 0.0f; + result.M32 = 0.0f; + + return result; + } + + /// + /// Creates a scale matrix that scales uniformly with the given scale with an offset from the given center. + /// + /// The uniform scale to use. + /// The center offset. + /// A scaling matrix. + public static Matrix3x2 CreateScale(float scale, Vector2 centerPoint) + { + Matrix3x2 result; + + float tx = centerPoint.X * (1 - scale); + float ty = centerPoint.Y * (1 - scale); + + result.M11 = scale; + result.M12 = 0.0f; + result.M21 = 0.0f; + result.M22 = scale; + result.M31 = tx; + result.M32 = ty; + + return result; + } + + /// + /// Creates a skew matrix from the given angles in radians. + /// + /// The X angle, in radians. + /// The Y angle, in radians. + /// A skew matrix. + public static Matrix3x2 CreateSkew(float radiansX, float radiansY) + { + Matrix3x2 result; + + float xTan = (float)System.Math.Tan(radiansX); + float yTan = (float)System.Math.Tan(radiansY); + + result.M11 = 1.0f; + result.M12 = yTan; + result.M21 = xTan; + result.M22 = 1.0f; + result.M31 = 0.0f; + result.M32 = 0.0f; + + return result; + } + + /// + /// Creates a skew matrix from the given angles in radians and a center point. + /// + /// The X angle, in radians. + /// The Y angle, in radians. + /// The center point. + /// A skew matrix. + public static Matrix3x2 CreateSkew(float radiansX, float radiansY, Vector2 centerPoint) + { + Matrix3x2 result; + + float xTan = (float)System.Math.Tan(radiansX); + float yTan = (float)System.Math.Tan(radiansY); + + float tx = -centerPoint.Y * xTan; + float ty = -centerPoint.X * yTan; + + result.M11 = 1.0f; + result.M12 = yTan; + result.M21 = xTan; + result.M22 = 1.0f; + result.M31 = tx; + result.M32 = ty; + + return result; + } + + /// + /// Creates a rotation matrix using the given rotation in radians. + /// + /// The amount of rotation, in radians. + /// A rotation matrix. + public static Matrix3x2 CreateRotation(float radians) + { + Matrix3x2 result; + + radians = (float)System.Math.IEEERemainder(radians, System.Math.PI * 2); + + float c, s; + + const float epsilon = 0.001f * (float)System.Math.PI / 180f; // 0.1% of a degree + + if (radians > -epsilon && radians < epsilon) + { + // Exact case for zero rotation. + c = 1; + s = 0; + } + else if (radians > System.Math.PI / 2 - epsilon && radians < System.Math.PI / 2 + epsilon) + { + // Exact case for 90 degree rotation. + c = 0; + s = 1; + } + else if (radians < -System.Math.PI + epsilon || radians > System.Math.PI - epsilon) + { + // Exact case for 180 degree rotation. + c = -1; + s = 0; + } + else if (radians > -System.Math.PI / 2 - epsilon && radians < -System.Math.PI / 2 + epsilon) + { + // Exact case for 270 degree rotation. + c = 0; + s = -1; + } + else + { + // Arbitrary rotation. + c = (float)System.Math.Cos(radians); + s = (float)System.Math.Sin(radians); + } + + // [ c s ] + // [ -s c ] + // [ 0 0 ] + result.M11 = c; + result.M12 = s; + result.M21 = -s; + result.M22 = c; + result.M31 = 0.0f; + result.M32 = 0.0f; + + return result; + } + + /// + /// Creates a rotation matrix using the given rotation in radians and a center point. + /// + /// The amount of rotation, in radians. + /// The center point. + /// A rotation matrix. + public static Matrix3x2 CreateRotation(float radians, Vector2 centerPoint) + { + Matrix3x2 result; + + radians = (float)System.Math.IEEERemainder(radians, System.Math.PI * 2); + + float c, s; + + const float epsilon = 0.001f * (float)System.Math.PI / 180f; // 0.1% of a degree + + if (radians > -epsilon && radians < epsilon) + { + // Exact case for zero rotation. + c = 1; + s = 0; + } + else if (radians > System.Math.PI / 2 - epsilon && radians < System.Math.PI / 2 + epsilon) + { + // Exact case for 90 degree rotation. + c = 0; + s = 1; + } + else if (radians < -System.Math.PI + epsilon || radians > System.Math.PI - epsilon) + { + // Exact case for 180 degree rotation. + c = -1; + s = 0; + } + else if (radians > -System.Math.PI / 2 - epsilon && radians < -System.Math.PI / 2 + epsilon) + { + // Exact case for 270 degree rotation. + c = 0; + s = -1; + } + else + { + // Arbitrary rotation. + c = (float)System.Math.Cos(radians); + s = (float)System.Math.Sin(radians); + } + + float x = centerPoint.X * (1 - c) + centerPoint.Y * s; + float y = centerPoint.Y * (1 - c) - centerPoint.X * s; + + // [ c s ] + // [ -s c ] + // [ x y ] + result.M11 = c; + result.M12 = s; + result.M21 = -s; + result.M22 = c; + result.M31 = x; + result.M32 = y; + + return result; + } + + /// + /// Calculates the determinant for this matrix. + /// The determinant is calculated by expanding the matrix with a third column whose values are (0,0,1). + /// + /// The determinant. + public float GetDeterminant() + { + // There isn't actually any such thing as a determinant for a non-square matrix, + // but this 3x2 type is really just an optimization of a 3x3 where we happen to + // know the rightmost column is always (0, 0, 1). So we expand to 3x3 format: + // + // [ M11, M12, 0 ] + // [ M21, M22, 0 ] + // [ M31, M32, 1 ] + // + // Sum the diagonal products: + // (M11 * M22 * 1) + (M12 * 0 * M31) + (0 * M21 * M32) + // + // Subtract the opposite diagonal products: + // (M31 * M22 * 0) + (M32 * 0 * M11) + (1 * M21 * M12) + // + // Collapse out the constants and oh look, this is just a 2x2 determinant! + + return (M11 * M22) - (M21 * M12); + } + + /// + /// Attempts to invert the given matrix. If the operation succeeds, the inverted matrix is stored in the result parameter. + /// + /// The source matrix. + /// The output matrix. + /// True if the operation succeeded, False otherwise. + public static bool Invert(Matrix3x2 matrix, out Matrix3x2 result) + { + float det = (matrix.M11 * matrix.M22) - (matrix.M21 * matrix.M12); + + if (System.Math.Abs(det) < float.Epsilon) + { + result = new Matrix3x2(float.NaN, float.NaN, float.NaN, float.NaN, float.NaN, float.NaN); + return false; + } + + float invDet = 1.0f / det; + + result.M11 = matrix.M22 * invDet; + result.M12 = -matrix.M12 * invDet; + result.M21 = -matrix.M21 * invDet; + result.M22 = matrix.M11 * invDet; + result.M31 = (matrix.M21 * matrix.M32 - matrix.M31 * matrix.M22) * invDet; + result.M32 = (matrix.M31 * matrix.M12 - matrix.M11 * matrix.M32) * invDet; + + return true; + } + + /// + /// Linearly interpolates from matrix1 to matrix2, based on the third parameter. + /// + /// The first source matrix. + /// The second source matrix. + /// The relative weighting of matrix2. + /// The interpolated matrix. + public static Matrix3x2 Lerp(Matrix3x2 matrix1, Matrix3x2 matrix2, float amount) + { + Matrix3x2 result; + + // First row + result.M11 = matrix1.M11 + (matrix2.M11 - matrix1.M11) * amount; + result.M12 = matrix1.M12 + (matrix2.M12 - matrix1.M12) * amount; + + // Second row + result.M21 = matrix1.M21 + (matrix2.M21 - matrix1.M21) * amount; + result.M22 = matrix1.M22 + (matrix2.M22 - matrix1.M22) * amount; + + // Third row + result.M31 = matrix1.M31 + (matrix2.M31 - matrix1.M31) * amount; + result.M32 = matrix1.M32 + (matrix2.M32 - matrix1.M32) * amount; + + return result; + } + + /// + /// Negates the given matrix by multiplying all values by -1. + /// + /// The source matrix. + /// The negated matrix. + public static Matrix3x2 Negate(Matrix3x2 value) + { + Matrix3x2 result; + + result.M11 = -value.M11; + result.M12 = -value.M12; + result.M21 = -value.M21; + result.M22 = -value.M22; + result.M31 = -value.M31; + result.M32 = -value.M32; + + return result; + } + + /// + /// Adds each matrix element in value1 with its corresponding element in value2. + /// + /// The first source matrix. + /// The second source matrix. + /// The matrix containing the summed values. + public static Matrix3x2 Add(Matrix3x2 value1, Matrix3x2 value2) + { + Matrix3x2 result; + + result.M11 = value1.M11 + value2.M11; + result.M12 = value1.M12 + value2.M12; + result.M21 = value1.M21 + value2.M21; + result.M22 = value1.M22 + value2.M22; + result.M31 = value1.M31 + value2.M31; + result.M32 = value1.M32 + value2.M32; + + return result; + } + + /// + /// Subtracts each matrix element in value2 from its corresponding element in value1. + /// + /// The first source matrix. + /// The second source matrix. + /// The matrix containing the resulting values. + public static Matrix3x2 Subtract(Matrix3x2 value1, Matrix3x2 value2) + { + Matrix3x2 result; + + result.M11 = value1.M11 - value2.M11; + result.M12 = value1.M12 - value2.M12; + result.M21 = value1.M21 - value2.M21; + result.M22 = value1.M22 - value2.M22; + result.M31 = value1.M31 - value2.M31; + result.M32 = value1.M32 - value2.M32; + + return result; + } + + /// + /// Multiplies two matrices together and returns the resulting matrix. + /// + /// The first source matrix. + /// The second source matrix. + /// The product matrix. + public static Matrix3x2 Multiply(Matrix3x2 value1, Matrix3x2 value2) + { + Matrix3x2 result; + + // First row + result.M11 = value1.M11 * value2.M11 + value1.M12 * value2.M21; + result.M12 = value1.M11 * value2.M12 + value1.M12 * value2.M22; + + // Second row + result.M21 = value1.M21 * value2.M11 + value1.M22 * value2.M21; + result.M22 = value1.M21 * value2.M12 + value1.M22 * value2.M22; + + // Third row + result.M31 = value1.M31 * value2.M11 + value1.M32 * value2.M21 + value2.M31; + result.M32 = value1.M31 * value2.M12 + value1.M32 * value2.M22 + value2.M32; + + return result; + } + + public Matrix4x4 ToMatrix4x4() + { + return new Matrix4x4( + M11, M12, 0, 0, + M21, M22, 0, 0, + 0, 0, 1, 0, + M31, M32, 0, 1 + ); + } + + /// + /// Scales all elements in a matrix by the given scalar factor. + /// + /// The source matrix. + /// The scaling value to use. + /// The resulting matrix. + public static Matrix3x2 Multiply(Matrix3x2 value1, float value2) + { + Matrix3x2 result; + + result.M11 = value1.M11 * value2; + result.M12 = value1.M12 * value2; + result.M21 = value1.M21 * value2; + result.M22 = value1.M22 * value2; + result.M31 = value1.M31 * value2; + result.M32 = value1.M32 * value2; + + return result; + } + + /// + /// Negates the given matrix by multiplying all values by -1. + /// + /// The source matrix. + /// The negated matrix. + public static Matrix3x2 operator -(Matrix3x2 value) + { + Matrix3x2 m; + + m.M11 = -value.M11; + m.M12 = -value.M12; + m.M21 = -value.M21; + m.M22 = -value.M22; + m.M31 = -value.M31; + m.M32 = -value.M32; + + return m; + } + + /// + /// Adds each matrix element in value1 with its corresponding element in value2. + /// + /// The first source matrix. + /// The second source matrix. + /// The matrix containing the summed values. + public static Matrix3x2 operator +(Matrix3x2 value1, Matrix3x2 value2) + { + Matrix3x2 m; + + m.M11 = value1.M11 + value2.M11; + m.M12 = value1.M12 + value2.M12; + m.M21 = value1.M21 + value2.M21; + m.M22 = value1.M22 + value2.M22; + m.M31 = value1.M31 + value2.M31; + m.M32 = value1.M32 + value2.M32; + + return m; + } + + /// + /// Subtracts each matrix element in value2 from its corresponding element in value1. + /// + /// The first source matrix. + /// The second source matrix. + /// The matrix containing the resulting values. + public static Matrix3x2 operator -(Matrix3x2 value1, Matrix3x2 value2) + { + Matrix3x2 m; + + m.M11 = value1.M11 - value2.M11; + m.M12 = value1.M12 - value2.M12; + m.M21 = value1.M21 - value2.M21; + m.M22 = value1.M22 - value2.M22; + m.M31 = value1.M31 - value2.M31; + m.M32 = value1.M32 - value2.M32; + + return m; + } + + /// + /// Multiplies two matrices together and returns the resulting matrix. + /// + /// The first source matrix. + /// The second source matrix. + /// The product matrix. + public static Matrix3x2 operator *(Matrix3x2 value1, Matrix3x2 value2) + { + Matrix3x2 m; + + // First row + m.M11 = value1.M11 * value2.M11 + value1.M12 * value2.M21; + m.M12 = value1.M11 * value2.M12 + value1.M12 * value2.M22; + + // Second row + m.M21 = value1.M21 * value2.M11 + value1.M22 * value2.M21; + m.M22 = value1.M21 * value2.M12 + value1.M22 * value2.M22; + + // Third row + m.M31 = value1.M31 * value2.M11 + value1.M32 * value2.M21 + value2.M31; + m.M32 = value1.M31 * value2.M12 + value1.M32 * value2.M22 + value2.M32; + + return m; + } + + /// + /// Scales all elements in a matrix by the given scalar factor. + /// + /// The source matrix. + /// The scaling value to use. + /// The resulting matrix. + public static Matrix3x2 operator *(Matrix3x2 value1, float value2) + { + Matrix3x2 m; + + m.M11 = value1.M11 * value2; + m.M12 = value1.M12 * value2; + m.M21 = value1.M21 * value2; + m.M22 = value1.M22 * value2; + m.M31 = value1.M31 * value2; + m.M32 = value1.M32 * value2; + + return m; + } + + /// + /// Returns a boolean indicating whether the given matrices are equal. + /// + /// The first source matrix. + /// The second source matrix. + /// True if the matrices are equal; False otherwise. + public static bool operator ==(Matrix3x2 value1, Matrix3x2 value2) + { + return (value1.M11 == value2.M11 && value1.M22 == value2.M22 && // Check diagonal element first for early out. + value1.M12 == value2.M12 && + value1.M21 == value2.M21 && + value1.M31 == value2.M31 && value1.M32 == value2.M32); + } + + /// + /// Returns a boolean indicating whether the given matrices are not equal. + /// + /// The first source matrix. + /// The second source matrix. + /// True if the matrices are not equal; False if they are equal. + public static bool operator !=(Matrix3x2 value1, Matrix3x2 value2) + { + return (value1.M11 != value2.M11 || value1.M12 != value2.M12 || + value1.M21 != value2.M21 || value1.M22 != value2.M22 || + value1.M31 != value2.M31 || value1.M32 != value2.M32); + } + + /// + /// Returns a boolean indicating whether the matrix is equal to the other given matrix. + /// + /// The other matrix to test equality against. + /// True if this matrix is equal to other; False otherwise. + public bool Equals(Matrix3x2 other) + { + return (M11 == other.M11 && M22 == other.M22 && // Check diagonal element first for early out. + M12 == other.M12 && + M21 == other.M21 && + M31 == other.M31 && M32 == other.M32); + } + + /// + /// Returns a boolean indicating whether the given Object is equal to this matrix instance. + /// + /// The Object to compare against. + /// True if the Object is equal to this matrix; False otherwise. + public override bool Equals(object obj) + { + if (obj is Matrix3x2) + { + return Equals((Matrix3x2)obj); + } + + return false; + } + + /// + /// Returns a String representing this matrix instance. + /// + /// The string representation. + public override string ToString() + { + CultureInfo ci = CultureInfo.CurrentCulture; + return String.Format(ci, "{{ {{M11:{0} M12:{1}}} {{M21:{2} M22:{3}}} {{M31:{4} M32:{5}}} }}", + M11.ToString(ci), M12.ToString(ci), + M21.ToString(ci), M22.ToString(ci), + M31.ToString(ci), M32.ToString(ci)); + } + + /// + /// Returns the hash code for this instance. + /// + /// The hash code. + public override int GetHashCode() + { + return M11.GetHashCode() + M12.GetHashCode() + + M21.GetHashCode() + M22.GetHashCode() + + M31.GetHashCode() + M32.GetHashCode(); + } + } +} diff --git a/src/Math/Matrix.cs b/src/Math/Matrix4x4.cs similarity index 78% rename from src/Math/Matrix.cs rename to src/Math/Matrix4x4.cs index ff2f57b7..671882da 100644 --- a/src/Math/Matrix.cs +++ b/src/Math/Matrix4x4.cs @@ -30,7 +30,7 @@ namespace MoonWorks.Math [Serializable] [DebuggerDisplay("{DebugDisplayString,nq}")] [StructLayout(LayoutKind.Sequential)] - public struct Matrix : IEquatable + public struct Matrix4x4 : IEquatable { #region Public Properties @@ -88,7 +88,7 @@ namespace MoonWorks.Math /// /// Returns the identity matrix. /// - public static Matrix Identity + public static Matrix4x4 Identity { get { @@ -281,7 +281,7 @@ namespace MoonWorks.Math #region Private Static Variables - private static Matrix identity = new Matrix( + private static Matrix4x4 identity = new Matrix4x4( 1f, 0f, 0f, 0f, 0f, 1f, 0f, 0f, 0f, 0f, 1f, 0f, @@ -311,7 +311,7 @@ namespace MoonWorks.Math /// A fourth row and second column value. /// A fourth row and third column value. /// A fourth row and fourth column value. - public Matrix( + public Matrix4x4( float m11, float m12, float m13, float m14, float m21, float m22, float m23, float m24, float m31, float m32, float m33, float m34, @@ -371,7 +371,7 @@ namespace MoonWorks.Math return false; } - Matrix m1 = new Matrix( + Matrix4x4 m1 = new Matrix4x4( M11 / scale.X, M12 / scale.X, M13 / scale.X, 0, M21 / scale.Y, M22 / scale.Y, M23 / scale.Y, 0, M31 / scale.Z, M32 / scale.Z, M33 / scale.Z, 0, @@ -383,9 +383,9 @@ namespace MoonWorks.Math } /// - /// Returns a determinant of this . + /// Returns a determinant of this . /// - /// Determinant of this + /// Determinant of this /// See more about determinant here - http://en.wikipedia.org/wiki/Determinant. /// public float Determinant() @@ -407,11 +407,11 @@ namespace MoonWorks.Math } /// - /// Compares whether current instance is equal to specified without any tolerance. + /// Compares whether current instance is equal to specified without any tolerance. /// - /// The to compare. + /// The to compare. /// true if the instances are equal; false otherwise. - public bool Equals(Matrix other) + public bool Equals(Matrix4x4 other) { return ( M11 == other.M11 && M12 == other.M12 && @@ -438,13 +438,13 @@ namespace MoonWorks.Math /// true if the instances are equal; false otherwise. public override bool Equals(object obj) { - return (obj is Matrix) && Equals((Matrix) obj); + return (obj is Matrix4x4) && Equals((Matrix4x4) obj); } /// - /// Gets the hash code of this . + /// Gets the hash code of this . /// - /// Hash code of this . + /// Hash code of this . public override int GetHashCode() { return ( @@ -456,13 +456,13 @@ namespace MoonWorks.Math } /// - /// Returns a representation of this in the format: + /// Returns a representation of this in the format: /// {M11:[] M12:[] M13:[] M14:[]} /// {M21:[] M12:[] M13:[] M14:[]} /// {M31:[] M32:[] M33:[] M34:[]} /// {M41:[] M42:[] M43:[] M44:[]} /// - /// A representation of this . + /// A representation of this . public override string ToString() { return ( @@ -490,12 +490,12 @@ namespace MoonWorks.Math #region Public Static Methods /// - /// Creates a new which contains sum of two matrixes. + /// Creates a new which contains sum of two matrixes. /// /// The first matrix to add. /// The second matrix to add. /// The result of the matrix addition. - public static Matrix Add(Matrix matrix1, Matrix matrix2) + public static Matrix4x4 Add(Matrix4x4 matrix1, Matrix4x4 matrix2) { matrix1.M11 += matrix2.M11; matrix1.M12 += matrix2.M12; @@ -517,12 +517,12 @@ namespace MoonWorks.Math } /// - /// Creates a new which contains sum of two matrixes. + /// Creates a new which contains sum of two matrixes. /// /// The first matrix to add. /// The second matrix to add. /// The result of the matrix addition as an output parameter. - public static void Add(ref Matrix matrix1, ref Matrix matrix2, out Matrix result) + public static void Add(ref Matrix4x4 matrix1, ref Matrix4x4 matrix2, out Matrix4x4 result) { result.M11 = matrix1.M11 + matrix2.M11; result.M12 = matrix1.M12 + matrix2.M12; @@ -543,20 +543,20 @@ namespace MoonWorks.Math } /// - /// Creates a new for spherical billboarding that rotates around specified object position. + /// Creates a new for spherical billboarding that rotates around specified object position. /// /// Position of billboard object. It will rotate around that vector. /// The camera position. /// The camera up vector. /// Optional camera forward vector. - /// The for spherical billboarding. - public static Matrix CreateBillboard( + /// The for spherical billboarding. + public static Matrix4x4 CreateBillboard( Vector3 objectPosition, Vector3 cameraPosition, Vector3 cameraUpVector, Nullable cameraForwardVector ) { - Matrix result; + Matrix4x4 result; // Delegate to the other overload of the function to do the work CreateBillboard( @@ -571,19 +571,19 @@ namespace MoonWorks.Math } /// - /// Creates a new for spherical billboarding that rotates around specified object position. + /// Creates a new for spherical billboarding that rotates around specified object position. /// /// Position of billboard object. It will rotate around that vector. /// The camera position. /// The camera up vector. /// Optional camera forward vector. - /// The for spherical billboarding as an output parameter. + /// The for spherical billboarding as an output parameter. public static void CreateBillboard( ref Vector3 objectPosition, ref Vector3 cameraPosition, ref Vector3 cameraUpVector, Vector3? cameraForwardVector, - out Matrix result + out Matrix4x4 result ) { Vector3 vector; Vector3 vector2; @@ -628,22 +628,22 @@ namespace MoonWorks.Math } /// - /// Creates a new for cylindrical billboarding that rotates around specified axis. + /// Creates a new for cylindrical billboarding that rotates around specified axis. /// /// Object position the billboard will rotate around. /// Camera position. /// Axis of billboard for rotation. /// Optional camera forward vector. /// Optional object forward vector. - /// The for cylindrical billboarding. - public static Matrix CreateConstrainedBillboard( + /// The for cylindrical billboarding. + public static Matrix4x4 CreateConstrainedBillboard( Vector3 objectPosition, Vector3 cameraPosition, Vector3 rotateAxis, Nullable cameraForwardVector, Nullable objectForwardVector ) { - Matrix result; + Matrix4x4 result; CreateConstrainedBillboard( ref objectPosition, ref cameraPosition, @@ -656,21 +656,21 @@ namespace MoonWorks.Math } /// - /// Creates a new for cylindrical billboarding that rotates around specified axis. + /// Creates a new for cylindrical billboarding that rotates around specified axis. /// /// Object position the billboard will rotate around. /// Camera position. /// Axis of billboard for rotation. /// Optional camera forward vector. /// Optional object forward vector. - /// The for cylindrical billboarding as an output parameter. + /// The for cylindrical billboarding as an output parameter. public static void CreateConstrainedBillboard( ref Vector3 objectPosition, ref Vector3 cameraPosition, ref Vector3 rotateAxis, Vector3? cameraForwardVector, Vector3? objectForwardVector, - out Matrix result + out Matrix4x4 result ) { float num; Vector3 vector; @@ -755,28 +755,28 @@ namespace MoonWorks.Math } /// - /// Creates a new which contains the rotation moment around specified axis. + /// Creates a new which contains the rotation moment around specified axis. /// /// The axis of rotation. /// The angle of rotation in radians. - /// The rotation . - public static Matrix CreateFromAxisAngle(Vector3 axis, float angle) + /// The rotation . + public static Matrix4x4 CreateFromAxisAngle(Vector3 axis, float angle) { - Matrix result; + Matrix4x4 result; CreateFromAxisAngle(ref axis, angle, out result); return result; } /// - /// Creates a new which contains the rotation moment around specified axis. + /// Creates a new which contains the rotation moment around specified axis. /// /// The axis of rotation. /// The angle of rotation in radians. - /// The rotation as an output parameter. + /// The rotation as an output parameter. public static void CreateFromAxisAngle( ref Vector3 axis, float angle, - out Matrix result + out Matrix4x4 result ) { float x = axis.X; float y = axis.Y; @@ -808,23 +808,23 @@ namespace MoonWorks.Math } /// - /// Creates a new rotation from a . + /// Creates a new rotation from a . /// /// of rotation moment. - /// The rotation . - public static Matrix CreateFromQuaternion(Quaternion quaternion) + /// The rotation . + public static Matrix4x4 CreateFromQuaternion(Quaternion quaternion) { - Matrix result; + Matrix4x4 result; CreateFromQuaternion(ref quaternion, out result); return result; } /// - /// Creates a new rotation from a . + /// Creates a new rotation from a . /// /// of rotation moment. - /// The rotation as an output parameter. - public static void CreateFromQuaternion(ref Quaternion quaternion, out Matrix result) + /// The rotation as an output parameter. + public static void CreateFromQuaternion(ref Quaternion quaternion, out Matrix4x4 result) { float num9 = quaternion.X * quaternion.X; float num8 = quaternion.Y * quaternion.Y; @@ -854,35 +854,35 @@ namespace MoonWorks.Math } /// - /// Creates a new rotation from the specified yaw, pitch and roll values. + /// Creates a new rotation from the specified yaw, pitch and roll values. /// /// The yaw rotation value in radians. /// The pitch rotation value in radians. /// The roll rotation value in radians. - /// The rotation . + /// The rotation . /// For more information about yaw, pitch and roll visit http://en.wikipedia.org/wiki/Euler_angles. /// - public static Matrix CreateFromYawPitchRoll(float yaw, float pitch, float roll) + public static Matrix4x4 CreateFromYawPitchRoll(float yaw, float pitch, float roll) { - Matrix matrix; + Matrix4x4 matrix; CreateFromYawPitchRoll(yaw, pitch, roll, out matrix); return matrix; } /// - /// Creates a new rotation from the specified yaw, pitch and roll values. + /// Creates a new rotation from the specified yaw, pitch and roll values. /// /// The yaw rotation value in radians. /// The pitch rotation value in radians. /// The roll rotation value in radians. - /// The rotation as an output parameter. + /// The rotation as an output parameter. /// For more information about yaw, pitch and roll visit http://en.wikipedia.org/wiki/Euler_angles. /// public static void CreateFromYawPitchRoll( float yaw, float pitch, float roll, - out Matrix result + out Matrix4x4 result ) { Quaternion quaternion; Quaternion.CreateFromYawPitchRoll(yaw, pitch, roll, out quaternion); @@ -890,34 +890,34 @@ namespace MoonWorks.Math } /// - /// Creates a new viewing . + /// Creates a new viewing . /// /// Position of the camera. /// Lookup vector of the camera. /// The direction of the upper edge of the camera. - /// The viewing . - public static Matrix CreateLookAt( + /// The viewing . + public static Matrix4x4 CreateLookAt( Vector3 cameraPosition, Vector3 cameraTarget, Vector3 cameraUpVector ) { - Matrix matrix; + Matrix4x4 matrix; CreateLookAt(ref cameraPosition, ref cameraTarget, ref cameraUpVector, out matrix); return matrix; } /// - /// Creates a new viewing . + /// Creates a new viewing . /// /// Position of the camera. /// Lookup vector of the camera. /// The direction of the upper edge of the camera. - /// The viewing as an output parameter. + /// The viewing as an output parameter. public static void CreateLookAt( ref Vector3 cameraPosition, ref Vector3 cameraTarget, ref Vector3 cameraUpVector, - out Matrix result + out Matrix4x4 result ) { Vector3 vectorA = Vector3.Normalize(cameraPosition - cameraTarget); Vector3 vectorB = Vector3.Normalize(Vector3.Cross(cameraUpVector, vectorA)); @@ -941,38 +941,38 @@ namespace MoonWorks.Math } /// - /// Creates a new projection for orthographic view. + /// Creates a new projection for orthographic view. /// /// Width of the viewing volume. /// Height of the viewing volume. /// Depth of the near plane. /// Depth of the far plane. - /// The new projection for orthographic view. - public static Matrix CreateOrthographic( + /// The new projection for orthographic view. + public static Matrix4x4 CreateOrthographic( float width, float height, float zNearPlane, float zFarPlane ) { - Matrix matrix; + Matrix4x4 matrix; CreateOrthographic(width, height, zNearPlane, zFarPlane, out matrix); return matrix; } /// - /// Creates a new projection for orthographic view. + /// Creates a new projection for orthographic view. /// /// Width of the viewing volume. /// Height of the viewing volume. /// Depth of the near plane. /// Depth of the far plane. - /// The new projection for orthographic view as an output parameter. + /// The new projection for orthographic view as an output parameter. public static void CreateOrthographic( float width, float height, float zNearPlane, float zFarPlane, - out Matrix result + out Matrix4x4 result ) { result.M11 = 2f / width; result.M12 = result.M13 = result.M14 = 0f; @@ -986,7 +986,7 @@ namespace MoonWorks.Math } /// - /// Creates a new projection for customized orthographic view. + /// Creates a new projection for customized orthographic view. /// /// Lower x-value at the near plane. /// Upper x-value at the near plane. @@ -994,8 +994,8 @@ namespace MoonWorks.Math /// Upper y-value at the near plane. /// Depth of the near plane. /// Depth of the far plane. - /// The new projection for customized orthographic view. - public static Matrix CreateOrthographicOffCenter( + /// The new projection for customized orthographic view. + public static Matrix4x4 CreateOrthographicOffCenter( float left, float right, float bottom, @@ -1003,7 +1003,7 @@ namespace MoonWorks.Math float zNearPlane, float zFarPlane ) { - Matrix matrix; + Matrix4x4 matrix; CreateOrthographicOffCenter( left, right, @@ -1017,7 +1017,7 @@ namespace MoonWorks.Math } /// - /// Creates a new projection for customized orthographic view. + /// Creates a new projection for customized orthographic view. /// /// Lower x-value at the near plane. /// Upper x-value at the near plane. @@ -1025,7 +1025,7 @@ namespace MoonWorks.Math /// Upper y-value at the near plane. /// Depth of the near plane. /// Depth of the far plane. - /// The new projection for customized orthographic view as an output parameter. + /// The new projection for customized orthographic view as an output parameter. public static void CreateOrthographicOffCenter( float left, float right, @@ -1033,7 +1033,7 @@ namespace MoonWorks.Math float top, float zNearPlane, float zFarPlane, - out Matrix result + out Matrix4x4 result ) { result.M11 = (float) (2.0 / ((double) right - (double) left)); result.M12 = 0.0f; @@ -1063,38 +1063,38 @@ namespace MoonWorks.Math } /// - /// Creates a new projection for perspective view. + /// Creates a new projection for perspective view. /// /// Width of the viewing volume. /// Height of the viewing volume. /// Distance to the near plane. /// Distance to the far plane. - /// The new projection for perspective view. - public static Matrix CreatePerspective( + /// The new projection for perspective view. + public static Matrix4x4 CreatePerspective( float width, float height, float nearPlaneDistance, float farPlaneDistance ) { - Matrix matrix; + Matrix4x4 matrix; CreatePerspective(width, height, nearPlaneDistance, farPlaneDistance, out matrix); return matrix; } /// - /// Creates a new projection for perspective view. + /// Creates a new projection for perspective view. /// /// Width of the viewing volume. /// Height of the viewing volume. /// Distance to the near plane. /// Distance to the far plane. - /// The new projection for perspective view as an output parameter. + /// The new projection for perspective view as an output parameter. public static void CreatePerspective( float width, float height, float nearPlaneDistance, float farPlaneDistance, - out Matrix result + out Matrix4x4 result ) { if (nearPlaneDistance <= 0f) { @@ -1123,20 +1123,20 @@ namespace MoonWorks.Math } /// - /// Creates a new projection for perspective view with field of view. + /// Creates a new projection for perspective view with field of view. /// /// Field of view in the y direction in radians. /// Width divided by height of the viewing volume. /// Distance to the near plane. /// Distance to the far plane. - /// The new projection for perspective view with FOV. - public static Matrix CreatePerspectiveFieldOfView( + /// The new projection for perspective view with FOV. + public static Matrix4x4 CreatePerspectiveFieldOfView( float fieldOfView, float aspectRatio, float nearPlaneDistance, float farPlaneDistance ) { - Matrix result; + Matrix4x4 result; CreatePerspectiveFieldOfView( fieldOfView, aspectRatio, @@ -1148,19 +1148,19 @@ namespace MoonWorks.Math } /// - /// Creates a new projection for perspective view with field of view. + /// Creates a new projection for perspective view with field of view. /// /// Field of view in the y direction in radians. /// Width divided by height of the viewing volume. /// Distance of the near plane. /// Distance of the far plane. - /// The new projection for perspective view with FOV as an output parameter. + /// The new projection for perspective view with FOV as an output parameter. public static void CreatePerspectiveFieldOfView( float fieldOfView, float aspectRatio, float nearPlaneDistance, float farPlaneDistance, - out Matrix result + out Matrix4x4 result ) { if ((fieldOfView <= 0f) || (fieldOfView >= 3.141593f)) { @@ -1194,7 +1194,7 @@ namespace MoonWorks.Math } /// - /// Creates a new projection for customized perspective view. + /// Creates a new projection for customized perspective view. /// /// Lower x-value at the near plane. /// Upper x-value at the near plane. @@ -1202,8 +1202,8 @@ namespace MoonWorks.Math /// Upper y-value at the near plane. /// Distance to the near plane. /// Distance to the far plane. - /// The new for customized perspective view. - public static Matrix CreatePerspectiveOffCenter( + /// The new for customized perspective view. + public static Matrix4x4 CreatePerspectiveOffCenter( float left, float right, float bottom, @@ -1211,7 +1211,7 @@ namespace MoonWorks.Math float nearPlaneDistance, float farPlaneDistance ) { - Matrix result; + Matrix4x4 result; CreatePerspectiveOffCenter( left, right, @@ -1225,7 +1225,7 @@ namespace MoonWorks.Math } /// - /// Creates a new projection for customized perspective view. + /// Creates a new projection for customized perspective view. /// /// Lower x-value at the near plane. /// Upper x-value at the near plane. @@ -1233,7 +1233,7 @@ namespace MoonWorks.Math /// Upper y-value at the near plane. /// Distance to the near plane. /// Distance to the far plane. - /// The new for customized perspective view as an output parameter. + /// The new for customized perspective view as an output parameter. public static void CreatePerspectiveOffCenter( float left, float right, @@ -1241,7 +1241,7 @@ namespace MoonWorks.Math float top, float nearPlaneDistance, float farPlaneDistance, - out Matrix result + out Matrix4x4 result ) { if (nearPlaneDistance <= 0f) { @@ -1271,25 +1271,25 @@ namespace MoonWorks.Math } /// - /// Creates a new rotation around X axis. + /// Creates a new rotation around X axis. /// /// Angle in radians. - /// The rotation around X axis. - public static Matrix CreateRotationX(float radians) + /// The rotation around X axis. + public static Matrix4x4 CreateRotationX(float radians) { - Matrix result; + Matrix4x4 result; CreateRotationX(radians, out result); return result; } /// - /// Creates a new rotation around X axis. + /// Creates a new rotation around X axis. /// /// Angle in radians. - /// The rotation around X axis as an output parameter. - public static void CreateRotationX(float radians, out Matrix result) + /// The rotation around X axis as an output parameter. + public static void CreateRotationX(float radians, out Matrix4x4 result) { - result = Matrix.Identity; + result = Matrix4x4.Identity; float val1 = (float) System.Math.Cos(radians); float val2 = (float) System.Math.Sin(radians); @@ -1301,25 +1301,25 @@ namespace MoonWorks.Math } /// - /// Creates a new rotation around Y axis. + /// Creates a new rotation around Y axis. /// /// Angle in radians. - /// The rotation around Y axis. - public static Matrix CreateRotationY(float radians) + /// The rotation around Y axis. + public static Matrix4x4 CreateRotationY(float radians) { - Matrix result; + Matrix4x4 result; CreateRotationY(radians, out result); return result; } /// - /// Creates a new rotation around Y axis. + /// Creates a new rotation around Y axis. /// /// Angle in radians. - /// The rotation around Y axis as an output parameter. - public static void CreateRotationY(float radians, out Matrix result) + /// The rotation around Y axis as an output parameter. + public static void CreateRotationY(float radians, out Matrix4x4 result) { - result = Matrix.Identity; + result = Matrix4x4.Identity; float val1 = (float) System.Math.Cos(radians); float val2 = (float) System.Math.Sin(radians); @@ -1331,25 +1331,25 @@ namespace MoonWorks.Math } /// - /// Creates a new rotation around Z axis. + /// Creates a new rotation around Z axis. /// /// Angle in radians. - /// The rotation around Z axis. - public static Matrix CreateRotationZ(float radians) + /// The rotation around Z axis. + public static Matrix4x4 CreateRotationZ(float radians) { - Matrix result; + Matrix4x4 result; CreateRotationZ(radians, out result); return result; } /// - /// Creates a new rotation around Z axis. + /// Creates a new rotation around Z axis. /// /// Angle in radians. - /// The rotation around Z axis as an output parameter. - public static void CreateRotationZ(float radians, out Matrix result) + /// The rotation around Z axis as an output parameter. + public static void CreateRotationZ(float radians, out Matrix4x4 result) { - result = Matrix.Identity; + result = Matrix4x4.Identity; float val1 = (float) System.Math.Cos(radians); float val2 = (float) System.Math.Sin(radians); @@ -1361,53 +1361,53 @@ namespace MoonWorks.Math } /// - /// Creates a new scaling . + /// Creates a new scaling . /// /// Scale value for all three axises. - /// The scaling . - public static Matrix CreateScale(float scale) + /// The scaling . + public static Matrix4x4 CreateScale(float scale) { - Matrix result; + Matrix4x4 result; CreateScale(scale, scale, scale, out result); return result; } /// - /// Creates a new scaling . + /// Creates a new scaling . /// /// Scale value for all three axises. - /// The scaling as an output parameter. - public static void CreateScale(float scale, out Matrix result) + /// The scaling as an output parameter. + public static void CreateScale(float scale, out Matrix4x4 result) { CreateScale(scale, scale, scale, out result); } /// - /// Creates a new scaling . + /// Creates a new scaling . /// /// Scale value for X axis. /// Scale value for Y axis. /// Scale value for Z axis. - /// The scaling . - public static Matrix CreateScale(float xScale, float yScale, float zScale) + /// The scaling . + public static Matrix4x4 CreateScale(float xScale, float yScale, float zScale) { - Matrix result; + Matrix4x4 result; CreateScale(xScale, yScale, zScale, out result); return result; } /// - /// Creates a new scaling . + /// Creates a new scaling . /// /// Scale value for X axis. /// Scale value for Y axis. /// Scale value for Z axis. - /// The scaling as an output parameter. + /// The scaling as an output parameter. public static void CreateScale( float xScale, float yScale, float zScale, - out Matrix result + out Matrix4x4 result ) { result.M11 = xScale; result.M12 = 0; @@ -1428,23 +1428,23 @@ namespace MoonWorks.Math } /// - /// Creates a new scaling . + /// Creates a new scaling . /// /// representing x,y and z scale values. - /// The scaling . - public static Matrix CreateScale(Vector3 scales) + /// The scaling . + public static Matrix4x4 CreateScale(Vector3 scales) { - Matrix result; + Matrix4x4 result; CreateScale(ref scales, out result); return result; } /// - /// Creates a new scaling . + /// Creates a new scaling . /// /// representing x,y and z scale values. - /// The scaling as an output parameter. - public static void CreateScale(ref Vector3 scales, out Matrix result) + /// The scaling as an output parameter. + public static void CreateScale(ref Vector3 scales, out Matrix4x4 result) { result.M11 = scales.X; result.M12 = 0; @@ -1465,28 +1465,28 @@ namespace MoonWorks.Math } /// - /// Creates a new that flattens geometry into a specified as if casting a shadow from a specified light source. + /// Creates a new that flattens geometry into a specified as if casting a shadow from a specified light source. /// /// A vector specifying the direction from which the light that will cast the shadow is coming. /// The plane onto which the new matrix should flatten geometry so as to cast a shadow. - /// A that can be used to flatten geometry onto the specified plane from the specified direction. - public static Matrix CreateShadow(Vector3 lightDirection, Plane plane) + /// A that can be used to flatten geometry onto the specified plane from the specified direction. + public static Matrix4x4 CreateShadow(Vector3 lightDirection, Plane plane) { - Matrix result; + Matrix4x4 result; CreateShadow(ref lightDirection, ref plane, out result); return result; } /// - /// Creates a new that flattens geometry into a specified as if casting a shadow from a specified light source. + /// Creates a new that flattens geometry into a specified as if casting a shadow from a specified light source. /// /// A vector specifying the direction from which the light that will cast the shadow is coming. /// The plane onto which the new matrix should flatten geometry so as to cast a shadow. - /// A that can be used to flatten geometry onto the specified plane from the specified direction as an output parameter. + /// A that can be used to flatten geometry onto the specified plane from the specified direction as an output parameter. public static void CreateShadow( ref Vector3 lightDirection, ref Plane plane, - out Matrix result) + out Matrix4x4 result) { float dot = ( (plane.Normal.X * lightDirection.X) + @@ -1517,28 +1517,28 @@ namespace MoonWorks.Math } /// - /// Creates a new translation . + /// Creates a new translation . /// /// X coordinate of translation. /// Y coordinate of translation. /// Z coordinate of translation. - /// The translation . - public static Matrix CreateTranslation( + /// The translation . + public static Matrix4x4 CreateTranslation( float xPosition, float yPosition, float zPosition ) { - Matrix result; + Matrix4x4 result; CreateTranslation(xPosition, yPosition, zPosition, out result); return result; } /// - /// Creates a new translation . + /// Creates a new translation . /// /// X,Y and Z coordinates of translation. - /// The translation as an output parameter. - public static void CreateTranslation(ref Vector3 position, out Matrix result) + /// The translation as an output parameter. + public static void CreateTranslation(ref Vector3 position, out Matrix4x4 result) { result.M11 = 1; result.M12 = 0; @@ -1559,29 +1559,29 @@ namespace MoonWorks.Math } /// - /// Creates a new translation . + /// Creates a new translation . /// /// X,Y and Z coordinates of translation. - /// The translation . - public static Matrix CreateTranslation(Vector3 position) + /// The translation . + public static Matrix4x4 CreateTranslation(Vector3 position) { - Matrix result; + Matrix4x4 result; CreateTranslation(ref position, out result); return result; } /// - /// Creates a new translation . + /// Creates a new translation . /// /// X coordinate of translation. /// Y coordinate of translation. /// Z coordinate of translation. - /// The translation as an output parameter. + /// The translation as an output parameter. public static void CreateTranslation( float xPosition, float yPosition, float zPosition, - out Matrix result + out Matrix4x4 result ) { result.M11 = 1; result.M12 = 0; @@ -1602,23 +1602,23 @@ namespace MoonWorks.Math } /// - /// Creates a new reflection . + /// Creates a new reflection . /// /// The plane that used for reflection calculation. - /// The reflection . - public static Matrix CreateReflection(Plane value) + /// The reflection . + public static Matrix4x4 CreateReflection(Plane value) { - Matrix result; + Matrix4x4 result; CreateReflection(ref value, out result); return result; } /// - /// Creates a new reflection . + /// Creates a new reflection . /// /// The plane that used for reflection calculation. - /// The reflection as an output parameter. - public static void CreateReflection(ref Plane value, out Matrix result) + /// The reflection as an output parameter. + public static void CreateReflection(ref Plane value, out Matrix4x4 result) { Plane plane; Plane.Normalize(ref value, out plane); @@ -1647,31 +1647,31 @@ namespace MoonWorks.Math } /// - /// Creates a new world . + /// Creates a new world . /// /// The position vector. /// The forward direction vector. /// The upward direction vector. Usually . - /// The world . - public static Matrix CreateWorld(Vector3 position, Vector3 forward, Vector3 up) + /// The world . + public static Matrix4x4 CreateWorld(Vector3 position, Vector3 forward, Vector3 up) { - Matrix ret; + Matrix4x4 ret; CreateWorld(ref position, ref forward, ref up, out ret); return ret; } /// - /// Creates a new world . + /// Creates a new world . /// /// The position vector. /// The forward direction vector. /// The upward direction vector. Usually . - /// The world as an output parameter. + /// The world as an output parameter. public static void CreateWorld( ref Vector3 position, ref Vector3 forward, ref Vector3 up, - out Matrix result + out Matrix4x4 result ) { Vector3 x, y, z; Vector3.Normalize(ref forward, out z); @@ -1680,7 +1680,7 @@ namespace MoonWorks.Math x.Normalize(); y.Normalize(); - result = new Matrix(); + result = new Matrix4x4(); result.Right = x; result.Up = y; result.Forward = z; @@ -1689,12 +1689,12 @@ namespace MoonWorks.Math } /// - /// Divides the elements of a by the elements of another matrix. + /// Divides the elements of a by the elements of another matrix. /// - /// Source . - /// Divisor . + /// Source . + /// Divisor . /// The result of dividing the matrix. - public static Matrix Divide(Matrix matrix1, Matrix matrix2) + public static Matrix4x4 Divide(Matrix4x4 matrix1, Matrix4x4 matrix2) { matrix1.M11 = matrix1.M11 / matrix2.M11; matrix1.M12 = matrix1.M12 / matrix2.M12; @@ -1716,12 +1716,12 @@ namespace MoonWorks.Math } /// - /// Divides the elements of a by the elements of another matrix. + /// Divides the elements of a by the elements of another matrix. /// - /// Source . - /// Divisor . + /// Source . + /// Divisor . /// The result of dividing the matrix as an output parameter. - public static void Divide(ref Matrix matrix1, ref Matrix matrix2, out Matrix result) + public static void Divide(ref Matrix4x4 matrix1, ref Matrix4x4 matrix2, out Matrix4x4 result) { result.M11 = matrix1.M11 / matrix2.M11; result.M12 = matrix1.M12 / matrix2.M12; @@ -1742,12 +1742,12 @@ namespace MoonWorks.Math } /// - /// Divides the elements of a by a scalar. + /// Divides the elements of a by a scalar. /// - /// Source . + /// Source . /// Divisor scalar. /// The result of dividing a matrix by a scalar. - public static Matrix Divide(Matrix matrix1, float divider) + public static Matrix4x4 Divide(Matrix4x4 matrix1, float divider) { float num = 1f / divider; matrix1.M11 = matrix1.M11 * num; @@ -1770,12 +1770,12 @@ namespace MoonWorks.Math } /// - /// Divides the elements of a by a scalar. + /// Divides the elements of a by a scalar. /// - /// Source . + /// Source . /// Divisor scalar. /// The result of dividing a matrix by a scalar as an output parameter. - public static void Divide(ref Matrix matrix1, float divider, out Matrix result) + public static void Divide(ref Matrix4x4 matrix1, float divider, out Matrix4x4 result) { float num = 1f / divider; result.M11 = matrix1.M11 * num; @@ -1797,22 +1797,22 @@ namespace MoonWorks.Math } /// - /// Creates a new which contains inversion of the specified matrix. + /// Creates a new which contains inversion of the specified matrix. /// - /// Source . + /// Source . /// The inverted matrix. - public static Matrix Invert(Matrix matrix) + public static Matrix4x4 Invert(Matrix4x4 matrix) { Invert(ref matrix, out matrix); return matrix; } /// - /// Creates a new which contains inversion of the specified matrix. + /// Creates a new which contains inversion of the specified matrix. /// - /// Source . + /// Source . /// The inverted matrix as output parameter. - public static void Invert(ref Matrix matrix, out Matrix result) + public static void Invert(ref Matrix4x4 matrix, out Matrix4x4 result) { /* * Use Laplace expansion theorem to calculate the inverse of a 4x4 matrix. @@ -2030,13 +2030,13 @@ namespace MoonWorks.Math } /// - /// Creates a new that contains linear interpolation of the values in specified matrixes. + /// Creates a new that contains linear interpolation of the values in specified matrixes. /// - /// The first . + /// The first . /// The second . /// Weighting value(between 0.0 and 1.0). /// >The result of linear interpolation of the specified matrixes. - public static Matrix Lerp(Matrix matrix1, Matrix matrix2, float amount) + public static Matrix4x4 Lerp(Matrix4x4 matrix1, Matrix4x4 matrix2, float amount) { matrix1.M11 = matrix1.M11 + ((matrix2.M11 - matrix1.M11) * amount); matrix1.M12 = matrix1.M12 + ((matrix2.M12 - matrix1.M12) * amount); @@ -2058,17 +2058,17 @@ namespace MoonWorks.Math } /// - /// Creates a new that contains linear interpolation of the values in specified matrixes. + /// Creates a new that contains linear interpolation of the values in specified matrixes. /// - /// The first . + /// The first . /// The second . /// Weighting value(between 0.0 and 1.0). /// The result of linear interpolation of the specified matrixes as an output parameter. public static void Lerp( - ref Matrix matrix1, - ref Matrix matrix2, + ref Matrix4x4 matrix1, + ref Matrix4x4 matrix2, float amount, - out Matrix result + out Matrix4x4 result ) { result.M11 = matrix1.M11 + ((matrix2.M11 - matrix1.M11) * amount); result.M12 = matrix1.M12 + ((matrix2.M12 - matrix1.M12) * amount); @@ -2089,14 +2089,14 @@ namespace MoonWorks.Math } /// - /// Creates a new that contains a multiplication of two matrix. + /// Creates a new that contains a multiplication of two matrix. /// - /// Source . - /// Source . + /// Source . + /// Source . /// Result of the matrix multiplication. - public static Matrix Multiply( - Matrix matrix1, - Matrix matrix2 + public static Matrix4x4 Multiply( + Matrix4x4 matrix1, + Matrix4x4 matrix2 ) { float m11 = ( (matrix1.M11 * matrix2.M11) + @@ -2214,12 +2214,12 @@ namespace MoonWorks.Math } /// - /// Creates a new that contains a multiplication of two matrix. + /// Creates a new that contains a multiplication of two matrix. /// - /// Source . - /// Source . + /// Source . + /// Source . /// Result of the matrix multiplication as an output parameter. - public static void Multiply(ref Matrix matrix1, ref Matrix matrix2, out Matrix result) + public static void Multiply(ref Matrix4x4 matrix1, ref Matrix4x4 matrix2, out Matrix4x4 result) { float m11 = ( (matrix1.M11 * matrix2.M11) + @@ -2336,12 +2336,12 @@ namespace MoonWorks.Math } /// - /// Creates a new that contains a multiplication of and a scalar. + /// Creates a new that contains a multiplication of and a scalar. /// - /// Source . + /// Source . /// Scalar value. /// Result of the matrix multiplication with a scalar. - public static Matrix Multiply(Matrix matrix1, float scaleFactor) + public static Matrix4x4 Multiply(Matrix4x4 matrix1, float scaleFactor) { matrix1.M11 *= scaleFactor; matrix1.M12 *= scaleFactor; @@ -2363,12 +2363,12 @@ namespace MoonWorks.Math } /// - /// Creates a new that contains a multiplication of and a scalar. + /// Creates a new that contains a multiplication of and a scalar. /// - /// Source . + /// Source . /// Scalar value. /// Result of the matrix multiplication with a scalar as an output parameter. - public static void Multiply(ref Matrix matrix1, float scaleFactor, out Matrix result) + public static void Multiply(ref Matrix4x4 matrix1, float scaleFactor, out Matrix4x4 result) { result.M11 = matrix1.M11 * scaleFactor; result.M12 = matrix1.M12 * scaleFactor; @@ -2392,9 +2392,9 @@ namespace MoonWorks.Math /// /// Returns a matrix with the all values negated. /// - /// Source . + /// Source . /// Result of the matrix negation. - public static Matrix Negate(Matrix matrix) + public static Matrix4x4 Negate(Matrix4x4 matrix) { matrix.M11 = -matrix.M11; matrix.M12 = -matrix.M12; @@ -2418,9 +2418,9 @@ namespace MoonWorks.Math /// /// Returns a matrix with the all values negated. /// - /// Source . + /// Source . /// Result of the matrix negation as an output parameter. - public static void Negate(ref Matrix matrix, out Matrix result) + public static void Negate(ref Matrix4x4 matrix, out Matrix4x4 result) { result.M11 = -matrix.M11; result.M12 = -matrix.M12; @@ -2441,12 +2441,12 @@ namespace MoonWorks.Math } /// - /// Creates a new that contains subtraction of one matrix from another. + /// Creates a new that contains subtraction of one matrix from another. /// - /// The first . - /// The second . + /// The first . + /// The second . /// The result of the matrix subtraction. - public static Matrix Subtract(Matrix matrix1, Matrix matrix2) + public static Matrix4x4 Subtract(Matrix4x4 matrix1, Matrix4x4 matrix2) { matrix1.M11 -= matrix2.M11; matrix1.M12 -= matrix2.M12; @@ -2468,12 +2468,12 @@ namespace MoonWorks.Math } /// - /// Creates a new that contains subtraction of one matrix from another. + /// Creates a new that contains subtraction of one matrix from another. /// - /// The first . - /// The second . + /// The first . + /// The second . /// The result of the matrix subtraction as an output parameter. - public static void Subtract(ref Matrix matrix1, ref Matrix matrix2, out Matrix result) + public static void Subtract(ref Matrix4x4 matrix1, ref Matrix4x4 matrix2, out Matrix4x4 result) { result.M11 = matrix1.M11 - matrix2.M11; result.M12 = matrix1.M12 - matrix2.M12; @@ -2497,10 +2497,10 @@ namespace MoonWorks.Math /// Swap the matrix rows and columns. /// /// The matrix for transposing operation. - /// The new which contains the transposing result. - public static Matrix Transpose(Matrix matrix) + /// The new which contains the transposing result. + public static Matrix4x4 Transpose(Matrix4x4 matrix) { - Matrix ret; + Matrix4x4 ret; Transpose(ref matrix, out ret); return ret; } @@ -2509,10 +2509,10 @@ namespace MoonWorks.Math /// Swap the matrix rows and columns. /// /// The matrix for transposing operation. - /// The new which contains the transposing result as an output parameter. - public static void Transpose(ref Matrix matrix, out Matrix result) + /// The new which contains the transposing result as an output parameter. + public static void Transpose(ref Matrix4x4 matrix, out Matrix4x4 result) { - Matrix ret; + Matrix4x4 ret; ret.M11 = matrix.M11; ret.M12 = matrix.M21; @@ -2537,19 +2537,19 @@ namespace MoonWorks.Math result = ret; } - public static Matrix Transform(Matrix value, Quaternion rotation) + public static Matrix4x4 Transform(Matrix4x4 value, Quaternion rotation) { - Matrix result; + Matrix4x4 result; Transform(ref value, ref rotation, out result); return result; } public static void Transform( - ref Matrix value, + ref Matrix4x4 value, ref Quaternion rotation, - out Matrix result + out Matrix4x4 result ) { - Matrix rotMatrix = CreateFromQuaternion(rotation); + Matrix4x4 rotMatrix = CreateFromQuaternion(rotation); Multiply(ref value, ref rotMatrix, out result); } @@ -2560,54 +2560,54 @@ namespace MoonWorks.Math /// /// Adds two matrixes. /// - /// Source on the left of the add sign. - /// Source on the right of the add sign. + /// Source on the left of the add sign. + /// Source on the right of the add sign. /// Sum of the matrixes. - public static Matrix operator +(Matrix matrix1, Matrix matrix2) + public static Matrix4x4 operator +(Matrix4x4 matrix1, Matrix4x4 matrix2) { - return Matrix.Add(matrix1, matrix2); + return Matrix4x4.Add(matrix1, matrix2); } /// - /// Divides the elements of a by the elements of another . + /// Divides the elements of a by the elements of another . /// - /// Source on the left of the div sign. - /// Divisor on the right of the div sign. + /// Source on the left of the div sign. + /// Divisor on the right of the div sign. /// The result of dividing the matrixes. - public static Matrix operator /(Matrix matrix1, Matrix matrix2) + public static Matrix4x4 operator /(Matrix4x4 matrix1, Matrix4x4 matrix2) { - return Matrix.Divide(matrix1, matrix2); + return Matrix4x4.Divide(matrix1, matrix2); } /// - /// Divides the elements of a by a scalar. + /// Divides the elements of a by a scalar. /// - /// Source on the left of the div sign. + /// Source on the left of the div sign. /// Divisor scalar on the right of the div sign. /// The result of dividing a matrix by a scalar. - public static Matrix operator /(Matrix matrix, float divider) + public static Matrix4x4 operator /(Matrix4x4 matrix, float divider) { - return Matrix.Divide(matrix, divider); + return Matrix4x4.Divide(matrix, divider); } /// - /// Compares whether two instances are equal without any tolerance. + /// Compares whether two instances are equal without any tolerance. /// - /// Source on the left of the equal sign. - /// Source on the right of the equal sign. + /// Source on the left of the equal sign. + /// Source on the right of the equal sign. /// true if the instances are equal; false otherwise. - public static bool operator ==(Matrix matrix1, Matrix matrix2) + public static bool operator ==(Matrix4x4 matrix1, Matrix4x4 matrix2) { return matrix1.Equals(matrix2); } /// - /// Compares whether two instances are not equal without any tolerance. + /// Compares whether two instances are not equal without any tolerance. /// - /// Source on the left of the not equal sign. - /// Source on the right of the not equal sign. + /// Source on the left of the not equal sign. + /// Source on the right of the not equal sign. /// true if the instances are not equal; false otherwise. - public static bool operator !=(Matrix matrix1, Matrix matrix2) + public static bool operator !=(Matrix4x4 matrix1, Matrix4x4 matrix2) { return !matrix1.Equals(matrix2); } @@ -2615,13 +2615,13 @@ namespace MoonWorks.Math /// /// Multiplies two matrixes. /// - /// Source on the left of the mul sign. - /// Source on the right of the mul sign. + /// Source on the left of the mul sign. + /// Source on the right of the mul sign. /// Result of the matrix multiplication. /// /// Using matrix multiplication algorithm - see http://en.wikipedia.org/wiki/Matrix_multiplication. /// - public static Matrix operator *(Matrix matrix1, Matrix matrix2) + public static Matrix4x4 operator *(Matrix4x4 matrix1, Matrix4x4 matrix2) { return Multiply(matrix1, matrix2); } @@ -2629,31 +2629,31 @@ namespace MoonWorks.Math /// /// Multiplies the elements of matrix by a scalar. /// - /// Source on the left of the mul sign. + /// Source on the left of the mul sign. /// Scalar value on the right of the mul sign. /// Result of the matrix multiplication with a scalar. - public static Matrix operator *(Matrix matrix, float scaleFactor) + public static Matrix4x4 operator *(Matrix4x4 matrix, float scaleFactor) { return Multiply(matrix, scaleFactor); } /// - /// Subtracts the values of one from another . + /// Subtracts the values of one from another . /// - /// Source on the left of the sub sign. - /// Source on the right of the sub sign. + /// Source on the left of the sub sign. + /// Source on the right of the sub sign. /// Result of the matrix subtraction. - public static Matrix operator -(Matrix matrix1, Matrix matrix2) + public static Matrix4x4 operator -(Matrix4x4 matrix1, Matrix4x4 matrix2) { return Subtract(matrix1, matrix2); } /// - /// Inverts values in the specified . + /// Inverts values in the specified . /// - /// Source on the right of the sub sign. + /// Source on the right of the sub sign. /// Result of the inversion. - public static Matrix operator -(Matrix matrix) + public static Matrix4x4 operator -(Matrix4x4 matrix) { return Negate(matrix); } diff --git a/src/Math/Plane.cs b/src/Math/Plane.cs index 091bbf63..c98eb7ce 100644 --- a/src/Math/Plane.cs +++ b/src/Math/Plane.cs @@ -216,7 +216,7 @@ namespace MoonWorks.Math /// The normalized plane to transform. /// The transformation matrix. /// The transformed plane. - public static Plane Transform(Plane plane, Matrix matrix) + public static Plane Transform(Plane plane, Matrix4x4 matrix) { Plane result; Transform(ref plane, ref matrix, out result); @@ -231,16 +231,16 @@ namespace MoonWorks.Math /// The transformed plane. public static void Transform( ref Plane plane, - ref Matrix matrix, + ref Matrix4x4 matrix, out Plane result ) { /* See "Transforming Normals" in * http://www.glprogramming.com/red/appendixf.html * for an explanation of how this works. */ - Matrix transformedMatrix; - Matrix.Invert(ref matrix, out transformedMatrix); - Matrix.Transpose( + Matrix4x4 transformedMatrix; + Matrix4x4.Invert(ref matrix, out transformedMatrix); + Matrix4x4.Transpose( ref transformedMatrix, out transformedMatrix ); diff --git a/src/Math/Quaternion.cs b/src/Math/Quaternion.cs index 620b0328..5a9b0aa0 100644 --- a/src/Math/Quaternion.cs +++ b/src/Math/Quaternion.cs @@ -370,11 +370,11 @@ namespace MoonWorks.Math } /// - /// Creates a new from the specified . + /// Creates a new from the specified . /// /// The rotation matrix. /// A quaternion composed from the rotation part of the matrix. - public static Quaternion CreateFromRotationMatrix(Matrix matrix) + public static Quaternion CreateFromRotationMatrix(Matrix4x4 matrix) { Quaternion quaternion; CreateFromRotationMatrix(ref matrix, out quaternion); @@ -382,11 +382,11 @@ namespace MoonWorks.Math } /// - /// Creates a new from the specified . + /// Creates a new from the specified . /// /// The rotation matrix. /// A quaternion composed from the rotation part of the matrix as an output parameter. - public static void CreateFromRotationMatrix(ref Matrix matrix, out Quaternion result) + public static void CreateFromRotationMatrix(ref Matrix4x4 matrix, out Quaternion result) { float sqrt; float half; diff --git a/src/Math/Vector2.cs b/src/Math/Vector2.cs index f7e6c8b8..4ac16bea 100644 --- a/src/Math/Vector2.cs +++ b/src/Math/Vector2.cs @@ -804,12 +804,12 @@ namespace MoonWorks.Math } /// - /// Creates a new that contains a transformation of 2d-vector by the specified . + /// Creates a new that contains a transformation of 2d-vector by the specified . /// /// Source . - /// The transformation . + /// The transformation . /// Transformed . - public static Vector2 Transform(Vector2 position, Matrix matrix) + public static Vector2 Transform(Vector2 position, Matrix4x4 matrix) { return new Vector2( (position.X * matrix.M11) + (position.Y * matrix.M21) + matrix.M41, @@ -818,14 +818,14 @@ namespace MoonWorks.Math } /// - /// Creates a new that contains a transformation of 2d-vector by the specified . + /// Creates a new that contains a transformation of 2d-vector by the specified . /// /// Source . - /// The transformation . + /// The transformation . /// Transformed as an output parameter. public static void Transform( ref Vector2 position, - ref Matrix matrix, + ref Matrix4x4 matrix, out Vector2 result ) { float x = (position.X * matrix.M11) + (position.Y * matrix.M21) + matrix.M41; @@ -866,32 +866,32 @@ namespace MoonWorks.Math } /// - /// Apply transformation on all vectors within array of by the specified and places the results in an another array. + /// Apply transformation on all vectors within array of by the specified and places the results in an another array. /// /// Source array. - /// The transformation . + /// The transformation . /// Destination array. public static void Transform( Vector2[] sourceArray, - ref Matrix matrix, + ref Matrix4x4 matrix, Vector2[] destinationArray ) { Transform(sourceArray, 0, ref matrix, destinationArray, 0, sourceArray.Length); } /// - /// Apply transformation on vectors within array of by the specified and places the results in an another array. + /// Apply transformation on vectors within array of by the specified and places the results in an another array. /// /// Source array. /// The starting index of transformation in the source array. - /// The transformation . + /// The transformation . /// Destination array. /// The starting index in the destination array, where the first should be written. /// The number of vectors to be transformed. public static void Transform( Vector2[] sourceArray, int sourceIndex, - ref Matrix matrix, + ref Matrix4x4 matrix, Vector2[] destinationArray, int destinationIndex, int length @@ -956,12 +956,12 @@ namespace MoonWorks.Math } /// - /// Creates a new that contains a transformation of the specified normal by the specified . + /// Creates a new that contains a transformation of the specified normal by the specified . /// /// Source which represents a normal vector. - /// The transformation . + /// The transformation . /// Transformed normal. - public static Vector2 TransformNormal(Vector2 normal, Matrix matrix) + public static Vector2 TransformNormal(Vector2 normal, Matrix4x4 matrix) { return new Vector2( (normal.X * matrix.M11) + (normal.Y * matrix.M21), @@ -970,14 +970,14 @@ namespace MoonWorks.Math } /// - /// Creates a new that contains a transformation of the specified normal by the specified . + /// Creates a new that contains a transformation of the specified normal by the specified . /// /// Source which represents a normal vector. - /// The transformation . + /// The transformation . /// Transformed normal as an output parameter. public static void TransformNormal( ref Vector2 normal, - ref Matrix matrix, + ref Matrix4x4 matrix, out Vector2 result ) { float x = (normal.X * matrix.M11) + (normal.Y * matrix.M21); @@ -987,14 +987,14 @@ namespace MoonWorks.Math } /// - /// Apply transformation on all normals within array of by the specified and places the results in an another array. + /// Apply transformation on all normals within array of by the specified and places the results in an another array. /// /// Source array. - /// The transformation . + /// The transformation . /// Destination array. public static void TransformNormal( Vector2[] sourceArray, - ref Matrix matrix, + ref Matrix4x4 matrix, Vector2[] destinationArray ) { TransformNormal( @@ -1008,18 +1008,18 @@ namespace MoonWorks.Math } /// - /// Apply transformation on normals within array of by the specified and places the results in an another array. + /// Apply transformation on normals within array of by the specified and places the results in an another array. /// /// Source array. /// The starting index of transformation in the source array. - /// The transformation . + /// The transformation . /// Destination array. /// The starting index in the destination array, where the first should be written. /// The number of normals to be transformed. public static void TransformNormal( Vector2[] sourceArray, int sourceIndex, - ref Matrix matrix, + ref Matrix4x4 matrix, Vector2[] destinationArray, int destinationIndex, int length diff --git a/src/Math/Vector3.cs b/src/Math/Vector3.cs index eadaf77d..746aecc5 100644 --- a/src/Math/Vector3.cs +++ b/src/Math/Vector3.cs @@ -1013,26 +1013,26 @@ namespace MoonWorks.Math } /// - /// Creates a new that contains a transformation of 3d-vector by the specified . + /// Creates a new that contains a transformation of 3d-vector by the specified . /// /// Source . - /// The transformation . + /// The transformation . /// Transformed . - public static Vector3 Transform(Vector3 position, Matrix matrix) + public static Vector3 Transform(Vector3 position, Matrix4x4 matrix) { Transform(ref position, ref matrix, out position); return position; } /// - /// Creates a new that contains a transformation of 3d-vector by the specified . + /// Creates a new that contains a transformation of 3d-vector by the specified . /// /// Source . - /// The transformation . + /// The transformation . /// Transformed as an output parameter. public static void Transform( ref Vector3 position, - ref Matrix matrix, + ref Matrix4x4 matrix, out Vector3 result ) { float x = ( @@ -1059,14 +1059,14 @@ namespace MoonWorks.Math } /// - /// Apply transformation on all vectors within array of by the specified and places the results in an another array. + /// Apply transformation on all vectors within array of by the specified and places the results in an another array. /// /// Source array. - /// The transformation . + /// The transformation . /// Destination array. public static void Transform( Vector3[] sourceArray, - ref Matrix matrix, + ref Matrix4x4 matrix, Vector3[] destinationArray ) { Debug.Assert( @@ -1093,18 +1093,18 @@ namespace MoonWorks.Math } /// - /// Apply transformation on vectors within array of by the specified and places the results in an another array. + /// Apply transformation on vectors within array of by the specified and places the results in an another array. /// /// Source array. /// The starting index of transformation in the source array. - /// The transformation . + /// The transformation . /// Destination array. /// The starting index in the destination array, where the first should be written. /// The number of vectors to be transformed. public static void Transform( Vector3[] sourceArray, int sourceIndex, - ref Matrix matrix, + ref Matrix4x4 matrix, Vector3[] destinationArray, int destinationIndex, int length @@ -1255,26 +1255,26 @@ namespace MoonWorks.Math } /// - /// Creates a new that contains a transformation of the specified normal by the specified . + /// Creates a new that contains a transformation of the specified normal by the specified . /// /// Source which represents a normal vector. - /// The transformation . + /// The transformation . /// Transformed normal. - public static Vector3 TransformNormal(Vector3 normal, Matrix matrix) + public static Vector3 TransformNormal(Vector3 normal, Matrix4x4 matrix) { TransformNormal(ref normal, ref matrix, out normal); return normal; } /// - /// Creates a new that contains a transformation of the specified normal by the specified . + /// Creates a new that contains a transformation of the specified normal by the specified . /// /// Source which represents a normal vector. - /// The transformation . + /// The transformation . /// Transformed normal as an output parameter. public static void TransformNormal( ref Vector3 normal, - ref Matrix matrix, + ref Matrix4x4 matrix, out Vector3 result ) { float x = (normal.X * matrix.M11) + (normal.Y * matrix.M21) + (normal.Z * matrix.M31); @@ -1286,14 +1286,14 @@ namespace MoonWorks.Math } /// - /// Apply transformation on all normals within array of by the specified and places the results in an another array. + /// Apply transformation on all normals within array of by the specified and places the results in an another array. /// /// Source array. - /// The transformation . + /// The transformation . /// Destination array. public static void TransformNormal( Vector3[] sourceArray, - ref Matrix matrix, + ref Matrix4x4 matrix, Vector3[] destinationArray ) { Debug.Assert( @@ -1311,18 +1311,18 @@ namespace MoonWorks.Math } /// - /// Apply transformation on normals within array of by the specified and places the results in an another array. + /// Apply transformation on normals within array of by the specified and places the results in an another array. /// /// Source array. /// The starting index of transformation in the source array. - /// The transformation . + /// The transformation . /// Destination array. /// The starting index in the destination array, where the first should be written. /// The number of normals to be transformed. public static void TransformNormal( Vector3[] sourceArray, int sourceIndex, - ref Matrix matrix, + ref Matrix4x4 matrix, Vector3[] destinationArray, int destinationIndex, int length diff --git a/src/Math/Vector4.cs b/src/Math/Vector4.cs index a78f3d27..1332bee4 100644 --- a/src/Math/Vector4.cs +++ b/src/Math/Vector4.cs @@ -942,12 +942,12 @@ namespace MoonWorks.Math } /// - /// Creates a new that contains a transformation of 2d-vector by the specified . + /// Creates a new that contains a transformation of 2d-vector by the specified . /// /// Source . - /// The transformation . + /// The transformation . /// Transformed . - public static Vector4 Transform(Vector2 position, Matrix matrix) + public static Vector4 Transform(Vector2 position, Matrix4x4 matrix) { Vector4 result; Transform(ref position, ref matrix, out result); @@ -955,12 +955,12 @@ namespace MoonWorks.Math } /// - /// Creates a new that contains a transformation of 3d-vector by the specified . + /// Creates a new that contains a transformation of 3d-vector by the specified . /// /// Source . - /// The transformation . + /// The transformation . /// Transformed . - public static Vector4 Transform(Vector3 position, Matrix matrix) + public static Vector4 Transform(Vector3 position, Matrix4x4 matrix) { Vector4 result; Transform(ref position, ref matrix, out result); @@ -968,24 +968,24 @@ namespace MoonWorks.Math } /// - /// Creates a new that contains a transformation of 4d-vector by the specified . + /// Creates a new that contains a transformation of 4d-vector by the specified . /// /// Source . - /// The transformation . + /// The transformation . /// Transformed . - public static Vector4 Transform(Vector4 vector, Matrix matrix) + public static Vector4 Transform(Vector4 vector, Matrix4x4 matrix) { Transform(ref vector, ref matrix, out vector); return vector; } /// - /// Creates a new that contains a transformation of 2d-vector by the specified . + /// Creates a new that contains a transformation of 2d-vector by the specified . /// /// Source . - /// The transformation . + /// The transformation . /// Transformed as an output parameter. - public static void Transform(ref Vector2 position, ref Matrix matrix, out Vector4 result) + public static void Transform(ref Vector2 position, ref Matrix4x4 matrix, out Vector4 result) { result = new Vector4( (position.X * matrix.M11) + (position.Y * matrix.M21) + matrix.M41, @@ -996,12 +996,12 @@ namespace MoonWorks.Math } /// - /// Creates a new that contains a transformation of 3d-vector by the specified . + /// Creates a new that contains a transformation of 3d-vector by the specified . /// /// Source . - /// The transformation . + /// The transformation . /// Transformed as an output parameter. - public static void Transform(ref Vector3 position, ref Matrix matrix, out Vector4 result) + public static void Transform(ref Vector3 position, ref Matrix4x4 matrix, out Vector4 result) { float x = ( (position.X * matrix.M11) + @@ -1034,12 +1034,12 @@ namespace MoonWorks.Math } /// - /// Creates a new that contains a transformation of 4d-vector by the specified . + /// Creates a new that contains a transformation of 4d-vector by the specified . /// /// Source . - /// The transformation . + /// The transformation . /// Transformed as an output parameter. - public static void Transform(ref Vector4 vector, ref Matrix matrix, out Vector4 result) + public static void Transform(ref Vector4 vector, ref Matrix4x4 matrix, out Vector4 result) { float x = ( (vector.X * matrix.M11) + @@ -1072,14 +1072,14 @@ namespace MoonWorks.Math } /// - /// Apply transformation on all vectors within array of by the specified and places the results in an another array. + /// Apply transformation on all vectors within array of by the specified and places the results in an another array. /// /// Source array. - /// The transformation . + /// The transformation . /// Destination array. public static void Transform( Vector4[] sourceArray, - ref Matrix matrix, + ref Matrix4x4 matrix, Vector4[] destinationArray ) { if (sourceArray == null) @@ -1107,18 +1107,18 @@ namespace MoonWorks.Math } /// - /// Apply transformation on vectors within array of by the specified and places the results in an another array. + /// Apply transformation on vectors within array of by the specified and places the results in an another array. /// /// Source array. /// The starting index of transformation in the source array. - /// The transformation . + /// The transformation . /// Destination array. /// The starting index in the destination array, where the first should be written. /// The number of vectors to be transformed. public static void Transform( Vector4[] sourceArray, int sourceIndex, - ref Matrix matrix, + ref Matrix4x4 matrix, Vector4[] destinationArray, int destinationIndex, int length