add Matrix3x2 and rename Matrix to Matrix4x4
parent
e6fa95b823
commit
09c03fece9
|
@ -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.
|
|
@ -33,7 +33,7 @@ namespace MoonWorks.Math
|
|||
/// <summary>
|
||||
/// Gets or sets the <see cref="Matrix"/> of the frustum.
|
||||
/// </summary>
|
||||
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.
|
||||
/// </summary>
|
||||
/// <param name="value">Combined matrix which usually is (View * Projection).</param>
|
||||
public BoundingFrustum(Matrix value)
|
||||
public BoundingFrustum(Matrix4x4 value)
|
||||
{
|
||||
this.matrix = value;
|
||||
this.CreatePlanes();
|
||||
|
|
|
@ -77,11 +77,11 @@ namespace MoonWorks.Math
|
|||
#region Public Methods
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="BoundingSphere"/> that contains a transformation of translation and scale from this sphere by the specified <see cref="Matrix"/>.
|
||||
/// Creates a new <see cref="BoundingSphere"/> that contains a transformation of translation and scale from this sphere by the specified <see cref="Matrix4x4"/>.
|
||||
/// </summary>
|
||||
/// <param name="matrix">The transformation <see cref="Matrix"/>.</param>
|
||||
/// <param name="matrix">The transformation <see cref="Matrix4x4"/>.</param>
|
||||
/// <returns>Transformed <see cref="BoundingSphere"/>.</returns>
|
||||
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
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="BoundingSphere"/> that contains a transformation of translation and scale from this sphere by the specified <see cref="Matrix"/>.
|
||||
/// Creates a new <see cref="BoundingSphere"/> that contains a transformation of translation and scale from this sphere by the specified <see cref="Matrix4x4"/>.
|
||||
/// </summary>
|
||||
/// <param name="matrix">The transformation <see cref="Matrix"/>.</param>
|
||||
/// <param name="matrix">The transformation <see cref="Matrix4x4"/>.</param>
|
||||
/// <param name="result">Transformed <see cref="BoundingSphere"/> as an output parameter.</param>
|
||||
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 *
|
||||
|
|
|
@ -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
|
||||
{
|
||||
/// <summary>
|
||||
/// A structure encapsulating a 3x2 matrix.
|
||||
/// </summary>
|
||||
public struct Matrix3x2 : IEquatable<Matrix3x2>
|
||||
{
|
||||
#region Public Fields
|
||||
/// <summary>
|
||||
/// The first element of the first row
|
||||
/// </summary>
|
||||
public float M11;
|
||||
/// <summary>
|
||||
/// The second element of the first row
|
||||
/// </summary>
|
||||
public float M12;
|
||||
/// <summary>
|
||||
/// The first element of the second row
|
||||
/// </summary>
|
||||
public float M21;
|
||||
/// <summary>
|
||||
/// The second element of the second row
|
||||
/// </summary>
|
||||
public float M22;
|
||||
/// <summary>
|
||||
/// The first element of the third row
|
||||
/// </summary>
|
||||
public float M31;
|
||||
/// <summary>
|
||||
/// The second element of the third row
|
||||
/// </summary>
|
||||
public float M32;
|
||||
#endregion Public Fields
|
||||
|
||||
private static readonly Matrix3x2 _identity = new Matrix3x2
|
||||
(
|
||||
1f, 0f,
|
||||
0f, 1f,
|
||||
0f, 0f
|
||||
);
|
||||
|
||||
/// <summary>
|
||||
/// Returns the multiplicative identity matrix.
|
||||
/// </summary>
|
||||
public static Matrix3x2 Identity
|
||||
{
|
||||
get { return _identity; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns whether the matrix is the identity matrix.
|
||||
/// </summary>
|
||||
public bool IsIdentity
|
||||
{
|
||||
get
|
||||
{
|
||||
return M11 == 1f && M22 == 1f && // Check diagonal element first for early out.
|
||||
M12 == 0f &&
|
||||
M21 == 0f &&
|
||||
M31 == 0f && M32 == 0f;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the translation component of this matrix.
|
||||
/// </summary>
|
||||
public Vector2 Translation
|
||||
{
|
||||
get
|
||||
{
|
||||
return new Vector2(M31, M32);
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
M31 = value.X;
|
||||
M32 = value.Y;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a Matrix3x2 from the given components.
|
||||
/// </summary>
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a translation matrix from the given vector.
|
||||
/// </summary>
|
||||
/// <param name="position">The translation position.</param>
|
||||
/// <returns>A translation matrix.</returns>
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a translation matrix from the given X and Y components.
|
||||
/// </summary>
|
||||
/// <param name="xPosition">The X position.</param>
|
||||
/// <param name="yPosition">The Y position.</param>
|
||||
/// <returns>A translation matrix.</returns>
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a scale matrix from the given X and Y components.
|
||||
/// </summary>
|
||||
/// <param name="xScale">Value to scale by on the X-axis.</param>
|
||||
/// <param name="yScale">Value to scale by on the Y-axis.</param>
|
||||
/// <returns>A scaling matrix.</returns>
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a scale matrix that is offset by a given center point.
|
||||
/// </summary>
|
||||
/// <param name="xScale">Value to scale by on the X-axis.</param>
|
||||
/// <param name="yScale">Value to scale by on the Y-axis.</param>
|
||||
/// <param name="centerPoint">The center point.</param>
|
||||
/// <returns>A scaling matrix.</returns>
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a scale matrix from the given vector scale.
|
||||
/// </summary>
|
||||
/// <param name="scales">The scale to use.</param>
|
||||
/// <returns>A scaling matrix.</returns>
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a scale matrix from the given vector scale with an offset from the given center point.
|
||||
/// </summary>
|
||||
/// <param name="scales">The scale to use.</param>
|
||||
/// <param name="centerPoint">The center offset.</param>
|
||||
/// <returns>A scaling matrix.</returns>
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a scale matrix that scales uniformly with the given scale.
|
||||
/// </summary>
|
||||
/// <param name="scale">The uniform scale to use.</param>
|
||||
/// <returns>A scaling matrix.</returns>
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a scale matrix that scales uniformly with the given scale with an offset from the given center.
|
||||
/// </summary>
|
||||
/// <param name="scale">The uniform scale to use.</param>
|
||||
/// <param name="centerPoint">The center offset.</param>
|
||||
/// <returns>A scaling matrix.</returns>
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a skew matrix from the given angles in radians.
|
||||
/// </summary>
|
||||
/// <param name="radiansX">The X angle, in radians.</param>
|
||||
/// <param name="radiansY">The Y angle, in radians.</param>
|
||||
/// <returns>A skew matrix.</returns>
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a skew matrix from the given angles in radians and a center point.
|
||||
/// </summary>
|
||||
/// <param name="radiansX">The X angle, in radians.</param>
|
||||
/// <param name="radiansY">The Y angle, in radians.</param>
|
||||
/// <param name="centerPoint">The center point.</param>
|
||||
/// <returns>A skew matrix.</returns>
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a rotation matrix using the given rotation in radians.
|
||||
/// </summary>
|
||||
/// <param name="radians">The amount of rotation, in radians.</param>
|
||||
/// <returns>A rotation matrix.</returns>
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a rotation matrix using the given rotation in radians and a center point.
|
||||
/// </summary>
|
||||
/// <param name="radians">The amount of rotation, in radians.</param>
|
||||
/// <param name="centerPoint">The center point.</param>
|
||||
/// <returns>A rotation matrix.</returns>
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Calculates the determinant for this matrix.
|
||||
/// The determinant is calculated by expanding the matrix with a third column whose values are (0,0,1).
|
||||
/// </summary>
|
||||
/// <returns>The determinant.</returns>
|
||||
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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Attempts to invert the given matrix. If the operation succeeds, the inverted matrix is stored in the result parameter.
|
||||
/// </summary>
|
||||
/// <param name="matrix">The source matrix.</param>
|
||||
/// <param name="result">The output matrix.</param>
|
||||
/// <returns>True if the operation succeeded, False otherwise.</returns>
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Linearly interpolates from matrix1 to matrix2, based on the third parameter.
|
||||
/// </summary>
|
||||
/// <param name="matrix1">The first source matrix.</param>
|
||||
/// <param name="matrix2">The second source matrix.</param>
|
||||
/// <param name="amount">The relative weighting of matrix2.</param>
|
||||
/// <returns>The interpolated matrix.</returns>
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Negates the given matrix by multiplying all values by -1.
|
||||
/// </summary>
|
||||
/// <param name="value">The source matrix.</param>
|
||||
/// <returns>The negated matrix.</returns>
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds each matrix element in value1 with its corresponding element in value2.
|
||||
/// </summary>
|
||||
/// <param name="value1">The first source matrix.</param>
|
||||
/// <param name="value2">The second source matrix.</param>
|
||||
/// <returns>The matrix containing the summed values.</returns>
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Subtracts each matrix element in value2 from its corresponding element in value1.
|
||||
/// </summary>
|
||||
/// <param name="value1">The first source matrix.</param>
|
||||
/// <param name="value2">The second source matrix.</param>
|
||||
/// <returns>The matrix containing the resulting values.</returns>
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Multiplies two matrices together and returns the resulting matrix.
|
||||
/// </summary>
|
||||
/// <param name="value1">The first source matrix.</param>
|
||||
/// <param name="value2">The second source matrix.</param>
|
||||
/// <returns>The product matrix.</returns>
|
||||
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
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Scales all elements in a matrix by the given scalar factor.
|
||||
/// </summary>
|
||||
/// <param name="value1">The source matrix.</param>
|
||||
/// <param name="value2">The scaling value to use.</param>
|
||||
/// <returns>The resulting matrix.</returns>
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Negates the given matrix by multiplying all values by -1.
|
||||
/// </summary>
|
||||
/// <param name="value">The source matrix.</param>
|
||||
/// <returns>The negated matrix.</returns>
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds each matrix element in value1 with its corresponding element in value2.
|
||||
/// </summary>
|
||||
/// <param name="value1">The first source matrix.</param>
|
||||
/// <param name="value2">The second source matrix.</param>
|
||||
/// <returns>The matrix containing the summed values.</returns>
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Subtracts each matrix element in value2 from its corresponding element in value1.
|
||||
/// </summary>
|
||||
/// <param name="value1">The first source matrix.</param>
|
||||
/// <param name="value2">The second source matrix.</param>
|
||||
/// <returns>The matrix containing the resulting values.</returns>
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Multiplies two matrices together and returns the resulting matrix.
|
||||
/// </summary>
|
||||
/// <param name="value1">The first source matrix.</param>
|
||||
/// <param name="value2">The second source matrix.</param>
|
||||
/// <returns>The product matrix.</returns>
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Scales all elements in a matrix by the given scalar factor.
|
||||
/// </summary>
|
||||
/// <param name="value1">The source matrix.</param>
|
||||
/// <param name="value2">The scaling value to use.</param>
|
||||
/// <returns>The resulting matrix.</returns>
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a boolean indicating whether the given matrices are equal.
|
||||
/// </summary>
|
||||
/// <param name="value1">The first source matrix.</param>
|
||||
/// <param name="value2">The second source matrix.</param>
|
||||
/// <returns>True if the matrices are equal; False otherwise.</returns>
|
||||
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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a boolean indicating whether the given matrices are not equal.
|
||||
/// </summary>
|
||||
/// <param name="value1">The first source matrix.</param>
|
||||
/// <param name="value2">The second source matrix.</param>
|
||||
/// <returns>True if the matrices are not equal; False if they are equal.</returns>
|
||||
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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a boolean indicating whether the matrix is equal to the other given matrix.
|
||||
/// </summary>
|
||||
/// <param name="other">The other matrix to test equality against.</param>
|
||||
/// <returns>True if this matrix is equal to other; False otherwise.</returns>
|
||||
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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a boolean indicating whether the given Object is equal to this matrix instance.
|
||||
/// </summary>
|
||||
/// <param name="obj">The Object to compare against.</param>
|
||||
/// <returns>True if the Object is equal to this matrix; False otherwise.</returns>
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
if (obj is Matrix3x2)
|
||||
{
|
||||
return Equals((Matrix3x2)obj);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a String representing this matrix instance.
|
||||
/// </summary>
|
||||
/// <returns>The string representation.</returns>
|
||||
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));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the hash code for this instance.
|
||||
/// </summary>
|
||||
/// <returns>The hash code.</returns>
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return M11.GetHashCode() + M12.GetHashCode() +
|
||||
M21.GetHashCode() + M22.GetHashCode() +
|
||||
M31.GetHashCode() + M32.GetHashCode();
|
||||
}
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
|
@ -216,7 +216,7 @@ namespace MoonWorks.Math
|
|||
/// <param name="plane">The normalized plane to transform.</param>
|
||||
/// <param name="matrix">The transformation matrix.</param>
|
||||
/// <returns>The transformed plane.</returns>
|
||||
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
|
|||
/// <param name="result">The transformed plane.</param>
|
||||
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
|
||||
);
|
||||
|
|
|
@ -370,11 +370,11 @@ namespace MoonWorks.Math
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="Quaternion"/> from the specified <see cref="Matrix"/>.
|
||||
/// Creates a new <see cref="Quaternion"/> from the specified <see cref="Matrix4x4"/>.
|
||||
/// </summary>
|
||||
/// <param name="matrix">The rotation matrix.</param>
|
||||
/// <returns>A quaternion composed from the rotation part of the matrix.</returns>
|
||||
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
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="Quaternion"/> from the specified <see cref="Matrix"/>.
|
||||
/// Creates a new <see cref="Quaternion"/> from the specified <see cref="Matrix4x4"/>.
|
||||
/// </summary>
|
||||
/// <param name="matrix">The rotation matrix.</param>
|
||||
/// <param name="result">A quaternion composed from the rotation part of the matrix as an output parameter.</param>
|
||||
public static void CreateFromRotationMatrix(ref Matrix matrix, out Quaternion result)
|
||||
public static void CreateFromRotationMatrix(ref Matrix4x4 matrix, out Quaternion result)
|
||||
{
|
||||
float sqrt;
|
||||
float half;
|
||||
|
|
|
@ -804,12 +804,12 @@ namespace MoonWorks.Math
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="Vector2"/> that contains a transformation of 2d-vector by the specified <see cref="Matrix"/>.
|
||||
/// Creates a new <see cref="Vector2"/> that contains a transformation of 2d-vector by the specified <see cref="Matrix4x4"/>.
|
||||
/// </summary>
|
||||
/// <param name="position">Source <see cref="Vector2"/>.</param>
|
||||
/// <param name="matrix">The transformation <see cref="Matrix"/>.</param>
|
||||
/// <param name="matrix">The transformation <see cref="Matrix4x4"/>.</param>
|
||||
/// <returns>Transformed <see cref="Vector2"/>.</returns>
|
||||
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
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="Vector2"/> that contains a transformation of 2d-vector by the specified <see cref="Matrix"/>.
|
||||
/// Creates a new <see cref="Vector2"/> that contains a transformation of 2d-vector by the specified <see cref="Matrix4x4"/>.
|
||||
/// </summary>
|
||||
/// <param name="position">Source <see cref="Vector2"/>.</param>
|
||||
/// <param name="matrix">The transformation <see cref="Matrix"/>.</param>
|
||||
/// <param name="matrix">The transformation <see cref="Matrix4x4"/>.</param>
|
||||
/// <param name="result">Transformed <see cref="Vector2"/> as an output parameter.</param>
|
||||
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
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// Apply transformation on all vectors within array of <see cref="Vector2"/> by the specified <see cref="Matrix"/> and places the results in an another array.
|
||||
/// Apply transformation on all vectors within array of <see cref="Vector2"/> by the specified <see cref="Matrix4x4"/> and places the results in an another array.
|
||||
/// </summary>
|
||||
/// <param name="sourceArray">Source array.</param>
|
||||
/// <param name="matrix">The transformation <see cref="Matrix"/>.</param>
|
||||
/// <param name="matrix">The transformation <see cref="Matrix4x4"/>.</param>
|
||||
/// <param name="destinationArray">Destination array.</param>
|
||||
public static void Transform(
|
||||
Vector2[] sourceArray,
|
||||
ref Matrix matrix,
|
||||
ref Matrix4x4 matrix,
|
||||
Vector2[] destinationArray
|
||||
) {
|
||||
Transform(sourceArray, 0, ref matrix, destinationArray, 0, sourceArray.Length);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Apply transformation on vectors within array of <see cref="Vector2"/> by the specified <see cref="Matrix"/> and places the results in an another array.
|
||||
/// Apply transformation on vectors within array of <see cref="Vector2"/> by the specified <see cref="Matrix4x4"/> and places the results in an another array.
|
||||
/// </summary>
|
||||
/// <param name="sourceArray">Source array.</param>
|
||||
/// <param name="sourceIndex">The starting index of transformation in the source array.</param>
|
||||
/// <param name="matrix">The transformation <see cref="Matrix"/>.</param>
|
||||
/// <param name="matrix">The transformation <see cref="Matrix4x4"/>.</param>
|
||||
/// <param name="destinationArray">Destination array.</param>
|
||||
/// <param name="destinationIndex">The starting index in the destination array, where the first <see cref="Vector2"/> should be written.</param>
|
||||
/// <param name="length">The number of vectors to be transformed.</param>
|
||||
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
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="Vector2"/> that contains a transformation of the specified normal by the specified <see cref="Matrix"/>.
|
||||
/// Creates a new <see cref="Vector2"/> that contains a transformation of the specified normal by the specified <see cref="Matrix4x4"/>.
|
||||
/// </summary>
|
||||
/// <param name="normal">Source <see cref="Vector2"/> which represents a normal vector.</param>
|
||||
/// <param name="matrix">The transformation <see cref="Matrix"/>.</param>
|
||||
/// <param name="matrix">The transformation <see cref="Matrix4x4"/>.</param>
|
||||
/// <returns>Transformed normal.</returns>
|
||||
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
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="Vector2"/> that contains a transformation of the specified normal by the specified <see cref="Matrix"/>.
|
||||
/// Creates a new <see cref="Vector2"/> that contains a transformation of the specified normal by the specified <see cref="Matrix4x4"/>.
|
||||
/// </summary>
|
||||
/// <param name="normal">Source <see cref="Vector2"/> which represents a normal vector.</param>
|
||||
/// <param name="matrix">The transformation <see cref="Matrix"/>.</param>
|
||||
/// <param name="matrix">The transformation <see cref="Matrix4x4"/>.</param>
|
||||
/// <param name="result">Transformed normal as an output parameter.</param>
|
||||
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
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// Apply transformation on all normals within array of <see cref="Vector2"/> by the specified <see cref="Matrix"/> and places the results in an another array.
|
||||
/// Apply transformation on all normals within array of <see cref="Vector2"/> by the specified <see cref="Matrix4x4"/> and places the results in an another array.
|
||||
/// </summary>
|
||||
/// <param name="sourceArray">Source array.</param>
|
||||
/// <param name="matrix">The transformation <see cref="Matrix"/>.</param>
|
||||
/// <param name="matrix">The transformation <see cref="Matrix4x4"/>.</param>
|
||||
/// <param name="destinationArray">Destination array.</param>
|
||||
public static void TransformNormal(
|
||||
Vector2[] sourceArray,
|
||||
ref Matrix matrix,
|
||||
ref Matrix4x4 matrix,
|
||||
Vector2[] destinationArray
|
||||
) {
|
||||
TransformNormal(
|
||||
|
@ -1008,18 +1008,18 @@ namespace MoonWorks.Math
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// Apply transformation on normals within array of <see cref="Vector2"/> by the specified <see cref="Matrix"/> and places the results in an another array.
|
||||
/// Apply transformation on normals within array of <see cref="Vector2"/> by the specified <see cref="Matrix4x4"/> and places the results in an another array.
|
||||
/// </summary>
|
||||
/// <param name="sourceArray">Source array.</param>
|
||||
/// <param name="sourceIndex">The starting index of transformation in the source array.</param>
|
||||
/// <param name="matrix">The transformation <see cref="Matrix"/>.</param>
|
||||
/// <param name="matrix">The transformation <see cref="Matrix4x4"/>.</param>
|
||||
/// <param name="destinationArray">Destination array.</param>
|
||||
/// <param name="destinationIndex">The starting index in the destination array, where the first <see cref="Vector2"/> should be written.</param>
|
||||
/// <param name="length">The number of normals to be transformed.</param>
|
||||
public static void TransformNormal(
|
||||
Vector2[] sourceArray,
|
||||
int sourceIndex,
|
||||
ref Matrix matrix,
|
||||
ref Matrix4x4 matrix,
|
||||
Vector2[] destinationArray,
|
||||
int destinationIndex,
|
||||
int length
|
||||
|
|
|
@ -1013,26 +1013,26 @@ namespace MoonWorks.Math
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="Vector3"/> that contains a transformation of 3d-vector by the specified <see cref="Matrix"/>.
|
||||
/// Creates a new <see cref="Vector3"/> that contains a transformation of 3d-vector by the specified <see cref="Matrix4x4"/>.
|
||||
/// </summary>
|
||||
/// <param name="position">Source <see cref="Vector3"/>.</param>
|
||||
/// <param name="matrix">The transformation <see cref="Matrix"/>.</param>
|
||||
/// <param name="matrix">The transformation <see cref="Matrix4x4"/>.</param>
|
||||
/// <returns>Transformed <see cref="Vector3"/>.</returns>
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="Vector3"/> that contains a transformation of 3d-vector by the specified <see cref="Matrix"/>.
|
||||
/// Creates a new <see cref="Vector3"/> that contains a transformation of 3d-vector by the specified <see cref="Matrix4x4"/>.
|
||||
/// </summary>
|
||||
/// <param name="position">Source <see cref="Vector3"/>.</param>
|
||||
/// <param name="matrix">The transformation <see cref="Matrix"/>.</param>
|
||||
/// <param name="matrix">The transformation <see cref="Matrix4x4"/>.</param>
|
||||
/// <param name="result">Transformed <see cref="Vector3"/> as an output parameter.</param>
|
||||
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
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// Apply transformation on all vectors within array of <see cref="Vector3"/> by the specified <see cref="Matrix"/> and places the results in an another array.
|
||||
/// Apply transformation on all vectors within array of <see cref="Vector3"/> by the specified <see cref="Matrix4x4"/> and places the results in an another array.
|
||||
/// </summary>
|
||||
/// <param name="sourceArray">Source array.</param>
|
||||
/// <param name="matrix">The transformation <see cref="Matrix"/>.</param>
|
||||
/// <param name="matrix">The transformation <see cref="Matrix4x4"/>.</param>
|
||||
/// <param name="destinationArray">Destination array.</param>
|
||||
public static void Transform(
|
||||
Vector3[] sourceArray,
|
||||
ref Matrix matrix,
|
||||
ref Matrix4x4 matrix,
|
||||
Vector3[] destinationArray
|
||||
) {
|
||||
Debug.Assert(
|
||||
|
@ -1093,18 +1093,18 @@ namespace MoonWorks.Math
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// Apply transformation on vectors within array of <see cref="Vector3"/> by the specified <see cref="Matrix"/> and places the results in an another array.
|
||||
/// Apply transformation on vectors within array of <see cref="Vector3"/> by the specified <see cref="Matrix4x4"/> and places the results in an another array.
|
||||
/// </summary>
|
||||
/// <param name="sourceArray">Source array.</param>
|
||||
/// <param name="sourceIndex">The starting index of transformation in the source array.</param>
|
||||
/// <param name="matrix">The transformation <see cref="Matrix"/>.</param>
|
||||
/// <param name="matrix">The transformation <see cref="Matrix4x4"/>.</param>
|
||||
/// <param name="destinationArray">Destination array.</param>
|
||||
/// <param name="destinationIndex">The starting index in the destination array, where the first <see cref="Vector3"/> should be written.</param>
|
||||
/// <param name="length">The number of vectors to be transformed.</param>
|
||||
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
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="Vector3"/> that contains a transformation of the specified normal by the specified <see cref="Matrix"/>.
|
||||
/// Creates a new <see cref="Vector3"/> that contains a transformation of the specified normal by the specified <see cref="Matrix4x4"/>.
|
||||
/// </summary>
|
||||
/// <param name="normal">Source <see cref="Vector3"/> which represents a normal vector.</param>
|
||||
/// <param name="matrix">The transformation <see cref="Matrix"/>.</param>
|
||||
/// <param name="matrix">The transformation <see cref="Matrix4x4"/>.</param>
|
||||
/// <returns>Transformed normal.</returns>
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="Vector3"/> that contains a transformation of the specified normal by the specified <see cref="Matrix"/>.
|
||||
/// Creates a new <see cref="Vector3"/> that contains a transformation of the specified normal by the specified <see cref="Matrix4x4"/>.
|
||||
/// </summary>
|
||||
/// <param name="normal">Source <see cref="Vector3"/> which represents a normal vector.</param>
|
||||
/// <param name="matrix">The transformation <see cref="Matrix"/>.</param>
|
||||
/// <param name="matrix">The transformation <see cref="Matrix4x4"/>.</param>
|
||||
/// <param name="result">Transformed normal as an output parameter.</param>
|
||||
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
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// Apply transformation on all normals within array of <see cref="Vector3"/> by the specified <see cref="Matrix"/> and places the results in an another array.
|
||||
/// Apply transformation on all normals within array of <see cref="Vector3"/> by the specified <see cref="Matrix4x4"/> and places the results in an another array.
|
||||
/// </summary>
|
||||
/// <param name="sourceArray">Source array.</param>
|
||||
/// <param name="matrix">The transformation <see cref="Matrix"/>.</param>
|
||||
/// <param name="matrix">The transformation <see cref="Matrix4x4"/>.</param>
|
||||
/// <param name="destinationArray">Destination array.</param>
|
||||
public static void TransformNormal(
|
||||
Vector3[] sourceArray,
|
||||
ref Matrix matrix,
|
||||
ref Matrix4x4 matrix,
|
||||
Vector3[] destinationArray
|
||||
) {
|
||||
Debug.Assert(
|
||||
|
@ -1311,18 +1311,18 @@ namespace MoonWorks.Math
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// Apply transformation on normals within array of <see cref="Vector3"/> by the specified <see cref="Matrix"/> and places the results in an another array.
|
||||
/// Apply transformation on normals within array of <see cref="Vector3"/> by the specified <see cref="Matrix4x4"/> and places the results in an another array.
|
||||
/// </summary>
|
||||
/// <param name="sourceArray">Source array.</param>
|
||||
/// <param name="sourceIndex">The starting index of transformation in the source array.</param>
|
||||
/// <param name="matrix">The transformation <see cref="Matrix"/>.</param>
|
||||
/// <param name="matrix">The transformation <see cref="Matrix4x4"/>.</param>
|
||||
/// <param name="destinationArray">Destination array.</param>
|
||||
/// <param name="destinationIndex">The starting index in the destination array, where the first <see cref="Vector3"/> should be written.</param>
|
||||
/// <param name="length">The number of normals to be transformed.</param>
|
||||
public static void TransformNormal(
|
||||
Vector3[] sourceArray,
|
||||
int sourceIndex,
|
||||
ref Matrix matrix,
|
||||
ref Matrix4x4 matrix,
|
||||
Vector3[] destinationArray,
|
||||
int destinationIndex,
|
||||
int length
|
||||
|
|
|
@ -942,12 +942,12 @@ namespace MoonWorks.Math
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="Vector4"/> that contains a transformation of 2d-vector by the specified <see cref="Matrix"/>.
|
||||
/// Creates a new <see cref="Vector4"/> that contains a transformation of 2d-vector by the specified <see cref="Matrix4x4"/>.
|
||||
/// </summary>
|
||||
/// <param name="value">Source <see cref="Vector2"/>.</param>
|
||||
/// <param name="matrix">The transformation <see cref="Matrix"/>.</param>
|
||||
/// <param name="matrix">The transformation <see cref="Matrix4x4"/>.</param>
|
||||
/// <returns>Transformed <see cref="Vector4"/>.</returns>
|
||||
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
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="Vector4"/> that contains a transformation of 3d-vector by the specified <see cref="Matrix"/>.
|
||||
/// Creates a new <see cref="Vector4"/> that contains a transformation of 3d-vector by the specified <see cref="Matrix4x4"/>.
|
||||
/// </summary>
|
||||
/// <param name="value">Source <see cref="Vector3"/>.</param>
|
||||
/// <param name="matrix">The transformation <see cref="Matrix"/>.</param>
|
||||
/// <param name="matrix">The transformation <see cref="Matrix4x4"/>.</param>
|
||||
/// <returns>Transformed <see cref="Vector4"/>.</returns>
|
||||
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
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="Vector4"/> that contains a transformation of 4d-vector by the specified <see cref="Matrix"/>.
|
||||
/// Creates a new <see cref="Vector4"/> that contains a transformation of 4d-vector by the specified <see cref="Matrix4x4"/>.
|
||||
/// </summary>
|
||||
/// <param name="value">Source <see cref="Vector4"/>.</param>
|
||||
/// <param name="matrix">The transformation <see cref="Matrix"/>.</param>
|
||||
/// <param name="matrix">The transformation <see cref="Matrix4x4"/>.</param>
|
||||
/// <returns>Transformed <see cref="Vector4"/>.</returns>
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="Vector4"/> that contains a transformation of 2d-vector by the specified <see cref="Matrix"/>.
|
||||
/// Creates a new <see cref="Vector4"/> that contains a transformation of 2d-vector by the specified <see cref="Matrix4x4"/>.
|
||||
/// </summary>
|
||||
/// <param name="value">Source <see cref="Vector2"/>.</param>
|
||||
/// <param name="matrix">The transformation <see cref="Matrix"/>.</param>
|
||||
/// <param name="matrix">The transformation <see cref="Matrix4x4"/>.</param>
|
||||
/// <param name="result">Transformed <see cref="Vector4"/> as an output parameter.</param>
|
||||
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
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="Vector4"/> that contains a transformation of 3d-vector by the specified <see cref="Matrix"/>.
|
||||
/// Creates a new <see cref="Vector4"/> that contains a transformation of 3d-vector by the specified <see cref="Matrix4x4"/>.
|
||||
/// </summary>
|
||||
/// <param name="value">Source <see cref="Vector3"/>.</param>
|
||||
/// <param name="matrix">The transformation <see cref="Matrix"/>.</param>
|
||||
/// <param name="matrix">The transformation <see cref="Matrix4x4"/>.</param>
|
||||
/// <param name="result">Transformed <see cref="Vector4"/> as an output parameter.</param>
|
||||
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
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="Vector4"/> that contains a transformation of 4d-vector by the specified <see cref="Matrix"/>.
|
||||
/// Creates a new <see cref="Vector4"/> that contains a transformation of 4d-vector by the specified <see cref="Matrix4x4"/>.
|
||||
/// </summary>
|
||||
/// <param name="value">Source <see cref="Vector4"/>.</param>
|
||||
/// <param name="matrix">The transformation <see cref="Matrix"/>.</param>
|
||||
/// <param name="matrix">The transformation <see cref="Matrix4x4"/>.</param>
|
||||
/// <param name="result">Transformed <see cref="Vector4"/> as an output parameter.</param>
|
||||
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
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// Apply transformation on all vectors within array of <see cref="Vector4"/> by the specified <see cref="Matrix"/> and places the results in an another array.
|
||||
/// Apply transformation on all vectors within array of <see cref="Vector4"/> by the specified <see cref="Matrix4x4"/> and places the results in an another array.
|
||||
/// </summary>
|
||||
/// <param name="sourceArray">Source array.</param>
|
||||
/// <param name="matrix">The transformation <see cref="Matrix"/>.</param>
|
||||
/// <param name="matrix">The transformation <see cref="Matrix4x4"/>.</param>
|
||||
/// <param name="destinationArray">Destination array.</param>
|
||||
public static void Transform(
|
||||
Vector4[] sourceArray,
|
||||
ref Matrix matrix,
|
||||
ref Matrix4x4 matrix,
|
||||
Vector4[] destinationArray
|
||||
) {
|
||||
if (sourceArray == null)
|
||||
|
@ -1107,18 +1107,18 @@ namespace MoonWorks.Math
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// Apply transformation on vectors within array of <see cref="Vector4"/> by the specified <see cref="Matrix"/> and places the results in an another array.
|
||||
/// Apply transformation on vectors within array of <see cref="Vector4"/> by the specified <see cref="Matrix4x4"/> and places the results in an another array.
|
||||
/// </summary>
|
||||
/// <param name="sourceArray">Source array.</param>
|
||||
/// <param name="sourceIndex">The starting index of transformation in the source array.</param>
|
||||
/// <param name="matrix">The transformation <see cref="Matrix"/>.</param>
|
||||
/// <param name="matrix">The transformation <see cref="Matrix4x4"/>.</param>
|
||||
/// <param name="destinationArray">Destination array.</param>
|
||||
/// <param name="destinationIndex">The starting index in the destination array, where the first <see cref="Vector4"/> should be written.</param>
|
||||
/// <param name="length">The number of vectors to be transformed.</param>
|
||||
public static void Transform(
|
||||
Vector4[] sourceArray,
|
||||
int sourceIndex,
|
||||
ref Matrix matrix,
|
||||
ref Matrix4x4 matrix,
|
||||
Vector4[] destinationArray,
|
||||
int destinationIndex,
|
||||
int length
|
||||
|
|
Loading…
Reference in New Issue