## Door knocked off hinge constraint by collisions

Erwin Coumans
Posts: 4209
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA
Contact:

### Re: Door knocked off hinge constraint by collisions

I'd still like a solution that works in the non-axis aligned case though.
You can set two components of the the local inertia tensor to zero, instead of using the angular factor. This will give you a 'fixed' hinge axis in local space, so you just orient the body accordinaly (and use a btCompoundShape if necessary). I plan on adding a btTransformShape to avoid the cost of btCompoundShape when the only purpose is just to shift the center of mass.
You still need to set the linear factor to zero.

Code: Select all

``````box->calculateLocalInertia(mass,localInertia);
localInertia[0] = 0;
localInertia[1] = 0;
body = new btRigidBody(..., localInertia);
body->setLinearFactor(btVector3(0,0,0));
//don't call body->setAngularFactor, because we already lock the angular motion using the inertia tensor
//don't need to create a btHingeConstraint either.
``````
An alternative would be to use Featherstone btMultiBody. It combines well with btRigidBody, so you don't pay a penalty in performance.
With btMultiBody you can attach two free moving bodies in a way so that the hinge axis will never be violated.

Yet another alternative would be to use the btDanztigSolver or btLemkeSolver (see Bullet/Demos/ForkLiftDemo). Right now, the solver is used for all objects, so performance would drop.
It is possible to use the btDantzigSolver or btLemkeSolver only for specific constraints, as a 'block' solver, in combination with regular iterative constraints (sequential impulse/projected gauss seidel).
I am working on a demo in the github repository to show the various options.

Please let us know if that inertia tensor workaround does the trick for you.
Thanks,
Erwin

bteitler
Posts: 10
Joined: Mon Jan 13, 2014 12:47 pm

### Re: Door knocked off hinge constraint by collisions

I didn't know about the inertia settings. Seems to be exactly what I needed. I tested it, and combined with the custom gravity per tick, this seems to perform pretty realistically. This should meet my requirements I think. Thanks for your help.

Flix
Posts: 456
Joined: Tue Dec 25, 2007 1:06 pm

### Re: Door knocked off hinge constraint by collisions

I know that this thread if almost officially closed. Anyway yesterday evening I've made a small Demo (and a couple of small videos) to show the benefits that can be derived from increasing the inertia tensor of a body inside a constaint. Hope it can help somebody
VIDEO - Door with local inertia multiplier = 1:

VIDEO - Door with local inertia multiplier = 100:

Please note that the "one axis trick" Erwin mentioned (i.e. only one local inertia component is not zero) has been applied to both cases: still, having a big multiplier improves stability at limits a lot (and this technique works for nearly every constraint type ).
DoorDemo.zip
DoorDemo.cpp