2

I am using Bullet Physics to simulate a box fixed two meters above the ground, and another one hanging down from it with a spring (or maybe better a rubberband of equilibrium length 0) simulated by a btGeneric6DofSpringConstraint.

btCollisionShape *shape = createBoxShape(0.2f, 0.2f, 0.2f);

btRigidBody *bodies[] = {
    createStaticStatic(shape),
    createDynamic(10 * getVolume(shape), shape),
};

bodies[0]->getWorldTransform().setOrigin({ 0.0f, 2.0f, 1.0f });
bodies[1]->getWorldTransform().setOrigin({ 0.0f, 1.0f, 1.0f });

// We can use 'btGeneric6DofSpring2Constraint' instead
btGeneric6DofSpringConstraint *spring = new btGeneric6DofSpringConstraint(
    *bodies[0], *bodies[1],
    { 0.0f, -0.2f, 0.0f }, { 0.0f, 0.2f, 0.0f },
    true
);

// Disable limits
spring->setLinearLowerLimit({  1.0f,  1.0f,  1.0f });
spring->setLinearUpperLimit({ -1.0f, -1.0f, -1.0f });

// Enable spring behavior
for (int i = 0; i < 3; ++i)
{
    spring->enableSpring(i, true);
    spring->setStiffness(i, 35.0f);
    spring->setDamping(i, 1.0f);
    spring->setEquilibriumPoint(i, 0);
}

world->addConstraint(spring);

Now I enounter the problem that no damping is applied to the spring, no matter what value I use in setDamping. I read that this can be fixed by using btGeneric6DofSpring2Constraint instead (note the 2 after the Spring). But now the spring behaves unpredictable (generates energy, changes direction, etc.) whenever the spring is not attached to the bodies centers of mass (as in the example above).

Has anybody any idea what could be the problem? What is the difference between btGeneric6DofSpringConstraint and btGeneric6DofSpring2Constraint anyway?

M. Winter
  • 416
  • 3
  • 15

0 Answers0