Changed vector-quaternion transformations to use standard q * v * q^-1 convention. Fixes issue [#1372]: "[Math] Vector transformation by Quaternion follows non-standard quaternion math convention".

This commit is contained in:
the_fiddler 2009-11-16 13:00:42 +00:00
parent 6471772777
commit 0605607e6a
6 changed files with 18 additions and 30 deletions

View file

@ -908,12 +908,10 @@ namespace OpenTK
/// <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(vec.X, vec.Y, 0, 0);
Quaternion i;
Quaternion t;
Quaternion v = new Quaternion(vec.X, vec.Y, 0, 0), i, t;
Quaternion.Invert(ref quat, out i);
t = i * v;
v = t * quat;
Quaternion.Multiply(ref quat, ref v, out t);
Quaternion.Multiply(ref t, ref i, out v);
result = new Vector2(v.X, v.Y);
}

View file

@ -796,12 +796,10 @@ namespace OpenTK
/// <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(vec.X, vec.Y, 0, 0);
Quaterniond i;
Quaterniond t;
Quaterniond v = new Quaterniond(vec.X, vec.Y, 0, 0), i, t;
Quaterniond.Invert(ref quat, out i);
t = i * v;
v = t * quat;
Quaterniond.Multiply(ref quat, ref v, out t);
Quaterniond.Multiply(ref t, ref i, out v);
result = new Vector2d(v.X, v.Y);
}

View file

@ -1115,12 +1115,10 @@ namespace OpenTK
/// <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(vec.X, vec.Y, vec.Z, 0);
Quaternion i;
Quaternion t;
Quaternion v = new Quaternion(vec.X, vec.Y, vec.Z, 0), i, t;
Quaternion.Invert(ref quat, out i);
t = i * v;
v = t * quat;
Quaternion.Multiply(ref quat, ref v, out t);
Quaternion.Multiply(ref t, ref i, out v);
result = new Vector3(v.X, v.Y, v.Z);
}

View file

@ -1111,12 +1111,10 @@ namespace OpenTK
/// <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(vec.X, vec.Y, vec.Z, 0);
Quaterniond i;
Quaterniond t;
Quaterniond v = new Quaterniond(vec.X, vec.Y, vec.Z, 0), i, t;
Quaterniond.Invert(ref quat, out i);
t = i * v;
v = t * quat;
Quaterniond.Multiply(ref quat, ref v, out t);
Quaterniond.Multiply(ref t, ref i, out v);
result = new Vector3d(v.X, v.Y, v.Z);
}

View file

@ -963,12 +963,10 @@ namespace OpenTK
/// <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(vec.X, vec.Y, vec.Z, vec.W);
Quaternion i;
Quaternion t;
Quaternion v = new Quaternion(vec.X, vec.Y, vec.Z, vec.W), i, t;
Quaternion.Invert(ref quat, out i);
t = i * v;
v = t * quat;
Quaternion.Multiply(ref quat, ref v, out t);
Quaternion.Multiply(ref t, ref i, out v);
result = new Vector4(v.X, v.Y, v.Z, v.W);
}

View file

@ -966,12 +966,10 @@ namespace OpenTK
/// <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(vec.X, vec.Y, vec.Z, vec.W);
Quaterniond i;
Quaterniond t;
Quaterniond v = new Quaterniond(vec.X, vec.Y, vec.Z, vec.W), i, t;
Quaterniond.Invert(ref quat, out i);
t = i * v;
v = t * quat;
Quaterniond.Multiply(ref quat, ref v, out t);
Quaterniond.Multiply(ref t, ref i, out v);
result = new Vector4d(v.X, v.Y, v.Z, v.W);
}