How to use btHingeConstraint?

Post Reply
Manish Bista
Posts: 6
Joined: Wed Feb 11, 2015 2:04 am

How to use btHingeConstraint?

Post 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?
User avatar
drleviathan
Posts: 849
Joined: Tue Sep 30, 2014 6:03 pm
Location: San Francisco

Re: How to use btHingeConstraint?

Post by drleviathan »

Did you remember to add the constraint to the btDynamicsWorld?
Xcoder79
Posts: 42
Joined: Sun Aug 07, 2011 5:27 am

Re: How to use btHingeConstraint?

Post 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);
Manish Bista
Posts: 6
Joined: Wed Feb 11, 2015 2:04 am

Re: How to use btHingeConstraint?

Post 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?
Basroil
Posts: 463
Joined: Fri Nov 30, 2012 4:50 am

Re: How to use btHingeConstraint?

Post 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
Post Reply