From 8b8ded32329c3d2dbd08be75698ea0daafdc8f39 Mon Sep 17 00:00:00 2001 From: Robert Rouhani Date: Fri, 18 Jan 2013 19:21:24 -0800 Subject: [PATCH] Added very basic implementations of all possible matrix sizes up to 4x4 Moved the indexers out of the Properties region and into their own Indexers region --- Source/OpenTK/Graphics/ES20/Helper.cs | 11 ++ Source/OpenTK/Graphics/OpenGL/GLHelper.cs | 81 ++++++++++++- Source/OpenTK/Math/Matrix2.cs | 134 ++++++++++++++++++++++ Source/OpenTK/Math/Matrix2d.cs | 34 ++++++ Source/OpenTK/Math/Matrix2x3.cs | 124 ++++++++++++++++++++ Source/OpenTK/Math/Matrix2x3d.cs | 34 ++++++ Source/OpenTK/Math/Matrix2x4.cs | 132 +++++++++++++++++++++ Source/OpenTK/Math/Matrix2x4d.cs | 34 ++++++ Source/OpenTK/Math/Matrix3.cs | 31 ++++- Source/OpenTK/Math/Matrix3d.cs | 31 ++++- Source/OpenTK/Math/Matrix3x2.cs | 125 ++++++++++++++++++++ Source/OpenTK/Math/Matrix3x2d.cs | 34 ++++++ Source/OpenTK/Math/Matrix3x4.cs | 55 ++++++++- Source/OpenTK/Math/Matrix3x4d.cs | 34 ++++++ Source/OpenTK/Math/Matrix4.cs | 49 +++++--- Source/OpenTK/Math/Matrix4d.cs | 51 ++++---- Source/OpenTK/Math/Matrix4x2.cs | 134 ++++++++++++++++++++++ Source/OpenTK/Math/Matrix4x2d.cs | 34 ++++++ Source/OpenTK/Math/Matrix4x3.cs | 57 ++++++++- Source/OpenTK/Math/Matrix4x3d.cs | 34 ++++++ Source/OpenTK/OpenTK.csproj | 12 ++ 21 files changed, 1210 insertions(+), 55 deletions(-) create mode 100644 Source/OpenTK/Math/Matrix2.cs create mode 100644 Source/OpenTK/Math/Matrix2d.cs create mode 100644 Source/OpenTK/Math/Matrix2x3.cs create mode 100644 Source/OpenTK/Math/Matrix2x3d.cs create mode 100644 Source/OpenTK/Math/Matrix2x4.cs create mode 100644 Source/OpenTK/Math/Matrix2x4d.cs create mode 100644 Source/OpenTK/Math/Matrix3x2.cs create mode 100644 Source/OpenTK/Math/Matrix3x2d.cs create mode 100644 Source/OpenTK/Math/Matrix3x4d.cs create mode 100644 Source/OpenTK/Math/Matrix4x2.cs create mode 100644 Source/OpenTK/Math/Matrix4x2d.cs create mode 100644 Source/OpenTK/Math/Matrix4x3d.cs diff --git a/Source/OpenTK/Graphics/ES20/Helper.cs b/Source/OpenTK/Graphics/ES20/Helper.cs index a14bee80..9ce72459 100644 --- a/Source/OpenTK/Graphics/ES20/Helper.cs +++ b/Source/OpenTK/Graphics/ES20/Helper.cs @@ -137,6 +137,17 @@ namespace OpenTK.Graphics.ES20 GL.Uniform4(location, quaternion.X, quaternion.Y, quaternion.Z, quaternion.W); } + public static void UniformMatrix2(int location, bool transpose, ref Matrix2 matrix) + { + unsafe + { + fixed (float* matrix_ptr = &matrix.Row0.X) + { + GL.UniformMatrix2(location, 1, transpose, matrix_ptr); + } + } + } + public static void UniformMatrix3(int location, bool transpose, ref Matrix3 matrix) { unsafe diff --git a/Source/OpenTK/Graphics/OpenGL/GLHelper.cs b/Source/OpenTK/Graphics/OpenGL/GLHelper.cs index b90f81fe..bc52cc15 100644 --- a/Source/OpenTK/Graphics/OpenGL/GLHelper.cs +++ b/Source/OpenTK/Graphics/OpenGL/GLHelper.cs @@ -409,6 +409,8 @@ namespace OpenTK.Graphics.OpenGL } } + #endregion + #region Uniform [CLSCompliant(false)] @@ -454,6 +456,50 @@ namespace OpenTK.Graphics.OpenGL GL.Uniform4(location, quaternion.X, quaternion.Y, quaternion.Z, quaternion.W); } + public static void UniformMatrix2(int location, bool transpose, ref Matrix2 matrix) + { + unsafe + { + fixed (float* matrix_ptr = &matrix.Row0.X) + { + GL.UniformMatrix2(location, 1, transpose, matrix_ptr); + } + } + } + + public static void UniformMatrix2x3(int location, bool transpose, ref Matrix2x3 matrix) + { + unsafe + { + fixed (float* matrix_ptr = &matrix.Row0.X) + { + GL.UniformMatrix2x3(location, 1, transpose, matrix_ptr); + } + } + } + + public static void UniformMatrix2x4(int location, bool transpose, ref Matrix2x4 matrix) + { + unsafe + { + fixed (float* matrix_ptr = &matrix.Row0.X) + { + GL.UniformMatrix2x4(location, 1, transpose, matrix_ptr); + } + } + } + + public static void UniformMatrix3x2(int location, bool transpose, ref Matrix3x2 matrix) + { + unsafe + { + fixed (float* matrix_ptr = &matrix.Row0.X) + { + GL.UniformMatrix3x2(location, 1, transpose, matrix_ptr); + } + } + } + public static void UniformMatrix3(int location, bool transpose, ref Matrix3 matrix) { unsafe @@ -476,6 +522,39 @@ namespace OpenTK.Graphics.OpenGL } } + public static void UniformMatrix3x4(int location, bool transpose, ref Matrix3x4 matrix) + { + unsafe + { + fixed (float* matrix_ptr = &matrix.Row0.X) + { + GL.UniformMatrix3x4(location, 1, transpose, matrix_ptr); + } + } + } + + public static void UniformMatrix4x2(int location, bool transpose, ref Matrix4x2 matrix) + { + unsafe + { + fixed (float* matrix_ptr = &matrix.Row0.X) + { + GL.UniformMatrix4x2(location, 1, transpose, matrix_ptr); + } + } + } + + public static void UniformMatrix4x3(int location, bool transpose, ref Matrix4x3 matrix) + { + unsafe + { + fixed (float* matrix_ptr = &matrix.Row0.X) + { + GL.UniformMatrix4x3(location, 1, transpose, matrix_ptr); + } + } + } + public static void UniformMatrix4(int location, bool transpose, ref Matrix4 matrix) { unsafe @@ -500,8 +579,6 @@ namespace OpenTK.Graphics.OpenGL #endregion - #endregion - #region Shaders #region GetActiveAttrib diff --git a/Source/OpenTK/Math/Matrix2.cs b/Source/OpenTK/Math/Matrix2.cs new file mode 100644 index 00000000..a3947fe4 --- /dev/null +++ b/Source/OpenTK/Math/Matrix2.cs @@ -0,0 +1,134 @@ +#region --- License --- +/* +Copyright (c) 2006 - 2008 The Open Toolkit library. + +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. + */ +#endregion + +using System; +using System.Runtime.InteropServices; + +namespace OpenTK +{ + public struct Matrix2 : IEquatable + { + #region Fields + + /// + /// Top row of the matrix. + /// + public Vector2 Row0; + + /// + /// Bottom row of the matrix. + /// + public Vector2 Row1; + + #endregion + + #region Constructors + + public Matrix2(Vector2 row0, Vector2 row1) + { + Row0 = row0; + Row1 = row1; + } + + public Matrix2( + float m00, float m01, + float m10, float m11) + { + Row0 = new Vector2(m00, m01); + Row1 = new Vector2(m10, m11); + } + + #endregion + + #region Public Members + + #region Properties + + public float Determinant + { + get + { + float m11 = Row0.X, m12 = Row0.Y, + m21 = Row1.X, m22 = Row1.Y; + + return m11 * m22 - m12 * m21; + } + } + + public Vector2 Column0 + { + get { return new Vector2(Row0.X, Row1.X); } + set { Row0.X = value.X; Row1.X = value.Y; } + } + + public Vector2 Column1 + { + get { return new Vector2(Row0.Y, Row1.Y); } + set { Row0.Y = value.X; Row1.Y = 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 M21 { get { return Row1.X; } set { Row1.X = value; } } + public float M22 { get { return Row1.Y; } set { Row1.Y = value; } } + + #endregion + + #region Indexers + + /// + /// 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 + + public bool Equals(Matrix2 other) + { + return + Row0 == other.Row0 && + Row1 == other.Row1; + } + + #endregion + } +} diff --git a/Source/OpenTK/Math/Matrix2d.cs b/Source/OpenTK/Math/Matrix2d.cs new file mode 100644 index 00000000..7309bf3e --- /dev/null +++ b/Source/OpenTK/Math/Matrix2d.cs @@ -0,0 +1,34 @@ +#region --- License --- +/* +Copyright (c) 2006 - 2008 The Open Toolkit library. + +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. + */ +#endregion + +using System; +using System.Runtime.InteropServices; + +namespace OpenTK +{ + //TODO copy from Matrix2.cs when it's mostly feature-complete. + /*public struct Matrix2d : IEquatable + { + }*/ +} diff --git a/Source/OpenTK/Math/Matrix2x3.cs b/Source/OpenTK/Math/Matrix2x3.cs new file mode 100644 index 00000000..38d5be98 --- /dev/null +++ b/Source/OpenTK/Math/Matrix2x3.cs @@ -0,0 +1,124 @@ +#region --- License --- +/* +Copyright (c) 2006 - 2008 The Open Toolkit library. + +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. + */ +#endregion + +using System; +using System.Collections.Generic; + +namespace OpenTK +{ + public struct Matrix2x3 : IEquatable + { + #region Fields + + public Vector3 Row0; + public Vector3 Row1; + + #endregion + + #region Constructors + + public Matrix2x3(Vector3 row0, Vector3 row1) + { + Row0 = row0; + Row1 = row1; + } + + public Matrix2x3( + float m00, float m01, float m02, + float m10, float m11, float m12) + { + Row0 = new Vector3(m00, m01, m02); + Row1 = new Vector3(m10, m11, m12); + } + + #endregion + + #region Public Members + + #region Properties + + public Vector2 Column0 + { + get { return new Vector2(Row0.X, Row1.X); } + set { Row0.X = value.X; Row1.X = value.Y; } + } + + public Vector2 Column1 + { + get { return new Vector2(Row0.Y, Row1.Y); } + set { Row0.Y = value.X; Row1.Y = 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 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; } } + + #endregion + + #region Indexers + + /// + /// 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 + + public bool Equals(Matrix2x3 other) + { + return + Row0 == other.Row0 && + Row1 == other.Row1; + } + + #endregion + } +} diff --git a/Source/OpenTK/Math/Matrix2x3d.cs b/Source/OpenTK/Math/Matrix2x3d.cs new file mode 100644 index 00000000..73a48678 --- /dev/null +++ b/Source/OpenTK/Math/Matrix2x3d.cs @@ -0,0 +1,34 @@ +#region --- License --- +/* +Copyright (c) 2006 - 2008 The Open Toolkit library. + +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. + */ +#endregion + +using System; +using System.Runtime.InteropServices; + +namespace OpenTK +{ + //TODO copy from Matrix2x3.cs when it's mostly feature-complete. + /*public struct Matrix2x3d : IEquatable + { + }*/ +} diff --git a/Source/OpenTK/Math/Matrix2x4.cs b/Source/OpenTK/Math/Matrix2x4.cs new file mode 100644 index 00000000..5f9bfefb --- /dev/null +++ b/Source/OpenTK/Math/Matrix2x4.cs @@ -0,0 +1,132 @@ +#region --- License --- +/* +Copyright (c) 2006 - 2008 The Open Toolkit library. + +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. + */ +#endregion + +using System; +using System.Runtime.InteropServices; + +namespace OpenTK +{ + public struct Matrix2x4 : IEquatable + { + #region Fields + + public Vector4 Row0; + public Vector4 Row1; + + #endregion + + #region Constructors + + public Matrix2x4(Vector4 row0, Vector4 row1) + { + Row0 = row0; + Row1 = row1; + } + + 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); + } + + #endregion + + #region Public Members + + #region Properties + + public Vector2 Column0 + { + get { return new Vector2(Row0.X, Row1.X); } + set { Row0.X = value.X; Row1.X = value.Y; } + } + + public Vector2 Column1 + { + get { return new Vector2(Row0.Y, Row1.Y); } + set { Row0.Y = value.X; Row1.Y = value.Y; } + } + + public Vector2 Column2 + { + get { return new Vector2(Row0.Z, Row1.Z); } + set { Row0.Z = value.X; Row1.Z = value.Y; } + } + + public Vector2 Column3 + { + get { return new Vector2(Row0.W, Row1.W); } + set { Row0.W = value.X; Row1.W = 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; } } + + #endregion + + #region Indexers + + /// + /// 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 + + public bool Equals(Matrix2x4 other) + { + return + Row0 == other.Row0 && + Row1 == other.Row1; + } + + #endregion + } +} diff --git a/Source/OpenTK/Math/Matrix2x4d.cs b/Source/OpenTK/Math/Matrix2x4d.cs new file mode 100644 index 00000000..fd5207d8 --- /dev/null +++ b/Source/OpenTK/Math/Matrix2x4d.cs @@ -0,0 +1,34 @@ +#region --- License --- +/* +Copyright (c) 2006 - 2008 The Open Toolkit library. + +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. + */ +#endregion + +using System; +using System.Runtime.InteropServices; + +namespace OpenTK +{ + //TODO copy from Matrix2x4.cs when it's mostly feature-complete. + /*public struct Matrix2x4d : IEquatable + { + }*/ +} diff --git a/Source/OpenTK/Math/Matrix3.cs b/Source/OpenTK/Math/Matrix3.cs index c3244749..1438bf3e 100644 --- a/Source/OpenTK/Math/Matrix3.cs +++ b/Source/OpenTK/Math/Matrix3.cs @@ -188,11 +188,36 @@ namespace OpenTK public float M33 { get { return Row2.Z; } set { Row2.Z = value; } } #endregion - + + #region Indexers + + /// + /// 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]; + else if (rowIndex == 2) return Row2[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; + else if (rowIndex == 2) Row2[columnIndex] = value; + throw new IndexOutOfRangeException("You tried to set this matrix at: (" + rowIndex + ", " + columnIndex + ")"); + } + } + + #endregion + #region Instance - + #region public void Invert() - + public void Invert() { this = Matrix3.Invert(this); diff --git a/Source/OpenTK/Math/Matrix3d.cs b/Source/OpenTK/Math/Matrix3d.cs index 69310356..93607af1 100644 --- a/Source/OpenTK/Math/Matrix3d.cs +++ b/Source/OpenTK/Math/Matrix3d.cs @@ -188,11 +188,36 @@ namespace OpenTK public double M33 { get { return Row2.Z; } set { Row2.Z = value; } } #endregion - + + #region Indexers + + /// + /// Gets or sets the value at a specified row and column. + /// + public double this[int rowIndex, int columnIndex] + { + get + { + if (rowIndex == 0) return Row0[columnIndex]; + else if (rowIndex == 1) return Row1[columnIndex]; + else if (rowIndex == 2) return Row2[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; + else if (rowIndex == 2) Row2[columnIndex] = value; + throw new IndexOutOfRangeException("You tried to set this matrix at: (" + rowIndex + ", " + columnIndex + ")"); + } + } + + #endregion + #region Instance - + #region public void Invert() - + public void Invert() { this = Matrix3d.Invert(this); diff --git a/Source/OpenTK/Math/Matrix3x2.cs b/Source/OpenTK/Math/Matrix3x2.cs new file mode 100644 index 00000000..c9a1f760 --- /dev/null +++ b/Source/OpenTK/Math/Matrix3x2.cs @@ -0,0 +1,125 @@ +#region --- License --- +/* +Copyright (c) 2006 - 2008 The Open Toolkit library. + +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. + */ +#endregion + +using System; +using System.Runtime.InteropServices; + +namespace OpenTK +{ + public struct Matrix3x2 : IEquatable + { + #region Fields + + public Vector2 Row0; + public Vector2 Row1; + public Vector2 Row2; + + #endregion + + #region Constructors + + public Matrix3x2(Vector2 row0, Vector2 row1, Vector2 row2) + { + Row0 = row0; + Row1 = row1; + Row2 = row2; + } + + public Matrix3x2( + float m00, float m01, + float m10, float m11, + float m20, float m21) + { + Row0 = new Vector2(m00, m01); + Row1 = new Vector2(m10, m11); + Row2 = new Vector2(m20, m21); + } + + #endregion + + #region Public Members + + #region Properties + + public Vector3 Column0 + { + get { return new Vector3(Row0.X, Row1.X, Row2.X); } + set { Row0.X = value.X; Row1.X = value.Y; Row2.X = value.Z; } + } + + public Vector3 Column1 + { + get { return new Vector3(Row0.Y, Row1.Y, Row2.Y); } + set { Row0.Y = value.X; Row1.Y = value.Y; Row2.Y = value.Z; } + } + + public float M11 { get { return Row0.X; } set { Row0.X = value; } } + public float M12 { get { return Row0.Y; } set { Row0.Y = 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 M31 { get { return Row2.X; } set { Row2.X = value; } } + public float M32 { get { return Row2.Y; } set { Row2.Y = value; } } + + #endregion + + #region Indexers + + /// + /// 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]; + else if (rowIndex == 2) return Row2[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; + else if (rowIndex == 2) Row2[columnIndex] = value; + throw new IndexOutOfRangeException("You tried to set this matrix at: (" + rowIndex + ", " + columnIndex + ")"); + } + } + + #endregion + + #endregion + + #region IEquatable Members + + public bool Equals(Matrix3x2 other) + { + return + Row0 == other.Row0 && + Row1 == other.Row1 && + Row2 == other.Row2; + } + + #endregion + } +} diff --git a/Source/OpenTK/Math/Matrix3x2d.cs b/Source/OpenTK/Math/Matrix3x2d.cs new file mode 100644 index 00000000..c38c7a97 --- /dev/null +++ b/Source/OpenTK/Math/Matrix3x2d.cs @@ -0,0 +1,34 @@ +#region --- License --- +/* +Copyright (c) 2006 - 2008 The Open Toolkit library. + +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. + */ +#endregion + +using System; +using System.Runtime.InteropServices; + +namespace OpenTK +{ + //TODO copy from Matrix3x2.cs when it's mostly feature-complete. + /*public struct Matrix3x2d : IEquatable + { + }*/ +} diff --git a/Source/OpenTK/Math/Matrix3x4.cs b/Source/OpenTK/Math/Matrix3x4.cs index 8a9a88f1..ef3c4f8a 100644 --- a/Source/OpenTK/Math/Matrix3x4.cs +++ b/Source/OpenTK/Math/Matrix3x4.cs @@ -1,9 +1,31 @@ -using System; +#region --- License --- +/* +Copyright (c) 2006 - 2008 The Open Toolkit library. + +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. + */ +#endregion + +using System; using System.Runtime.InteropServices; -using OpenTK; - -namespace TopHat.Mathematics +namespace OpenTK { /// /// Represents a 3x4 Matrix @@ -176,6 +198,31 @@ namespace TopHat.Mathematics #endregion + #region Indexers + + /// + /// 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]; + else if (rowIndex == 2) return Row2[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; + else if (rowIndex == 2) Row2[columnIndex] = value; + throw new IndexOutOfRangeException("You tried to set this matrix at: (" + rowIndex + ", " + columnIndex + ")"); + } + } + + #endregion + #region Instance #region public void Invert() diff --git a/Source/OpenTK/Math/Matrix3x4d.cs b/Source/OpenTK/Math/Matrix3x4d.cs new file mode 100644 index 00000000..be023cad --- /dev/null +++ b/Source/OpenTK/Math/Matrix3x4d.cs @@ -0,0 +1,34 @@ +#region --- License --- +/* +Copyright (c) 2006 - 2008 The Open Toolkit library. + +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. + */ +#endregion + +using System; +using System.Runtime.InteropServices; + +namespace OpenTK +{ + //TODO copy from Matrix3x4.cs when it's mostly feature-complete. + /*public struct Matrix3x4d : IEquatable + { + }*/ +} diff --git a/Source/OpenTK/Math/Matrix4.cs b/Source/OpenTK/Math/Matrix4.cs index f27de106..1e728f7b 100644 --- a/Source/OpenTK/Math/Matrix4.cs +++ b/Source/OpenTK/Math/Matrix4.cs @@ -117,24 +117,6 @@ namespace OpenTK #region Properties - /// - /// 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]; - else if(rowIndex == 2) return Row2[columnIndex]; - else if(rowIndex == 3) return Row3[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; - else if(rowIndex == 2) Row2[columnIndex] = value; - else if(rowIndex == 3) Row3[columnIndex] = value; - throw new IndexOutOfRangeException("You tried to set this matrix at: (" + rowIndex + ", " + columnIndex + ")"); - } - } - /// /// The determinant of this matrix /// Gets the determinant of this matrix. @@ -164,6 +146,7 @@ namespace OpenTK public Vector4 Column0 { get { return new Vector4(Row0.X, Row1.X, Row2.X, Row3.X); } + set { Row0.X = value.X; Row1.X = value.Y; Row2.X = value.Z; Row3.X = value.W; } } /// @@ -172,6 +155,7 @@ namespace OpenTK public Vector4 Column1 { get { return new Vector4(Row0.Y, Row1.Y, Row2.Y, Row3.Y); } + set { Row0.Y = value.X; Row1.Y = value.Y; Row2.Y = value.Z; Row3.Y = value.W; } } /// @@ -180,6 +164,7 @@ namespace OpenTK public Vector4 Column2 { get { return new Vector4(Row0.Z, Row1.Z, Row2.Z, Row3.Z); } + set { Row0.Z = value.X; Row1.Z = value.Y; Row2.Z = value.Z; Row3.Z = value.W; } } /// @@ -188,6 +173,7 @@ namespace OpenTK public Vector4 Column3 { get { return new Vector4(Row0.W, Row1.W, Row2.W, Row3.W); } + set { Row0.W = value.X; Row1.W = value.Y; Row2.W = value.Z; Row3.W = value.W; } } /// @@ -272,6 +258,33 @@ namespace OpenTK #endregion + #region Indexers + + /// + /// 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]; + else if (rowIndex == 2) return Row2[columnIndex]; + else if (rowIndex == 3) return Row3[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; + else if (rowIndex == 2) Row2[columnIndex] = value; + else if (rowIndex == 3) Row3[columnIndex] = value; + throw new IndexOutOfRangeException("You tried to set this matrix at: (" + rowIndex + ", " + columnIndex + ")"); + } + } + + #endregion + #region Instance #region public void Invert() diff --git a/Source/OpenTK/Math/Matrix4d.cs b/Source/OpenTK/Math/Matrix4d.cs index 7653f016..9dfcb80a 100644 --- a/Source/OpenTK/Math/Matrix4d.cs +++ b/Source/OpenTK/Math/Matrix4d.cs @@ -114,24 +114,6 @@ namespace OpenTK #region Properties - /// - /// Gets or sets the value at a specified row and column. - /// - public double this[int rowIndex, int columnIndex] { get{ - if(rowIndex == 0) return Row0[columnIndex]; - else if(rowIndex == 1) return Row1[columnIndex]; - else if(rowIndex == 2) return Row2[columnIndex]; - else if(rowIndex == 3) return Row3[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; - else if(rowIndex == 2) Row2[columnIndex] = value; - else if(rowIndex == 3) Row3[columnIndex] = value; - throw new IndexOutOfRangeException("You tried to set this matrix at: (" + rowIndex + ", " + columnIndex + ")"); - } - } - /// /// The determinant of this matrix /// @@ -263,11 +245,38 @@ namespace OpenTK #endregion - #region Instance + #region Indexers - #region public void Invert() + /// + /// Gets or sets the value at a specified row and column. + /// + public double this[int rowIndex, int columnIndex] + { + get + { + if (rowIndex == 0) return Row0[columnIndex]; + else if (rowIndex == 1) return Row1[columnIndex]; + else if (rowIndex == 2) return Row2[columnIndex]; + else if (rowIndex == 3) return Row3[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; + else if (rowIndex == 2) Row2[columnIndex] = value; + else if (rowIndex == 3) Row3[columnIndex] = value; + throw new IndexOutOfRangeException("You tried to set this matrix at: (" + rowIndex + ", " + columnIndex + ")"); + } + } - /// + #endregion + + #region Instance + + #region public void Invert() + + /// /// Converts this instance into its inverse. /// public void Invert() diff --git a/Source/OpenTK/Math/Matrix4x2.cs b/Source/OpenTK/Math/Matrix4x2.cs new file mode 100644 index 00000000..ab08a7b7 --- /dev/null +++ b/Source/OpenTK/Math/Matrix4x2.cs @@ -0,0 +1,134 @@ +#region --- License --- +/* +Copyright (c) 2006 - 2008 The Open Toolkit library. + +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. + */ +#endregion + +using System; +using System.Runtime.InteropServices; + +namespace OpenTK +{ + public struct Matrix4x2 : IEquatable + { + #region Fields + + public Vector2 Row0; + public Vector2 Row1; + public Vector2 Row2; + public Vector2 Row3; + + #endregion + + #region Constructors + + public Matrix4x2(Vector2 row0, Vector2 row1, Vector2 row2, Vector2 row3) + { + Row0 = row0; + Row1 = row1; + Row2 = row2; + Row3 = row3; + } + + public Matrix4x2( + float m00, float m01, + float m10, float m11, + float m20, float m21, + float m30, float m31) + { + Row0 = new Vector2(m00, m01); + Row1 = new Vector2(m10, m11); + Row2 = new Vector2(m20, m21); + Row3 = new Vector2(m30, m31); + } + + #endregion + + #region Public Members + + #region Properties + + public Vector4 Column0 + { + get { return new Vector4(Row0.X, Row1.X, Row2.X, Row3.X); } + set { Row0.X = value.X; Row1.X = value.Y; Row2.X = value.Z; Row3.X = value.W; } + } + + public Vector4 Column1 + { + get { return new Vector4(Row0.Y, Row1.Y, Row2.Y, Row3.X); } + set { Row0.Y = value.X; Row1.Y = value.Y; Row2.Y = value.Z; Row3.Y = value.W; } + } + + public float M11 { get { return Row0.X; } set { Row0.X = value; } } + public float M12 { get { return Row0.Y; } set { Row0.Y = 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 M31 { get { return Row2.X; } set { Row2.X = value; } } + public float M32 { get { return Row2.Y; } set { Row2.Y = value; } } + public float M41 { get { return Row3.X; } set { Row3.X = value; } } + public float M42 { get { return Row3.Y; } set { Row3.Y = value; } } + + #endregion + + #region Indexers + + /// + /// 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]; + else if (rowIndex == 2) return Row2[columnIndex]; + else if (rowIndex == 3) return Row3[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; + else if (rowIndex == 2) Row2[columnIndex] = value; + else if (rowIndex == 3) Row3[columnIndex] = value; + throw new IndexOutOfRangeException("You tried to set this matrix at: (" + rowIndex + ", " + columnIndex + ")"); + } + } + + #endregion + + #endregion + + #region IEquatable Members + + public bool Equals(Matrix4x2 other) + { + return + Row0 == other.Row0 && + Row1 == other.Row1 && + Row2 == other.Row2 && + Row3 == other.Row3; + } + + #endregion + } +} diff --git a/Source/OpenTK/Math/Matrix4x2d.cs b/Source/OpenTK/Math/Matrix4x2d.cs new file mode 100644 index 00000000..17294fc0 --- /dev/null +++ b/Source/OpenTK/Math/Matrix4x2d.cs @@ -0,0 +1,34 @@ +#region --- License --- +/* +Copyright (c) 2006 - 2008 The Open Toolkit library. + +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. + */ +#endregion + +using System; +using System.Runtime.InteropServices; + +namespace OpenTK +{ + //TODO copy from Matrix4x2.cs when it's mostly feature-complete. + /*public struct Matrix4x2d : IEquatable + { + }*/ +} diff --git a/Source/OpenTK/Math/Matrix4x3.cs b/Source/OpenTK/Math/Matrix4x3.cs index d2715453..b43c44be 100644 --- a/Source/OpenTK/Math/Matrix4x3.cs +++ b/Source/OpenTK/Math/Matrix4x3.cs @@ -1,9 +1,31 @@ -using System; +#region --- License --- +/* +Copyright (c) 2006 - 2008 The Open Toolkit library. + +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. + */ +#endregion + +using System; using System.Runtime.InteropServices; -using OpenTK; - -namespace TopHat.Mathematics +namespace OpenTK { /// /// Represents a 3x4 Matrix @@ -177,6 +199,33 @@ namespace TopHat.Mathematics #endregion + #region Indexers + + /// + /// 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]; + else if (rowIndex == 2) return Row2[columnIndex]; + else if (rowIndex == 3) return Row3[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; + else if (rowIndex == 2) Row2[columnIndex] = value; + else if (rowIndex == 3) Row3[columnIndex] = value; + throw new IndexOutOfRangeException("You tried to set this matrix at: (" + rowIndex + ", " + columnIndex + ")"); + } + } + + #endregion + #region Instance #region public void Invert() diff --git a/Source/OpenTK/Math/Matrix4x3d.cs b/Source/OpenTK/Math/Matrix4x3d.cs new file mode 100644 index 00000000..bb262dfd --- /dev/null +++ b/Source/OpenTK/Math/Matrix4x3d.cs @@ -0,0 +1,34 @@ +#region --- License --- +/* +Copyright (c) 2006 - 2008 The Open Toolkit library. + +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. + */ +#endregion + +using System; +using System.Runtime.InteropServices; + +namespace OpenTK +{ + //TODO copy from Matrix4x3.cs when it's mostly feature-complete. + /*public struct Matrix4x3d : IEquatable + { + }*/ +} diff --git a/Source/OpenTK/OpenTK.csproj b/Source/OpenTK/OpenTK.csproj index c89bb8f1..1e1d14f1 100644 --- a/Source/OpenTK/OpenTK.csproj +++ b/Source/OpenTK/OpenTK.csproj @@ -132,9 +132,21 @@ + + + + + + + + + + + +