Merge pull request #331 from MatthiasHarvey/develop

Vector transform operators see #329
This commit is contained in:
William Deich 2016-02-20 14:18:40 -05:00
commit 4c8a3598e1
2 changed files with 196 additions and 2 deletions

View file

@ -1114,6 +1114,29 @@ namespace OpenTK
mat.Row3.Z;
}
/// <summary>Transform a Vector by the given Matrix</summary>
/// <param name="vec">The vector to transform</param>
/// <param name="mat">The desired transformation</param>
/// <returns>The transformed vector</returns>
public static Vector3 Transform(Vector3 vec, Matrix3 mat)
{
Vector3 result;
Transform(ref vec, ref mat, out result);
return result;
}
/// <summary>Transform a Vector by the given Matrix</summary>
/// <param name="vec">The vector to transform</param>
/// <param name="mat">The desired transformation</param>
/// <param name="result">The transformed vector</param>
public static void Transform(ref Vector3 vec, ref Matrix3 mat, out Vector3 result)
{
result = new Vector3(
vec.X * mat.Row0.X + vec.Y * mat.Row1.X + vec.Z * mat.Row2.X,
vec.X * mat.Row0.Y + vec.Y * mat.Row1.Y + vec.Z * mat.Row2.Y,
vec.X * mat.Row0.Z + vec.Y * mat.Row1.Z + vec.Z * mat.Row2.Z);
}
/// <summary>Transform a Vector by the given Matrix</summary>
/// <param name="vec">The vector to transform</param>
/// <param name="mat">The desired transformation</param>
@ -1168,6 +1191,50 @@ namespace OpenTK
Vector3.Add(ref vec, ref temp, out result);
}
/// <summary>Transform a Vector by the given Matrix using right-handed notation</summary>
/// <param name="vec">The vector to transform</param>
/// <param name="mat">The desired transformation</param>
public static Vector3 RightHandedTransform(Vector3 vec, Matrix3 mat)
{
Vector3 result;
RightHandedTransform(ref vec, ref mat, out result);
return result;
}
/// <summary>Transform a Vector by the given Matrix using right-handed notation</summary>
/// <param name="vec">The vector to transform</param>
/// <param name="mat">The desired transformation</param>
/// <param name="result">The transformed vector</param>
public static void RightHandedTransform(ref Vector3 vec, ref Matrix3 mat, out Vector3 result)
{
result = new Vector3(
mat.Row0.X * vec.X + mat.Row0.Y * vec.Y + mat.Row0.Z * vec.Z,
mat.Row1.X * vec.X + mat.Row1.Y * vec.Y + mat.Row1.Z * vec.Z,
mat.Row2.X * vec.X + mat.Row2.Y * vec.Y + mat.Row2.Z * vec.Z);
}
/// <summary>Transform a Vector by the given Matrix using right-handed notation</summary>
/// <param name="vec">The vector to transform</param>
/// <param name="mat">The desired transformation</param>
public static Vector3 RightHandedTransform(Vector3 vec, Matrix4 mat)
{
Vector3 result;
RightHandedTransform(ref vec, ref mat, out result);
return result;
}
/// <summary>Transform a Vector by the given Matrix using right-handed notation</summary>
/// <param name="vec">The vector to transform</param>
/// <param name="mat">The desired transformation</param>
/// <param name="result">The transformed vector</param>
public static void RightHandedTransform(ref Vector3 vec, ref Matrix4 mat, out Vector3 result)
{
result = new Vector3(
mat.Row0.X * vec.X + mat.Row0.Y * vec.Y + mat.Row0.Z * vec.Z + mat.Row0.W,
mat.Row1.X * vec.X + mat.Row1.Y * vec.Y + mat.Row1.Z * vec.Z + mat.Row1.W,
mat.Row2.X * vec.X + mat.Row2.Y * vec.Y + mat.Row2.Z * vec.Z + mat.Row2.W);
}
/// <summary>Transform a Vector3 by the given Matrix, and project the resulting Vector4 back to a Vector3</summary>
/// <param name="vec">The vector to transform</param>
/// <param name="mat">The desired transformation</param>
@ -1502,7 +1569,72 @@ namespace OpenTK
vec.Z *= scale.Z;
return vec;
}
/// <summary>
/// Transform a Vector by the given Matrix.
/// </summary>
/// <param name="vec">The vector to transform</param>
/// <param name="mat">The desired transformation</param>
/// <returns>The transformed vector</returns>
public static Vector3 operator *(Vector3 vec, Matrix3 mat)
{
Vector3 result;
Vector3.Transform(ref vec, ref mat, out result);
return result;
}
/// <summary>
/// Transform a Vector by the given Matrix.
/// </summary>
/// <param name="vec">The vector to transform</param>
/// <param name="mat">The desired transformation</param>
/// <returns>The transformed vector</returns>
public static Vector3 operator *(Vector3 vec, Matrix4 mat)
{
Vector3 result;
Vector3.Transform(ref vec, ref mat, out result);
return result;
}
/// <summary>
/// Transform a Vector by the given Matrix using right-handed notation
/// </summary>
/// <param name="vec">The vector to transform</param>
/// <param name="mat">The desired transformation</param>
/// <returns>The transformed vector</returns>
public static Vector3 operator *(Matrix3 mat, Vector3 vec)
{
Vector3 result;
Vector3.RightHandedTransform(ref vec, ref mat, out result);
return result;
}
/// <summary>
/// Transform a Vector by the given Matrix using right-handed notation
/// </summary>
/// <param name="vec">The vector to transform</param>
/// <param name="mat">The desired transformation</param>
/// <returns>The transformed vector</returns>
public static Vector3 operator *(Matrix4 mat, Vector3 vec)
{
Vector3 result;
Vector3.RightHandedTransform(ref vec, ref mat, out result);
return result;
}
/// <summary>
/// Transforms a vector by a quaternion rotation.
/// </summary>
/// <param name="vec">The vector to transform.</param>
/// <param name="quat">The quaternion to rotate the vector by.</param>
/// <returns></returns>
public static Vector3 operator *(Quaternion quat, Vector3 vec)
{
Vector3 result;
Vector3.Transform(ref vec, ref quat, out result);
return result;
}
/// <summary>
/// Divides an instance by a scalar.
/// </summary>

