Implementing a distance-based spring constraint?

Post Reply
Posts: 1
Joined: Sun Jun 17, 2012 7:15 pm

Implementing a distance-based spring constraint?

Post by medgno » Sun Jun 17, 2012 7:25 pm

I am trying to implement a mechanical model where some elements are attached via springs that are free to rotate at both ends. In other words, I want the restitution force to depend only on the distance between the two anchor points. For now, I'm attaching two cylinders together, with one of them having zero mass to be a static object.

From what I've been able to get out of btGeneric6DofSpringConstraint, it seems that it only allows rotation at one end. In order to try to solve this, I've added a 'dummy' object inside of my two anchor points, attached these dummy objects to the intended spring anchor points with btPoint2PointConstraints, and using the following code to make the dummy objects not participate in collision

Code: Select all

bodyFirst->setCollisionFlags(bodyFirst->getCollisionFlags() | btCollisionObject::CF_NO_CONTACT_RESPONSE);
However, I've been unable to get any behavior that's remotely realistic. Usually, both objects just stay motionless in space. I'm not sure how many of these problems are from my own code (and from interfacing with an external graphics library) and how many are with what I'm trying to get Bullet to do.

My questions are the following:

Is there an easy way to accomplish a distance-based spring? Whether I need to compute the forces myself or not, I don't mind.

Should the method I'm using actually work?

Thank you all!

Post Reply