Fixed Vector3.Transform signature to return a Vector3, not a Vector4. It was previously impossible to transform a Vector3 structure without intermediate conversions to Vector4.

This commit is contained in:
the_fiddler 2009-11-03 11:45:20 +00:00
parent 3d6d476d16
commit 9ce7437cbd
2 changed files with 29 additions and 32 deletions

View file

@ -1076,14 +1076,10 @@ namespace OpenTK
/// <param name="vec">The vector to transform</param> /// <param name="vec">The vector to transform</param>
/// <param name="mat">The desired transformation</param> /// <param name="mat">The desired transformation</param>
/// <returns>The transformed vector</returns> /// <returns>The transformed vector</returns>
public static Vector4 Transform(Vector3 vec, Matrix4 mat) public static Vector3 Transform(Vector3 vec, Matrix4 mat)
{ {
Vector4 v4 = new Vector4(vec.X, vec.Y, vec.Z, 1.0f); Vector3 result;
Vector4 result; Transform(ref vec, ref mat, out result);
result.X = Vector4.Dot(v4, mat.Column0);
result.Y = Vector4.Dot(v4, mat.Column1);
result.Z = Vector4.Dot(v4, mat.Column2);
result.W = Vector4.Dot(v4, mat.Column3);
return result; return result;
} }
@ -1091,10 +1087,11 @@ namespace OpenTK
/// <param name="vec">The vector to transform</param> /// <param name="vec">The vector to transform</param>
/// <param name="mat">The desired transformation</param> /// <param name="mat">The desired transformation</param>
/// <param name="result">The transformed vector</param> /// <param name="result">The transformed vector</param>
public static void Transform(ref Vector3 vec, ref Matrix4 mat, out Vector4 result) public static void Transform(ref Vector3 vec, ref Matrix4 mat, out Vector3 result)
{ {
Vector4 v4 = new Vector4(vec.X, vec.Y, vec.Z, 1.0f); Vector4 v4 = new Vector4(vec.X, vec.Y, vec.Z, 1.0f);
Vector4.Transform(ref v4, ref mat, out result); Vector4.Transform(ref v4, ref mat, out v4);
result = v4.Xyz;
} }
/// <summary>Transform a Vector3 by the given Matrix, and project the resulting Vector4 back to a Vector3</summary> /// <summary>Transform a Vector3 by the given Matrix, and project the resulting Vector4 back to a Vector3</summary>
@ -1103,8 +1100,9 @@ namespace OpenTK
/// <returns>The transformed vector</returns> /// <returns>The transformed vector</returns>
public static Vector3 TransformPerspective(Vector3 vec, Matrix4 mat) public static Vector3 TransformPerspective(Vector3 vec, Matrix4 mat)
{ {
Vector4 h = Transform(vec, mat); Vector3 result;
return new Vector3(h.X / h.W, h.Y / h.W, h.Z / h.W); TransformPerspective(ref vec, ref mat, out result);
return result;
} }
/// <summary>Transform a Vector3 by the given Matrix, and project the resulting Vector4 back to a Vector3</summary> /// <summary>Transform a Vector3 by the given Matrix, and project the resulting Vector4 back to a Vector3</summary>
@ -1113,11 +1111,11 @@ namespace OpenTK
/// <param name="result">The transformed vector</param> /// <param name="result">The transformed vector</param>
public static void TransformPerspective(ref Vector3 vec, ref Matrix4 mat, out Vector3 result) public static void TransformPerspective(ref Vector3 vec, ref Matrix4 mat, out Vector3 result)
{ {
Vector4 h; Vector4 v = new Vector4(vec);
Vector3.Transform(ref vec, ref mat, out h); Vector4.Transform(ref v, ref mat, out v);
result.X = h.X / h.W; result.X = v.X / v.W;
result.Y = h.Y / h.W; result.Y = v.Y / v.W;
result.Z = h.Z / h.W; result.Z = v.Z / v.W;
} }
#endregion #endregion

View file

@ -1072,24 +1072,22 @@ namespace OpenTK
/// <param name="vec">The vector to transform</param> /// <param name="vec">The vector to transform</param>
/// <param name="mat">The desired transformation</param> /// <param name="mat">The desired transformation</param>
/// <returns>The transformed vector</returns> /// <returns>The transformed vector</returns>
public static Vector4d Transform(Vector3d vec, Matrix4d mat) public static Vector3d Transform(Vector3d vec, Matrix4d mat)
{ {
Vector4d v4 = new Vector4d(vec.X, vec.Y, vec.Z, 1.0f); Vector3d result;
return new Vector4d( Transform(ref vec, ref mat, out result);
Vector4d.Dot(v4, mat.Column0), return result;
Vector4d.Dot(v4, mat.Column1),
Vector4d.Dot(v4, mat.Column2),
Vector4d.Dot(v4, mat.Column3));
} }
/// <summary>Transform a Vector by the given Matrix</summary> /// <summary>Transform a Vector by the given Matrix</summary>
/// <param name="vec">The vector to transform</param> /// <param name="vec">The vector to transform</param>
/// <param name="mat">The desired transformation</param> /// <param name="mat">The desired transformation</param>
/// <param name="result">The transformed vector</param> /// <param name="result">The transformed vector</param>
public static void Transform(ref Vector3d vec, ref Matrix4d mat, out Vector4d result) public static void Transform(ref Vector3d vec, ref Matrix4d mat, out Vector3d result)
{ {
Vector4d v4 = new Vector4d(vec.X, vec.Y, vec.Z, 1.0f); Vector4d v4 = new Vector4d(vec.X, vec.Y, vec.Z, 1.0f);
Vector4d.Transform(ref v4, ref mat, out result); Vector4d.Transform(ref v4, ref mat, out v4);
result = v4.Xyz;
} }
/// <summary> /// <summary>
@ -1100,8 +1098,9 @@ namespace OpenTK
/// <returns>The transformed vector</returns> /// <returns>The transformed vector</returns>
public static Vector3d TransformPerspective(Vector3d vec, Matrix4d mat) public static Vector3d TransformPerspective(Vector3d vec, Matrix4d mat)
{ {
Vector4d h = Transform(vec, mat); Vector3d result;
return new Vector3d(h.X / h.W, h.Y / h.W, h.Z / h.W); TransformPerspective(ref vec, ref mat, out result);
return result;
} }
/// <summary>Transform a Vector3d by the given Matrix, and project the resulting Vector4d back to a Vector3d</summary> /// <summary>Transform a Vector3d by the given Matrix, and project the resulting Vector4d back to a Vector3d</summary>
@ -1110,11 +1109,11 @@ namespace OpenTK
/// <param name="result">The transformed vector</param> /// <param name="result">The transformed vector</param>
public static void TransformPerspective(ref Vector3d vec, ref Matrix4d mat, out Vector3d result) public static void TransformPerspective(ref Vector3d vec, ref Matrix4d mat, out Vector3d result)
{ {
Vector4d h; Vector4d v = new Vector4d(vec);
Vector3d.Transform(ref vec, ref mat, out h); Vector4d.Transform(ref v, ref mat, out v);
result.X = h.X / h.W; result.X = v.X / v.W;
result.Y = h.Y / h.W; result.Y = v.Y / v.W;
result.Z = h.Z / h.W; result.Z = v.Z / v.W;
} }
#endregion #endregion