remove a constraint for certain condition

sebateau22
Posts: 5
Joined: Sun May 22, 2011 6:09 pm

remove a constraint for certain condition

Post by sebateau22 »

Hi!

I have a hinge constraint between two bodies A and B. I'd like to remove it when X of body A is greater than 0.

XA= FirstRigidBody->getCenterOfMassPosition().getX();
if(XA>0){


}

what should i put between the brackets of the if?

Thanks
marios
Posts: 52
Joined: Mon Jul 19, 2010 3:11 am

Re: remove a constraint for certain condition

Post by marios »

just store somewhere pointer to that constraint you want to delete, and than between brackets:

Code: Select all

dynamicsWorld->removeConstraint(constraint_ptr);
or better, you can use

Code: Select all

FirstRigidBody->getConstraintRef(index)
but you must know constraint index (if you have only one constraint connected to FirstRigidBody it should be 0)
sebateau22
Posts: 5
Joined: Sun May 22, 2011 6:09 pm

Re: remove a constraint for certain condition

Post by sebateau22 »

dynamicsWorld->removeConstraint(constraint_ptr);

this is what i did before posting the message but it does not work. In my case, i have to compute a robot arm throwing a ball. The ball should be fixed to the arm till the position of the ball reaches x=0. Then the arm releases the ball. But, checking the position of the ball it oscillates with the arm around 0 (the arm has a 6dofspringconstraint with equilibrium point at x=0 explaining why i said the ball oscillates with the arm).

FirstRigidBody->getConstraintRef(index)

Using that, the program just crashes. I tried with index 0 1 2 3 4 5 but the program crashes when the ball reaches the condition...

Any other suggestion?