Code: Select all
void Physics::initObjects(){
collisionConfiguration = new btDefaultCollisionConfiguration();
dispatcher = new btCollisionDispatcher(collisionConfiguration);
overlappingPairCache = new btDbvtBroadphase();
solver = new btSequentialImpulseConstraintSolver();
dynamicsWorld = new btDiscreteDynamicsWorld(dispatcher, overlappingPairCache, solver, collisionConfiguration);
dynamicsWorld->setGravity(btVector3(0,-10,0));
}
btDiscreteDynamicsWorld* Physics::getDynamicsWorld(){
return dynamicsWorld;
}
std::vector<btCollisionShape *> Physics::getCollisionShapes(){
return collisionShapes;
}
Code: Select all
physicsEngine = new Physics();
physicsEngine->initObjects();
_fallShape = new btSphereShape(0.1);
_groundShape = new btStaticPlaneShape(btVector3(0,1,0),1);
Code: Select all
bool
Play::frameStarted
(const Ogre::FrameEvent& evt)
{
_deltaT = evt.timeSinceLastFrame;
physicsEngine->getDynamicsWorld()->stepSimulation(_deltaT, 1);
return true;
}
Code: Select all
bool
Play::frameEnded
(const Ogre::FrameEvent& evt)
{
physicsEngine->getDynamicsWorld()->stepSimulation(evt.timeSinceLastFrame, 1);
return true;
}
Code: Select all
void Play::createBullet(){
//here create node+entity
MyMotionState* fallMotionState = new MyMotionState(
btTransform(btQuaternion(oriWeapon.w, -oriWeapon.x, -oriWeapon.y, -oriWeapon.z),btVector3(posWeapon.x, posWeapon.y, posWeapon.z)), nodeStems);
btScalar mass = 1;
btVector3 fallInertia(0,0,0);
_fallShape->calculateLocalInertia(mass,fallInertia);
btRigidBody::btRigidBodyConstructionInfo fallRigidBodyCI(
mass,fallMotionState,_fallShape,fallInertia);
_fallRigidBody = new btRigidBody(fallRigidBodyCI);
physicsEngine->getDynamicsWorld()->addRigidBody(_fallRigidBody);
_fallRigidBody->activate(true);
btVector3 impulse = btVector3(0.f,0.f,20000.f);
_fallRigidBody->setLinearVelocity(btVector3(0,0,20000));
_fallRigidBody->applyCentralImpulse(impulse);//
}