コード例 #1
0
ファイル: PlayState.cpp プロジェクト: enriqueforner/Hunter
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);
      
  }
}
コード例 #2
0
ファイル: PlayState.cpp プロジェクト: enriqueforner/Hunter
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); 
}
コード例 #3
0
//Constructor
EnvironmentObject::EnvironmentObject(PGFrameListener* frameListener, OgreBulletDynamics::DynamicsWorld *mWorld, int mNumEntitiesInstanced, SceneManager* mSceneMgr, std::string object[24])
{
	//Initialise variables
	mName = object[0];
	mMesh = object[1];
	mPosition = Vector3(atof(object[2].c_str()), atof(object[3].c_str()), atof(object[4].c_str()));
	mOrientation = Quaternion(atof(object[5].c_str()), atof(object[6].c_str()), atof(object[7].c_str()), atof(object[8].c_str()));
	mScale = Vector3(atof(object[9].c_str()), atof(object[10].c_str()), atof(object[11].c_str()));
	mRestitution = atof(object[12].c_str());
	mFriction = atof(object[13].c_str());
	mMass = atof(object[14].c_str());
	mAnimated = atoi(object[15].c_str());
	mXMovement = atof(object[16].c_str());
	mYMovement = atof(object[17].c_str());
	mZMovement = atof(object[18].c_str());
	mSpeed = atof(object[19].c_str());;
	mRotationX = atof(object[20].c_str());
	mRotationY = atof(object[21].c_str());
	mRotationZ = atof(object[22].c_str());
	mBillBoard = atoi(object[23].c_str());

	//Initially targets haven't been hit
	counted = false;

	//Generate new Ogre entity
	Entity* entity = mSceneMgr->createEntity(mName + StringConverter::toString(mNumEntitiesInstanced), mMesh);
	
	//Create bounding box for entity
	AxisAlignedBox boundingB = entity->getBoundingBox();
	Vector3 size = boundingB.getSize() * mScale;
	size /= 2.0f;
	size *= 0.97f;
	
	//Attach entity to a scene node so it can be displayed in the environment
	SceneNode* objectNode = mSceneMgr->getRootSceneNode()->createChildSceneNode();
 	objectNode->attachObject(entity);
	objectNode->setScale(mScale);
	
	//Generate a new rigidbody for the object
	mBody = new OgreBulletDynamics::RigidBody(mName + StringConverter::toString(mNumEntitiesInstanced), mWorld);

	//Different objects require different collision shapes
	if(mName == "Target") {
		OgreBulletCollisions::CylinderCollisionShape* ccs = new OgreBulletCollisions::CylinderCollisionShape(size, Ogre::Vector3(0,0,1));	
		mBody->setShape(objectNode, ccs, mRestitution, mFriction, mMass, mPosition, mOrientation);
		mBody->setDebugDisplayEnabled(true);
		mBody->getBulletRigidBody()->setCollisionFlags(mBody->getBulletRigidBody()->getCollisionFlags()  | btCollisionObject::CF_CUSTOM_MATERIAL_CALLBACK);
	} 
	else if(mName == "Palm") {
		OgreBulletCollisions::StaticMeshToShapeConverter* acs = new OgreBulletCollisions::StaticMeshToShapeConverter(entity);
		OgreBulletCollisions::TriangleMeshCollisionShape* ccs = acs->createTrimesh();
		OgreBulletCollisions::CollisionShape* finalCollisionShape = (OgreBulletCollisions::CollisionShape*) ccs;
	
		Ogre::Vector3 scale = objectNode->getScale();
		btVector3 scale2(scale.x, scale.y, scale.z);
		finalCollisionShape->getBulletShape()->setLocalScaling(scale2);
		mBody->setShape(objectNode, (OgreBulletCollisions::CollisionShape*) ccs, mRestitution, mFriction, mMass, mPosition, mOrientation);
		mBody->getBulletRigidBody()->setFriction(0.5f);
		palmAnimation = entity->getAnimationState("my_animation");
	}
	else if(mName == "GoldCoconut") {
		float biggestSize = 0;
		if (size.x > biggestSize)
			biggestSize = size.x;
		if (size.y > biggestSize)
			biggestSize = size.y;
		if (size.z > biggestSize)
			biggestSize = size.z;

		entity->setMaterialName("GoldCoconut");
		OgreBulletCollisions::CollisionShape *sceneSphereShape = new OgreBulletCollisions::SphereCollisionShape(biggestSize);
 		mBody->setShape(objectNode, sceneSphereShape, mRestitution, mFriction, mMass, mPosition, mOrientation);
		mBody->getBulletRigidBody()->setCollisionFlags(mBody->getBulletRigidBody()->getCollisionFlags()  | btCollisionObject::CF_CUSTOM_MATERIAL_CALLBACK);
	}
	else {
		if (mName=="Orange" ||mName=="Blue" || mName=="Red" || mName=="Block")
		{
			mMass=50;
		}
		if (mName == "Orange")
			entity->setMaterialName("Orange");
		else if (mName == "Blue")
			entity->setMaterialName("Blue");
		else if (mName == "Red")
			entity->setMaterialName("Red");
		OgreBulletCollisions::BoxCollisionShape* sceneBoxShape = new OgreBulletCollisions::BoxCollisionShape(size);
		mBody->setShape(objectNode, sceneBoxShape, mRestitution, mFriction, mMass, mPosition, mOrientation);
		mBody->getBulletRigidBody()->setCollisionFlags(mBody->getBulletRigidBody()->getCollisionFlags()  | btCollisionObject::CF_CUSTOM_MATERIAL_CALLBACK);
	}

	mBody->setCastShadows(true);

	//Add a billboard for scores if necessary
	if(mBillBoard != 0) {
		mText = new MovableText("targetText" + StringConverter::toString(mNumEntitiesInstanced), "100", "000_@KaiTi_33", 17.0f);
		mText->setTextAlignment(MovableText::H_CENTER, MovableText::V_ABOVE); // Center horizontally and display above the node
		
		//Create scene node for bill board and attach text to it
		mBillNode = static_cast<SceneNode*>(mSceneMgr->getRootSceneNode()->createChild());
		mBillNode->attachObject(mText);
		mBillNode->setPosition(mPosition.x, mPosition.y + 50, mPosition.z);
		mBillNode->setVisible(false);
		//Set animation to off initially
		mTextAnim = 0;
		mTextBool = false;
		mTextPos = mBody->getCenterOfMassPosition();
	} else {
		mText = NULL;	
		mBillNode = NULL;
		mTextAnim = NULL;
		mTextBool = NULL;
		mTextPos = NULL;
	}
}