Modified Transform(ref Vector4, ref Matrix4, out Vector4) overload to work correctly when the ref and out parameters point to the same Vector4.
Modified Transform(Vector4, Matrix4): Vector4 to call the reference overload internally. Faster and reduces code duplication.
This commit is contained in:
parent
26b969b23e
commit
3d6d476d16
2 changed files with 12 additions and 46 deletions
|
@ -925,10 +925,7 @@ namespace OpenTK
|
|||
public static Vector4 Transform(Vector4 vec, Matrix4 mat)
|
||||
{
|
||||
Vector4 result;
|
||||
result.X = Vector4.Dot(vec, mat.Column0);
|
||||
result.Y = Vector4.Dot(vec, mat.Column1);
|
||||
result.Z = Vector4.Dot(vec, mat.Column2);
|
||||
result.W = Vector4.Dot(vec, mat.Column3);
|
||||
Transform(ref vec, ref mat, out result);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -938,25 +935,11 @@ namespace OpenTK
|
|||
/// <param name="result">The transformed vector</param>
|
||||
public static void Transform(ref Vector4 vec, ref Matrix4 mat, out Vector4 result)
|
||||
{
|
||||
result.X = vec.X * mat.Row0.X +
|
||||
vec.Y * mat.Row1.X +
|
||||
vec.Z * mat.Row2.X +
|
||||
vec.W * mat.Row3.X;
|
||||
|
||||
result.Y = vec.X * mat.Row0.Y +
|
||||
vec.Y * mat.Row1.Y +
|
||||
vec.Z * mat.Row2.Y +
|
||||
vec.W * mat.Row3.Y;
|
||||
|
||||
result.Z = vec.X * mat.Row0.Z +
|
||||
vec.Y * mat.Row1.Z +
|
||||
vec.Z * mat.Row2.Z +
|
||||
vec.W * mat.Row3.Z;
|
||||
|
||||
result.W = vec.X * mat.Row0.W +
|
||||
vec.Y * mat.Row1.W +
|
||||
vec.Z * mat.Row2.W +
|
||||
vec.W * mat.Row3.W;
|
||||
result = new Vector4(
|
||||
vec.X * mat.Row0.X + vec.Y * mat.Row1.X + vec.Z * mat.Row2.X + vec.W * mat.Row3.X,
|
||||
vec.X * mat.Row0.Y + vec.Y * mat.Row1.Y + vec.Z * mat.Row2.Y + vec.W * mat.Row3.Y,
|
||||
vec.X * mat.Row0.Z + vec.Y * mat.Row1.Z + vec.Z * mat.Row2.Z + vec.W * mat.Row3.Z,
|
||||
vec.X * mat.Row0.W + vec.Y * mat.Row1.W + vec.Z * mat.Row2.W + vec.W * mat.Row3.W);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
|
|
@ -928,10 +928,7 @@ namespace OpenTK
|
|||
public static Vector4d Transform(Vector4d vec, Matrix4d mat)
|
||||
{
|
||||
Vector4d result;
|
||||
result.X = Vector4d.Dot(vec, mat.Column0);
|
||||
result.Y = Vector4d.Dot(vec, mat.Column1);
|
||||
result.Z = Vector4d.Dot(vec, mat.Column2);
|
||||
result.W = Vector4d.Dot(vec, mat.Column3);
|
||||
Transform(ref vec, ref mat, out result);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -941,25 +938,11 @@ namespace OpenTK
|
|||
/// <param name="result">The transformed vector</param>
|
||||
public static void Transform(ref Vector4d vec, ref Matrix4d mat, out Vector4d result)
|
||||
{
|
||||
result.X = vec.X * mat.Row0.X +
|
||||
vec.Y * mat.Row1.X +
|
||||
vec.Z * mat.Row2.X +
|
||||
vec.W * mat.Row3.X;
|
||||
|
||||
result.Y = vec.X * mat.Row0.Y +
|
||||
vec.Y * mat.Row1.Y +
|
||||
vec.Z * mat.Row2.Y +
|
||||
vec.W * mat.Row3.Y;
|
||||
|
||||
result.Z = vec.X * mat.Row0.Z +
|
||||
vec.Y * mat.Row1.Z +
|
||||
vec.Z * mat.Row2.Z +
|
||||
vec.W * mat.Row3.Z;
|
||||
|
||||
result.W = vec.X * mat.Row0.W +
|
||||
vec.Y * mat.Row1.W +
|
||||
vec.Z * mat.Row2.W +
|
||||
vec.W * mat.Row3.W;
|
||||
result = new Vector4d(
|
||||
vec.X * mat.Row0.X + vec.Y * mat.Row1.X + vec.Z * mat.Row2.X + vec.W * mat.Row3.X,
|
||||
vec.X * mat.Row0.Y + vec.Y * mat.Row1.Y + vec.Z * mat.Row2.Y + vec.W * mat.Row3.Y,
|
||||
vec.X * mat.Row0.Z + vec.Y * mat.Row1.Z + vec.Z * mat.Row2.Z + vec.W * mat.Row3.Z,
|
||||
vec.X * mat.Row0.W + vec.Y * mat.Row1.W + vec.Z * mat.Row2.W + vec.W * mat.Row3.W);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
|
Loading…
Reference in a new issue