我尝试创建一个使用Bullet Physics
附加到铰链的框。
这是我的代码:
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);
我想知道如何获得RigidBodyA
的位置和旋转,以便我可以通过openGL
将其绘制到屏幕上。
我尝试过以下内容:
btTransform trans;
m_pHinge->getRigidBodyA().getMotionState()->getWorldTransform(trans);
......但那没有用。
你对我做错了什么有任何想法吗?
感谢您的回答。