Quaternion Integration: velocity and acceleration

Please don't post Bullet support questions here, use the above forums instead.
Post Reply
SinisterMephisto
Posts: 20
Joined: Tue Sep 01, 2009 4:19 pm

Quaternion Integration: velocity and acceleration

Post by SinisterMephisto »

I was wondering how you guys implemented your rotational integrations.
I know most books only talk about the first derivative of orientation and most engines only implement the first.

I saw these functions last night and they were in my head all morning. I am currently on the train home and i though i should just ask before i arrive.

Code: Select all

q'(q,w) = 1/2qw  //W = anglar velocity transformed into quarternion [w,0]. you knew that.
But while going through some of Insomniac's publications on their site I read that
We should not multiply quaternions with scalar values (As quaternions should ideally be unit when we multiply them with other vectors)

Hence 0.5f*q should be

Code: Select all

slerp(Quaternion.Identity, q, 0.5f);
But every one I have seen scaled theirs (Basically a lerp) //I guess the inaccuracy is negligible

Secondly Angular acceleration has me a bit confused.

Code: Select all

//q = orientation
//W = anglar velocity transformed into Quarternion [w,dot].
//dot = -2w'.w' //. = dot product
//w' = q' //first derivative
q"(q,w,w') = 1/2qw 
What is the order of operations for -2w'.w'?
Do you use Quaternion.Dot(-2w',w') or -2 * Quaternion.Dot(w',w')?

the final code

Code: Select all

//mimicing s= ut +1/2at^2
q(t+dt) = q(t) + q'*dt + 1/2q"dt^2; 
Is there really a need for the angular acceleration (Second derivative)?
Would all these lerping and damping that occurs after not increase the amount of error in the system?
If you use the physics for some controlled system would it not save you all that extra control logic if every thing was slerped?

This is probably stupid and I am probably over thinking it.
mikeshafer
Posts: 49
Joined: Fri Feb 24, 2012 10:45 am

Re: Quaternion Integration: velocity and acceleration

Post by mikeshafer »

So I use slerp in my engine for animation. The idea between slerp is that you know where you want to go and you want to go somewhere in between. For physics, you don't know where you're going to end up, but you have a deltaAngularVelocity. So you do an Euler integration. I think Bullet does a straight Quaternion integration. Here is what Bullet does:

Code: Select all


btQuaternion dorn (axis.x(),axis.y(),axis.z(),btCos( fAngle*timeStep*btScalar(0.5) ));
btQuaternion orn0 = curTrans.getRotation();

btQuaternion predictedOrn = dorn * orn0;
predictedOrn.normalize();

predictedTransform.setRotation(predictedOrn);

This is what I do:

Code: Select all


   MEHVector4 axisAngle = m_angularVelocity;
   axisAngle.SetW(0.0);
   axisAngle.Normalize();
   axisAngle.SetW(m_angularVelocity.Magnitude() * elapsedSecs);
   MEHMatrix4 angularMov;
   angularMov.ToRotateFromAxisAngle(axisAngle);
   
   MEHVector3 pos = m_worldMat[3];
   m_worldMat *= angularMov;
   m_worldMat[3] = pos;

HTH,
Mike
SinisterMephisto
Posts: 20
Joined: Tue Sep 01, 2009 4:19 pm

Re: Quaternion Integration: velocity and acceleration

Post by SinisterMephisto »

Oh, I found the solution to my problem but thanks.


Code: Select all

//Velocity Verlet
//Rotations
Vector3 newW = iInv * t;

Quaternion halfQ= PIKHelper.ScaleQ(q, 0.5f);
Quaternion qDot = halfQ * (new Quaternion(w.x, w.y, w.z, 0));

float qd = Quaternion.Dot(qDot,qDot)* -2.0f;
Quaternion qDotDot = halfQ * (new Quaternion(newW.x, newW.y, newW.z, qd));
Post Reply