예제 #1
0
 void PlayState::CreationWolf(){ //Poner wolves
    int posH = 4;
    int H = -20;
    int V = 0;
    for (int i = 0; i < 19; ++i){  
      Entity *entity = NULL;
      
      std::stringstream uniqueName;
      uniqueName <<"wolf" << _numEntities; 
      
      OBEntity *obentity = new OBEntity(uniqueName.str()); 
      
      entity = _sceneMgr->createEntity(uniqueName.str(), "Lobo.mesh");     

      SceneNode *node = _sceneMgr->getRootSceneNode()->
      createChildSceneNode(entity->getName());
      node->attachObject(entity);

      node->yaw(Ogre::Degree(180));

      obentity->setSceneNode(node);

      OgreBulletCollisions::StaticMeshToShapeConverter *trimeshConverter = NULL; 
      OgreBulletCollisions::CollisionShape *bodyShape = NULL;
      OgreBulletDynamics::RigidBody *rigidBody = NULL;

      trimeshConverter = new 
      OgreBulletCollisions::StaticMeshToShapeConverter(entity);
      bodyShape = trimeshConverter->createConvex();
      delete trimeshConverter;

      obentity->setCollisionShape(bodyShape);
      rigidBody = new OgreBulletDynamics::RigidBody(uniqueName.str(), _world);

      rigidBody->setShape(node, bodyShape,
         0.0 /* Restitucion */, 0.6 /* Friccion */,
         150.0 /* Masa */, Ogre::Vector3(-70 + V, 0, H + posH),  // 0,0,35
         node->_getDerivedOrientation()/* Orientacion */); 
      rigidBody->setLinearVelocity(Ogre::Vector3::ZERO);

      obentity->setRigidBody(rigidBody);  
   
      _obEntities.push_back(obentity);
      _numEntities ++;
      posH = posH + 4;
      if(i ==9){
          H = -20;
          posH = 6;
          V = -10;
      }
    }  
 }
예제 #2
0
void PlayState::AddAndThrowDynamicObject(std::string type, double force) {
  _timeLastObject = SHOOT_COOLDOWN;   // Segundos para anadir uno nuevo

  Vector3 size = Vector3::ZERO; 
  Vector3 position = (_camera->getDerivedPosition() 
     + _camera->getDerivedDirection().normalisedCopy() * 10);
 
  Entity *entity = NULL;
  std::stringstream uniqueName;
  uniqueName <<type << _numEntities;
  OBEntity *obentity = new OBEntity(uniqueName.str());

  entity = _sceneMgr->createEntity(uniqueName.str(), "PiedraLanzar.mesh");

  SceneNode *node = _sceneMgr->getRootSceneNode()->
    createChildSceneNode(entity->getName());
  node->attachObject(entity);

  obentity->setSceneNode(node);

  OgreBulletCollisions::StaticMeshToShapeConverter *trimeshConverter = NULL; 
  OgreBulletCollisions::CollisionShape *bodyShape = NULL;
  OgreBulletDynamics::RigidBody *rigidBody = NULL;

  trimeshConverter = new 
    OgreBulletCollisions::StaticMeshToShapeConverter(entity);
  bodyShape = trimeshConverter->createConvex();
  delete trimeshConverter;

  obentity->setCollisionShape(bodyShape);

  uniqueName << "rig";
  rigidBody = new OgreBulletDynamics::RigidBody(uniqueName.str(), _world);

  rigidBody->setShape(node, bodyShape,
         0.0 /* Restitucion */, 1.0 /* Friccion */,
         50.0 /* Masa */, position /* Posicion inicial */,
         Quaternion::IDENTITY /* Orientacion */);

  rigidBody->setLinearVelocity(
     _camera->getDerivedDirection().normalisedCopy() * force);  

  obentity->setRigidBody(rigidBody);

  _numEntities++;

  // Anadimos los objetos a las deques  
  _trackedBody = rigidBody;
  _obEntities.push_back(obentity);
}