不知道這是否是你追求的,但是這是基本的剛體物理我的設置代碼:
#include "btBulletDynamicsCommon.h"
...
m_pBroadphase = new btDbvtBroadphase();
m_pCollisionConfig = new btDefaultCollisionConfiguration();
m_pCollisionDispatcher = new btCollisionDispatcher(m_pCollisionConfig);
m_pSolver = new btSequentialImpulseConstraintSolver();
m_pDynamicsWorld = new btDiscreteDynamicsWorld(m_pCollisionDispatcher,
m_pBroadphase,
m_pSolver,
m_pCollisionConfig);
這只是一個增加機構世界的事情後...
btRigidBody::btRigidBodyConstructionInfo info;
// set physical properties like mass, coefficient of restitution etc
info.m_mass = 10;
info.m_restitution = 0.5;
...
// Use a motion state to link the physics body with the graphics object.
// This is the glue between Bullet and your code, called by bullet to update the
// position & orientation of the object
info.m_motionState = new YourCustomMotionState(...) ;
btRigidBody* pRigidBody = new btRigidBody(info);
m_pDynamicsWorld->addRigidBody(pRigidBody);
...然後每幀更新世界狀態。
m_pDynamicsWorld->stepSimulation(deltaTime, m_maxSubSteps);
這將會給你一個簡單的物理模擬與在機構的移動方式控制碰撞和相互彈開,子彈剛體。
如果您能夠編譯並運行演示程序,哪一個與您之後的行爲類型最匹配? – 2011-04-05 23:31:09