Hi guys
I have been dabbling with a custom physics solver (Mainly just for the integration) and I came across the following formulas
Here is the formula of the equation. (Only q’(t) and q"(t))
//Angular velocity q'
// q - orientation in quaternion
// w - angular velocity in vector3
Quaternion q_dot = 0.5 * q* W; //where W = new Quaternion (w.x, w.y, w.z, 0)
//Eq 2.1
float dot = -2 * Quaternion.Dot(q_dot, q_dot); //the equation was -2q'.q'
//a is a vector gotten by multiplying Inverse Inertia tensor by Torque: not a problem
Quaternion alpha = new Quaternion(a.x, a.y, a.z, dot);
//Angular acceleration q"
Quaternion q_dotdot = 0.5 * q *alpha;
//when integrated
//Angular version of s = ut + 1/2at^2
//dt - elapsed time float
Quaternion result = q_dot * dt + 0.5f * q_dotdot * dt * dt;
transform.rotation * = Normalize(result);
//PS: I know unity does not have scaling and normalization operations so I wrote custom version
//Just in case you were checking
My questions:
- Multiplying quaternions with scalar value. Naturally this should not even have an effect as quaternions should be of unit value before rotating. The guys at insomniac also said scalar multiplications should be replaced with
Quarternion.Slerp(Quaternion.Identity, yourQuaternion, yourScale); //Expensive of a physics system
//or
Quarternion.Lerp(Quaternion.Identity, yourQuaternion, yourScale); //In accurate even when normalized after
The problem is most implementations i have seen of this people just straight up multiply, Why?
-
The second equations is really what gets me. I have seen no code implementation of it
Eq 2.1) Could -2q’.q’ mean: 2 * Quaternion.Dot(q_dot, q_dot) or Quaternion.Dot( -2 *q_dot, q_dot) -
The final equations contains a lot of quaternion scaling.
Basically every where there is scaling confuses me.
I hop i have not confused any potential helpers.
Regards