コード例 #1
0
void World::processInput()
{
	using namespace OIS;
	static Ogre::Timer timer;
	static unsigned long lastTime = 0;
	unsigned long currentTime = timer.getMilliseconds();

	//Calculate the amount of time passed since the last frame
	Real timeScale = (currentTime - lastTime) * 0.001f;
	if (timeScale < 0.001f)
		timeScale = 0.001f;
	lastTime = currentTime;

	//Get the current state of the keyboard and mouse
	keyboard->capture();
	mouse->capture();

	//Always exit if ESC is pressed
	if (keyboard->isKeyDown(KC_ESCAPE))
		running = false;

	//Reload the scene if R is pressed
	static bool reloadedLast = false;
	if (keyboard->isKeyDown(KC_R) && !reloadedLast){
		unload();
		load();
		reloadedLast = true;
	}
	else {
		reloadedLast = false;
	}

	//Get mouse movement
	const OIS::MouseState &ms = mouse->getMouseState();

	//Update camera rotation based on the mouse
	camYaw += Radian(-ms.X.rel / 200.0f);
	camPitch += Radian(-ms.Y.rel / 200.0f);
	camera->setOrientation(Quaternion::IDENTITY);
	camera->pitch(camPitch);
	camera->yaw(camYaw);

	//Allow the camera to move around with the arrow/WASD keys
	Ogre::Vector3 trans(0, 0, 0);
	if (keyboard->isKeyDown(KC_UP) || keyboard->isKeyDown(KC_W))
		trans.z = -1;
	if (keyboard->isKeyDown(KC_DOWN) || keyboard->isKeyDown(KC_S))
		trans.z = 1;
	if (keyboard->isKeyDown(KC_RIGHT) || keyboard->isKeyDown(KC_D))
		trans.x = 1;
	if (keyboard->isKeyDown(KC_LEFT) || keyboard->isKeyDown(KC_A))
		trans.x = -1;
	if (keyboard->isKeyDown(KC_PGUP) || keyboard->isKeyDown(KC_E))
		trans.y = 1;
	if (keyboard->isKeyDown(KC_PGDOWN) || keyboard->isKeyDown(KC_Q))
		trans.y = -1;

	//Shift = speed boost
	if (keyboard->isKeyDown(KC_LSHIFT) || keyboard->isKeyDown(KC_RSHIFT))
		trans *= 2;

	trans *= 50;
	camera->moveRelative(trans * timeScale);

	//Make sure the camera doesn't go under the terrain
	Ogre::Vector3 camPos = camera->getPosition();
	float terrY = HeightFunction::getTerrainHeight(camPos.x, camPos.z);
	if (camPos.y < terrY + 3 || !keyboard->isKeyDown(KC_SPACE)){		//Space = fly
		camPos.y = terrY + 3;
		camera->setPosition(camPos);
	}
}
コード例 #2
0
ファイル: Example5.cpp プロジェクト: ghoulsblade/vegaogre
void World::processInput()
{
	using namespace OIS;
	static Ogre::Timer timer;
	static unsigned long lastTime = 0;
	unsigned long currentTime = timer.getMilliseconds();

	//Calculate the amount of time passed since the last frame
	Real timeScale = (currentTime - lastTime) * 0.001f;
	if (timeScale < 0.001f)
		timeScale = 0.001f;
	lastTime = currentTime;

	//Get the current state of the keyboard and mouse
	keyboard->capture();
	mouse->capture();
	const OIS::MouseState &ms = mouse->getMouseState();

	//[NOTE] When the left mouse button is pressed, add trees
	if (ms.buttonDown(MB_Left)){
		//Choose a random tree rotation
		Degree yaw = Degree(Math::RangeRandom(0, 360));

		//Choose a random scale
		Real scale = Math::RangeRandom(0.5f, 0.6f);

		//Calculate a position
		Ogre::Vector3 centerPos = camera->getPosition() + (camera->getOrientation() * Ogre::Vector3(0, 0, -50));
		Radian rndAng = Radian(Math::RangeRandom(0, Math::TWO_PI));
		Real rndLen = Math::RangeRandom(0, 20);
		centerPos.x += Math::Sin(rndAng) * rndLen;
		centerPos.z += Math::Cos(rndAng) * rndLen;

		//And add the tree
		treeLoader->addTree(myTree, centerPos, yaw, scale);
		//[NOTE] Dynamic trees are very easy, as you can see. No additional setup is required for
		//the dynamic addition / removal of trees to work. Simply call addTree(), etc. as needed.
	}

	//[NOTE] When the right mouse button is pressed, delete trees
	if (ms.buttonDown(MB_Right)){
		//Calculate a position in front of the camera
		Ogre::Vector3 centerPos = camera->getPosition() + (camera->getOrientation() * Ogre::Vector3(0, 0, -50));

		//Delete trees within 20 units radius of the center position
		treeLoader->deleteTrees(centerPos, 20);
		//[NOTE] Dynamic trees are very easy, as you can see. No additional setup is required for
		//the dynamic addition / removal of trees to work. Simply call deleteTrees(), etc. as needed.
	}

	//Always exit if ESC is pressed
	if (keyboard->isKeyDown(KC_ESCAPE))
		running = false;

	//Reload the scene if R is pressed
	static bool reloadedLast = false;
	if (keyboard->isKeyDown(KC_R) && !reloadedLast){
		unload();
		load();
		reloadedLast = true;
	}
	else {
		reloadedLast = false;
	}

	//Update camera rotation based on the mouse
	camYaw += Radian(-ms.X.rel / 200.0f);
	camPitch += Radian(-ms.Y.rel / 200.0f);
	camera->setOrientation(Quaternion::IDENTITY);
	camera->pitch(camPitch);
	camera->yaw(camYaw);

	//Allow the camera to move around with the arrow/WASD keys
	Ogre::Vector3 trans(0, 0, 0);
	if (keyboard->isKeyDown(KC_UP) || keyboard->isKeyDown(KC_W))
		trans.z = -1;
	if (keyboard->isKeyDown(KC_DOWN) || keyboard->isKeyDown(KC_S))
		trans.z = 1;
	if (keyboard->isKeyDown(KC_RIGHT) || keyboard->isKeyDown(KC_D))
		trans.x = 1;
	if (keyboard->isKeyDown(KC_LEFT) || keyboard->isKeyDown(KC_A))
		trans.x = -1;
	if (keyboard->isKeyDown(KC_PGUP) || keyboard->isKeyDown(KC_E))
		trans.y = 1;
	if (keyboard->isKeyDown(KC_PGDOWN) || keyboard->isKeyDown(KC_Q))
		trans.y = -1;

	//Shift = speed boost
	if (keyboard->isKeyDown(KC_LSHIFT) || keyboard->isKeyDown(KC_RSHIFT))
		trans *= 2;

	trans *= 100;
	camera->moveRelative(trans * timeScale);

	//Make sure the camera doesn't go under the terrain
	Ogre::Vector3 camPos = camera->getPosition();
	float terrY = HeightFunction::getTerrainHeight(camPos.x, camPos.z);
	if (camPos.y < terrY + 5 || keyboard->isKeyDown(KC_SPACE)){		//Space = walk
		camPos.y = terrY + 5;
		camera->setPosition(camPos);
	}
}
コード例 #3
0
	bool frameStarted(const Ogre::FrameEvent& evt){
		if(vidas==0)
			return false;
		_key->capture();
		_mouse->capture();
		
		float movSpeed = 500.0f;


		if (_key->isKeyDown(OIS::KC_ESCAPE))
			return false;

		Ogre::Vector3 t(0,0,0);

		if (_key->isKeyDown(OIS::KC_W))
			if (freemoving)
				t += Ogre::Vector3(0,0,-10);
			else
				nave->moverAdelante();
		if (_key->isKeyDown(OIS::KC_S))
			if (freemoving)
				t += Ogre::Vector3(0,0,10);
			else
				nave->moverAtras();

		if (_key->isKeyDown(OIS::KC_A))
			if (freemoving)
				t += Ogre::Vector3(-10,0,0);
			else
				nave->moverIzquierda();

		if (_key->isKeyDown(OIS::KC_D))
			if (freemoving)
				t += Ogre::Vector3(10,0,0);
			else
				nave->moverDerecha();
		if (_key->isKeyDown(OIS::KC_UP))
			nave->moverArriba();

		if (_key->isKeyDown(OIS::KC_DOWN))
			nave->moverAbajo();

		if (!_key->isKeyDown(OIS::KC_A) && !_key->isKeyDown(OIS::KC_D))
			nave->reset();

		if(_key->isKeyDown(OIS::KC_I))
			std::cout<<"CAMARA:"<<_cam->getPosition()<<std::endl
					 <<"NAVE:"<<nave->nodoNave->getPosition()<<std::endl;

		_cam->moveRelative(t*evt.timeSinceLastFrame*movSpeed);
		if (freemoving){
			float rotX = _mouse->getMouseState().X.rel * evt.timeSinceLastFrame* -1;
			float rotY = _mouse->getMouseState().Y.rel * evt.timeSinceLastFrame * -1;
		
			_cam->yaw(Ogre::Radian(rotX));
			_cam->pitch(Ogre::Radian(rotY));
		}
		for (int i = 0; i < num_monedas; i++)
		{
			moneda[i]->animState->addTime(evt.timeSinceLastFrame);
		}

		for (int i = 0; i < num_obstaculo; i++)
		{
			obstaculo[i]->animState->addTime(evt.timeSinceLastFrame);
		}

		for (int i = 0; i < num_monedas; i++)
		{
			if (moneda[i]->visible && nave->getBox().intersects(moneda[i]->getBox())){
				moneda[i]->visible = false;
				moneda[i]->nodoMoneda->setVisible(false);
				puntaje+=100;
				mostrarPuntaje();
			}
		}
		
		for (int i = 0; i < num_aros; i++)
		{
			Ogre::AxisAlignedBox boxNave = nave->getBox();
			Ogre::Vector3 centro = nave->getCenter();
			if (aro[i]->visible &&
				nave->getBox().intersects(aro[i]->getBox()) && 
				aro[i]->adentro(boxNave, centro))
			{
				aro[i]->visible = false;
				aro[i]->nodoAro->setVisible(false);
				puntaje+=200;
				mostrarPuntaje();
			}
		}
		
		for (int i = 0; i < num_obstaculo; i++)
		{
			if (obstaculo[i]->visible && nave->getBox().intersects(obstaculo[i]->getBox())){
				obstaculo[i]->visible = false;
				obstaculo[i]->nodoObstaculo->setVisible(false);
				vidas-=1;
				mostrarPuntaje();
			}
		}
		
		nave->animStateDer->addTime(evt.timeSinceLastFrame);
		nave->animStateIzq->addTime(evt.timeSinceLastFrame);
		return true;
	}
