Door knocked off hinge constraint by collisions

User avatar
Erwin Coumans
Site Admin
Posts: 4183
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA
Contact:

Re: Door knocked off hinge constraint by collisions

Post by Erwin Coumans » Fri Jan 17, 2014 8:32 pm

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

Post by bteitler » Sat Jan 18, 2014 11:19 am

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

Post by Flix » Sun Jan 19, 2014 9:45 am

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 :wink:
VIDEO - Door with local inertia multiplier = 1:
Image
VIDEO - Door with local inertia multiplier = 100:
Image
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 :D ).
DoorDemo.zip
DoorDemo.cpp
(11.3 KiB) Downloaded 61 times
P.S. I've experienced the same issue with non-axis aligned btHingeConstraints bteitler faced. I had no time to fix it yesterday, but as a workaround, it's possible to use a btSliderConstraint (yes! a btSliderConstraint :!: ) instead (and that is what was used in the videos I've posted).

Hope this can be useful. Bye.

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

Re: Door knocked off hinge constraint by collisions

Post by bteitler » Wed Jan 22, 2014 5:55 am

Hmm, the hinged door solution with local inertia set to 0 for two of the axes doesn't seem to play nice with with static objects. The door simply rotates through the static objects instead of "blocking" the rotation as I'd expect.

Post Reply