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="mat">The desired transformation</param>
/// <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);
Vector4 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);
Vector3 result;
Transform(ref vec, ref mat, out result);
return result;
}
@ -1091,10 +1087,11 @@ namespace OpenTK
/// <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 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.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>
@ -1103,8 +1100,9 @@ namespace OpenTK
/// <returns>The transformed vector</returns>
public static Vector3 TransformPerspective(Vector3 vec, Matrix4 mat)
{
Vector4 h = Transform(vec, mat);
return new Vector3(h.X / h.W, h.Y / h.W, h.Z / h.W);
Vector3 result;
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>
@ -1113,11 +1111,11 @@ namespace OpenTK
/// <param name="result">The transformed vector</param>
public static void TransformPerspective(ref Vector3 vec, ref Matrix4 mat, out Vector3 result)
{
Vector4 h;
Vector3.Transform(ref vec, ref mat, out h);
result.X = h.X / h.W;
result.Y = h.Y / h.W;
result.Z = h.Z / h.W;
Vector4 v = new Vector4(vec);
Vector4.Transform(ref v, ref mat, out v);
result.X = v.X / v.W;
result.Y = v.Y / v.W;
result.Z = v.Z / v.W;
}
#endregion

View file

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