Ejemplo n.º 1
0
	void OperatorControl()
	{
		// Loop counter to ensure that the program is running (debug helper
		// that can be removed when things get more stable)
		int sanity, bigSanity = 0;
		
		gamepad.Update();

		while (IsOperatorControl() && IsEnabled())
		{
			controls = Controls::GetInstance();
			
			controls->SetSpeed(LEFT_DRIVE_PWM, -1.0 * gamepad.GetRightY());
			controls->SetSpeed(RIGHT_DRIVE_PWM, -1.0 * gamepad.GetRightY());
			
			gamepad.Update();
			
			dsLCD->Clear();
			dsLCD->PrintfLine(DriverStationLCD::kUser_Line1, "2013 Test Fix");
			dsLCD->PrintfLine(DriverStationLCD::kUser_Line2, "Teleop Mode");
			dsLCD->PrintfLine(DriverStationLCD::kUser_Line6, "bigSanity: %d", sanity);
			dsLCD->UpdateLCD();
			sanity++;
			if (0 == sanity % 20)
			{
				bigSanity++;
			}

			Wait(0.05);				// wait for a motor update time
		}
	}
Ejemplo n.º 2
0
void Controls::mousePressHandler(int button, int state, int x, int y) 
{
    if ((state == GLUT_DOWN) && (button == GLUT_LEFT_BUTTON))
    {
        controls.setLeftButton(true);
        controls.setOldx(x);
        controls.setOldy(y);
    }
    else if((state == GLUT_UP) && (button == GLUT_LEFT_BUTTON))
    {
        controls.setLeftButton(false);
    }

    else if((state == GLUT_DOWN) && (button == GLUT_RIGHT_BUTTON))
    {
        controls.setOldx(x);
        controls.setOldy(y);
        controls.setRightButton(true);
    }
    else if((state == GLUT_UP) && (button == GLUT_RIGHT_BUTTON))
    {
        controls.setRightButton(false);
    }

    glutPostRedisplay();
}
Ejemplo n.º 3
0
void Touch::UpdateTouches(Controls& controls) // Called from HandleUpdate
{
    zoom_ = false; // reset bool

    Input* input = GetSubsystem<Input>();

    // Zoom in/out
    if (input->GetNumTouches() == 2)
    {
        TouchState* touch1 = input->GetTouch(0);
        TouchState* touch2 = input->GetTouch(1);

        // Check for zoom pattern (touches moving in opposite directions and on empty space)
        if (!touch1->touchedElement_ && !touch2->touchedElement_ && ((touch1->delta_.y_ > 0 && touch2->delta_.y_ < 0) || (touch1->delta_.y_ < 0 && touch2->delta_.y_ > 0)))
            zoom_ = true;
        else
            zoom_ = false;

        if (zoom_)
        {
            int sens = 0;
            // Check for zoom direction (in/out)
            if (Abs(touch1->position_.y_ - touch2->position_.y_) > Abs(touch1->lastPosition_.y_ - touch2->lastPosition_.y_))
                sens = -1;
            else
                sens = 1;
            cameraDistance_ += Abs(touch1->delta_.y_ - touch2->delta_.y_) * sens * touchSensitivity_ / 50.0f;
            cameraDistance_ = Clamp(cameraDistance_, CAMERA_MIN_DIST, CAMERA_MAX_DIST); // Restrict zoom range to [1;20]
        }
    }

    // Gyroscope (emulated by SDL through a virtual joystick)
    if (useGyroscope_ && input->GetNumJoysticks() > 0)  // numJoysticks = 1 on iOS & Android
    {
        JoystickState* joystick = input->GetJoystickByIndex(0);
        if (joystick->GetNumAxes() >= 2)
        {
            if (joystick->GetAxisPosition(0) < -GYROSCOPE_THRESHOLD)
                controls.Set(CTRL_LEFT, true);
            if (joystick->GetAxisPosition(0) > GYROSCOPE_THRESHOLD)
                controls.Set(CTRL_RIGHT, true);
            if (joystick->GetAxisPosition(1) < -GYROSCOPE_THRESHOLD)
                controls.Set(CTRL_FORWARD, true);
            if (joystick->GetAxisPosition(1) > GYROSCOPE_THRESHOLD)
                controls.Set(CTRL_BACK, true);
        }
    }
}
Ejemplo n.º 4
0
/*void Weapon::FixedUpdate(float timeStep)
{
    Actor::FixedUpdate(timeStep);
    //something
    //SetLeftHandOffset();
}*/
void Weapon::Update(Controls& ctrl, float timeStep)
{
    lefthand_target_=node_->GetWorldTransform()*lefthand_off_;
    //node_->SetPosition(Vector3(0.2f, 0.2f, 0.2f));//objectNode
    //this is called from the pawn controlling it, fron thier fixed update, like a state
    if(reloading_)
        Reload(timeStep);

    if (ctrl.IsDown(CTRL_FIRE))
        Fire(timeStep);
    else
        ReleaseFire();
}
Ejemplo n.º 5
0
int main() {
    controls.setPC(comm.getPC());
    controls.setup();
//    comm.printPosition();
    comm.printGains();

    controlsInterrupt.attach_us(&controls, &Controls::loop, 1000);

    while(1) {
        controls.updateIMUS();
        comm.check();
        
        
        if (serialCounter++>100) {
//            comm.printPosition();
//            comm.getPC()->printf("%f\n", controls.getTheta1());
//            comm.getPC()->printf("%f", controls.motor.getPWM());
            serialCounter = 0;
           // float z[4] = {1,2,0,0};
//            comm.getPC()->printf("%f\n",controls.target.getTheta2ForTarget(z));
        }
    }
}
Ejemplo n.º 6
0
int main (int argc, char **argv)
{ 
     GtkBuilder	*gtkBuilder;
     Controls*	 pControls = NULL;
     Proc*	 pProc	   = NULL;
     
     
     
     pControls = new Controls();
     pProc     = new Proc();

     
     
     
     gtk_set_locale();
     /* Initialize the widget set */
     gtk_init (&argc, &argv); 
     /* Create the main window */


     gtkBuilder= gtk_builder_new(); 
     gtk_builder_add_from_file(gtkBuilder,"npMain.glade",NULL);

     if(pControls->Initialize(gtkBuilder) == 0)
     {
	  pControls->DoRoute(gtkBuilder, (void*)pProc);
	  pProc->Set(pControls);  
	  gtk_widget_show_all (pControls->mainWindow);
	  gtk_main ();
	
     }
     g_object_unref ( G_OBJECT(gtkBuilder) );
     delete pControls;
     delete pProc;
     return 0;
}
Ejemplo n.º 7
0
// map SDL keyboard events to notifications
// ESC key -> quit
// arrow keys ->  notify Controls object
// space bar -> notify Controls object of Primary Action (fire a missle.)
void sendEventsToControls(Controls &controls) {
    SDL_Event event;
	while(SDL_PollEvent(&event)){
        bool state = false;
        switch(event.type) {
            case SDL_QUIT:
    			isRunning = false;
	       		break;
	       	case SDL_KEYDOWN:
                state = true;
                // fall through
            case SDL_KEYUP:
                switch(event.key.keysym.sym) {
                    case SDLK_ESCAPE:
        				isRunning = false;
        				break;
        			case SDLK_UP:
                        controls.up(state);
                        break;
        			case SDLK_DOWN:
                        controls.down(state);
                        break;
        			case SDLK_LEFT:
                        controls.left(state);
                        break;
        			case SDLK_RIGHT:
                        controls.right(state);
                        break;
        			case SDLK_SPACE:
                        controls.primary(state);
                        break;
                }  // end key symbol switch
			break;
		} // end event type switch
    }  // end PollEvent loop
}
Ejemplo n.º 8
0
int main(int argc, char **argv)
{
  ros::init(argc, argv, "controls_node");
  Controls controls;
  controls.loop();
}
Ejemplo n.º 9
0
int IndieLib()
{
    // ----- IndieLib intialization -----

    CIndieLib *mI = CIndieLib::instance();
    if (!mI->init()) return 0;

    // ----- Get Window Dimensions

    int winWidth = mI->_window->getWidth();
    int winHeight = mI->_window->getHeight();

    srand(static_cast<unsigned int>(time(0)));

    // ----- Surface loading -----

    IND_Surface *mSurfaceBack = IND_Surface::newSurface();
    if (!mI->_surfaceManager->add(mSurfaceBack, "../SpaceGame/resources/Backgrounds/18.jpg", IND_OPAQUE, IND_32)) return 0;

    /*IND_Animation* mTestA = IND_Animation::newAnimation();
    if (!mI->_animationManager->addToSurface(mTestA, "resources/animations/dust.xml", IND_ALPHA, IND_32, 255, 0, 255)) return 0;
    mTestA->getActualFramePos(0);*/

    // Loading 2D Entities

    // Background
    IND_Entity2d* mBack = IND_Entity2d::newEntity2d();
    mI->_entity2dManager->add(mBack);
    mBack->setSurface(mSurfaceBack);
    mBack->setScale((float)winWidth / mSurfaceBack->getWidth(), (float)winHeight / mSurfaceBack->getHeight());

    Controls* controls = new Controls();
    controls->loadSettings();

    ErrorHandler* error = new ErrorHandler();
    error->initialize(mI);

    Hud* mHud = new Hud();
    mHud->createHud(mI);

    Menu* mMenu = new Menu();
    mMenu->createMenu(mI);

    Save* quickSave = new Save();

    if (!SoundEngine::initialize())
    {
        error->writeError(200, 100, "Error", "SoundEngine");
    }

    vector<Planet*> mPlanets;
    Ship* mShip = NULL;

    bool loadSave = false;
    float mDelta = 0.0f;

    IND_Timer* mTimer = new IND_Timer;
    mTimer->start();

    while (!mI->_input->onKeyPress(IND_ESCAPE) && !mI->_input->quit() && !mMenu->isExit())
    {
        // get delta time
        mDelta = mI->_render->getFrameTime() / 1000.0f;

        if (mI->_input->isKeyPressed(controls->getMenu()))
        {
            mMenu->show();
            SoundEngine::getSoundEngine()->setAllSoundsPaused(true);
        }
        if (!mMenu->isHidden())
        {
            mMenu->updateMenu(mHud, quickSave, mPlanets, mShip);
            loadSave = mHud->getLoadingText()->isShow();
        }
        else
        {
            if (loadSave)
            {
                mDelta = 0.0;
                loadSave = false;
                SoundEngine::getSoundEngine()->setAllSoundsPaused(true);
                mHud->getLoadingText()->setShow(false);
                quickSave->loadSave(mI, mShip, mPlanets);
                mHud->showHud();
            }

            if (mShip != NULL)
            {
                if (mI->_input->onKeyPress(controls->getQuickSave()))
                {
                    quickSave->makeSave(mI, mShip, mPlanets);
                }

                mHud->updateHud(mShip);

                if (mI->_input->onKeyPress(controls->getQuickLoad()))
                {
                    deleteObjects(mHud, mShip, mPlanets);
                    loadSave = true;
                }
                if (mShip->isDestroyed())
                {
                    SoundEngine::getSoundEngine()->setAllSoundsPaused(true);
                    mHud->updateGameOverText(mShip->getScore());
                    deleteObjects(mHud, mShip, mPlanets);
                    mHud->getLoadingText()->setShow(false);
                    mHud->getGameOverText()->setShow(true);
                    mMenu->show();
                }
                if(mShip!=NULL)
                {
                    //----- Collisions -----
                    checkShipPlanetsCollisions(mI, mPlanets, mShip);
                    checkBulletsPlanetsCollisions(mI, mPlanets, mShip);
                    checkBulletsShipCollisions(mI, mPlanets, mShip);

                    //----- Movement update -----
                    mShip->updateShip(controls, mDelta);
                    if ((mTimer->getTicks() / 1000.0f) >= 3.0f)
                    {
                        mTimer->start();
                        mPlanets.at(rand() % mPlanets.size())->addSatellite();
                    }
                    for (vector<Planet*>::iterator it = mPlanets.begin(); it != mPlanets.end(); ++it)
                    {
                        (*it)->updatePlanet(mDelta, (mShip->getPosX() + 0.25f * mShip->getHeight() * cos(mShip->getAngleZRadian())), (mShip->getPosY() - 0.25f * mShip->getHeight() * sin(mShip->getAngleZRadian())));
                    }
                }
            }
        }

        //mI->_render->showFpsInWindowTitle();
        mI->_input->update();
        mI->_render->beginScene();
        mI->_entity2dManager->renderEntities2d();
        mI->_render->endScene();
    }

    // ----- Free -----
    delete controls;
    delete error;
    delete mHud;
    delete mMenu;
    delete quickSave;
    mI->_surfaceManager->remove(mSurfaceBack);
    mI->_entity2dManager->remove(mBack);
    deleteObjects(mHud, mShip, mPlanets);
    mI->end();
    return 0;
}
Ejemplo n.º 10
0
void InGameMenu::update(Controls & c, BattleType bt, vector<Monster> party)
{
	m = RequestMode::NONE;

	if (state == State::DEFAULT)
	{
		if (c.isPressedForFirstTime(Control::C_DOWN))
		{
			boxSelected = rollOverAdd(boxSelected, 0, NUM_OF_SIDE_BAR_BOXES - 1, 1);
		}
		else if (c.isPressedForFirstTime(Control::C_UP))
		{
			boxSelected = rollOverAdd(boxSelected, 0, NUM_OF_SIDE_BAR_BOXES - 1, -1);
		}
		else if (c.isPressedForFirstTime(Control::CANCEL) || c.isPressedForFirstTime(Control::START))
		{
			//m = RequestMode::CLOSE;
		}
		else if (c.isPressedForFirstTime(Control::ACCEPT))
		{
			if (boxSelected == 0)
			{
				//player
				state = State::PLAYER;
			}
			else if (boxSelected == 1)
			{
				//bag
			}
			else if (boxSelected == 2)
			{
				//party
				state = State::PARTY;
				boxSelected = 0;
			}
			else if (boxSelected == 3)
			{
				//map
			}
			else if (boxSelected == 4)
			{
				//phone
			}
			else if (boxSelected == 5)
			{
				//save
			}
			else if (boxSelected == 6)
			{
				//main menu
				state = State::MAIN_MENU;
				boxSelected = 1; //0 is yes, 1 is no
			}
			else if (boxSelected == 7)
			{
				//quit
				//m = RequestMode::CLOSE;
			}
		}
	}
	else if (state == State::PLAYER)
	{
		if(c.isPressedForFirstTime(Control::CANCEL))
		{
			state = State::DEFAULT;
		}
	}
	else if (state == State::BAG)
	{
		if (c.isPressedForFirstTime(Control::CANCEL))
		{
			state = State::DEFAULT;
		}
	}
	else if (state == State::PARTY)
	{
		if (c.isPressedForFirstTime(Control::CANCEL))
		{
			state = State::DEFAULT;
			boxSelected = 2;
		}
		if (c.isPressedForFirstTime(Control::C_UP))
		{
			boxSelected = rollOverAdd(boxSelected, 0, party.size() - 1, -1);
		}
		else if (c.isPressedForFirstTime(Control::C_DOWN))
		{
			boxSelected = rollOverAdd(boxSelected, 0, party.size() - 1, 1);
		}
	}
	else if (state == MAIN_MENU)
	{
		if (c.isPressedForFirstTime(Control::CANCEL))
		{
			state = State::DEFAULT;
			boxSelected = 6;
		}
		else if (c.isPressedForFirstTime(Control::ACCEPT))
		{
			if (boxSelected == 0)
			{
				m = RequestMode::QUIT;
			}
			else
			{
				state = State::DEFAULT;
				boxSelected = 6;
			}
		}
		if (c.isPressedForFirstTime(Control::C_LEFT))
		{
			boxSelected = rollOverAdd(boxSelected, 0, 1, -1);
		}
		else if (c.isPressedForFirstTime(Control::C_RIGHT))
		{
			boxSelected = rollOverAdd(boxSelected, 0, 1, 1);
		}
	}
	
}
Ejemplo n.º 11
0
void WatchDogClass::CheckControls()
{
	WControls.Update();
	
	SolidSystem = WControls.SolidGrid;
	CanTakeDistance = WControls.TakeDistance;
	
	LastTime = CurrentTime;
	CurrentTime = glfwGetTime();
	DiffTime = CurrentTime - LastTime;
	
	MainMotorsSpeed = WControls.MainMotorsVelocity;
	float speed, aspeed;
	switch (MainMotorsSpeed) 
	{
		case SPEED1:
			speed = Speed1;
			aspeed = Angle1;
			break;
		case SPEED2:
			speed = Speed2;
			aspeed = Angle2;
			break;
		case SPEED3:
			speed = Speed3;
			aspeed = Angle3;
			break;
	}
	
	if(WControls.MovingForward && !FronCollision)
	{
		MainMotorsMove = FORWARD;
		Position += Vector3f(speed * DiffTime, Angle);
	}
	else if(WControls.MovingBackward && !BackCollision)
	{
		MainMotorsMove = BACKWARD;
		Position -= Vector3f(speed * DiffTime, Angle);
	}
	else if(WControls.MovingLeft)
	{
		MainMotorsMove = RIGHT;
		
		if(Angle>360.0f)Angle-=360.0f;
		Angle+=aspeed * DiffTime;
	}
	else if(WControls.MovingRight)
	{
		MainMotorsMove = LEFT;
		
		if(Angle<0.0f)Angle+=360.0f;
		Angle-=aspeed * DiffTime;
	}
	else
		MainMotorsMove = STOP;
	
	
	if(WControls.MovingGripperUp)
		OtherMove = UP_GRIPPER;
	else if(WControls.MovingGripperDown)
		OtherMove = DOWN_GRIPPER;
	else if(WControls.MovingGripperClose)
		OtherMove = CLOSE_GRIPPER;
	else if(WControls.MovingGripperOpen)
		OtherMove = OPEN_GRIPPER;
	else 
		OtherMove = STOP;
	
	
	
	if(WControls.MovingCamUp)
		SlaveMove = CAM2_UP;
	else if(WControls.MovingCamDown)
		SlaveMove= CAM2_DOWN;
	else if(WControls.MovingCamLeft)
		SlaveMove = CAM2_LEFT;
	else if(WControls.MovingCamRight)
		 SlaveMove = CAM2_RIGHT;
	else if(WControls.Laser)
	{
		if(LaserON)
		{
			SlaveMove = LASERS_OFF;
			LaserON = false;
		}
		else 
		{
			SlaveMove = LASERS_ON;
			LaserON = false;
		}
	}
	else 
		SlaveMove = IDLE;

	if(GetKeyNewpress('P') && (USB->Error || !USB->HIDisOpen))
		USB->HIDReOpen();
	
	SendInstruction();
}
Ejemplo n.º 12
0
Archivo: Game.cpp Proyecto: JonnyIrl/AI
int main()
{
	//gamestates
	Menu* menu;
	PlayGame* play;
	Pause* pause;
	Splash* splash;
	//ScoreScreen* controls;
	Controls* controls;
	ScoreScreen* scoreScreen;

	// Create the main window 
	//Screen dimension constants

	
	sf::RenderWindow window(sf::VideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, 32), "Space Wars!");
	
	/*Initialsie the game modes*/
	menu = new Menu(SCREEN_WIDTH, SCREEN_HEIGHT);
	play = new PlayGame(SCREEN_WIDTH, SCREEN_HEIGHT);
	pause = new Pause(SCREEN_WIDTH, SCREEN_HEIGHT);
	splash = new Splash(SCREEN_WIDTH, SCREEN_HEIGHT);
	controls = new Controls(SCREEN_WIDTH, SCREEN_HEIGHT);
	scoreScreen = new ScoreScreen(SCREEN_WIDTH, SCREEN_HEIGHT);

	//clock & frame rate
	sf::Clock mclock;
	sf::Time timeSinceLastUpdate;
	window.setFramerateLimit(60);
	// Start game loop 
	while (window.isOpen())
	{
		//get time between frames
		timeSinceLastUpdate = mclock.getElapsedTime();
		float time = timeSinceLastUpdate.asSeconds();//get update time
		mclock.restart();


		// Process events 
		sf::Event Event;
		while (window.pollEvent(Event))
		{
			// Close window : exit 
			if (Event.type == sf::Event::Closed)
				window.close();

			// Escape key : exit 
			if ((Event.type == sf::Event::KeyPressed) && (Event.key.code == sf::Keyboard::Escape))
				window.close();
		}
		//updates
		switch (GameStateController::GetInstance()->getGameState())
		{
		case GameStateController::MENU:
			menu->Update(time, window, Event);
			break;
		case GameStateController::PLAY:
			play->Update(time, timeSinceLastUpdate);
			break;
		case GameStateController::CREDITS:
			break;
		case GameStateController::PAUSE:
			break;
		case GameStateController::SPLASH:
			break;
		case GameStateController::SCORESCREEN:
			scoreScreen->Update();
			break;
		case GameStateController::CONTROLS:
			controls->Update(time, window, Event);
			break;
		}//end switch

		//prepare frame
		window.clear(sf::Color::White);

		//draw
		switch (GameStateController::GetInstance()->getGameState())
		{
		case GameStateController::MENU:
			menu->Draw(window);
			break;
		case GameStateController::PLAY:
			play->Draw(window);
			break;
		case GameStateController::CREDITS:
			break;
		case GameStateController::PAUSE:
			break;
		case GameStateController::SPLASH:
			break;
		case GameStateController::SCORESCREEN:
			scoreScreen->Draw(window);
			break;
		case GameStateController::CONTROLS:
			controls->Draw(window);
			break;
		}//end switch


		// Finally, display rendered frame on screen 
		window.display();
	} //loop back for next frame
	
	//delete pointers
	delete menu;
	delete play;
	delete pause;
	delete splash;
	delete controls;

	return EXIT_SUCCESS;
}
Ejemplo n.º 13
0
void SceneReplication::HandlePhysicsPreStep(StringHash eventType, VariantMap& eventData)
{
    // This function is different on the client and server. The client collects controls (WASD controls + yaw angle)
    // and sets them to its server connection object, so that they will be sent to the server automatically at a
    // fixed rate, by default 30 FPS. The server will actually apply the controls (authoritative simulation.)
    Network* network = GetSubsystem<Network>();
    Connection* serverConnection = network->GetServerConnection();
    
    // Client: collect controls
    if (serverConnection)
    {
        UI* ui = GetSubsystem<UI>();
        Input* input = GetSubsystem<Input>();
        Controls controls;
        
        // Copy mouse yaw
        controls.yaw_ = yaw_;
        
        // Only apply WASD controls if there is no focused UI element
        if (!ui->GetFocusElement())
        {
            controls.Set(CTRL_FORWARD, input->GetKeyDown('W'));
            controls.Set(CTRL_BACK, input->GetKeyDown('S'));
            controls.Set(CTRL_LEFT, input->GetKeyDown('A'));
            controls.Set(CTRL_RIGHT, input->GetKeyDown('D'));
        }
        
        serverConnection->SetControls(controls);
        // In case the server wants to do position-based interest management using the NetworkPriority components, we should also
        // tell it our observer (camera) position. In this sample it is not in use, but eg. the NinjaSnowWar game uses it
        serverConnection->SetPosition(cameraNode_->GetPosition());
    }
    // Server: apply controls to client objects
    else if (network->IsServerRunning())
    {
        const Vector<SharedPtr<Connection> >& connections = network->GetClientConnections();
        
        for (unsigned i = 0; i < connections.Size(); ++i)
        {
            Connection* connection = connections[i];
            // Get the object this connection is controlling
            Node* ballNode = serverObjects_[connection];
            if (!ballNode)
                continue;
            
            RigidBody* body = ballNode->GetComponent<RigidBody>();
            
            // Get the last controls sent by the client
            const Controls& controls = connection->GetControls();
            // Torque is relative to the forward vector
            Quaternion rotation(0.0f, controls.yaw_, 0.0f);
            
            const float MOVE_TORQUE = 3.0f;
            
            // Movement torque is applied before each simulation step, which happen at 60 FPS. This makes the simulation
            // independent from rendering framerate. We could also apply forces (which would enable in-air control),
            // but want to emphasize that it's a ball which should only control its motion by rolling along the ground
            if (controls.buttons_ & CTRL_FORWARD)
                body->ApplyTorque(rotation * Vector3::RIGHT * MOVE_TORQUE);
            if (controls.buttons_ & CTRL_BACK)
                body->ApplyTorque(rotation * Vector3::LEFT * MOVE_TORQUE);
            if (controls.buttons_ & CTRL_LEFT)
                body->ApplyTorque(rotation * Vector3::FORWARD * MOVE_TORQUE);
            if (controls.buttons_ & CTRL_RIGHT)
                body->ApplyTorque(rotation * Vector3::BACK * MOVE_TORQUE);
        }
    }
}
Ejemplo n.º 14
0
void Controls::mouseMotionHandler(int x, int y)
{
    int viewport[4];
    glGetIntegerv(GL_VIEWPORT, viewport );

    // Rotate Camera
    if(controls.getLeftButton() == true && controls.getRightButton() == false)
    {
        //We fmod it by 360 because it is easier to see that it rotated 360 degrees instead of 720 degrees.
        //camera.setRotatex( fmod(camera.getRotatex() + (y - controls.getOldy()), 360) );
        //camera.setRotatey( fmod(camera.getRotatey() + (x - controls.getOldx()), 360) ); 
		camera.pitch((y - controls.getOldy())/2.0f);
		camera.yaw((x - controls.getOldx())/2.0f);
    }
    // Translate Camera
    else if(controls.getLeftButton() == false && controls.getRightButton() == true)
    {
        //camera.setTranslatex( camera.getTranslatex() +  .1f * (x - controls.getOldx()) ); 
        //camera.setTranslatey( camera.getTranslatey() + -.1f * (y - controls.getOldy()) ); 
		camera.upd(-(y - controls.getOldy())/5.0f);
		camera.leftr(-(x - controls.getOldx())/5.0f);
    }
    // Scale Camera
    else if(controls.getLeftButton() == true && controls.getRightButton() == true)
    {
        camera.setScale( camera.getScale() + float(y-controls.getOldy())/viewport[3] ); 
    }

    controls.setOldy(y);
    controls.setOldx(x);

    glutPostRedisplay();
}