Inertia problem - why does this not work ? [Solved]

JohanW
Posts: 2
Joined: Sun Jan 25, 2009 11:11 am

Inertia problem - why does this not work ? [Solved]

Post by JohanW »

Hello.

When I write the following code, the smulation runs as it should. Like this: http://waldeback.se/public/bulletproble ... ullet1.jpg

Code: Select all

...
btVector3 btinertia(inertia.x, inertia.y, inertia.z );
if( this->m_bDynamic ) { this->m_pCollisionShape->calculateLocalInertia(this->m_initialMass, btinertia); }
btRigidBody::btRigidBodyConstructionInfo rbInfo(this->m_initialMass, this->m_pMotionState, this->m_pCollisionShape, btinertia );
...
where inertia is my own 3D vector class and this->m_pCollisionShape is created by: this->m_pCollisionShape = new btBoxShape(...)

But if I change the code to the following, the objects refuses to rotate. Like this: http://waldeback.se/public/bulletproble ... ullet2.jpg

Code: Select all

...
btVector3 btinertia(inertia.x, inertia.y, inertia.z );
btVector3 btinertia2(inertia.x, inertia.y, inertia.z );
if( this->m_bDynamic ) { this->m_pCollisionShape->calculateLocalInertia(this->m_initialMass, btinertia); }
btRigidBody::btRigidBodyConstructionInfo rbInfo(this->m_initialMass, this->m_pMotionState, this->m_pCollisionShape, btinertia2 );
...
Why ???

Best Regards
Johan

EDIT: I'm using bullet version 2.73
Last edited by JohanW on Sun Jan 25, 2009 9:26 pm, edited 1 time in total.
sparkprime
Posts: 508
Joined: Fri May 30, 2008 2:51 am
Location: Ossining, New York

Re: Inertia problem - why does this not work ?

Post by sparkprime »

Are you aware that calculateLocalInertia calculates an inertia in a shape-dependent fashion and writes it back to the vector you give it?

The second code you gave does not make much sense as the computed inertia is discarded. I suggest comparing Bullet's computed inertia (that you use in the first case) with your own inertia (that you use in the second case) and see why your own one doesn't work. Why not just let bullet compute the inertia?
JohanW
Posts: 2
Joined: Sun Jan 25, 2009 11:11 am

Re: Inertia problem - why does this not work ? [Solved]

Post by JohanW »

Aha, ok, i see.

Yes, the problem was that I had misunderstood the purpose of the calculateLocalInertia function.

Thank you.