PDA

View Full Version : OK, then simple question about Quats

M/\dm/\n
04-30-2003, 12:47 AM
How can I create simpe animation, knife movement for example.
Firstly, I translate it to needed position, rotate it with 3quats, then I calculate how the end position should look like 1 trans +3 quats. Finally, I calculate difference final trans/quat-start trans/quat and every frame call trans/quat+diff*t
Is that right?

Gavin
04-30-2003, 04:11 AM
animating along a path... or just simple linear or...?

M/\dm/\n
04-30-2003, 05:33 AM
Preferably non-linear, it's called Cubic interploration, yes?

oliii
04-30-2003, 09:31 AM
why 3 quats? you should only need one. If you have a start orientation matrix and an end orientation matrix, convert them to quats, then you can interpolate from one to another, linearly or non linearly.

oliii
04-30-2003, 09:35 AM
btw, some quaternion interpolation code

bool Vector::Interpolate(const Vector&amp; V0, const Vector&amp; V1, float Fraction)
{
float OneMinusFraction = 1.0f - Fraction;
x = OneMinusFraction * V0.x + Fraction * V1.x;
y = OneMinusFraction * V0.y + Fraction * V1.y;
z = OneMinusFraction * V0.z + Fraction * V1.z;
}

bool Quaternion::Interpolate(const Quaternion &amp;Quat1,const Quaternion &amp;Quat2,float Fraction)
{
//--------------------------------------------------------------------------------
// There are two quaternions for each orientation, this will cause problems if we don't
// eliminate one (i.e. zero crossover problem), so see if quaternions are on opposite sides of a
// 4 dimensional hypersphere (the degenerate case) and if so, flip one to the otherside (same
// orientation but now no zero crossover problem)
//--------------------------------------------------------------------------------
Quaternion NormQuat2 = Quat2; //Used to get rid of degenerate case

if ((Quat1.DotProduct(NormQuat2)) < 0.0f)
NormQuat2 *= -1.0f; //See comment above

//--------------------------------------------------------------------------------
// The degenerate case has been removed, can now interpolate normally
//--------------------------------------------------------------------------------
V.Interpolate(Quat1.V, NormQuat2.V, Fraction);

R = Quat1.R * Fraction;
R += NormQuat2.R * (1.0f - Fraction);

return Normalise();
}