Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I'm working on similar code at the moment. My approach is use the Bullet Physics Rag Doll Demo as a starting point. It has a rag doll with body parts connected by joints. </p> <p>I'm then using the Bullet Physics Dynamic Control Demo to learn to bend the joints. The challenging part at the moment is setting all the parameters.</p> <p>I suggest you learn how to create two rigid bodies connected by a constraint and then to activate the constraint motor to bend the joint. </p> <p>The following is some code that I'm working with to learn how rigid bodies and constraints work in Bullet Physics. The code creates two blocks connected by a hinge constraint. The update function bends the hinge constraint slowly over time. </p> <p>Now that I've got this I'll be going back to the Rag Doll and adjusting the joints.</p> <pre><code>class Simple { private: btScalar targetAngle; btCollisionShape* alphaCollisionShape; btCollisionShape* bravoCollisionShape; btRigidBody* alphaRigidBody; btRigidBody* bravoRigidBody; btHingeConstraint* hingeConstraint; btDynamicsWorld* dynamicsWorld; public: ~Simple( void ) { } btRigidBody* createRigidBody( btCollisionShape* collisionShape, btScalar mass, const btTransform&amp; transform ) const { // calculate inertia btVector3 localInertia( 0.0f, 0.0f, 0.0f ); collisionShape-&gt;calculateLocalInertia( mass, localInertia ); // create motion state btDefaultMotionState* defaultMotionState = new btDefaultMotionState( transform ); // create rigid body btRigidBody::btRigidBodyConstructionInfo rigidBodyConstructionInfo( mass, defaultMotionState, collisionShape, localInertia ); btRigidBody* rigidBody = new btRigidBody( rigidBodyConstructionInfo ); return rigidBody; } void Init( btDynamicsWorld* dynamicsWorld ) { this-&gt;targetAngle = 0.0f; this-&gt;dynamicsWorld = dynamicsWorld; // create collision shapes const btVector3 alphaBoxHalfExtents( 0.5f, 0.5f, 0.5f ); alphaCollisionShape = new btBoxShape( alphaBoxHalfExtents ); // const btVector3 bravoBoxHalfExtents( 0.5f, 0.5f, 0.5f ); bravoCollisionShape = new btBoxShape( bravoBoxHalfExtents ); // create alpha rigid body const btScalar alphaMass = 10.0f; btTransform alphaTransform; alphaTransform.setIdentity(); const btVector3 alphaOrigin( 54.0f, 0.5f, 50.0f ); alphaTransform.setOrigin( alphaOrigin ); alphaRigidBody = createRigidBody( alphaCollisionShape, alphaMass, alphaTransform ); dynamicsWorld-&gt;addRigidBody( alphaRigidBody ); // create bravo rigid body const btScalar bravoMass = 1.0f; btTransform bravoTransform; bravoTransform.setIdentity(); const btVector3 bravoOrigin( 56.0f, 0.5f, 50.0f ); bravoTransform.setOrigin( bravoOrigin ); bravoRigidBody = createRigidBody( bravoCollisionShape, bravoMass, bravoTransform ); dynamicsWorld-&gt;addRigidBody( bravoRigidBody ); // create a constraint const btVector3 pivotInA( 1.0f, 0.0f, 0.0f ); const btVector3 pivotInB( -1.0f, 0.0f, 0.0f ); btVector3 axisInA( 0.0f, 1.0f, 0.0f ); btVector3 axisInB( 0.0f, 1.0f, 0.0f ); bool useReferenceFrameA = false; hingeConstraint = new btHingeConstraint( *alphaRigidBody, *bravoRigidBody, pivotInA, pivotInB, axisInA, axisInB, useReferenceFrameA ); // set constraint limit const btScalar low = -M_PI; const btScalar high = M_PI; hingeConstraint-&gt;setLimit( low, high ); // add constraint to the world const bool isDisableCollisionsBetweenLinkedBodies = false; dynamicsWorld-&gt;addConstraint( hingeConstraint, isDisableCollisionsBetweenLinkedBodies ); } void Update( float deltaTime ) { alphaRigidBody-&gt;activate(); bravoRigidBody-&gt;activate(); bool isEnableMotor = true; btScalar maxMotorImpulse = 1.0f; // 1.0f / 8.0f is about the minimum hingeConstraint-&gt;enableMotor( isEnableMotor ); hingeConstraint-&gt;setMaxMotorImpulse( maxMotorImpulse ); targetAngle += 0.1f * deltaTime; hingeConstraint-&gt;setMotorTarget( targetAngle, deltaTime ); } }; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload