Applying force through constraints [Solved]

nathn123
Posts: 7
Joined: Tue Jan 19, 2016 1:51 pm

Applying force through constraints [Solved]

Post by nathn123 »

Hey all

I have set up an interpretation of a hill-type muscle in bullet using 3 rigid bodies ,a spring2point and a slider. i have calculated the forces generated by the muscle i just need help to apply these forces through the constraints just wondering if anyone knows of any ways to apply these forces
Last edited by nathn123 on Tue Mar 15, 2016 4:40 pm, edited 1 time in total.
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Re: Applying force through constraints

Post by Erwin Coumans »

Constraints compute their own constraint forces. If you computed your own forces, you don't need to use a constraint to apply them, just apply the force directly to a rigid body (or multi body).

Say, you have a btHingeConstraint, and want to apply a torque along the hinge axis, you can use the following snippet:

Code: Select all

        btScalar torque = ...
        btHingeConstraint* hinge = ...
        btRigidBody& bodyA = hinge->getRigidBodyA();
        btTransform trA = bodyA.getWorldTransform();
        btVector3 hingeAxisInWorld = trA.getBasis()*hinge->getFrameOffsetA().getBasis().getColumn(2);
        hinge->getRigidBodyA().applyTorque(-hingeAxisInWorld*torque);
        hinge->getRigidBodyB().applyTorque(hingeAxisInWorld*torque);
You may also consider using a btMultiBody with revolute joints, instead of btRigidBody and btHingeConstraint.
Then you can apply a joint torque using

Code: Select all

multiBody->addJointTorque(linkIndex,torque);
nathn123
Posts: 7
Joined: Tue Jan 19, 2016 1:51 pm

Re: Applying force through constraints

Post by nathn123 »

thanks for the reply, had a feeling thats what i needed todo but was hoping that there would be a more realistic approach since in real muscles the force doesn't come from the bone :lol:
also with regard to the multibody, the way i have designed the muscles and calculation of force it needs a physical representation to work