Hello All,
I am new to using bulletSDk, and had a conceptual question regarding the spring cotraint in release 2.76. :
How do I set the rest length of a spring constraint ?
Also what do the input parameters of the constructor - frameA , and frameB - refer to ?
i.e are these the local space pivots of the two input rigid bodies ?
Any help and / or example source code will be highly appreiciated
thanks in advance ,
shajay.
newbie btGeneric6DofSpringConstraint question
-
- Posts: 56
- Joined: Sat Mar 08, 2008 12:37 am
Re: newbie btGeneric6DofSpringConstraint question
Hello,
FrameA and FrameB are constraint frames in local spaces A and B respectively
Limits give the allowable range of movement if frameB in frameA space
(or vice versa if useLinearReferenceFrameA == false)
Try to play with the following snippet of code:
You may put it into ConstraintDemo.cpp and set
to turn off all other constraints in this demo
Thanks,
Roman
FrameA and FrameB are constraint frames in local spaces A and B respectively
Limits give the allowable range of movement if frameB in frameA space
(or vice versa if useLinearReferenceFrameA == false)
Try to play with the following snippet of code:
Code: Select all
{ // create a generic 6DOF constraint with spring that has rest length 10
// and connected to dynamic body at point (-5, 0, 0)
btScalar springRestLen(10.f);
btScalar pivotOffset(-5.f);
btScalar springRange(7.f); // allowed oscillation range
btTransform tr;
tr.setIdentity();
tr.setOrigin(btVector3(btScalar(0.), btScalar(0.), btScalar(0.)));
tr.getBasis().setEulerZYX(0,0,0);
btRigidBody* pBodyA = localCreateRigidBody( 0.0, tr, shape); // static body
pBodyA->setActivationState(DISABLE_DEACTIVATION);
btTransform frameInA;
frameInA = btTransform::getIdentity();
frameInA.setOrigin(btVector3(btScalar(0.), btScalar(0.), btScalar(0.))); // in A coordinate systam
tr.setIdentity();
tr.setOrigin(btVector3(btScalar(springRestLen - pivotOffset), btScalar(0.), btScalar(0.))); // this is (15, 0, 0)
tr.getBasis().setEulerZYX(0,0,0);
btRigidBody* pBodyB = localCreateRigidBody(1.0, tr, shape); // dynamic body
pBodyB->setActivationState(DISABLE_DEACTIVATION);
btTransform frameInB;
frameInB = btTransform::getIdentity();
frameInB.setOrigin(btVector3(pivotOffset, btScalar(0.), btScalar(0.))); // in B coordinate systam
btGeneric6DofSpringConstraint* pGen6DOFSpring = new btGeneric6DofSpringConstraint(*pBodyA, *pBodyB, frameInA, frameInB, true);
// in WCS we should have offset between origin of frameB and frameA.
// It should be equal to springRestLen, so we should set proper limits
// we set useLinearReferenceFrameA to true, so limits wil be in A coordinate system
pGen6DOFSpring->setLinearUpperLimit(btVector3(springRestLen + springRange, 0., 0.));
pGen6DOFSpring->setLinearLowerLimit(btVector3(springRestLen - springRange, 0., 0.));
// lock all rorations
pGen6DOFSpring->setAngularLowerLimit(btVector3(0.f, 0.f, 0.f));
pGen6DOFSpring->setAngularUpperLimit(btVector3(0.f, 0.f, 0.f));
// add constraint to world
m_dynamicsWorld->addConstraint(pGen6DOFSpring, true);
// draw constraint frames and limits
pGen6DOFSpring->setDbgDrawSize(btScalar(5.f));
// enable spring
pGen6DOFSpring->enableSpring(0, true);
pGen6DOFSpring->setStiffness(0, 39.478f); // period 1 sec for !kG body
pGen6DOFSpring->setDamping(0, 0.01f); // add some damping
// constraint force mixing prevents "locking" on limits
pGen6DOFSpring->setParam(BT_CONSTRAINT_STOP_CFM, 1.0e-5f, 5);
pGen6DOFSpring->setEquilibriumPoint(); // set current position as equilibrium point
}
Code: Select all
#define ENABLE_ALL_DEMOS 0
Thanks,
Roman
-
- Posts: 2
- Joined: Wed Mar 03, 2010 6:11 pm
Re: newbie btGeneric6DofSpringConstraint question
Hey Roman,
thank you very much for the response.. it really helped a lot in clearing up the concepts..
regards,
shajay.
thank you very much for the response.. it really helped a lot in clearing up the concepts..
regards,
shajay.