Hi,
I would like to create a spring between two rigid bodies by using the slider constraint (btSliderConstraint). I have tried different things but I cannot achieve the spring effect.
Any ideas which parameters is the most suitable to have a spring between two RBs?
Thanks
Create a string with slider constraint
-
- Posts: 56
- Joined: Sat Mar 08, 2008 12:37 am
Re: Create a string with slider constraint
Hello,
Unfortunately spring is not supported for the slider joint for now.
But you can use the 6DOF joint with spring, this will give the same effect
Try the following code:
See also Demos/ConstraintDemo.cpp
Hope this will help,
Roman Ponomarev
Unfortunately spring is not supported for the slider joint for now.
But you can use the 6DOF joint with spring, this will give the same effect
Try the following code:
Code: Select all
{ // create a generic 6DOF constraint with springs
btTransform tr;
tr.setIdentity();
tr.setOrigin(btVector3(btScalar(-10.), btScalar(0.), btScalar(0.)));
tr.getBasis().setEulerZYX(0,0,0);
btRigidBody* pBodyA = localCreateRigidBody( 0.0, tr, shape);
pBodyA->setActivationState(DISABLE_DEACTIVATION);
tr.setIdentity();
tr.setOrigin(btVector3(btScalar(0.), btScalar(0.), btScalar(0.)));
tr.getBasis().setEulerZYX(0,0,0);
btRigidBody* pBodyB = localCreateRigidBody(1.0, tr, shape);
pBodyB->setActivationState(DISABLE_DEACTIVATION);
btTransform frameInA, frameInB;
frameInA = btTransform::getIdentity();
frameInA.setOrigin(btVector3(btScalar(10.), btScalar(0.), btScalar(0.)));
frameInB = btTransform::getIdentity();
frameInB.setOrigin(btVector3(btScalar(0.), btScalar(0.), btScalar(0.)));
btGeneric6DofSpringConstraint* pGen6DOFSpring = new btGeneric6DofSpringConstraint(*pBodyA, *pBodyB, frameInA, frameInB, true);
pGen6DOFSpring->setLinearUpperLimit(btVector3(5., 0., 0.));
pGen6DOFSpring->setLinearLowerLimit(btVector3(-5., 0., 0.));
pGen6DOFSpring->setAngularLowerLimit(btVector3(0.f, 0.f, 0.f));
pGen6DOFSpring->setAngularUpperLimit(btVector3(0.f, 0.f, 0.f));
m_dynamicsWorld->addConstraint(pGen6DOFSpring, true);
pGen6DOFSpring->setDbgDrawSize(btScalar(5.f));
pGen6DOFSpring->enableSpring(0, true);
pGen6DOFSpring->setStiffness(0, 39.478f);
pGen6DOFSpring->setDamping(0, 0.5f);
pGen6DOFSpring->setEquilibriumPoint();
}
Hope this will help,
Roman Ponomarev