btGeneric6DofSpringConstraint spring problems

RJNelson68
Posts: 73
Joined: Tue Oct 06, 2009 3:19 pm

btGeneric6DofSpringConstraint spring problems

Post by RJNelson68 »

I'm using the following code that is based upon the code in the constraint demo (nearly the same) to all me to set up axis stabilizing for rigid bodies. The angular limits work just fine, but the spring has no effect. When an impulse is applied to the object, the free axis travel to the end of their limit and stop. From seeing the demo, I thought the spring should snap the axis back to the initial position. Unfortunately, this is not happening and I cannot see a reason for it. I've tried sever stiffness values from the 39.478 provided in the demo to a wide range of others, nothing helped. I've also tried a multitude of damping ranges between 0 and 1. No help there.

I was hoping that perhaps someone could tell me what might prevent the spring from working?

Code: Select all

void BtVehicleBody::addAxisStabilizer(Point3F upperAngLimits, Point3F lowerAngLimits, Point3F angularStiffness, Point3F angularDamping)
{
	btRigidBody *mBalancer = new btRigidBody(btRigidBody::btRigidBodyConstructionInfo( 0, 0, 0, btVector3( 0, 0, 0 )));
	mWorld->getDynamicsWorld()->addRigidBody(mBalancer);

	btVector3 btUpperAngLimits = btCast<btVector3>(upperAngLimits);
	btVector3 btLowerAngLimits = btCast<btVector3>(lowerAngLimits);

	btTransform frameA(btTransform::getIdentity());
    btTransform frameB(btTransform::getIdentity());

    frameA.getBasis().setEulerZYX( SIMD_2_PI, SIMD_2_PI, SIMD_2_PI );
	
	mBalancer->getWorldTransform().getBasis().setEulerZYX( SIMD_2_PI, SIMD_2_PI, SIMD_2_PI );
	mBalancer->setActivationState(DISABLE_DEACTIVATION);

    btGeneric6DofSpringConstraint * axisStabilzer = new btGeneric6DofSpringConstraint(*mActor, *mBalancer, frameA, frameB, true);
	
	axisStabilzer->setLinearUpperLimit(btVector3(SIMD_INFINITY, SIMD_INFINITY, SIMD_INFINITY));
	axisStabilzer->setLinearLowerLimit(btVector3(-SIMD_INFINITY, -SIMD_INFINITY, -SIMD_INFINITY));

	axisStabilzer->setAngularUpperLimit(btUpperAngLimits);
	axisStabilzer->setAngularLowerLimit(btLowerAngLimits);

	mWorld->getDynamicsWorld()->addConstraint(axisStabilzer);
	axisStabilzer->enableSpring(3, true);
	axisStabilzer->setStiffness(3, angularStiffness.x);
	axisStabilzer->setDamping(3, angularDamping.x);
	
	axisStabilzer->enableSpring(4, true);
	axisStabilzer->setStiffness(4, angularStiffness.y);
	axisStabilzer->setDamping(4, angularDamping.y);
	
	axisStabilzer->enableSpring(5, true);
	axisStabilzer->setStiffness(5, angularStiffness.z);
	axisStabilzer->setDamping(5, angularDamping.z);
	
	axisStabilzer->setEquilibriumPoint();
}
RJNelson68
Posts: 73
Joined: Tue Oct 06, 2009 3:19 pm

Re: btGeneric6DofSpringConstraint spring problems

Post by RJNelson68 »

I still can't figure this out. I've back traced as far as I could and everything is stepping as it should, the joint limits work and the rigid body works, yet the spring is doing nothing.

Is their some combination that is required with the linear portion (i.e. index 0 to 2)?

By the way I'm using Bullet 2.80-rev2531.