mirror of
https://github.com/Ryujinx/Opentk.git
synced 2024-12-24 18:05:34 +00:00
Implemented Tranform(Vector, Quaternion) overloads. Fixes issue [#1028]: "[Math] Add vector transformation by quaternion".
This commit is contained in:
parent
b5eb7fdb93
commit
eb92aa8223
|
@ -885,6 +885,41 @@ namespace OpenTK
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
#region Transform
|
||||||
|
|
||||||
|
/// <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 result of the operation.</returns>
|
||||||
|
public static Vector2 Transform(Vector2 vec, Quaternion quat)
|
||||||
|
{
|
||||||
|
Vector2 result;
|
||||||
|
Transform(ref vec, ref quat, 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>
|
||||||
|
/// <param name="result">The result of the operation.</param>
|
||||||
|
public static void Transform(ref Vector2 vec, ref Quaternion quat, out Vector2 result)
|
||||||
|
{
|
||||||
|
Quaternion v = new Quaternion() { X = vec.X, Y = vec.Y, Z = 0, W = 0 };
|
||||||
|
Quaternion i;
|
||||||
|
Quaternion t;
|
||||||
|
Quaternion.Invert(ref quat, out i);
|
||||||
|
t = i * v;
|
||||||
|
v = t * quat;
|
||||||
|
|
||||||
|
result = new Vector2(v.X, v.Y);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Operators
|
#region Operators
|
||||||
|
|
|
@ -773,6 +773,41 @@ namespace OpenTK
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
#region Transform
|
||||||
|
|
||||||
|
/// <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 result of the operation.</returns>
|
||||||
|
public static Vector2d Transform(Vector2d vec, Quaterniond quat)
|
||||||
|
{
|
||||||
|
Vector2d result;
|
||||||
|
Transform(ref vec, ref quat, 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>
|
||||||
|
/// <param name="result">The result of the operation.</param>
|
||||||
|
public static void Transform(ref Vector2d vec, ref Quaterniond quat, out Vector2d result)
|
||||||
|
{
|
||||||
|
Quaterniond v = new Quaterniond() { X = vec.X, Y = vec.Y, Z = 0, W = 0 };
|
||||||
|
Quaterniond i;
|
||||||
|
Quaterniond t;
|
||||||
|
Quaterniond.Invert(ref quat, out i);
|
||||||
|
t = i * v;
|
||||||
|
v = t * quat;
|
||||||
|
|
||||||
|
result = new Vector2d(v.X, v.Y);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Operators
|
#region Operators
|
||||||
|
|
|
@ -1094,6 +1094,37 @@ namespace OpenTK
|
||||||
result = v4.Xyz;
|
result = v4.Xyz;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <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 result of the operation.</returns>
|
||||||
|
public static Vector3 Transform(Vector3 vec, Quaternion quat)
|
||||||
|
{
|
||||||
|
Vector3 result;
|
||||||
|
Transform(ref vec, ref quat, 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>
|
||||||
|
/// <param name="result">The result of the operation.</param>
|
||||||
|
public static void Transform(ref Vector3 vec, ref Quaternion quat, out Vector3 result)
|
||||||
|
{
|
||||||
|
Quaternion v = new Quaternion() { X = vec.X, Y = vec.Y, Z = vec.Z, W = 0 };
|
||||||
|
Quaternion i;
|
||||||
|
Quaternion t;
|
||||||
|
Quaternion.Invert(ref quat, out i);
|
||||||
|
t = i * v;
|
||||||
|
v = t * quat;
|
||||||
|
|
||||||
|
result = new Vector3(v.X, v.Y, v.Z);
|
||||||
|
}
|
||||||
|
|
||||||
/// <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>
|
||||||
/// <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>
|
||||||
|
|
|
@ -1090,6 +1090,37 @@ namespace OpenTK
|
||||||
result = v4.Xyz;
|
result = v4.Xyz;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <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 result of the operation.</returns>
|
||||||
|
public static Vector3d Transform(Vector3d vec, Quaterniond quat)
|
||||||
|
{
|
||||||
|
Vector3d result;
|
||||||
|
Transform(ref vec, ref quat, 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>
|
||||||
|
/// <param name="result">The result of the operation.</param>
|
||||||
|
public static void Transform(ref Vector3d vec, ref Quaterniond quat, out Vector3d result)
|
||||||
|
{
|
||||||
|
Quaterniond v = new Quaterniond() { X = vec.X, Y = vec.Y, Z = vec.Z, W = 0 };
|
||||||
|
Quaterniond i;
|
||||||
|
Quaterniond t;
|
||||||
|
Quaterniond.Invert(ref quat, out i);
|
||||||
|
t = i * v;
|
||||||
|
v = t * quat;
|
||||||
|
|
||||||
|
result = new Vector3d(v.X, v.Y, v.Z);
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Transform a Vector3d by the given Matrix, and project the resulting Vector4 back to a Vector3
|
/// Transform a Vector3d by the given Matrix, and project the resulting Vector4 back to a Vector3
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
|
@ -942,6 +942,37 @@ namespace OpenTK
|
||||||
vec.X * mat.Row0.W + vec.Y * mat.Row1.W + vec.Z * mat.Row2.W + vec.W * mat.Row3.W);
|
vec.X * mat.Row0.W + vec.Y * mat.Row1.W + vec.Z * mat.Row2.W + vec.W * mat.Row3.W);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <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 result of the operation.</returns>
|
||||||
|
public static Vector4 Transform(Vector4 vec, Quaternion quat)
|
||||||
|
{
|
||||||
|
Vector4 result;
|
||||||
|
Transform(ref vec, ref quat, 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>
|
||||||
|
/// <param name="result">The result of the operation.</param>
|
||||||
|
public static void Transform(ref Vector4 vec, ref Quaternion quat, out Vector4 result)
|
||||||
|
{
|
||||||
|
Quaternion v = new Quaternion() { X = vec.X, Y = vec.Y, Z = vec.Z, W = vec.W };
|
||||||
|
Quaternion i;
|
||||||
|
Quaternion t;
|
||||||
|
Quaternion.Invert(ref quat, out i);
|
||||||
|
t = i * v;
|
||||||
|
v = t * quat;
|
||||||
|
|
||||||
|
result = new Vector4(v.X, v.Y, v.Z, v.W);
|
||||||
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
|
@ -945,6 +945,37 @@ namespace OpenTK
|
||||||
vec.X * mat.Row0.W + vec.Y * mat.Row1.W + vec.Z * mat.Row2.W + vec.W * mat.Row3.W);
|
vec.X * mat.Row0.W + vec.Y * mat.Row1.W + vec.Z * mat.Row2.W + vec.W * mat.Row3.W);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <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 result of the operation.</returns>
|
||||||
|
public static Vector4d Transform(Vector4d vec, Quaterniond quat)
|
||||||
|
{
|
||||||
|
Vector4d result;
|
||||||
|
Transform(ref vec, ref quat, 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>
|
||||||
|
/// <param name="result">The result of the operation.</param>
|
||||||
|
public static void Transform(ref Vector4d vec, ref Quaterniond quat, out Vector4d result)
|
||||||
|
{
|
||||||
|
Quaterniond v = new Quaterniond() { X = vec.X, Y = vec.Y, Z = vec.Z, W = vec.W };
|
||||||
|
Quaterniond i;
|
||||||
|
Quaterniond t;
|
||||||
|
Quaterniond.Invert(ref quat, out i);
|
||||||
|
t = i * v;
|
||||||
|
v = t * quat;
|
||||||
|
|
||||||
|
result = new Vector4d(v.X, v.Y, v.Z, v.W);
|
||||||
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
Loading…
Reference in a new issue