Rigid Body Constraint Question

User avatar
sio2interactive
Posts: 31
Joined: Tue Jul 29, 2008 10:26 am

Rigid Body Constraint Question

Post by sio2interactive »

Im trying to put a 2 axis constraint on a rigid body, and Im using btHingeConstraint, this is my initialization code below:

Code: Select all


		const btVector3 pivot( 0.0f, 0.0f, -radius );
		btVector3 axis( 1.0f, 0.0f, 0.0f );
		btHingeConstraint *_btHingeConstraint = new btHingeConstraint( *_btRigidBody, pivot, axis );
		_btSoftRigidDynamicsWorld->addConstraint( _btHingeConstraint, true );

and im using _btRigidBody->setAngularVelocity( btVector3( -180.0f, 0.0f, 0.0f ) ); to test the constraint on the X axis and everything is fine...

The problem comes when I try to put the constraint on the X and Y axis at the same time... to do so I modify the following code:

btVector3 axis( 1.0f, 1.0f, 0.0f );

and use:

_btRigidBody->setAngularVelocity( btVector3( -180.0f, -180.0f, 0.0f ) ); in order to test, but my rigid body is like going offscreen and disappear...

I also try to create 2 separate constraint 1 on X and 1 on Y, and use 2 separate setAngularVelocity call but no success...

What Im am doing wrong? Is there a way to put 2 constraint on different axis on a rigid body? What Im trying to do is like a punching bag ( a cylinder attached to a certain point in space ) that when I click it "angles" on the X and Y axis simultaneously... Help!

Tks in advance,

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

Re: Rigid Body Constraint Question

Post by Erwin Coumans »

The btHingeConstraint only has a single axis (and this axis should be unit length), so it is not suitable.

For a punching bag, you could consider using one of the following:
  • btConeTwistConstraint with limits, see Demos\RagdollDemo
  • btGeneric6DofConstraint with limits, see Demos\GenericJointDemo
  • btPoint2PointConstraint, and make sure the collision detection deals with limits
  • a soft body rope
Hope this helps,
Erwin
User avatar
sio2interactive
Posts: 31
Joined: Tue Jul 29, 2008 10:26 am

Re: Rigid Body Constraint Question

Post by sio2interactive »

Allright got it! It help a bunch tks!