Problem with HingeConstraint limits

gabba
Posts: 9
Joined: Thu Mar 19, 2009 3:20 am

Problem with HingeConstraint limits

Post by gabba »

Hi,

It seems that HingeConstraint (and other constraints involving an angle limit) doesn't like at all limits that are near or above PI (i.e. 180 degrees).

I tested this in ConstraintDemo.cpp. This works:

Code: Select all

spDoorHinge->setLimit( 0.0f, M_PI_2 );
However this doesn't work at all: the door starts spinning like mad once it crosses the 180 degrees angle:

Code: Select all

spDoorHinge->setLimit( -M_PI, -M_PI_2 );
this has the same problem:

Code: Select all

spDoorHinge->setLimit( M_PI_2, M_PI );
I've found a workaround by inverting the axis:

Code: Select all

 btVector3 btAxisA( 0.0f, -1.0f, 0.0f )
That allows me to define constraints in the quadrant that's otherwise problematic. But the workaround is unintuitive and complicates my code - you may want to consider it as a bug...

Is there a way to define the angular limits relative to the referential of the object, instead of having them be absolute/"relative to the world"? I'd like to be able to place a door (or pinball paddle, in my case) in any position without having to recalculate the limits every time.

Thanks!

Edit: I'm using Bullet 2.74
User avatar
rponomarev
Posts: 56
Joined: Sat Mar 08, 2008 12:37 am

Re: Problem with HingeConstraint limits

Post by rponomarev »

Yes, there is a problem when angle limits are close to -PI or PI
We added an issue http://code.google.com/p/bullet/issues/detail?id=217 and will fix it in future.

As a workaround you could create a dummy static body (without mass and shape) and set hinge limits relative to its frame instead of using world coordinate system

Thanks for pointing on that,
Roman
gabba
Posts: 9
Joined: Thu Mar 19, 2009 3:20 am

Re: Problem with HingeConstraint limits

Post by gabba »

rponomarev wrote: As a workaround you could create a dummy static body (without mass and shape) and set hinge limits relative to its frame instead of using world coordinate system
Would you mind pasting a few lines of code to give an example of setting hinge limits relative to the frame of another static body? While I understand what the axis and anchor do, I purposedly avoided using the methods that take a frame or frames as parameters, since I don't understand very well what frames are or do.
gabba
Posts: 9
Joined: Thu Mar 19, 2009 3:20 am

Re: Problem with HingeConstraint limits

Post by gabba »

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

Re: Problem with HingeConstraint limits

Post by Erwin Coumans »

You could check out some of the constraint demos in the Bullet SDK. There should be some constraints using two constraint frames, frame in A and frame in B.

Hope this helps,
Erwin
gabba
Posts: 9
Joined: Thu Mar 19, 2009 3:20 am

Re: Problem with HingeConstraint limits

Post by gabba »

Thanks. I still don't understand very much how to use the functions that use frameInA and frameInB as arguments, but the one that builds a HingeConstraint from an axis and pivot has a boolean that helps with this, and that I missed at first.