I'm creating a hinge joint between two rigid bodies. I'm confused as to why the constructor needs 2 pivot points and 2 axis. I think I'm confused, but I'm believe a hinge joint has only one axis of rotation, and the pivot position must be shared between both rigid bodies.
I'm also having trouble understanding the "btHingeConstraint::setAxis" method. I believe this intention of this method is to set the axis of rotation for the hinge. However, when I use setAxis, the hinge's frames are also reset resulting in an incorrect joint.
Thanks for your help.
Hinge Joint frames and axis
-
- Posts: 168
- Joined: Tue Jan 04, 2011 11:47 pm
Re: Hinge Joint frames and axis
It's an old post but no one replied yet. Just in case someone would search for the same question.
In the constructor:
btHingeConstraint (btRigidBody &rbA, btRigidBody &rbB, const btVector3 &pivotInA, const btVector3 &pivotInB, btVector3 &axisInA, btVector3 &axisInB, bool useReferenceFrameA=false)
The pivot and axis both refer to their local position in the two rigidbodies, so we need two pivots and two axis.
In the constructor:
btHingeConstraint (btRigidBody &rbA, btRigidBody &rbB, const btVector3 &pivotInA, const btVector3 &pivotInB, btVector3 &axisInA, btVector3 &axisInB, bool useReferenceFrameA=false)
The pivot and axis both refer to their local position in the two rigidbodies, so we need two pivots and two axis.
-
- Posts: 6
- Joined: Wed Feb 20, 2013 6:14 am
Re: Hinge Joint frames and axis
How can i get this local axis ?
can you post s piece of code that can do this ?
thak you
can you post s piece of code that can do this ?
thak you
-
- Posts: 21
- Joined: Mon Feb 11, 2013 1:57 pm
Re: Hinge Joint frames and axis
Hope this little example helps:
Code: Select all
...
// Hinge "system" will start 4 units above origin
btTransform offsetTransform;
offsetTransform.setIdentity();
offsetTransform.setOrigin( btVector3( 0, 4, 0 ) );
// Creating a static capsule rigid body
btCollisionShape* capsuleShape = new btCapsuleShape( btScalar( 0.05 ), btScalar( 0.2 ) );
btRigidBody *capsuleBody1 = localCreateRigidBody( btScalar( 0 ), offsetTransform, capsuleShape );
capsuleBody1->setDamping( 0.05f, 0.85f );
// Creating capsule rigid body that hangs from previous static rigid body
btTransform parentEndTransform;
parentEndTransform.setIdentity();
// This rigid body should be below the previous one, whose length was 0.2 + 2 * 0.05
parentEndTransform.setOrigin( btVector3( 0, btScalar( -0.3 ), 0 ) );
btRigidBody *capsuleBody2 = localCreateRigidBody( btScalar(100.), offsetTransform * parentEndTransform, capsuleShape );
capsuleBody2->setDamping( 0.05f, 0.85f );
// Creating hinge constraint
// Local pivot in A is at the bottom of the object while local pivot in B is at its top
// Hinge axis is Z in this example
btHingeConstraint *joint1 = new btHingeConstraint( *capsuleBody1,
*capsuleBody2,
btVector3( btScalar( 0.0 ), btScalar( -0.3 / 2.0 ), btScalar( 0.0 ) ),
btVector3( btScalar( 0.0 ), btScalar( 0.3 / 2.0 ), btScalar( 0.0 ) ),
btVector3( btScalar( 0.0 ), btScalar( 0.0 ), btScalar( 1.0 ) ),
btVector3( btScalar( 0.0 ), btScalar( 0.0 ), btScalar( 1.0 ) ) );
// Limits of hinge constraint could be set here
// joint1->setLimit( btScalar( DEGREETORAD( -30 ) ), btScalar( DEGREETORAD( 60 ) ) );
m_dynamicsWorld->addConstraint( joint1, true );
...