Page 1 of 1

How to use btHingeConstraint?

Posted: Sat Feb 14, 2015 3:31 pm
by Manish Bista
I used the following code:

Code: Select all

btTransform localA, localB;
localA.setIdentity();
localB.setIdentity();
localA.setOrigin(btVector3(btScalar(0.0), btScalar(0.0), btScalar(0.0)));
localB.setOrigin(btVector3(btScalar(0.0), btScalar(0.0), btScalar(0.0)));
hingeC = new btHingeConstraint(bodyA, bodyB, localA, localB);
hingeC->setLimit(btScalar(0.0), btScalar(0.0));
Unfortunately, the rigid bodies aren`t connected as they should have. When I hit one of them with a bullet, the other rigid body shows no signs of movement at all, which shows that they aren`t connected at all. What could be the possible error?

Re: How to use btHingeConstraint?

Posted: Sat Feb 14, 2015 6:01 pm
by drleviathan
Did you remember to add the constraint to the btDynamicsWorld?

Re: How to use btHingeConstraint?

Posted: Sat Feb 14, 2015 6:51 pm
by Xcoder79
Try doing this

btRigidBody* Hinge;

const btVector3 btPivotA(10.f + 2.1f, -2.0f, 0.0f );
btVector3 btAxisA( 0.0f, 1.0f, 0.0f );

new btHingeConstraint( *Hinge, btPivotA, btAxisA );

m_dynamicsWorld->addConstraint(Hinge);

Re: How to use btHingeConstraint?

Posted: Sun Feb 15, 2015 12:13 am
by Manish Bista
thanks guys, it`s working now. Also, I noticed that hinges only rotate about z-axis. With z-axis of the body pointing out of the screen and applying right hand thumb rule, shouldn`t the body move anti clockwise direction for an increasing value of angle to rotate about z? That is, when I set limit from 0 to 90 degs(applied by changing into radians) the body rotates clockwise, it`s initial orientation is horizontal(angle = 0), rotates clockwise and final orientation is vertical(angle = 90). And, might be a very silly question to ask but how is the initial angle(angle = 0) when rotating about any axes defined? I mean, is it the angle made with negative x- axis or some other axes?

Re: How to use btHingeConstraint?

Posted: Mon Feb 16, 2015 12:47 am
by Basroil
Manish Bista wrote: And, might be a very silly question to ask but how is the initial angle(angle = 0) when rotating about any axes defined? I mean, is it the angle made with negative x- axis or some other axes?
0 can be defined when you use two initial A-B transformations in construction, just rotate your B body's transform around it's z by your initial angle. The 0 will then be something different than your initial angle :D