Spring Constraint problem

sara
Posts: 39
Joined: Thu Mar 24, 2011 3:50 pm

Spring Constraint problem

Post by sara »

Hi,

I am trying to connect two bodies (one static and one dynamic) using a spring in Bullet. I am using the btGeneric6DofSpringCOnstraint.

The dynamic body hangs from the static body.

During the simulation, I am changing the mass of the dynamic body:

Code: Select all

btVector3 localInertia;
btb->getCollisionShape()->calculateLocalInertia(mass,localInertia);
btb->setMassProps(mass,localInertia);
btb->updateInertiaTensor();
//m_dynamicsWorld->addRigidBody(btb);
btb->activate(true);
However, no matter what mass I use, the body is still hanging at a same distance from the static body.

Any idea of why this is happening?
norbie
Posts: 21
Joined: Mon Feb 11, 2013 1:57 pm

Re: Spring Constraint problem

Post by norbie »

Hello,

I tried something similar, but could not get the spring effect to work as far as it was attached directly to a static body. Finally instead of making a static rigid body for the spring attachment, I created a normal rigid body, and "pinned" it, so that it can not move, using a btGeneric6DofConstraint with all 6 dof-s locked, something like this:

Code: Select all

		btTransform localA, localB;
...
		btRigidBody *capsuleBody1 = localCreateRigidBody( btScalar( 1 ), offsetTransform * capsuleTransform, capsuleShape );
...
			localB.setIdentity();
			btGeneric6DofConstraint *joint0 = new btGeneric6DofConstraint( *capsuleBody1, localB, false );
			m_dynamicsWorld->addConstraint( joint0, true );
...
		btRigidBody *capsuleBody2 = localCreateRigidBody( btScalar(100.), offsetTransform * parentEndTransform * ownTransform * capsuleTransform, capsuleShape );
...
		btGeneric6DofSpringConstraint *joint1 = new btGeneric6DofSpringConstraint( *capsuleBody1, *capsuleBody2, localA, localB, true );
		joint1->setAngularLowerLimit( btVector3( 1, 1, 1 ) );
		joint1->setAngularUpperLimit( btVector3( -1, -1, -1 ) );
		joint1->enableSpring( 0, true );
		joint1->enableSpring( 1, true );
		joint1->enableSpring( 2, true );
		joint1->setStiffness( 0, 20.f );
		joint1->setStiffness( 1, 20.f );
		joint1->setStiffness( 2, 20.f );
		m_dynamicsWorld->addConstraint( joint1, true );
Here capsuleBody1 was originally a static rigid body. Now it is a normal rigid body"fixed" by joint0.

I know it does not answer the original question, but it might help.
sara
Posts: 39
Joined: Thu Mar 24, 2011 3:50 pm

Re: Spring Constraint problem

Post by sara »

Thanks!

I'll try it out.