I am glad it works, but personally I would be suspicious and assume I might potentially miss a transform somewhere.
I'm almost sure this code works fine. The rigid body behaves quite predictably and very similar to simulation I made in Unity.
I could share my code if anyone wanted to play with it.
I'd also be happy if anyone could look again at the original code, which works, and its other variant that I think should work as well but for some reason doesn't.
Original code:
oriMat = quaternion.ToMatrix(self.ori)
inertia_world = self.inertia_local * oriMat
matrix.Invert(inertia_world)
angAcc = vector.Transform(self.totalTorque, inertia_world)
To recap: oriMat is effectively local-to-world transform. self.totalTorque is torque in world space. So this code transforms local inertia to world inertia and uses its inverse along with world torque to compute world angular acceleration.
Modified version:
oriMat = quaternion.ToMatrix(self.ori)
self.totalTorque = vector.Transform(self.totalTorque, matrix.Inverted(oriMat))
angAcc = vector.Transform(self.totalTorque, matrix.Inverted(self.inertia_local))
angAcc = vector.Transform(angAcc, oriMat)
Here I wanted to do the torque-inertia transform in local space. To do so, I transform self.totalTorque to rigid body's local space using inverse of oriMat. Then I mul that by inverted local inertia to get angular acceleration in local space. Finally, I transform angular acceleration to world space by transforming it with oriMat.
For some reason this variant doesn't yield correct behaviour of my rigid body and I really can't tell why. Anyone?