A couple more maths functions

This commit is contained in:
Tom Edwards 2013-02-23 18:26:34 +00:00
parent 11114ca4ea
commit b20b21d228
2 changed files with 25 additions and 2 deletions

View file

@ -280,6 +280,17 @@ namespace OpenTK
Row2.Xyz = Row2.Xyz.Normalized(); Row2.Xyz = Row2.Xyz.Normalized();
} }
/// <summary>
/// Returns an inverted copy of this instance.
/// </summary>
public Matrix4 Inverted()
{
Matrix4 m = this;
if (m.Determinant != 0)
m.Invert();
return m;
}
/// <summary> /// <summary>
/// Gets the translation component of this instance. /// Gets the translation component of this instance.
/// </summary> /// </summary>
@ -343,7 +354,8 @@ namespace OpenTK
q.Y = (float)((Row2[1] + Row1[2]) * sq); q.Y = (float)((Row2[1] + Row1[2]) * sq);
} }
return q.Normalized(); q.Normalize();
return q;
} }
} }

View file

@ -192,7 +192,6 @@ namespace OpenTK
/// <summary> /// <summary>
/// Returns a copy of the Quaternion scaled to unit length. /// Returns a copy of the Quaternion scaled to unit length.
/// </summary> /// </summary>
/// <returns></returns>
public Quaternion Normalized() public Quaternion Normalized()
{ {
Quaternion q = this; Quaternion q = this;
@ -200,6 +199,18 @@ namespace OpenTK
return q; return q;
} }
public void Invert()
{
W = -W;
}
public Quaternion Inverted()
{
var q = this;
q.Invert();
return q;
}
#region public void Normalize() #region public void Normalize()
/// <summary> /// <summary>