bool frameStarted(const Ogre::FrameEvent& evt){
		_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))
			t += Ogre::Vector3(0,0,-10);

		if (_key->isKeyDown(OIS::KC_S))
			t += Ogre::Vector3(0,0,10);

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

		if (_key->isKeyDown(OIS::KC_D))
			t += Ogre::Vector3(10,0,0);

		_cam->moveRelative(t*evt.timeSinceLastFrame*movSpeed);
		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));
		

		return true;
	}
Exemple #2
0
void InputHandler::capture()
{
    if (keyboard == 0 && mouse == 0)
    {
        try {
            keyboard = static_cast<OIS::Keyboard*>
                           (ois->createInputObject(OIS::OISKeyboard, true));
            keyboard->setEventCallback(this);

            mouse = static_cast<OIS::Mouse*>
                        (ois->createInputObject(OIS::OISMouse, true));
            mouse->setEventCallback(this);

            cout << "[libclois-lane] Keyboard and mouse acquired!" << endl;
        } catch (OIS::Exception &e) {
            cout << "[libclois-lane] " << e.eText << endl;
        }
    }
    else
    {
        try {
            keyboard->capture();
            mouse->capture();
	} catch (OIS::Exception &e) {
            cout << "[libclois-lane] " << e.eText << endl;
            keyboard = 0;
            mouse = 0;
        }
    }
}
Exemple #3
0
	bool frameStarted(const Ogre::FrameEvent& evt)
	{
		if (mExit)
			return false;
		if (mWindow->isClosed())
			return false;

		mKeyboard->capture();
		mMouse->capture();

		if (mKeyboard->isKeyDown(OIS::KC_A) || mKeyboard->isKeyDown(OIS::KC_LEFT))
			mCamera->moveRelative(Ogre::Vector3(-evt.timeSinceLastFrame*20, 0, 0));

		if (mKeyboard->isKeyDown(OIS::KC_D) || mKeyboard->isKeyDown(OIS::KC_RIGHT))
			mCamera->moveRelative(Ogre::Vector3(evt.timeSinceLastFrame*20, 0, 0));

		if (mKeyboard->isKeyDown(OIS::KC_W) || mKeyboard->isKeyDown(OIS::KC_UP))
			mCamera->moveRelative(Ogre::Vector3(0, 0, -evt.timeSinceLastFrame*20));

		if (mKeyboard->isKeyDown(OIS::KC_S) || mKeyboard->isKeyDown(OIS::KC_DOWN))
			mCamera->moveRelative(Ogre::Vector3(0, 0, evt.timeSinceLastFrame*20));

		mGUI->injectFrameEntered(evt.timeSinceLastFrame);

		return true;
	}
      // frame listener
   bool frameStarted(const FrameEvent &evt)
    {
      mKeyboard->capture();

        // update physics simulation
      dynamicsWorld->stepSimulation(evt.timeSinceLastFrame,50);
        return mContinue;
    }
      // framelistener
   bool frameStarted(const FrameEvent &evt)
    {
      mKeyboard->capture();

        // EN:: update physics simulation
        // BR:: atualiza simulação da física
      dynamicsWorld->stepSimulation(evt.timeSinceLastFrame,50);
        return mContinue;
    }
Exemple #6
0
	bool frameStarted(const FrameEvent &evt)
	{
		mKeyboard->capture();
		return !mKeyboard->isKeyDown(OIS::KC_ESCAPE);
	}
