Cylinder inertia

Diggsey
Posts: 1
Joined: Tue Feb 16, 2010 4:07 pm

Cylinder inertia

Post by Diggsey »

Hi :)

I'm probably going to sound really picky, but in btCylinderShape.cpp, the inertia is calculate using a box approximation:

Code: Select all

void	btCylinderShape::calculateLocalInertia(btScalar mass,btVector3& inertia) const
{
	//approximation of box shape, todo: implement cylinder shape inertia before people notice ;-)
	btVector3 halfExtents = getHalfExtentsWithMargin();

	btScalar lx=btScalar(2.)*(halfExtents.x());
	btScalar ly=btScalar(2.)*(halfExtents.y());
	btScalar lz=btScalar(2.)*(halfExtents.z());

	inertia.setValue(mass/(btScalar(12.0)) * (ly*ly + lz*lz),
					mass/(btScalar(12.0)) * (lx*lx + lz*lz),
					mass/(btScalar(12.0)) * (lx*lx + ly*ly));

}
(I guess I noticed :P )

It seems an easy enough fix to get the correct inertia - http://en.wikipedia.org/wiki/List_of_mo ... ia_tensors
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Re: Cylinder inertia

Post by Erwin Coumans »

Good point, it is one of those approximations. How did you find out? By watching the cylinder move, or by looking at the source code? ;-)

Are you interested to create a patch with an optional backwards compatibility setting (in case some games want to update and keep the old approximation)
Thanks!
Erwin