If viewing the catapult from the side, where it fires objects to the right, I want the arm to push back to -45 degrees, lying against the base of the catapult. After some event (whether a keypress or a collision or a certain time has passed; this part isn't important), I want the catapult arm to be propelled rapidly to vertical, 90 degrees. I'd like to be able to vary that second angle so I can launch things at different trajectories. My gut reaction was to use a generic 6 degrees of freedom constraint with a spring between the launch arm and the beam that supports it. But I can't seem to get the values to give me the result that I want. Even after playing with the numbers, they don't seem to make sense.
Here's my code for the constraint in question:
Code: Select all
//launchBeam-crossBeam constraint
frameInA = btTransform::getIdentity();
frameInA.setOrigin(btVector3(0, 0, scale*1));
frameInB = btTransform::getIdentity();
frameInB.setOrigin(btVector3(0, 0, 0));
launchBeam->body->setActivationState(DISABLE_DEACTIVATION);
btGeneric6DofSpringConstraint* pGen6DOF3 = new btGeneric6DofSpringConstraint(*launchBeam->body, *crossBeam->body, frameInA, frameInB, true);
pGen6DOF3->setAngularLowerLimit(btVector3(-.841, -SIMD_EPSILON,-SIMD_EPSILON));
pGen6DOF3->setAngularUpperLimit(btVector3(90*(SIMD_PI/180), SIMD_EPSILON,SIMD_EPSILON));
world->addConstraint(pGen6DOF3, true);
pGen6DOF3->enableSpring(3, true);
pGen6DOF3->setStiffness(3, 39.478f);
pGen6DOF3->setDamping(3, .3f);
pGen6DOF3->setEquilibriumPoint(3,SIMD_HALF_PI);
I'd be open to suggestions on alternative ways to get my desired behavior as well.
Thanks for any help.