Page 1 of 1

Scaling result of getInvInertiaTensorWorld?

Posted: Wed Aug 16, 2017 8:48 pm
by Silverlan
My engine uses a different scale than my physics implementation, so I need to scale everything accordingly when giving data to / retrieving data from bullet.
That works just fine, but I'm not sure about btRigidBody::getInvInertiaTensorWorld. According to this article all inertias have to be scaled by X. getInvInertiaTensorWorld returns a matrix, do I just scale the last column?

Re: Scaling result of getInvInertiaTensorWorld?

Posted: Thu Aug 17, 2017 12:37 pm
by drleviathan
I think you would be better off to scale the non-inverse inertia values assigned to the btRigidBody and then leave the inverse inertia alone. That wiki page may be incorrect. See this thread.

Re: Scaling result of getInvInertiaTensorWorld?

Posted: Thu Aug 17, 2017 1:14 pm
by Silverlan
drleviathan wrote:I think you would be better off to scale the non-inverse inertia values assigned to the btRigidBody and then leave the inverse inertia alone. That wiki page may be incorrect. See this thread.
Hm... btRigidBody::getLocalInertia returns a vector3, not matrix. My main goal is to calculate the torque I need to apply to an object over a period of time t to reach an angular velocity v.
Pseudo code:

Code: Select all

auto targetAngularVelocity = Vector3(0,M_PI,0);
auto t = 1.f; // Time after which target angular velocity should be reached
auto torque = (targetAngularVelocity /t) *inverse(rigidBody->getInvInertiaTensorWorld());
So applying the torque to the rigidBody for the period of time t should result in the object having the angular velocity targetAngularVelocity, I believe the formula should be correct (The equivalent for linear force/velocity works just fine).
How can I do that using btRigidBody::getLocalInertia instead of btRigidBody::getInvInertiaTensorWorld?

Re: Scaling result of getInvInertiaTensorWorld?

Posted: Thu Aug 17, 2017 8:19 pm
by drleviathan
Yes, btRigidBody::getLocalInertia() returns a btVector3 because it assumes the inertia tensor is diagonal in the local frame which means only the diagonal components are non-trivial. You set the local inertia diagonal (scaled as necessary) and then you let Bullet compute the InvInertiaTensorWorld for you. In other words, you scale the local inertia once when you set it, and then the world-frame inverse inertia tensor will be scaled for you when you ask for it.

Meanwhile: are you sure you want to twist the object around using torque? If you can achieve what you want by adjusting the angular velocity (maybe you can't, I dunno what exactly you're trying to do) then you should consider doing that: it is simpler.

Re: Scaling result of getInvInertiaTensorWorld?

Posted: Thu Aug 17, 2017 8:56 pm
by Silverlan
drleviathan wrote:Meanwhile: are you sure you want to twist the object around using torque? If you can achieve what you want by adjusting the angular velocity (maybe you can't, I dunno what exactly you're trying to do) then you should consider doing that: it is simpler.
I want to simulate a quadcopter and I'm applying torque on the rotors, which would be more realistic I believe?

Anyway, I ended up scaling the inverted inertia matrix by the squared world scale and with that I get an accurate result. That means the wiki page was indeed incorrect, thanks for the tip!