diff --git a/Source/OpenTK/Math/Matrix2.cs b/Source/OpenTK/Math/Matrix2.cs
index bfefb914..5a0000c5 100644
--- a/Source/OpenTK/Math/Matrix2.cs
+++ b/Source/OpenTK/Math/Matrix2.cs
@@ -47,7 +47,7 @@ namespace OpenTK
///
/// The identity matrix.
///
- public static Matrix2 Identity = new Matrix2(Vector2.UnitX, Vector2.UnitY);
+ public static readonly Matrix2 Identity = new Matrix2(Vector2.UnitX, Vector2.UnitY);
///
/// The zero matrix.
@@ -169,7 +169,17 @@ namespace OpenTK
#region Instance
+ #region public void Transpose()
+ ///
+ /// Converts this instance to it's transpose.
+ ///
+ public void Transpose()
+ {
+ this = Matrix2.Transpose(this);
+ }
+
+ #endregion
#endregion
@@ -530,7 +540,7 @@ namespace OpenTK
/// A new Matrix2 which holds the result of the multiplication
public static Matrix2 operator *(float left, Matrix2 right)
{
- return Matrix2.Mult(right, left);
+ return Mult(right, left);
}
///
@@ -541,7 +551,7 @@ namespace OpenTK
/// A new Matrix2 which holds the result of the multiplication
public static Matrix2 operator *(Matrix2 left, float right)
{
- return Matrix2.Mult(left, right);
+ return Mult(left, right);
}
///
@@ -552,7 +562,7 @@ namespace OpenTK
/// A new Matrix2 which holds the result of the multiplication
public static Matrix2 operator *(Matrix2 left, Matrix2 right)
{
- return Matrix2.Mult(left, right);
+ return Mult(left, right);
}
///
@@ -563,7 +573,7 @@ namespace OpenTK
/// A new Matrix2x3 which holds the result of the multiplication
public static Matrix2x3 operator *(Matrix2 left, Matrix2x3 right)
{
- return Matrix2.Mult(left, right);
+ return Mult(left, right);
}
///
@@ -574,7 +584,7 @@ namespace OpenTK
/// A new Matrix2x4 which holds the result of the multiplication
public static Matrix2x4 operator *(Matrix2 left, Matrix2x4 right)
{
- return Matrix2.Mult(left, right);
+ return Mult(left, right);
}
///
@@ -585,7 +595,7 @@ namespace OpenTK
/// A new Matrix2 which holds the result of the addition
public static Matrix2 operator +(Matrix2 left, Matrix2 right)
{
- return Matrix2.Add(left, right);
+ return Add(left, right);
}
///
@@ -596,7 +606,7 @@ namespace OpenTK
/// A new Matrix2 which holds the result of the subtraction
public static Matrix2 operator -(Matrix2 left, Matrix2 right)
{
- return Matrix2.Subtract(left, right);
+ return Subtract(left, right);
}
///
diff --git a/Source/OpenTK/Math/Matrix2x3.cs b/Source/OpenTK/Math/Matrix2x3.cs
index b2aaae8e..383591e3 100644
--- a/Source/OpenTK/Math/Matrix2x3.cs
+++ b/Source/OpenTK/Math/Matrix2x3.cs
@@ -47,7 +47,7 @@ namespace OpenTK
///
/// The zero matrix.
///
- public static Matrix2x3 Zero = new Matrix2x3(Vector3.Zero, Vector3.Zero);
+ public static readonly Matrix2x3 Zero = new Matrix2x3(Vector3.Zero, Vector3.Zero);
#endregion
@@ -174,12 +174,435 @@ namespace OpenTK
#region Static
+ #region CreateRotation
+ ///
+ /// Builds a rotation matrix.
+ ///
+ /// The counter-clockwise angle in radians.
+ /// The resulting Matrix2x3 instance.
+ public static void CreateRotation(float angle, out Matrix2x3 result)
+ {
+ float cos = (float)System.Math.Cos(angle);
+ float sin = (float)System.Math.Sin(angle);
+
+ result.Row0.X = cos;
+ result.Row0.Y = sin;
+ result.Row0.Z = 0;
+ result.Row1.X = -sin;
+ result.Row1.Y = cos;
+ result.Row1.Z = 0;
+ }
+
+ ///
+ /// Builds a rotation matrix.
+ ///
+ /// The counter-clockwise angle in radians.
+ /// The resulting Matrix2x3 instance.
+ public static Matrix2x3 CreateRotation(float angle)
+ {
+ Matrix2x3 result;
+ CreateRotation(angle, out result);
+ return result;
+ }
+
+ #endregion
+
+ #region CreateScale
+
+ ///
+ /// Creates a scale matrix.
+ ///
+ /// Single scale factor for the x, y, and z axes.
+ /// A scale matrix.
+ public static void CreateScale(float scale, out Matrix2x3 result)
+ {
+ result.Row0.X = scale;
+ result.Row0.Y = 0;
+ result.Row0.Z = 0;
+ result.Row1.X = 0;
+ result.Row1.Y = scale;
+ result.Row1.Z = 0;
+ }
+
+ ///
+ /// Creates a scale matrix.
+ ///
+ /// Single scale factor for the x and y axes.
+ /// A scale matrix.
+ public static Matrix2x3 CreateScale(float scale)
+ {
+ Matrix2x3 result;
+ CreateScale(scale, out result);
+ return result;
+ }
+
+ ///
+ /// Creates a scale matrix.
+ ///
+ /// Scale factors for the x and y axes.
+ /// A scale matrix.
+ public static void CreateScale(Vector2 scale, out Matrix2x3 result)
+ {
+ result.Row0.X = scale.X;
+ result.Row0.Y = 0;
+ result.Row0.Z = 0;
+ result.Row1.X = 0;
+ result.Row1.Y = scale.Y;
+ result.Row1.Z = 0;
+ }
+
+ ///
+ /// Creates a scale matrix.
+ ///
+ /// Scale factors for the x and y axes.
+ /// A scale matrix.
+ public static Matrix2x3 CreateScale(Vector2 scale)
+ {
+ Matrix2x3 result;
+ CreateScale(scale, out result);
+ return result;
+ }
+
+ ///
+ /// Creates a scale matrix.
+ ///
+ /// Scale factor for the x axis.
+ /// Scale factor for the y axis.
+ /// A scale matrix.
+ public static void CreateScale(float x, float y, out Matrix2x3 result)
+ {
+ result.Row0.X = x;
+ result.Row0.Y = 0;
+ result.Row0.Z = 0;
+ result.Row1.X = 0;
+ result.Row1.Y = y;
+ result.Row1.Z = 0;
+ }
+
+ ///
+ /// Creates a scale matrix.
+ ///
+ /// Scale factor for the x axis.
+ /// Scale factor for the y axis.
+ /// A scale matrix.
+ public static Matrix2x3 CreateScale(float x, float y)
+ {
+ Matrix2x3 result;
+ CreateScale(x, y, out result);
+ return result;
+ }
+
+ #endregion
+
+ #region Multiply Functions
+
+ ///
+ /// Multiplies and instance by a scalar.
+ ///
+ /// The left operand of the multiplication.
+ /// The right operand of the multiplication.
+ /// A new instance that is the result of the multiplication.
+ public static void Mult(ref Matrix2x3 left, float right, out Matrix2x3 result)
+ {
+ result.Row0.X = left.Row0.X * right;
+ result.Row0.Y = left.Row0.Y * right;
+ result.Row0.Z = left.Row0.Z * right;
+ result.Row1.X = left.Row1.X * right;
+ result.Row1.Y = left.Row1.Y * right;
+ result.Row1.Z = left.Row1.Z * right;
+ }
+
+ ///
+ /// Multiplies and instance by a scalar.
+ ///
+ /// The left operand of the multiplication.
+ /// The right operand of the multiplication.
+ /// A new instance that is the result of the multiplication.
+ public static Matrix2x3 Mult(Matrix2x3 left, float right)
+ {
+ Matrix2x3 result;
+ Mult(ref left, right, out result);
+ return result;
+ }
+
+ ///
+ /// Multiplies two instances.
+ ///
+ /// The left operand of the multiplication.
+ /// The right operand of the multiplication.
+ /// A new instance that is the result of the multiplication.
+ public static void Mult(ref Matrix2x3 left, ref Matrix3x2 right, out Matrix2 result)
+ {
+ float lM11 = left.Row0.X, lM12 = left.Row0.Y, lM13 = left.Row0.Z,
+ lM21 = left.Row1.X, lM22 = left.Row1.Y, lM23 = left.Row1.Z,
+ rM11 = right.Row0.X, rM12 = right.Row0.Y,
+ rM21 = right.Row1.X, rM22 = right.Row1.Y,
+ rM31 = right.Row2.X, rM32 = right.Row2.Y;
+
+ result.Row0.X = ((lM11 * rM11) + (lM12 * rM21)) + (lM13 * rM31);
+ result.Row0.Y = ((lM11 * rM12) + (lM12 * rM22)) + (lM13 * rM32);
+ result.Row1.X = ((lM21 * rM11) + (lM22 * rM21)) + (lM23 * rM31);
+ result.Row1.Y = ((lM21 * rM12) + (lM22 * rM22)) + (lM23 * rM32);
+ }
+
+ ///
+ /// Multiplies two instances.
+ ///
+ /// The left operand of the multiplication.
+ /// The right operand of the multiplication.
+ /// A new instance that is the result of the multiplication.
+ public static Matrix2 Mult(Matrix2x3 left, Matrix3x2 right)
+ {
+ Matrix2 result;
+ Mult(ref left, ref right, out result);
+ return result;
+ }
+
+ ///
+ /// Multiplies two instances.
+ ///
+ /// The left operand of the multiplication.
+ /// The right operand of the multiplication.
+ /// A new instance that is the result of the multiplication.
+ public static void Mult(ref Matrix2x3 left, ref Matrix3 right, out Matrix2x3 result)
+ {
+ float lM11 = left.Row0.X, lM12 = left.Row0.Y, lM13 = left.Row0.Z,
+ lM21 = left.Row1.X, lM22 = left.Row1.Y, lM23 = left.Row1.Z,
+ rM11 = right.Row0.X, rM12 = right.Row0.Y, rM13 = right.Row0.Z,
+ rM21 = right.Row1.X, rM22 = right.Row1.Y, rM23 = right.Row1.Z,
+ rM31 = right.Row2.X, rm32 = right.Row2.Y, rM33 = right.Row2.Z;
+
+ result.Row0.X = ((lM11 * rM11) + (lM12 * rM21)) + (lM13 * rM31);
+ result.Row0.Y = ((lM11 * rM12) + (lM12 * rM22)) + (lM13 * rm32);
+ result.Row0.Z = ((lM11 * rM13) + (lM12 * rM23)) + (lM13 * rM33);
+ result.Row1.X = ((lM21 * rM11) + (lM22 * rM21)) + (lM23 * rM31);
+ result.Row1.Y = ((lM21 * rM12) + (lM22 * rM22)) + (lM23 * rm32);
+ result.Row1.Z = ((lM21 * rM13) + (lM22 * rM23)) + (lM23 * rM33);
+ }
+
+ ///
+ /// Multiplies two instances.
+ ///
+ /// The left operand of the multiplication.
+ /// The right operand of the multiplication.
+ /// A new instance that is the result of the multiplication.
+ public static Matrix2x3 Mult(Matrix2x3 left, Matrix3 right)
+ {
+ Matrix2x3 result;
+ Mult(ref left, ref right, out result);
+ return result;
+ }
+
+ ///
+ /// Multiplies two instances.
+ ///
+ /// The left operand of the multiplication.
+ /// The right operand of the multiplication.
+ /// A new instance that is the result of the multiplication.
+ public static void Mult(ref Matrix2x3 left, ref Matrix3x4 right, out Matrix2x4 result)
+ {
+ float lM11 = left.Row0.X, lM12 = left.Row0.Y, lM13 = left.Row0.Z,
+ lM21 = left.Row1.X, lM22 = left.Row1.Y, lM23 = left.Row1.Z,
+ rM11 = right.Row0.X, rM12 = right.Row0.Y, rM13 = right.Row0.Z, rM14 = right.Row0.W,
+ rM21 = right.Row1.X, rM22 = right.Row1.Y, rM23 = right.Row1.Z, rM24 = right.Row1.W,
+ rM31 = right.Row2.X, rm32 = right.Row2.Y, rM33 = right.Row2.Z, rM34 = right.Row2.W;
+
+ result.Row0.X = ((lM11 * rM11) + (lM12 * rM21)) + (lM13 * rM31);
+ result.Row0.Y = ((lM11 * rM12) + (lM12 * rM22)) + (lM13 * rm32);
+ result.Row0.Z = ((lM11 * rM13) + (lM12 * rM23)) + (lM13 * rM33);
+ result.Row0.W = ((lM11 * rM14) + (lM12 * rM24)) + (lM13 * rM34);
+ result.Row1.X = ((lM21 * rM11) + (lM22 * rM21)) + (lM23 * rM31);
+ result.Row1.Y = ((lM21 * rM12) + (lM22 * rM22)) + (lM23 * rm32);
+ result.Row1.Z = ((lM21 * rM13) + (lM22 * rM23)) + (lM23 * rM33);
+ result.Row1.W = ((lM21 * rM14) + (lM22 * rM24)) + (lM23 * rM34);
+ }
+
+ ///
+ /// Multiplies two instances.
+ ///
+ /// The left operand of the multiplication.
+ /// The right operand of the multiplication.
+ /// A new instance that is the result of the multiplication.
+ public static Matrix2x4 Mult(Matrix2x3 left, Matrix3x4 right)
+ {
+ Matrix2x4 result;
+ Mult(ref left, ref right, out result);
+ return result;
+ }
+
+ #endregion
+
+ #region Add
+
+ ///
+ /// Adds two instances.
+ ///
+ /// The left operand of the addition.
+ /// The right operand of the addition.
+ /// A new instance that is the result of the addition.
+ public static void Add(ref Matrix2x3 left, ref Matrix2x3 right, out Matrix2x3 result)
+ {
+ result.Row0.X = left.Row0.X + right.Row0.X;
+ result.Row0.Y = left.Row0.Y + right.Row0.Y;
+ result.Row0.Z = left.Row0.Z + right.Row0.Z;
+ result.Row1.X = left.Row1.X + right.Row1.X;
+ result.Row1.Y = left.Row1.Y + right.Row1.Y;
+ result.Row1.Z = left.Row1.Z + right.Row1.Z;
+ }
+
+ ///
+ /// Adds two instances.
+ ///
+ /// The left operand of the addition.
+ /// The right operand of the addition.
+ /// A new instance that is the result of the addition.
+ public static Matrix2x3 Add(Matrix2x3 left, Matrix2x3 right)
+ {
+ Matrix2x3 result;
+ Add(ref left, ref right, out result);
+ return result;
+ }
+
+ #endregion
+
+ #region Subtract
+
+ ///
+ /// Subtracts two instances.
+ ///
+ /// The left operand of the subtraction.
+ /// The right operand of the subtraction.
+ /// A new instance that is the result of the subtraction.
+ public static void Subtract(ref Matrix2x3 left, ref Matrix2x3 right, out Matrix2x3 result)
+ {
+ result.Row0.X = left.Row0.X - right.Row0.X;
+ result.Row0.Y = left.Row0.Y - right.Row0.Y;
+ result.Row0.Z = left.Row0.Z - right.Row0.Z;
+ result.Row1.X = left.Row1.X - right.Row1.X;
+ result.Row1.Y = left.Row1.Y - right.Row1.Y;
+ result.Row1.Z = left.Row1.Z - right.Row1.Z;
+ }
+
+ ///
+ /// Subtracts two instances.
+ ///
+ /// The left operand of the subtraction.
+ /// The right operand of the subtraction.
+ /// A new instance that is the result of the subtraction.
+ public static Matrix2x3 Subtract(Matrix2x3 left, Matrix2x3 right)
+ {
+ Matrix2x3 result;
+ Subtract(ref left, ref right, out result);
+ return result;
+ }
+
+ #endregion
+
+ #region Invert Functions
+
+ #endregion
+
+ #region Transpose
+
+ ///
+ /// Calculate the transpose of the given matrix.
+ ///
+ /// The matrix to transpose.
+ /// The transpose of the given matrix.
+ public static void Transpose(ref Matrix2x3 mat, out Matrix3x2 result)
+ {
+ result.Row0.X = mat.Row0.X;
+ result.Row0.Y = mat.Row1.X;
+ result.Row1.X = mat.Row0.Y;
+ result.Row1.Y = mat.Row1.Y;
+ result.Row2.X = mat.Row0.Z;
+ result.Row2.Y = mat.Row1.Z;
+ }
+
+ #endregion
#endregion
#region Operators
+ ///
+ /// Scalar multiplication.
+ ///
+ /// left-hand operand
+ /// right-hand operand
+ /// A new Matrix2x3 which holds the result of the multiplication
+ public static Matrix2x3 operator *(float left, Matrix2x3 right)
+ {
+ return Mult(right, left);
+ }
+
+ ///
+ /// Scalar multiplication.
+ ///
+ /// left-hand operand
+ /// right-hand operand
+ /// A new Matrix2x3 which holds the result of the multiplication
+ public static Matrix2x3 operator *(Matrix2x3 left, float right)
+ {
+ return Mult(left, right);
+ }
+
+ ///
+ /// Matrix multiplication
+ ///
+ /// left-hand operand
+ /// right-hand operand
+ /// A new Matrix2 which holds the result of the multiplication
+ public static Matrix2 operator *(Matrix2x3 left, Matrix3x2 right)
+ {
+ return Mult(left, right);
+ }
+
+ ///
+ /// Matrix multiplication
+ ///
+ /// left-hand operand
+ /// right-hand operand
+ /// A new Matrix2x3 which holds the result of the multiplication
+ public static Matrix2x3 operator *(Matrix2x3 left, Matrix3 right)
+ {
+ return Mult(left, right);
+ }
+
+ ///
+ /// Matrix multiplication
+ ///
+ /// left-hand operand
+ /// right-hand operand
+ /// A new Matrix2x4 which holds the result of the multiplication
+ public static Matrix2x4 operator *(Matrix2x3 left, Matrix3x4 right)
+ {
+ return Mult(left, right);
+ }
+
+ ///
+ /// Matrix addition
+ ///
+ /// left-hand operand
+ /// right-hand operand
+ /// A new Matrix2x3 which holds the result of the addition
+ public static Matrix2x3 operator +(Matrix2x3 left, Matrix2x3 right)
+ {
+ return Add(left, right);
+ }
+
+ ///
+ /// Matrix subtraction
+ ///
+ /// left-hand operand
+ /// right-hand operand
+ /// A new Matrix2x3 which holds the result of the subtraction
+ public static Matrix2x3 operator -(Matrix2x3 left, Matrix2x3 right)
+ {
+ return Subtract(left, right);
+ }
+
///
/// Compares two instances for equality.
///
diff --git a/Source/OpenTK/Math/Matrix2x4.cs b/Source/OpenTK/Math/Matrix2x4.cs
index 848091b1..9597e8e8 100644
--- a/Source/OpenTK/Math/Matrix2x4.cs
+++ b/Source/OpenTK/Math/Matrix2x4.cs
@@ -27,111 +27,667 @@ using System.Runtime.InteropServices;
namespace OpenTK
{
- public struct Matrix2x4 : IEquatable
- {
- #region Fields
+ public struct Matrix2x4 : IEquatable
+ {
+ #region Fields
- public Vector4 Row0;
- public Vector4 Row1;
+ ///
+ /// Top row of the matrix.
+ ///
+ public Vector4 Row0;
- ///
- /// The zero matrix.
- ///
- public static Matrix2x4 Zero = new Matrix2x4(Vector4.Zero, Vector4.Zero);
+ ///
+ /// Bottom row of the matrix.
+ ///
+ public Vector4 Row1;
- #endregion
+ ///
+ /// The zero matrix.
+ ///
+ public static readonly Matrix2x4 Zero = new Matrix2x4(Vector4.Zero, Vector4.Zero);
- #region Constructors
+ #endregion
- public Matrix2x4(Vector4 row0, Vector4 row1)
- {
- Row0 = row0;
- Row1 = row1;
- }
+ #region Constructors
- public Matrix2x4(
- float m00, float m01, float m02, float m03,
- float m10, float m11, float m12, float m13)
- {
- Row0 = new Vector4(m00, m01, m02, m03);
- Row1 = new Vector4(m10, m11, m12, m13);
- }
+ ///
+ /// Constructs a new instance.
+ ///
+ /// Top row of the matrix.
+ /// Bottom row of the matrix.
+ public Matrix2x4(Vector4 row0, Vector4 row1)
+ {
+ Row0 = row0;
+ Row1 = row1;
+ }
- #endregion
+ ///
+ /// Constructs a new instance
+ ///
+ /// First item of the first row of the matrix.
+ /// Second item of the first row of the matrix.
+ /// Third item of the first row of the matrix.
+ /// Fourth item of the first row of the matrix.
+ /// First item of the second row of the matrix.
+ /// Second item of the second row of the matrix.
+ /// Third item of the second row of the matrix.
+ /// Fourth item of the second row of the matrix.
+ public Matrix2x4(
+ float m00, float m01, float m02, float m03,
+ float m10, float m11, float m12, float m13)
+ {
+ Row0 = new Vector4(m00, m01, m02, m03);
+ Row1 = new Vector4(m10, m11, m12, m13);
+ }
- #region Public Members
+ #endregion
- #region Properties
+ #region Public Members
- public Vector2 Column0
- {
- get { return new Vector2(Row0.X, Row1.X); }
- set { Row0.X = value.X; Row1.X = value.Y; }
- }
+ #region Properties
- public Vector2 Column1
- {
- get { return new Vector2(Row0.Y, Row1.Y); }
- set { Row0.Y = value.X; Row1.Y = value.Y; }
- }
+ public Vector2 Column0
+ {
+ get { return new Vector2(Row0.X, Row1.X); }
+ set { Row0.X = value.X; Row1.X = value.Y; }
+ }
- public Vector2 Column2
- {
- get { return new Vector2(Row0.Z, Row1.Z); }
- set { Row0.Z = value.X; Row1.Z = value.Y; }
- }
+ public Vector2 Column1
+ {
+ get { return new Vector2(Row0.Y, Row1.Y); }
+ set { Row0.Y = value.X; Row1.Y = value.Y; }
+ }
- public Vector2 Column3
- {
- get { return new Vector2(Row0.W, Row1.W); }
- set { Row0.W = value.X; Row1.W = value.Y; }
- }
+ public Vector2 Column2
+ {
+ get { return new Vector2(Row0.Z, Row1.Z); }
+ set { Row0.Z = value.X; Row1.Z = value.Y; }
+ }
- public float M11 { get { return Row0.X; } set { Row0.X = value; } }
- public float M12 { get { return Row0.Y; } set { Row0.Y = value; } }
- public float M13 { get { return Row0.Z; } set { Row0.Z = value; } }
- public float M14 { get { return Row0.W; } set { Row0.W = value; } }
- public float M21 { get { return Row1.X; } set { Row1.X = value; } }
- public float M22 { get { return Row1.Y; } set { Row1.Y = value; } }
- public float M23 { get { return Row1.Z; } set { Row1.Z = value; } }
- public float M24 { get { return Row1.W; } set { Row1.W = value; } }
+ public Vector2 Column3
+ {
+ get { return new Vector2(Row0.W, Row1.W); }
+ set { Row0.W = value.X; Row1.W = value.Y; }
+ }
- #endregion
+ public float M11 { get { return Row0.X; } set { Row0.X = value; } }
+ public float M12 { get { return Row0.Y; } set { Row0.Y = value; } }
+ public float M13 { get { return Row0.Z; } set { Row0.Z = value; } }
+ public float M14 { get { return Row0.W; } set { Row0.W = value; } }
+ public float M21 { get { return Row1.X; } set { Row1.X = value; } }
+ public float M22 { get { return Row1.Y; } set { Row1.Y = value; } }
+ public float M23 { get { return Row1.Z; } set { Row1.Z = value; } }
+ public float M24 { get { return Row1.W; } set { Row1.W = value; } }
- #region Indexers
+ #endregion
- ///
- /// Gets or sets the value at a specified row and column.
- ///
- public float this[int rowIndex, int columnIndex]
- {
- get
- {
- if (rowIndex == 0) return Row0[columnIndex];
- else if (rowIndex == 1) return Row1[columnIndex];
- throw new IndexOutOfRangeException("You tried to access this matrix at: (" + rowIndex + ", " + columnIndex + ")");
- }
- set
- {
- if (rowIndex == 0) Row0[columnIndex] = value;
- else if (rowIndex == 1) Row1[columnIndex] = value;
- throw new IndexOutOfRangeException("You tried to set this matrix at: (" + rowIndex + ", " + columnIndex + ")");
- }
- }
+ #region Indexers
- #endregion
+ ///
+ /// Gets or sets the value at a specified row and column.
+ ///
+ public float this[int rowIndex, int columnIndex]
+ {
+ get
+ {
+ if (rowIndex == 0) return Row0[columnIndex];
+ else if (rowIndex == 1) return Row1[columnIndex];
+ throw new IndexOutOfRangeException("You tried to access this matrix at: (" + rowIndex + ", " + columnIndex + ")");
+ }
+ set
+ {
+ if (rowIndex == 0) Row0[columnIndex] = value;
+ else if (rowIndex == 1) Row1[columnIndex] = value;
+ throw new IndexOutOfRangeException("You tried to set this matrix at: (" + rowIndex + ", " + columnIndex + ")");
+ }
+ }
- #endregion
+ #endregion
- #region IEquatable Members
+ #region Static
- public bool Equals(Matrix2x4 other)
- {
- return
- Row0 == other.Row0 &&
- Row1 == other.Row1;
- }
+ #region CreateRotation
- #endregion
- }
+ ///
+ /// Builds a rotation matrix.
+ ///
+ /// The counter-clockwise angle in radians.
+ /// The resulting Matrix2x4 instance.
+ public static void CreateRotation(float angle, out Matrix2x4 result)
+ {
+ float cos = (float)System.Math.Cos(angle);
+ float sin = (float)System.Math.Sin(angle);
+
+ result.Row0.X = cos;
+ result.Row0.Y = sin;
+ result.Row0.Z = 0;
+ result.Row0.W = 0;
+ result.Row1.X = -sin;
+ result.Row1.Y = cos;
+ result.Row1.Z = 0;
+ result.Row1.W = 0;
+ }
+
+ ///
+ /// Builds a rotation matrix.
+ ///
+ /// The counter-clockwise angle in radians.
+ /// The resulting Matrix2x3 instance.
+ public static Matrix2x4 CreateRotation(float angle)
+ {
+ Matrix2x4 result;
+ CreateRotation(angle, out result);
+ return result;
+ }
+
+ #endregion
+
+ #region CreateScale
+
+ ///
+ /// Creates a scale matrix.
+ ///
+ /// Single scale factor for the x, y, and z axes.
+ /// A scale matrix.
+ public static void CreateScale(float scale, out Matrix2x4 result)
+ {
+ result.Row0.X = scale;
+ result.Row0.Y = 0;
+ result.Row0.Z = 0;
+ result.Row0.W = 0;
+ result.Row1.X = 0;
+ result.Row1.Y = scale;
+ result.Row1.Z = 0;
+ result.Row1.W = 0;
+ }
+
+ ///
+ /// Creates a scale matrix.
+ ///
+ /// Single scale factor for the x and y axes.
+ /// A scale matrix.
+ public static Matrix2x4 CreateScale(float scale)
+ {
+ Matrix2x4 result;
+ CreateScale(scale, out result);
+ return result;
+ }
+
+ ///
+ /// Creates a scale matrix.
+ ///
+ /// Scale factors for the x and y axes.
+ /// A scale matrix.
+ public static void CreateScale(Vector2 scale, out Matrix2x4 result)
+ {
+ result.Row0.X = scale.X;
+ result.Row0.Y = 0;
+ result.Row0.Z = 0;
+ result.Row0.W = 0;
+ result.Row1.X = 0;
+ result.Row1.Y = scale.Y;
+ result.Row1.Z = 0;
+ result.Row1.W = 0;
+ }
+
+ ///
+ /// Creates a scale matrix.
+ ///
+ /// Scale factors for the x and y axes.
+ /// A scale matrix.
+ public static Matrix2x4 CreateScale(Vector2 scale)
+ {
+ Matrix2x4 result;
+ CreateScale(scale, out result);
+ return result;
+ }
+
+ ///
+ /// Creates a scale matrix.
+ ///
+ /// Scale factor for the x axis.
+ /// Scale factor for the y axis.
+ /// A scale matrix.
+ public static void CreateScale(float x, float y, out Matrix2x4 result)
+ {
+ result.Row0.X = x;
+ result.Row0.Y = 0;
+ result.Row0.Z = 0;
+ result.Row0.W = 0;
+ result.Row1.X = 0;
+ result.Row1.Y = y;
+ result.Row1.Z = 0;
+ result.Row1.W = 0;
+ }
+
+ ///
+ /// Creates a scale matrix.
+ ///
+ /// Scale factor for the x axis.
+ /// Scale factor for the y axis.
+ /// A scale matrix.
+ public static Matrix2x4 CreateScale(float x, float y)
+ {
+ Matrix2x4 result;
+ CreateScale(x, y, out result);
+ return result;
+ }
+
+ #endregion
+
+ #region Multiply Functions
+
+ ///
+ /// Multiplies and instance by a scalar.
+ ///
+ /// The left operand of the multiplication.
+ /// The right operand of the multiplication.
+ /// A new instance that is the result of the multiplication.
+ public static void Mult(ref Matrix2x4 left, float right, out Matrix2x4 result)
+ {
+ result.Row0.X = left.Row0.X * right;
+ result.Row0.Y = left.Row0.Y * right;
+ result.Row0.Z = left.Row0.Z * right;
+ result.Row0.W = left.Row0.W * right;
+ result.Row1.X = left.Row1.X * right;
+ result.Row1.Y = left.Row1.Y * right;
+ result.Row1.Z = left.Row1.Z * right;
+ result.Row1.W = left.Row1.W * right;
+ }
+
+ ///
+ /// Multiplies and instance by a scalar.
+ ///
+ /// The left operand of the multiplication.
+ /// The right operand of the multiplication.
+ /// A new instance that is the result of the multiplication.
+ public static Matrix2x4 Mult(Matrix2x4 left, float right)
+ {
+ Matrix2x4 result;
+ Mult(ref left, right, out result);
+ return result;
+ }
+
+ ///
+ /// Multiplies two instances.
+ ///
+ /// The left operand of the multiplication.
+ /// The right operand of the multiplication.
+ /// A new instance that is the result of the multiplication.
+ public static void Mult(ref Matrix2x4 left, ref Matrix4x2 right, out Matrix2 result)
+ {
+ float lM11 = left.Row0.X, lM12 = left.Row0.Y, lM13 = left.Row0.Z, lM14 = left.Row0.W,
+ lM21 = left.Row1.X, lM22 = left.Row1.Y, lM23 = left.Row1.Z, lM24 = left.Row1.W,
+ rM11 = right.Row0.X, rM12 = right.Row0.Y,
+ rM21 = right.Row1.X, rM22 = right.Row1.Y,
+ rM31 = right.Row2.X, rM32 = right.Row2.Y,
+ rM41 = right.Row3.X, rM42 = right.Row3.Y;
+
+ result.Row0.X = (((lM11 * rM11) + (lM12 * rM21)) + (lM13 * rM31)) + (lM14 * rM41);
+ result.Row0.Y = (((lM11 * rM12) + (lM12 * rM22)) + (lM13 * rM32)) + (lM14 * rM42);
+ result.Row1.X = (((lM21 * rM11) + (lM22 * rM21)) + (lM23 * rM31)) + (lM24 * rM41);
+ result.Row1.Y = (((lM21 * rM12) + (lM22 * rM22)) + (lM23 * rM32)) + (lM24 * rM42);
+ }
+
+ ///
+ /// Multiplies two instances.
+ ///
+ /// The left operand of the multiplication.
+ /// The right operand of the multiplication.
+ /// A new instance that is the result of the multiplication.
+ public static Matrix2 Mult(Matrix2x4 left, Matrix4x2 right)
+ {
+ Matrix2 result;
+ Mult(ref left, ref right, out result);
+ return result;
+ }
+
+ ///
+ /// Multiplies two instances.
+ ///
+ /// The left operand of the multiplication.
+ /// The right operand of the multiplication.
+ /// A new instance that is the result of the multiplication.
+ public static void Mult(ref Matrix2x4 left, ref Matrix4x3 right, out Matrix2x3 result)
+ {
+ float lM11 = left.Row0.X, lM12 = left.Row0.Y, lM13 = left.Row0.Z, lM14 = left.Row0.W,
+ lM21 = left.Row1.X, lM22 = left.Row1.Y, lM23 = left.Row1.Z, lM24 = left.Row1.W,
+ rM11 = right.Row0.X, rM12 = right.Row0.Y, rM13 = right.Row0.Z,
+ rM21 = right.Row1.X, rM22 = right.Row1.Y, rM23 = right.Row1.Z,
+ rM31 = right.Row2.X, rM32 = right.Row2.Y, rM33 = right.Row2.Z,
+ rM41 = right.Row3.X, rM42 = right.Row3.Y, rM43 = right.Row3.Z;
+
+ result.Row0.X = (((lM11 * rM11) + (lM12 * rM21)) + (lM13 * rM31)) + (lM14 * rM41);
+ result.Row0.Y = (((lM11 * rM12) + (lM12 * rM22)) + (lM13 * rM32)) + (lM14 * rM42);
+ result.Row0.Z = (((lM11 * rM13) + (lM12 * rM23)) + (lM13 * rM33)) + (lM14 * rM43);
+ result.Row1.X = (((lM21 * rM11) + (lM22 * rM21)) + (lM23 * rM31)) + (lM24 * rM41);
+ result.Row1.Y = (((lM21 * rM12) + (lM22 * rM22)) + (lM23 * rM32)) + (lM24 * rM42);
+ result.Row1.Z = (((lM21 * rM13) + (lM22 * rM23)) + (lM23 * rM33)) + (lM24 * rM43);
+ }
+
+ ///
+ /// Multiplies two instances.
+ ///
+ /// The left operand of the multiplication.
+ /// The right operand of the multiplication.
+ /// A new instance that is the result of the multiplication.
+ public static Matrix2x3 Mult(Matrix2x4 left, Matrix4x3 right)
+ {
+ Matrix2x3 result;
+ Mult(ref left, ref right, out result);
+ return result;
+ }
+
+ ///
+ /// Multiplies two instances.
+ ///
+ /// The left operand of the multiplication.
+ /// The right operand of the multiplication.
+ /// A new instance that is the result of the multiplication.
+ public static void Mult(ref Matrix2x4 left, ref Matrix4 right, out Matrix2x4 result)
+ {
+ float lM11 = left.Row0.X, lM12 = left.Row0.Y, lM13 = left.Row0.Z, lM14 = left.Row0.W,
+ lM21 = left.Row1.X, lM22 = left.Row1.Y, lM23 = left.Row1.Z, lM24 = left.Row1.W,
+ rM11 = right.Row0.X, rM12 = right.Row0.Y, rM13 = right.Row0.Z, rM14 = right.Row0.W,
+ rM21 = right.Row1.X, rM22 = right.Row1.Y, rM23 = right.Row1.Z, rM24 = right.Row1.W,
+ rM31 = right.Row2.X, rM32 = right.Row2.Y, rM33 = right.Row2.Z, rM34 = right.Row2.W,
+ rM41 = right.Row3.X, rM42 = right.Row3.Y, rM43 = right.Row3.Z, rM44 = right.Row3.W;
+
+ result.Row0.X = (((lM11 * rM11) + (lM12 * rM21)) + (lM13 * rM31)) + (lM14 * rM41);
+ result.Row0.Y = (((lM11 * rM12) + (lM12 * rM22)) + (lM13 * rM32)) + (lM14 * rM42);
+ result.Row0.Z = (((lM11 * rM13) + (lM12 * rM23)) + (lM13 * rM33)) + (lM14 * rM43);
+ result.Row0.W = (((lM11 * rM14) + (lM12 * rM24)) + (lM13 * rM34)) + (lM14 * rM44);
+ result.Row1.X = (((lM21 * rM11) + (lM22 * rM21)) + (lM23 * rM31)) + (lM24 * rM41);
+ result.Row1.Y = (((lM21 * rM12) + (lM22 * rM22)) + (lM23 * rM32)) + (lM24 * rM42);
+ result.Row1.Z = (((lM21 * rM13) + (lM22 * rM23)) + (lM23 * rM33)) + (lM24 * rM43);
+ result.Row1.W = (((lM21 * rM14) + (lM22 * rM24)) + (lM23 * rM34)) + (lM24 * rM44);
+ }
+
+ ///
+ /// Multiplies two instances.
+ ///
+ /// The left operand of the multiplication.
+ /// The right operand of the multiplication.
+ /// A new instance that is the result of the multiplication.
+ public static Matrix2x4 Mult(Matrix2x4 left, Matrix4 right)
+ {
+ Matrix2x4 result;
+ Mult(ref left, ref right, out result);
+ return result;
+ }
+
+ #endregion
+
+ #region Add
+
+ ///
+ /// Adds two instances.
+ ///
+ /// The left operand of the addition.
+ /// The right operand of the addition.
+ /// A new instance that is the result of the addition.
+ public static void Add(ref Matrix2x4 left, ref Matrix2x4 right, out Matrix2x4 result)
+ {
+ result.Row0.X = left.Row0.X + right.Row0.X;
+ result.Row0.Y = left.Row0.Y + right.Row0.Y;
+ result.Row0.Z = left.Row0.Z + right.Row0.Z;
+ result.Row0.W = left.Row0.W + right.Row0.W;
+ result.Row1.X = left.Row1.X + right.Row1.X;
+ result.Row1.Y = left.Row1.Y + right.Row1.Y;
+ result.Row1.Z = left.Row1.Z + right.Row1.Z;
+ result.Row1.W = left.Row1.W + right.Row1.W;
+ }
+
+ ///
+ /// Adds two instances.
+ ///
+ /// The left operand of the addition.
+ /// The right operand of the addition.
+ /// A new instance that is the result of the addition.
+ public static Matrix2x4 Add(Matrix2x4 left, Matrix2x4 right)
+ {
+ Matrix2x4 result;
+ Add(ref left, ref right, out result);
+ return result;
+ }
+
+ #endregion
+
+ #region Subtract
+
+ ///
+ /// Subtracts two instances.
+ ///
+ /// The left operand of the subtraction.
+ /// The right operand of the subtraction.
+ /// A new instance that is the result of the subtraction.
+ public static void Subtract(ref Matrix2x4 left, ref Matrix2x4 right, out Matrix2x4 result)
+ {
+ result.Row0.X = left.Row0.X - right.Row0.X;
+ result.Row0.Y = left.Row0.Y - right.Row0.Y;
+ result.Row0.Z = left.Row0.Z - right.Row0.Z;
+ result.Row0.W = left.Row0.W - right.Row0.W;
+ result.Row1.X = left.Row1.X - right.Row1.X;
+ result.Row1.Y = left.Row1.Y - right.Row1.Y;
+ result.Row1.Z = left.Row1.Z - right.Row1.Z;
+ result.Row1.W = left.Row1.W - right.Row1.W;
+ }
+
+ ///
+ /// Subtracts two instances.
+ ///
+ /// The left operand of the subtraction.
+ /// The right operand of the subtraction.
+ /// A new instance that is the result of the subtraction.
+ public static Matrix2x4 Subtract(Matrix2x4 left, Matrix2x4 right)
+ {
+ Matrix2x4 result;
+ Subtract(ref left, ref right, out result);
+ return result;
+ }
+
+ #endregion
+
+ #region Invert Functions
+
+ #endregion
+
+ #region Transpose
+
+ ///
+ /// Calculate the transpose of the given matrix.
+ ///
+ /// The matrix to transpose.
+ /// The transpose of the given matrix.
+ public static void Transpose(ref Matrix2x4 mat, out Matrix4x2 result)
+ {
+ result.Row0.X = mat.Row0.X;
+ result.Row0.Y = mat.Row1.X;
+ result.Row1.X = mat.Row0.Y;
+ result.Row1.Y = mat.Row1.Y;
+ result.Row2.X = mat.Row0.Z;
+ result.Row2.Y = mat.Row1.Z;
+ result.Row3.X = mat.Row0.W;
+ result.Row3.Y = mat.Row1.W;
+ }
+
+ ///
+ /// Calculate the transpose of the given matrix.
+ ///
+ /// The matrix to transpose.
+ /// The transpose of the given matrix.
+ public static Matrix4x2 Transpose(Matrix2x4 mat)
+ {
+ Matrix4x2 result;
+ Transpose(ref mat, out result);
+ return result;
+ }
+
+ #endregion
+
+ #endregion
+
+ #region Operators
+
+ ///
+ /// Scalar multiplication.
+ ///
+ /// left-hand operand
+ /// right-hand operand
+ /// A new Matrix2x4 which holds the result of the multiplication
+ public static Matrix2x4 operator *(float left, Matrix2x4 right)
+ {
+ return Mult(right, left);
+ }
+
+ ///
+ /// Scalar multiplication.
+ ///
+ /// left-hand operand
+ /// right-hand operand
+ /// A new Matrix2x4 which holds the result of the multiplication
+ public static Matrix2x4 operator *(Matrix2x4 left, float right)
+ {
+ return Mult(left, right);
+ }
+
+ ///
+ /// Matrix multiplication
+ ///
+ /// left-hand operand
+ /// right-hand operand
+ /// A new Matrix2 which holds the result of the multiplication
+ public static Matrix2 operator *(Matrix2x4 left, Matrix4x2 right)
+ {
+ return Mult(left, right);
+ }
+
+ ///
+ /// Matrix multiplication
+ ///
+ /// left-hand operand
+ /// right-hand operand
+ /// A new Matrix2x3 which holds the result of the multiplication
+ public static Matrix2x3 operator *(Matrix2x4 left, Matrix4x3 right)
+ {
+ return Mult(left, right);
+ }
+
+ ///
+ /// Matrix multiplication
+ ///
+ /// left-hand operand
+ /// right-hand operand
+ /// A new Matrix2x4 which holds the result of the multiplication
+ public static Matrix2x4 operator *(Matrix2x4 left, Matrix4 right)
+ {
+ return Mult(left, right);
+ }
+
+ ///
+ /// Matrix addition
+ ///
+ /// left-hand operand
+ /// right-hand operand
+ /// A new Matrix2 which holds the result of the addition
+ public static Matrix2x4 operator +(Matrix2x4 left, Matrix2x4 right)
+ {
+ return Add(left, right);
+ }
+
+ ///
+ /// Matrix subtraction
+ ///
+ /// left-hand operand
+ /// right-hand operand
+ /// A new Matrix2x4 which holds the result of the subtraction
+ public static Matrix2x4 operator -(Matrix2x4 left, Matrix2x4 right)
+ {
+ return Subtract(left, right);
+ }
+
+ ///
+ /// Compares two instances for equality.
+ ///
+ /// The first instance.
+ /// The second instance.
+ /// True, if left equals right; false otherwise.
+ public static bool operator ==(Matrix2x4 left, Matrix2x4 right)
+ {
+ return left.Equals(right);
+ }
+
+ ///
+ /// Compares two instances for inequality.
+ ///
+ /// The first instance.
+ /// The second instance.
+ /// True, if left does not equal right; false otherwise.
+ public static bool operator !=(Matrix2x4 left, Matrix2x4 right)
+ {
+ return !left.Equals(right);
+ }
+
+ #endregion
+
+ #region Overrides
+
+ #region public override string ToString()
+
+ ///
+ /// Returns a System.String that represents the current Matrix4.
+ ///
+ /// The string representation of the matrix.
+ public override string ToString()
+ {
+ return String.Format("{0}\n{1}", Row0, Row1);
+ }
+
+ #endregion
+
+ #region public override int GetHashCode()
+
+ ///
+ /// Returns the hashcode for this instance.
+ ///
+ /// A System.Int32 containing the unique hashcode for this instance.
+ public override int GetHashCode()
+ {
+ return Row0.GetHashCode() ^ Row1.GetHashCode();
+ }
+
+ #endregion
+
+ #region public override bool Equals(object obj)
+
+ ///
+ /// Indicates whether this instance and a specified object are equal.
+ ///
+ /// The object to compare to.
+ /// True if the instances are equal; false otherwise.
+ public override bool Equals(object obj)
+ {
+ if (!(obj is Matrix2x4))
+ return false;
+
+ return this.Equals((Matrix2x4)obj);
+ }
+
+ #endregion
+
+ #endregion
+
+ #endregion
+
+ #region IEquatable Members
+
+ public bool Equals(Matrix2x4 other)
+ {
+ return
+ Row0 == other.Row0 &&
+ Row1 == other.Row1;
+ }
+
+ #endregion
+ }
}
diff --git a/Source/OpenTK/Math/Matrix3x2.cs b/Source/OpenTK/Math/Matrix3x2.cs
index 8eceb7bb..ef5d8966 100644
--- a/Source/OpenTK/Math/Matrix3x2.cs
+++ b/Source/OpenTK/Math/Matrix3x2.cs
@@ -55,6 +55,12 @@ namespace OpenTK
#region Constructors
+ ///
+ /// Constructs a new instance.
+ ///
+ /// Top row of the matrix.
+ /// Second row of the matrix.
+ /// Bottom row of the matrix.
public Matrix3x2(Vector2 row0, Vector2 row1, Vector2 row2)
{
Row0 = row0;
@@ -62,6 +68,15 @@ namespace OpenTK
Row2 = row2;
}
+ ///
+ /// Constructs a new instance
+ ///
+ /// First item of the first row of the matrix.
+ /// Second item of the first row of the matrix.
+ /// First item of the second row of the matrix.
+ /// Second item of the second row of the matrix.
+ /// First item of the third row of the matrix.
+ /// Second item of the third row of the matrix.
public Matrix3x2(
float m00, float m01,
float m10, float m11,