2013-01-19 03:21:24 +00:00
|
|
|
|
#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
|
|
|
|
|
{
|
2013-01-19 08:29:22 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Represents a 2x3 matrix.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public struct Matrix2x3 : IEquatable<Matrix2x3>
|
|
|
|
|
{
|
|
|
|
|
#region Fields
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Top row of the matrix.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public Vector3 Row0;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Bottom row of the matrix.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public Vector3 Row1;
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region Constructors
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Constructs a new instance.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="row0">Top row of the matrix.</param>
|
|
|
|
|
/// <param name="row1">Bottom row of the matrix.</param>
|
|
|
|
|
public Matrix2x3(Vector3 row0, Vector3 row1)
|
|
|
|
|
{
|
|
|
|
|
Row0 = row0;
|
|
|
|
|
Row1 = row1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Constructs a new instance
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="m00">First item of the first row of the matrix.</param>
|
|
|
|
|
/// <param name="m01">Second item of the first row of the matrix.</param>
|
|
|
|
|
/// <param name="m02">Third item of the first row of the matrix.</param>
|
|
|
|
|
/// <param name="m10">First item of the second row of the matrix.</param>
|
|
|
|
|
/// <param name="m11">Second item of the second row of the matrix.</param>
|
|
|
|
|
/// <param name="m12">Third item of the second row of the matrix.</param>
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the first column of this matrix.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public Vector2 Column0
|
|
|
|
|
{
|
|
|
|
|
get { return new Vector2(Row0.X, Row1.X); }
|
|
|
|
|
set { Row0.X = value.X; Row1.X = value.Y; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the second column of this matrix.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public Vector2 Column1
|
|
|
|
|
{
|
|
|
|
|
get { return new Vector2(Row0.Y, Row1.Y); }
|
|
|
|
|
set { Row0.Y = value.X; Row1.Y = value.Y; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the third column of this matrix.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public Vector2 Column2
|
|
|
|
|
{
|
|
|
|
|
get { return new Vector2(Row0.Z, Row1.Z); }
|
|
|
|
|
set { Row0.Z = value.X; Row1.Z = value.Y; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets the value at row 1, column 1 of this instance.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public float M11 { get { return Row0.X; } set { Row0.X = value; } }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets the value at row 1, column 2 of this instance.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public float M12 { get { return Row0.Y; } set { Row0.Y = value; } }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets the value at row 1, column 3 of this instance.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public float M13 { get { return Row0.Z; } set { Row0.Z = value; } }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets the value at row 2, column 1 of this instance.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public float M21 { get { return Row1.X; } set { Row1.X = value; } }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets the value at row 2, column 2 of this instance.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public float M22 { get { return Row1.Y; } set { Row1.Y = value; } }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets the value at row 2, column 3 of this instance.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public float M23 { get { return Row1.Z; } set { Row1.Z = value; } }
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region Indexers
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets the value at a specified row and column.
|
|
|
|
|
/// </summary>
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
#region Operators
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Compares two instances for equality.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="left">The first instance.</param>
|
|
|
|
|
/// <param name="right">The second instance.</param>
|
|
|
|
|
/// <returns>True, if left equals right; false otherwise.</returns>
|
|
|
|
|
public static bool operator ==(Matrix2x3 left, Matrix2x3 right)
|
|
|
|
|
{
|
|
|
|
|
return left.Equals(right);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Compares two instances for inequality.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="left">The first instance.</param>
|
|
|
|
|
/// <param name="right">The second instance.</param>
|
|
|
|
|
/// <returns>True, if left does not equal right; false otherwise.</returns>
|
|
|
|
|
public static bool operator !=(Matrix2x3 left, Matrix2x3 right)
|
|
|
|
|
{
|
|
|
|
|
return !left.Equals(right);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region Overrides
|
|
|
|
|
|
|
|
|
|
#region public override string ToString()
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Returns a System.String that represents the current Matrix2x3.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns>The string representation of the matrix.</returns>
|
|
|
|
|
public override string ToString()
|
|
|
|
|
{
|
|
|
|
|
return String.Format("{0}\n{1}", Row0, Row1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region public override int GetHashCode()
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Returns the hashcode for this instance.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns>A System.Int32 containing the unique hashcode for this instance.</returns>
|
|
|
|
|
public override int GetHashCode()
|
|
|
|
|
{
|
|
|
|
|
return Row0.GetHashCode() ^ Row1.GetHashCode();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region public override bool Equals(object obj)
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Indicates whether this instance and a specified object are equal.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="obj">The object to compare tresult.</param>
|
|
|
|
|
/// <returns>True if the instances are equal; false otherwise.</returns>
|
|
|
|
|
public override bool Equals(object obj)
|
|
|
|
|
{
|
|
|
|
|
if (!(obj is Matrix2x3))
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
return this.Equals((Matrix2x3)obj);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region IEquatable<Matrix2x3> Members
|
|
|
|
|
|
|
|
|
|
/// <summary>Indicates whether the current matrix is equal to another matrix.</summary>
|
|
|
|
|
/// <param name="other">An matrix to compare with this matrix.</param>
|
|
|
|
|
/// <returns>true if the current matrix is equal to the matrix parameter; otherwise, false.</returns>
|
|
|
|
|
public bool Equals(Matrix2x3 other)
|
|
|
|
|
{
|
|
|
|
|
return
|
|
|
|
|
Row0 == other.Row0 &&
|
|
|
|
|
Row1 == other.Row1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
}
|
2013-01-19 03:21:24 +00:00
|
|
|
|
}
|