コード例 #4
0
	bool frameStarted(const Ogre::FrameEvent &evt){		
		_key->capture();
		_mouse->capture();

		float movSpeed = 1000.0f;

		for( int i = 0 ; i < 8 ; ++i ){
			torre[i]->animState->addTime(evt.timeSinceLastFrame);
		}

		if (_key->isKeyDown(OIS::KC_ESCAPE))
			return false;

		Ogre::Vector3 t(0,0,0);
		Ogre::Vector3 tOgro(0,0,0);


		if (_key->isKeyDown(OIS::KC_W)){
			//t += Ogre::Vector3(0,0,-10);
			nave->moverAdelante();
		}

		if (_key->isKeyDown(OIS::KC_S))
			nave->moverAtras();

		if (_key->isKeyDown(OIS::KC_A)){
			//t += Ogre::Vector3(-10,0,0);
			nave->moverIzquierda();
		}
		if (_key->isKeyDown(OIS::KC_D)){
			//t += Ogre::Vector3(10,0,0);
			nave->moverDerecha();	
		}


		if(!(_key->isKeyDown(OIS::KC_D)) && !(_key->isKeyDown(OIS::KC_A))){
			nave->arreglar();
		}


		if (_key->isKeyDown(OIS::KC_UP)){
			nave->moverArriba();
		}

		if (_key->isKeyDown(OIS::KC_DOWN)){
			nave->moverAbajo();
		}

		if (_key->isKeyDown(OIS::KC_RIGHT)){
			nave->rotarDerecha();
		}

		if (_key->isKeyDown(OIS::KC_LEFT)){
			nave->rotarIzquierda();
		}

		if (_key->isKeyDown(OIS::KC_Q)){
			std::cout<<nave->x<<" "<<nave->y<<" "<<nave->z<<std::endl;
		}

		float rotX = _mouse->getMouseState().X.rel * evt.timeSinceLastFrame* -1;
		float rotY = _mouse->getMouseState() .Y.rel * evt.timeSinceLastFrame * -1;
		//_cam->yaw(Ogre::Radian(rotX));
		//_cam->pitch(Ogre::Radian(rotY));
		//_cam->moveRelative(t*evt.timeSinceLastFrame*movSpeed);
		//_cam->lookAt(nave->nodoNave->_getDerivedPosition());
		heli[0]->nodoHelice->rotate(Ogre::Vector3(0.0,1.0,0.0),Ogre::Radian(Ogre::Degree(-1.0)));
		heli[1]->nodoHelice->rotate(Ogre::Vector3(0.0,1.0,0.0),Ogre::Radian(Ogre::Degree(-1.0)));
		return true;
	}