View file

@ -1017,6 +1017,29 @@ namespace OpenTK
result = new Vector4(v.X, v.Y, v.Z, v.W);
}
/// <summary>Transform a Vector by the given Matrix using right-handed notation</summary>
/// <param name="vec">The vector to transform</param>
/// <param name="mat">The desired transformation</param>
public static Vector4 RightHandedTransform(Vector4 vec, Matrix4 mat)
{
Vector4 result;
RightHandedTransform(ref vec, ref mat, out result);
return result;
}
/// <summary>Transform a Vector by the given Matrix using right-handed notation</summary>
/// <param name="vec">The vector to transform</param>
/// <param name="mat">The desired transformation</param>
/// <param name="result">The transformed vector</param>
public static void RightHandedTransform(ref Vector4 vec, ref Matrix4 mat, out Vector4 result)
{
result = new OpenTK.Vector4(
mat.Row0.X * vec.X + mat.Row0.Y * vec.Y + mat.Row0.Z * vec.Z + mat.Row0.W * vec.W,
mat.Row1.X * vec.X + mat.Row1.Y * vec.Y + mat.Row1.Z * vec.Z + mat.Row1.W * vec.W,
mat.Row2.X * vec.X + mat.Row2.Y * vec.Y + mat.Row2.Z * vec.Z + mat.Row2.W * vec.W,
mat.Row3.X * vec.X + mat.Row3.Y * vec.Y + mat.Row3.Z * vec.Z + mat.Row3.W * vec.W);
}
#endregion
#endregion
@ -1505,7 +1528,46 @@ namespace OpenTK
vec.W *= scale.W;
return vec;
}
/// <summary>
/// Transform a Vector by the given Matrix.
/// </summary>
/// <param name="vec">The vector to transform</param>
/// <param name="mat">The desired transformation</param>
/// <returns>The transformed vector</returns>
public static Vector4 operator *(Vector4 vec, Matrix4 mat)
{
Vector4 result;
Vector4.Transform(ref vec, ref mat, out result);
return result;
}
/// <summary>
/// Transform a Vector by the given Matrix using right-handed notation
/// </summary>
/// <param name="vec">The vector to transform</param>
/// <param name="mat">The desired transformation</param>
/// <returns>The transformed vector</returns>
public static Vector4 operator *(Matrix4 mat, Vector4 vec)
{
Vector4 result;
Vector4.RightHandedTransform(ref vec, ref mat, out result);
return result;
}
/// <summary>
/// Transforms a vector by a quaternion rotation.
/// </summary>
/// <param name="vec">The vector to transform.</param>
/// <param name="quat">The quaternion to rotate the vector by.</param>
/// <returns>The transformed vector</returns>
public static Vector4 operator *(Quaternion quat, Vector4 vec)
{
Vector4 result;
Vector4.Transform(ref vec, ref quat, out result);
return result;
}
/// <summary>
/// Divides an instance by a scalar.
/// </summary>