How do I get the Position of a btRigid that is attached to a btHingeConstraint

105 views Asked by At

I try to create a box, that is attached to a hinge using Bullet Physics.

Here is my Code:

float mass = 2.0f;

btCollisionShape * shape = new btBoxShape(btVector3(5.0f, 5.0f, 5.0f));
btVector3 inertia ;
shape->calculateLocalInertia(mass, inertia);

btDefaultMotionState * motionState = new btDefaultMotionState(btTransform(btQuaternion(0,0,0,1), btVector3(0, 10, 0)));

btRigidBody::btRigidBodyConstructionInfo  CI (mass, motionState, shape, inertia);

m_pRigidBody = new btRigidBody(CI);

btVector3 PivotIn(0, 20, 0);
btVector3 AxisIn(0, 0, 1);

m_pHinge = new btHingeConstraint(*m_pRigidBody, PivotIn, AxisIn);
float   targetVelocity = 1.0f;
float   maxMotorImpulse = 1.0f;
m_pHinge->enableAngularMotor(true,targetVelocity,maxMotorImpulse);

pDynamicsWorld->addConstraint(m_pHinge);

I am wondering how can I get the Position and Rotation of the RigidBodyA, so I can draw it probably to the screen via openGL.

I tried something like the following:

btTransform trans;
m_pHinge->getRigidBodyA().getMotionState()->getWorldTransform(trans);

...but that didn't work.

Do you have any Idea of what am I doing wrong?

Thank you for any answers.

0

There are 0 answers