How to correctly apply an impulse or force with Bullet C ++

1

I'm trying to make a super hyper basic mega FPS game, and I need to make use of the powerful BULLET physics library, however I can not apply a force or anything, nothing moves, I have the following:

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;
}

In my Play class I have:

physicsEngine = new Physics();
  physicsEngine->initObjects();
  _fallShape = new btSphereShape(0.1);
  _groundShape = new btStaticPlaneShape(btVector3(0,1,0),1);

in the Ogre frameStarted method:

_deltaT = evt.timeSinceLastFrame;
physicsEngine->getDynamicsWorld()->stepSimulation(_deltaT, 1

btVector3 impulse = btVector3(0.f,0.f,-20.f);
_fallRigidBody->applyCentralForce(impulse);

void Play::createBullet(){

//Creo entidad
//Creo nodo
//Adjunto
//Etc

//Parte de Fisica 
   MyMotionState* fallMotionState = new MyMotionState(
     btTransform(btQuaternion(oriWeapon.w, -oriWeapon.x, -oriWeapon.y, -oriWeapon.z),btVector3(posWeapon.x, posWeapon.y, posWeapon.z)), nodeStems);
  btScalar mass = 0.017;
  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); 

}

); 
    
asked by Strelok 24.04.2017 в 21:46
source

0 answers