Exemple #7
0
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow) {
#else
int main(int argc, char** argv) {
#endif
    Window window("Sample_InteractiveWater", 1024, 768, true);
    RenderParameters_t renderParameters;
    renderParameters.width = 1024;
    renderParameters.height = 768;
    renderParameters.displayFormat = DISPLAY_FORMAT_X8R8G8B8;
    renderParameters.refreshRate = 0;
    renderParameters.depthStencilBits = DEPTH_STENCIL_BITS_D24X8;

    Renderer::GetInstance()->Initialize(RENDER_SYSTEM_OPENGL, window, renderParameters);
    Renderer::GetInstance()->SetClearColor(0.2f, 0.2f, 0.2f);

    // Water surface creation
    const int NUM_VERTICES = 64;
    SurfaceTriangles_t surface;
    surface.numVertices = NUM_VERTICES * NUM_VERTICES;
    surface.numNormals = NUM_VERTICES * NUM_VERTICES;
    surface.numTexCoords = NUM_VERTICES * NUM_VERTICES;
    surface.vertices = new Vector3[surface.numVertices];
    surface.normals = new Vector3[surface.numNormals];
    surface.texCoords = new Vector2[surface.numTexCoords];

    Vector3* buffer = new Vector3[surface.numVertices];
    Vector3* buffer2 = surface.vertices;

    size_t idx = 0;
    const int NUM_CELLS = NUM_VERTICES - 1;
    float step = 2.0f / NUM_CELLS;
    float uvStep = 1.0f / NUM_VERTICES;

    for (size_t i = 0; i < NUM_VERTICES; i++) {
        for (size_t j = 0; j < NUM_VERTICES; j++) {
            idx = i * NUM_VERTICES + j;
            buffer[idx] = surface.vertices[idx] = Vector3(j * step - 1.0f, i * step - 1.0f, 0.0f);
            surface.normals[idx] = -Vector3::LOOK;
            surface.texCoords[idx] = Vector2(uvStep * j, uvStep * i);
        }
    }

    surface.numIndices = NUM_CELLS * NUM_CELLS * 6;
    surface.indices = new unsigned short[surface.numIndices];
    idx = 0;

    for (size_t i = 0; i < NUM_CELLS; i++) {
        for (size_t j = 0; j < NUM_CELLS; j++) {
            surface.indices[idx++] = i * NUM_VERTICES + j;
            surface.indices[idx++] = (i + 1) * NUM_VERTICES + j;
            surface.indices[idx++] = (i + 1) * NUM_VERTICES + j + 1;

            surface.indices[idx++] = i * NUM_VERTICES + j;
            surface.indices[idx++] = (i + 1) * NUM_VERTICES + j + 1;
            surface.indices[idx++] = i * NUM_VERTICES + j + 1;
        }
    }

    Mesh waterMesh(MESH_TYPE_DYNAMIC);
    waterMesh.AddSurface(&surface);

    VertexAttributesMap_t vertexAttributes;
    vertexAttributes[VERTEX_ATTRIBUTES_POSITION] = 0;
    vertexAttributes[VERTEX_ATTRIBUTES_NORMAL] = 1;
    vertexAttributes[VERTEX_ATTRIBUTES_TEX_COORDS] = 2;
    waterMesh.Initialize(vertexAttributes);

    // Material surface
    Shader* waterShader = Renderer::GetInstance()->CreateShader();
    waterShader->SetSourceFile("Shaders/vert", "Shaders/frag");

    Material waterMaterial(waterShader);
    Texture2D* waterTexture = Renderer::GetInstance()->CreateTexture2DFromFile("Media/water.jpg");
    waterMaterial.SetUniformTexture("waterTexture", waterTexture);

    // Water node
    Node waterNode;
    waterNode.SetMaterial(&waterMaterial);
    waterNode.SetMesh(&waterMesh);
    Renderer::GetInstance()->GetSceneTree().AddNode(&waterNode);

    Renderer::GetInstance()->CameraLookAt(Vector3(0.0f, 0.0f, -3.5f), Vector3::ZERO);

    // Create the OIS system if present
#ifdef OIS_AVAILABLE

    size_t windowHandle = (size_t)window.GetHandle();

    OIS::ParamList paramList;
    paramList.insert(pair<string, string>("WINDOW", to_string(windowHandle)));

#if defined OIS_WIN32_PLATFORM
    paramList.insert(pair<string, string>("w32_mouse", "DISCL_FOREGROUND"));
    paramList.insert(pair<string, string>("w32_mouse", "DISCL_NONEXCLUSIVE"));
#elif defined OIS_LINUX_PLATFORM
    paramList.insert(pair<string, string>("x11_mouse_grab", "false"));
    paramList.insert(pair<string, string>("x11_mouse_hide", "false"));
#endif

    OIS::InputManager* inputManager = OIS::InputManager::createInputSystem(paramList);

    OIS::Keyboard* keyboard = static_cast<OIS::Keyboard*>(inputManager->createInputObject(OIS::OISKeyboard, false));
    OIS::Mouse* mouse = static_cast<OIS::Mouse*>(inputManager->createInputObject(OIS::OISMouse, false));

    const OIS::MouseState& ms = mouse->getMouseState();
    ms.width = window.GetWidth();
    ms.height = window.GetHeight();
#endif

    //Renderer::GetInstance()->SetRenderFillMode(RENDER_MODE_WIREFRAME);
    float splashForce = 0.1f;
    float damping = 0.999f;
    float maxHeight = 0.15f;

    while (window.IsOpen()) {
        WindowEvent windowEvent;
        if (window.PollEvents(windowEvent)) {
        }

        // Poll the mouse if OIS is present
#ifdef OIS_AVAILABLE
        keyboard->capture();

        if (keyboard->isKeyDown(OIS::KC_ESCAPE)) {
            break;
        }

        mouse->capture();

        // If we clicked on the surface, get the point on the water plane and send it to the shader
        // for it to compute the ripples

        if (mouse->getMouseState().buttonDown(OIS::MB_Left)) {
            Vector3 pos = Renderer::GetInstance()->ScreenToWorldPoint(Vector2((float)mouse->getMouseState().X.abs, (float)mouse->getMouseState().Y.abs));

            // Transform the position into the range [0, 1] so that we can map it as texture coordinates of the water plane
            // Because the water plane ranges from (-1, -1) to (1, 1), the transformation is trivial
            Vector2 point;
            point.y = pos.x / 2.0f + 0.5f;
            point.x = pos.y / 2.0f + 0.5f;

            if (point.x >= 0.0f && point.y >= 0.0f && point.x <= 1.0f && point.y <= 1.0f) {
                //waterShader->SetUniformVector2("disturbancePoint", pos.x, pos.y);
                /*
                size_t i = (size_t) min(maxf(point.x * NUM_VERTICES, 1), NUM_VERTICES - 1);
                size_t j = (size_t) minsf(maxf(point.y * NUM_VERTICES, 1), NUM_VERTICES - 1);
                size_t idx = i * NUM_VERTICES + j;

                buffer[idx].z = splashForce;
                buffer[idx + 1].z = splashForce;
                buffer[idx - 1].z = splashForce;
                buffer[(i + 1) * NUM_VERTICES + j].z = splashForce;
                buffer[(i - 1) * NUM_VERTICES + j].z = splashForce;
                buffer[(i + 1) * NUM_VERTICES + j + 1].z = splashForce;
                buffer[(i + 1) * NUM_VERTICES + j - 1].z = splashForce;
                buffer[(i - 1) * NUM_VERTICES + j + 1].z = splashForce;
                buffer[(i - 1) * NUM_VERTICES + j - 1].z = splashForce;
                */
            } else {
                //waterShader->SetUniformVector2("disturbancePoint", -1.0f, -1.0f);
            }
        }
#endif
        for (size_t i = 1; i < NUM_VERTICES - 1; i++) {
            for (size_t j = 1; j < NUM_VERTICES - 1; j++) {
                idx = i * NUM_VERTICES + j;

                buffer[idx].z = (buffer2[idx - 1].z + buffer2[idx + 1].z +
                                 buffer2[(i - 1) * NUM_VERTICES + j].z +
                                 buffer2[(i + 1) * NUM_VERTICES + j].z) / 2.0f - buffer[idx].z;
                buffer[idx].z *= damping;
            }
        }

        for (size_t i = 1; i < NUM_VERTICES - 1; i++) {
            for (size_t j = 1; j < NUM_VERTICES - 1; j++) {
                idx = i * NUM_VERTICES + j;

                surface.normals[idx] = (buffer[idx + 1] - buffer[idx - 1]).Normalized();
            }
        }

        buffer2 = surface.vertices;
        surface.vertices = buffer;
        buffer = buffer2;
        waterMesh.UpdateMeshData();

        Renderer::GetInstance()->Clear();
        Renderer::GetInstance()->Render();
        Renderer::GetInstance()->EndRender();

        Renderer::GetInstance()->PresentFrame();
    }

    delete[] buffer;

    return 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(OIS::KC_ESCAPE))
		running = false;

	//Reload the scene if R is pressed
	static bool reloadedLast = false;
	if (keyboard->isKeyDown(OIS::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 *= 4;
	else
		trans *= 0.5f;

	trans *= 30;
	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 + 1.5 || !keyboard->isKeyDown(KC_SPACE)){		//Space = walk
		camPos.y = terrY + 1.5;
		camera->setPosition(camPos);
	}
}
Exemple #9
0
	bool frameStarted(const Ogre::FrameEvent& evt){
		
		Ogre::Vector3 translate(0,0,0);
		
		_Keyboard->capture();
			

		if(_Keyboard->isKeyDown(OIS::KC_ESCAPE)){
			return false;
		}


		if(_Keyboard->isKeyDown(OIS::KC_W)){
			translate += Ogre::Vector3(0,0,-1);
		}

		if(_Keyboard->isKeyDown(OIS::KC_S)){
			translate += Ogre::Vector3(0,0,1);
		}

		if(_Keyboard->isKeyDown(OIS::KC_A)){
			translate += Ogre::Vector3(-1,0,0);
		}

		if(_Keyboard->isKeyDown(OIS::KC_D)){
			translate += Ogre::Vector3(1,0,0);
		}

		/* Agregadas por mi */

		if(_Keyboard->isKeyDown(OIS::KC_UP)){
			_nodeRuedaSimple0->pitch(Ogre::Radian(-10));
			_nodeRuedaSimple1->pitch(Ogre::Radian(-10));
			_nodeRuedaSimple2->pitch(Ogre::Radian(-10));
			_nodeRuedaSimple3->pitch(Ogre::Radian(-10));

			_nodeRuedaSimple0->translate(0,0,5);
			_nodeRuedaSimple1->translate(0,0,5);
			_nodeRuedaSimple2->translate(0,0,5);
			_nodeRuedaSimple3->translate(0,0,5);
			_nodeChasisCarro->translate(0,0,5);
			eje->translate(0.0,0.0,5.0);
			desplazamiento += 5;

			if (desplazamiento >= 6500 && i<25) {
				eje->scale(1.1,1.1,1.1);
				i++;
			}
		}

		if(_Keyboard->isKeyDown(OIS::KC_RIGHT)){
/*			_nodeRuedaSimple00->yaw(Ogre::Radian(5));
			_nodeRuedaSimple11->yaw(Ogre::Radian(5));
			_nodeRuedaSimple22->yaw(Ogre::Radian(5));
			_nodeRuedaSimple33->yaw(Ogre::Radian(5));*/

			_nodeRuedaSimple0->translate(-3,0,0);
			_nodeRuedaSimple1->translate(-3,0,0);
			_nodeRuedaSimple2->translate(-3,0,0);
			_nodeRuedaSimple3->translate(-3,0,0);
			_nodeChasisCarro->translate(-3,0,0);
		}

		if(_Keyboard->isKeyDown(OIS::KC_LEFT)){
		/*	_nodeRuedaSimple00->yaw(Ogre::Radian(-5));
			_nodeRuedaSimple11->yaw(Ogre::Radian(-5));
			_nodeRuedaSimple22->yaw(Ogre::Radian(-5));
			_nodeRuedaSimple33->yaw(Ogre::Radian(-5)); */

			_nodeRuedaSimple0->translate(3,0,0);
			_nodeRuedaSimple1->translate(3,0,0);
			_nodeRuedaSimple2->translate(3,0,0);
			_nodeRuedaSimple3->translate(3,0,0);
			_nodeChasisCarro->translate(3,0,0);
		}


		_Cam->moveRelative(translate*evt.timeSinceLastFrame * 600);
		

		_Mouse->capture();
		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));


		return true;
	}
	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;
	}
Exemple #11
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();
	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);
	}
}
	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;
	}