// -------------------------------------------------------------------------
void OgreBulletListener::button1Pressed()
{

    // small unique impulse under cursor.
    Ogre::Vector3 pickPos;
    Ogre::Ray rayTo;
    OgreBulletDynamics::RigidBody * body = 
        getBodyUnderCursorUsingBullet(pickPos, rayTo);
        //getBodyUnderCursorUsingOgre(pickPos, rayTo);
    if (body)
    {  
        if (!(body->isStaticObject() 
            || body->isKinematicObject()
            ))
        {

            body->enableActiveState ();

            const Ogre::Vector3 relPos (pickPos - body->getCenterOfMassPosition());
            const Ogre::Vector3 impulse (rayTo.getDirection ());

            body->applyImpulse (impulse * mImpulseForce, relPos);		

        }

        getDebugLines();
        mDebugRayLine->addLine (rayTo.getOrigin(), pickPos);
        mDebugRayLine->draw();	
    }  
}
Esempio n. 2
0
void PlayState::ColocarWolfAndRedilAndPig() {
  // CREACION REDIL PARA PONER ANIMALES
  Entity *entityRedil = _sceneMgr->createEntity("Redil","Redil.mesh");
  SceneNode *nodeRedil = _sceneMgr->createSceneNode("Redil");
  nodeRedil->attachObject(entityRedil);
  //nodeRedil-> setPosition(9,7,20);

  _sceneMgr->getRootSceneNode()->addChild(nodeRedil);
  OgreBulletCollisions::StaticMeshToShapeConverter *trimeshConverterR = new 
          OgreBulletCollisions::StaticMeshToShapeConverter(entityRedil);

  OgreBulletCollisions::TriangleMeshCollisionShape *TrimeshR = 
          trimeshConverterR->createTrimesh();

  OgreBulletDynamics::RigidBody *rigidObjectR = new 
    OgreBulletDynamics::RigidBody("Redil", _world);
  rigidObjectR->setShape(nodeRedil, TrimeshR, 0.5, 0.5, 0, Ogre::Vector3(30,0,0), 
       Quaternion::IDENTITY);        
  
  int posx[] = {30,35,35};
  int posz[] = {0,-2,2};
  int posD[] = {0,-120,200};
  
  for (int i = 0; i < 3; ++i){
      std::ostringstream os;
      os << "pigA" << i;

      Ogre::Entity* entc = _sceneMgr->createEntity(os.str(), "CerdoAnim.mesh");
      Ogre::SceneNode* nodecer = _sceneMgr->createSceneNode(os.str());
      nodecer->attachObject(entc);
      nodecer-> setPosition(posx[i],0,posz[i]);
      // roll --> z
      // pitch --> x
      // yaw --> y
      nodecer->yaw(Ogre::Degree(posD[i]));
      _sceneMgr->getRootSceneNode()->addChild(nodecer);
      
  }
}
// -------------------------------------------------------------------------
OgreBulletDynamics::RigidBody* OgreBulletListener::getBodyUnderCursorUsingOgre(Ogre::Vector3 &intersectionPoint, Ray &rayTo)
{
    rayTo = mCamera->getCameraToViewportRay (mInputListener->getAbsMouseX(), mInputListener->getAbsMouseY());

    mRayQuery->setRay (rayTo);
    const RaySceneQueryResult& result = mRayQuery->execute();
    if (!result.empty())
    {
        RaySceneQueryResult::const_iterator i = result.begin();

        mRayQuery->setSortByDistance (true, 1);//only one hit
        while((i != result.end()))
        {
            SceneNode *node = i->movable->getParentSceneNode() ;
#if (OGRE_VERSION >=  ((1 << 16) | (5 << 8) | 0)) // must have at least shoggoth (1.5.0)
			intersectionPoint = node->_getDerivedPosition ();
#else
			intersectionPoint = node->getWorldPosition ();
#endif
            const unsigned short num = node->numAttachedObjects();
            MovableObject* movable;
            for (unsigned short cur = 0;cur < num; cur++)
            {
                movable = node->getAttachedObject(cur);
                if (movable->getMovableType() == OgreBulletCollisions::Object::mMovableType) 
                {
                    OgreBulletCollisions::Object *object = static_cast <OgreBulletCollisions::Object *>(movable);
                    OgreBulletDynamics::RigidBody *body = static_cast <OgreBulletDynamics::RigidBody *>(object);
                    setDebugText ("Hit :" + body->getName());

                    return body;
                }
            }
            ++i;
        }	
    }// if results.	 
    return 0;
}
Esempio n. 4
0
//-------------------------------------------------------------------------------------
SimpleRigidBody* TUMBU::createSimpleRigidBody(OgreBulletDynamics::DynamicsWorld* physicWorld, Ogre::Entity* entity, Ogre::SceneNode* node, const Ogre::Vector3 &pos, const Ogre::Quaternion &q, const Ogre::Real bodyRestitution, const Ogre::Real bodyFriction, bool shadows, TumbuEnums::PhysicObjectTag tag){
	SimpleRigidBody* simpleRigidBody = new SimpleRigidBody( mSceneMgr, tag );

    simpleRigidBody->entity = entity;
    simpleRigidBody->entity->setCastShadows( shadows );

	trimeshConverter = new OgreBulletCollisions::StaticMeshToShapeConverter( simpleRigidBody->entity );
	simpleRigidBody->shape = trimeshConverter->createTrimesh();
    delete trimeshConverter;

    OgreBulletDynamics::RigidBody *sceneRigid = new OgreBulletDynamics::RigidBody(
		entity->getName() + "Rigid" + Ogre::StringConverter::toString( mNumEntitiesInstanced ),
        physicWorld );

	simpleRigidBody->node =node;
	simpleRigidBody->setOgreBulletRigidBody( sceneRigid );

    sceneRigid->setStaticShape( simpleRigidBody->node, simpleRigidBody->shape, bodyRestitution, bodyFriction, pos );

    mNumEntitiesInstanced++;

    return simpleRigidBody;
}
Esempio n. 5
0
void MapManager::AddObstacle(MapArea* area, Objects* input)
{
	if(input->mLoaded)
		return;

	char areaString[30];
	sprintf(areaString, "map_area_%d", area->getIndex());

	//get the area node from map node.
	Ogre::SceneNode* areaNode = (Ogre::SceneNode*)mMapNode->getChild(Ogre::String(areaString));

	char cubeString[30];
	sprintf(cubeString, "cube_%d", input->index);
	
	Ogre::Entity* cubeEntity = mSceneMgr->createEntity(Ogre::String(cubeString),"cube.mesh");
			
	cubeEntity->setMaterialName("Cube");

	//cubeEntity->getMesh()->setAutoBuildEdgeLists(true);
	//cubeEntity->getMesh()->buildEdgeList();
	
	cubeEntity->setCastShadows(false);

	//create a node for the cube
	Ogre::SceneNode* cubeNode = areaNode->createChildSceneNode(Ogre::String(cubeString));

	//attach the cube to the node
	cubeNode->attachObject(cubeEntity);

	//move the cube to it's position
	cubeNode->setPosition(input->mPosition);
	
	//cube entity actual size = 100 by 100 by 100

	Ogre::Vector3 scale;
	scale.x = Ogre::Real(0.01f)*input->sizeWidth;
	scale.y = 0.1f;
	scale.z = Ogre::Real(0.01f)*input->sizeHeight;
	cubeNode->setScale(scale);

	input->mLoaded = true;

	Ogre::Vector3 size = cubeEntity->getBoundingBox().getSize();
	size /= 2.f;
	size *= 0.96f;
	//size rescale. refer to prac07 for full calculation
	size.x *= Ogre::Real(0.01f)*input->sizeWidth;
	size.y *= Ogre::Real(0.1f);
	size.z *= Ogre::Real(0.01f)*input->sizeHeight;

	OgreBulletCollisions::BoxCollisionShape *sceneBoxShape = new OgreBulletCollisions::BoxCollisionShape(size);
	OgreBulletDynamics::RigidBody *boxBody = new OgreBulletDynamics::RigidBody("BoxRigid" + Ogre::StringConverter::toString(input->index), 
		PhysicManager::getSingletonPtr()->getPhysicWorld(),
		PhysicManager::COL_OBSTACLE,
		PhysicManager::mObstacleCollideWith);

	boxBody->setStaticShape(cubeNode, sceneBoxShape,
		1.f,
		1.f,
		input->mPosition,
		Ogre::Quaternion(0,0,0,1));

	mRigidBodyList.push_back(boxBody);
	
	mNumEntitiesInstanced++;
}
Esempio n. 6
0
void PlayState::CrearBosqueAndColina(){
    int distH = 0;
    int distV = 0;
    int numArboles = 0;
    int numArbolesGlobal = 0;
    int mover = 40;
    //Parte Izquierda y Parte Derecha
    for (int i = 0; i < 192; i++){
      std::stringstream uniqueName;
      uniqueName <<"tree" << numArbolesGlobal;
      Entity *entityArbol = _sceneMgr->createEntity(uniqueName.str(),"ArbolJuego.mesh");
      SceneNode *nodeArbol = _sceneMgr->createSceneNode(uniqueName.str());
      nodeArbol->attachObject(entityArbol);
      _sceneMgr->getRootSceneNode()->addChild(nodeArbol);

      OgreBulletCollisions::StaticMeshToShapeConverter *trimeshConverterR = new 
        OgreBulletCollisions::StaticMeshToShapeConverter(entityArbol);

      OgreBulletCollisions::TriangleMeshCollisionShape *TrimeshR = 
        trimeshConverterR->createTrimesh(); 

      OgreBulletDynamics::RigidBody *rigidObjectA = new 
      OgreBulletDynamics::RigidBody(uniqueName.str(), _world);
        rigidObjectA->setShape(nodeArbol, TrimeshR, 0.5, 0.5, 0, Ogre::Vector3(-(0 + distV), 0, mover + distH), 
        Quaternion::IDENTITY); 
      distH = distH + 8;
      numArbolesGlobal = numArbolesGlobal + 1;
      numArboles = numArboles +1;
      if(numArboles == 8){
          distV = distV + 6;
          numArboles = 0;
          distH = 0;
      }
      if(numArbolesGlobal == 96){
          mover = -100;
          distV = 0;
      }
    }
    //Parte Final
    distV = 0;
    distH = 0;
    for (int i = 0; i < 30; ++i){
      std::stringstream uniqueName;
      uniqueName <<"tree" << numArbolesGlobal;
      Entity *entityArbol = _sceneMgr->createEntity(uniqueName.str(),"ArbolJuego.mesh");
      SceneNode *nodeArbol = _sceneMgr->createSceneNode(uniqueName.str());
      nodeArbol->attachObject(entityArbol);
      _sceneMgr->getRootSceneNode()->addChild(nodeArbol);

      OgreBulletCollisions::StaticMeshToShapeConverter *trimeshConverterR = new 
        OgreBulletCollisions::StaticMeshToShapeConverter(entityArbol);

      OgreBulletCollisions::TriangleMeshCollisionShape *TrimeshR = 
        trimeshConverterR->createTrimesh(); 

      OgreBulletDynamics::RigidBody *rigidObjectA = new 
      OgreBulletDynamics::RigidBody(uniqueName.str(), _world);
        rigidObjectA->setShape(nodeArbol, TrimeshR, 0.5, 0.5, 0, Ogre::Vector3(-85 -(distV), 0, -47 + distH), 
        Quaternion::IDENTITY); 
      numArbolesGlobal = numArbolesGlobal + 1;
      distH = distH + 7;
      if(i==14){
          distV = distV + 6;
          distH = 3;
      }
    }

    Entity *entityColina = _sceneMgr->createEntity("Colina","ColinaJugador.mesh");
    SceneNode *nodeColina = _sceneMgr->createSceneNode("Colina");
    nodeColina->attachObject(entityColina);
    _sceneMgr->getRootSceneNode()->addChild(nodeColina);

    OgreBulletCollisions::StaticMeshToShapeConverter *trimeshConverterR = new 
      OgreBulletCollisions::StaticMeshToShapeConverter(entityColina);

    OgreBulletCollisions::TriangleMeshCollisionShape *TrimeshR = 
      trimeshConverterR->createTrimesh(); 

    OgreBulletDynamics::RigidBody *rigidObjectColina = new 
    OgreBulletDynamics::RigidBody("Colina", _world);
      rigidObjectColina->setShape(nodeColina, TrimeshR, 0.5, 0.5, 0, Ogre::Vector3(55,0.50,0), 
      Quaternion::IDENTITY); 
}