Hey Y'all,
I've been trying to build a little physics engine for fun, mostly based on this document. It lists the following function for implementing rotation (on page 15):
q² = q¹ + (∆t/2)q¹ ∗ ω²
Where:
- q² is the orientation of the current time step (as a quaternion)
- q¹ is the orientation of the previous time step
- ∆t is the time delta
- ω² is the angular velocity of the current time step (treated as a quaternion with a 0 scalar)
- ∗ represents quaternion multiplication
I implemented this as follows
Transform.Rotation += (deltaTime.DeltaF / 2) * Transform.Rotation * new quat(AngularVelocity, 0);
//AngularVelocity is a vec3
I am using GlmSharp for vec3 and quat, which implements quaternion addition component-wise, which I'm pretty sure is fine:
/// <summary>
/// Returns a quat from component-wise application of operator+ (lhs + rhs).
/// </summary>
public static quat operator+(quat lhs, quat rhs) => new quat(lhs.x + rhs.x, lhs.y + rhs.y, lhs.z + rhs.z, lhs.w + rhs.w);
However this causes warping on my objects as they accumulate rotation:
This is without apply any kind of scaling or translation.
Searching around the web I found very little people talking about using quaternion addition, so am I interpreting the document's function incorrectly? I have tried implementing angular velocity in other ways but none of them have worked. What am I missing?
Thanks for reading and have a nice day!