so real quick I'm simulating 3D rigidbody dynamics. This is what I have:
mat3x3 rotmat = body.rotation().normalised().toRotationMatrix(); mat3x3 tensor = rotmat * (body._bodyInertiaTensor * body.mass).inversed() * rotmat.transposed(); body._angularMtm += torque * dt; body._angVel = body._inputOmega + (tensor * body._angularMtm);
In this case,
_bodyInertiaTensor is the following matrix:
1/12 0 0 0 1/12 0 0 0 1/12
(for a cuboid, in this case of unit dimensions)
here's the setup:
body.rotation() gives me a quaternion,
dt is my timestep factor.
axis-wise, it follows openGL: Y-up/X-right/Z-backward
now for the problem: if my object is not rotated (ie.
q(1, 0, 0, 0)), then everything works fine. I apply a torque
t: v3(1, 0, 0) which rotates me around the local X (pitch), which is also the global X.
if I rotate (yaw) my object 90 degrees left, so that
rot: q(1/√2, 0, 1/√2, 0), then apply a torque
t: v3(1, 0, 0) --- i get the expected pitch (local X, global Z) but also an unwanted 'local roll' angular velocity (local Z, global X).
after lots of searching I have no idea what this is about. this question looked promising at first, but the more i thought about it the less i think it applies.
since the angular momentum doesn't have unwanted values in the other axes, i'm thinking 99% the problem lies somewhere in the tensor matrix that i'm calculating...
EDIT: upon further investigation, i lied about the inertia tensor: it's rather something like
0.10 0 0 0 0.10 0 0 0 0.04
for a cuboid of 0.5x0.5x1. experimenting a bit, the problem i described doesn't appear when the inertia is symmetrical about all axes (ie. it's a (1, 1, 1) thing). though, the applied torque is along a principal axis, is it not?