Esempio n. 1
0
void inputFn()
{
	sf::Event evt;
	while (window.GetEvent(evt)) {
		if (window.GetInput().IsKeyDown(sf::Key::Down)) {
			if (max_tess > 1) max_tess -= 1;
		}
		else if(window.GetInput().IsKeyDown(sf::Key::Up)) {
			if (max_tess < 50) max_tess += 1;
		}
		switch (evt.Type) {
			case sf::Event::Closed:
				window.Close();
				break;
			case sf::Event::KeyPressed:
				fflag = evt.Key.Code;
				break;
			case sf::Event::KeyReleased:
				fflag = 0;
				if (evt.Key.Code == 'r')
					move = !move;
				break;
			case sf::Event::MouseMoved:
				mouse = vec2(evt.MouseMove.X, 
							WIN_H - evt.MouseMove.Y);
				break;
			default:
				break;
		}
	}
}
Esempio n. 2
0
	void handleEvents()
	{
		const sf::Input& Input = App->GetInput();
		bool shiftDown = Input.IsKeyDown(sf::Key::LShift) || Input.IsKeyDown(sf::Key::RShift);
		sf::Event Event;
		while (App->GetEvent(Event))
		{
			if (Event.Type == sf::Event::Closed)
				App->Close();
			if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Escape))
				App->Close();
			
			// This is for grading your code. DO NOT REMOVE
			if(Event.Type == sf::Event::KeyPressed && Event.Key.Code == sf::Key::Space) {
				firing = 6;
			} 
			if(Event.Type == sf::Event::KeyReleased && Event.Key.Code == sf::Key::Space) {
				firing = 0;
			}

			if(Event.Type == sf::Event::KeyPressed && Event.Key.Code == sf::Key::F12){
				render = RenderEngine();
				render.init();
			}

			
			if (Event.Type == sf::Event::Resized)
			{ glViewport(0, 0, Event.Size.Width, Event.Size.Height); }
		}
	}
Esempio n. 3
0
	void handleEvents()
	{
		const sf::Input& Input = App->GetInput();
		bool shiftDown = Input.IsKeyDown(sf::Key::LShift) || Input.IsKeyDown(sf::Key::RShift);
		sf::Event Event;
		while (App->GetEvent(Event))
		{
			// Close window : exit
			if (Event.Type == sf::Event::Closed)
				App->Close();

			// Escape key : exit
			if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Escape))
				App->Close();

			if (Event.Type == sf::Event::Resized)
			{
				glViewport(0, 0, Event.Size.Width, Event.Size.Height);
			}
		}
	}
Esempio n. 4
0
void handleInput() {
  sf::Event evt;
  while (window.GetEvent(evt)) {
    switch (evt.Type) {
      case sf::Event::Closed:
        // Close the window.  This will cause the game loop to exit,
        // because the IsOpened() function will no longer return true.
        window.Close();
        break;
      case sf::Event::KeyPressed:
        if (evt.Key.Code == sf::Key::W) {
          cameraZ -= .1f;
        } else if (evt.Key.Code == sf::Key::S) {
          cameraZ += .1f;
        } else if (evt.Key.Code == sf::Key::A) {
          cameraX -= .1f;
        } else if (evt.Key.Code == sf::Key::D) {
          cameraX += .1f;
        }
        break;
    }
  }
}
Esempio n. 5
0
int main ( int argc, char **argv )
{
	// On cr�e notre fen�tre gr�ce � SFML
	Application.Create( sf::VideoMode( 800, 500, 32 ), "SFML : Bullet physics", sf::Style::Titlebar | sf::Style::Resize | sf::Style::Close);
    //Application.Create(sf::VideoMode::GetMode(0), "SFML Window", sf::Style::Fullscreen);
	// Creation d'une fen�tre plein �cran avec le meilleur mode vid�o
  	
    
    
    /// Bullet physics
	
    ///collision configuration contains default setup for memory, collision setup
	myCollisionConfiguration = new btDefaultCollisionConfiguration();
	
	///use the default collision dispatcher. For parallel processing you can use a diffent dispatcher (see Extras/BulletMultiThreaded)
	myDispatcher = new	btCollisionDispatcher(myCollisionConfiguration);
	
	myBroadphase = new btDbvtBroadphase();
	
	///the default constraint solver. For parallel processing you can use a different solver (see Extras/BulletMultiThreaded)
	mySequentialImpulseConstraintSolver = new btSequentialImpulseConstraintSolver;
	
	// initialisation du monde bullet
	myWorld = new btDiscreteDynamicsWorld(myDispatcher,myBroadphase,mySequentialImpulseConstraintSolver,myCollisionConfiguration);
	
	// On d�finit la gravit�, de fa�on � ce que les objets tombent vers le bas (-Y).
	myWorld->setGravity( btVector3(0,-10,0) );
	
	/// SOL ///////////////////////////////////////////
	// create a shape
	btCollisionShape* shape_sol = new btBoxShape( btVector3(100,1,100) );
	
	myTransform.setIdentity();
	myTransform.setOrigin( btVector3(0,0,0) );
	
	btVector3 localInertiaSol(0,0,0);
	
	btScalar mass = 0;
	
	// Using motionstate is recommended, it provides interpolation capabilities, and only synchronizes 'active' objects
	myMotionState_Sol = new btDefaultMotionState(myTransform);
	btRigidBody::btRigidBodyConstructionInfo rbInfo_sol( mass, myMotionState_Sol, shape_sol, localInertiaSol );
	body_sol = new btRigidBody(rbInfo_sol);
	
	// Add the body to the dynamics world
	myWorld->addRigidBody(body_sol);

 
    
    
    
    // Create a clock for measuring time elapsed
    sf::Clock montre;
    //Variable pour calculer le delta de d�placement de la souris quand les clicks droit et gauche de la souris sont enfonc� pour manipuler la cam�ra
  
    // Pour d�clancher la chute d'un seul kapla quand la touche Espace est relach�e
	bool trigger = false; 
 
	unsigned int windowsWidth = Application.GetWidth();
    unsigned int windowsHeight = Application.GetHeight();
    
    
    int startPointX(0),startPointY(0);
    float deltaX(0),deltaY(0),prevDeltaX(1),prevDeltaY(1);
    int   MouseX(0);
    int   MouseY(0);
    bool show = true;
    
	//unsigned int sizeWidth = sf::Window::GetWidth();
    
    //On initialise une cam�ra qui sera plac� par d�faut par le constructeur
    Camera camcam(110,60.0,60.0);
    Cursor cursor;
bool test = false;
       
    float time;

 // pour avoir les infos clavier en temps r�el
	const sf::Input& Input = Application.GetInput();
	// Notre boucle d'affichage
	while(Application.IsOpened() )
	{
        Application.ShowMouseCursor (false);
        // r�f�rence vers l'entr�e associ�e � une fen�tre (pour r�cup�rer les donn�s clavier en temps r�el
        
        sf::Event Event;
        //Utilise les fl�che pour d�placer le Kapla qui va �tre lach�
        // Get some useless input states, just to illustrate the tutorial
        bool         LeftKeyDown     = Input.IsKeyDown(sf::Key::Left);
        bool         RightKeyDown     = Input.IsKeyDown(sf::Key::Right);
        bool         UpKeyDown     = Input.IsKeyDown(sf::Key::Up);
        bool         DownKeyDown     = Input.IsKeyDown(sf::Key::Down);
        
        bool         RightButtonDown = Input.IsMouseButtonDown(sf::Mouse::Right);
        bool         LeftButtonDown = Input.IsMouseButtonDown(sf::Mouse::Left);
        bool         Espace     = Input.IsKeyDown(sf::Key::Space);
        bool         Shift     = Input.IsKeyDown(sf::Key::LShift);
        MouseX  =   Input.GetMouseX() ;
        MouseY  =   Input.GetMouseY() ;
        
        if (LeftButtonDown) 
        {
                if (show ) 
                {
                    montre.Reset();
                    startPointY = MouseY;
                    startPointX = MouseX;
                //cout<< "start point" <<startPointX<< endl;
                    
                    show = false;
                }
                time = montre.GetElapsedTime();
            //cout<< time << endl;
           
                if (time > 0.02) 
                {
                
                    deltaX = ((MouseX-startPointX));
                
                    deltaY = ((MouseY-startPointY));
                    //show = true;
                cout<< deltaX<< endl;
                    if ((prevDeltaX != deltaX)||(prevDeltaY != deltaY)) {
                        camcam.tumble(deltaX/5,deltaY/5);
                        show = true;
                        //montre.Reset();
                        prevDeltaX = deltaX;
                        prevDeltaY = deltaY;
                        
                    }
            }
            
        }else
        {
            show = true;
            cursor.set((MouseX - windowsWidth/2), (MouseY - windowsHeight/2));
        }
        
        if (Shift) {
            test=true; 
        }else{
            test=false;
        }
        
        

        if (LeftKeyDown) {
            camcam.tumble(0.005, 0);
            LeftKeyDown = false;
        }
        if (RightKeyDown) {
            camcam.tumble(-0.005, 0);
            RightKeyDown = false;
        }
        if (UpKeyDown) {
            camcam.tumble(0, 0.005);
        }
        if (DownKeyDown) {
            camcam.tumble(0, -0.005);
        }
        //unsigned int delta =mouseT3 - mouseT1;
        //cout << delta<< endl;
        
        
        
        
        while (Application.GetEvent(Event))
        {
            
            if (Event.Type == sf::Event::Resized)
                glViewport(0, 0, Event.Size.Width, Event.Size.Height);
            // Fen�tre ferm�e
            if (Event.Type == sf::Event::Closed)
                Application.Close();
            
            // Touche 'echap' appuy�e
            if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Escape))
                Application.Close();
            if ((Event.Type == sf::Event::KeyReleased) && (Event.Key.Code == sf::Key::Space)) {
                /// box ///////////////////////////////////////////
                // create a shape
                btCollisionShape* shape_kapla = new btBoxShape( btVector3(3,1,15) );
                
                myTransform.setIdentity();
                int dropX((MouseX - windowsWidth/2));
                int dropY((MouseY - windowsHeight/2));
                myTransform.setOrigin(btVector3(dropX,5,dropY));
                
                btVector3 localInertia(0,0,0);
                
                mass = 0.5f;
                
                shape_kapla->calculateLocalInertia( mass, localInertia );
                
                //using motionstate is recommended, it provides interpolation capabilities, and only synchronizes 'active' objects
                myMotionState = new btDefaultMotionState(myTransform);
                btRigidBody::btRigidBodyConstructionInfo myBoxRigidBodyConstructionInfo( mass,myMotionState, shape_kapla, localInertia );
                body_kapla = new btRigidBody(myBoxRigidBodyConstructionInfo);
                
                //add the body to the dynamics world
                
                myWorld->addRigidBody(body_kapla);
                trigger=true;
            }
        }

        Application.SetActive();
         
        
        

        
        //NEED convertiseur coord souris -> coord du plan visible par la cam�ra
        // le d�placement sur le plan de la fen�tre est proportionel � celui du plan de construction
        
        // dessin  le curseur
        //cursor.drawKapla(1,15,3); 
        
        
        //touche espace enfonc�e et relach�e
       if ((Espace))
        {
           
         
        }              
                                   
        if (myWorld)
		{
			myWorld->stepSimulation( 0.0001 );
		}

       
        camcam.display();
        
        cursor.drawKapla(15, 3, 1);
        // On recup�re la matrice OpenGL transform�e par Bullet qu'on appliquera � notre boite
        if (trigger)
        {
                myMotionState->m_graphicsWorldTrans.getOpenGLMatrix( matrix );
            glPushMatrix();
            glMultMatrixf( matrix );
            box(3,1,15);
            glPopMatrix();
            
        }
        
        
		box(100,1,100);
		// On a	ffiche le sol;
        if (test==true)
        {
                   }
		
		
        
		
		// swap buffers, etc
		Application.Display();
        
	}
}
Esempio n. 6
0
void handleInput() {
    
    // this handles setting keyboard booleans for motion
    go_forward = Input.IsKeyDown(sf::Key::W);
    go_backward = Input.IsKeyDown(sf::Key::S);
    go_left = Input.IsKeyDown(sf::Key::A);
    go_right = Input.IsKeyDown(sf::Key::D);
    go_up = Input.IsKeyDown(sf::Key::Space);
    go_down = Input.IsKeyDown(sf::Key::C);
    
    
    // Event loop, for processing user input, etc.  For more info, see:
    // http://www.sfml-dev.org/tutorials/1.6/window-events.php
    sf::Event evt;
    while (window.GetEvent(evt)) {
        
        switch (evt.Type) {
            case sf::Event::Closed: 
                // Close the window.  This will cause the game loop to exit,
                // because the IsOpened() function will no longer return true.
                window.Close(); 
                break;
            case sf::Event::Resized: 
                // If the window is resized, then we need to change the perspective
                // transformation and viewport
                glViewport(0, 0, evt.Size.Width, evt.Size.Height);
                break;
                
                // Mouse Movement
            case sf::Event::MouseMoved:
                if (!mouseInit) {
                    cur_mouse = STPoint2(evt.MouseMove.X, evt.MouseMove.Y);
                    last_mouse = cur_mouse;
                    mouseInit = true;
                }
                else {
                    cur_mouse = STPoint2(evt.MouseMove.X, evt.MouseMove.Y);
                }
                mouse_move = cur_mouse - last_mouse;
                
                h_angle += .01 * mouse_move.x;
                v_angle += .01 * mouse_move.y;
                if (v_angle < 0) {
                    v_angle = 0.01;
                }
                else if (v_angle > MY_PI) {
                    v_angle = MY_PI-.01;
                }
                
                current_forward = STVector3(sin(v_angle)*cos(h_angle),cos(v_angle),sin(v_angle)*sin(h_angle));
                current_forward.Normalize();
                current_right = STVector3::Cross(current_forward, Up);
                current_right.Normalize();
                
                last_mouse = cur_mouse;
                break;
                
                // Key presses
            case sf::Event::KeyPressed:
                switch (evt.Key.Code) {
                    case sf::Key::Escape:
                        window.Close();
                        break;
                        
                    default:
                        break;
                }
                
            default: 
                break;
        }
    }
}
	void handleEvents()
	{
		sf::Event Event;
		while (App->GetEvent(Event))
		{
			// Close window : exit
			if (Event.Type == sf::Event::Closed)
				App->Close();
			
			// Escape key : exit
			if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Escape))
				App->Close();

			if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Space))
				board->newGame(true);
			
			// This is for grading your code. DO NOT REMOVE
			if(Event.Type == sf::Event::KeyPressed && Event.Key.Code == sf::Key::Equal)
			{
				unsigned char *dest;
				unsigned int w = App->GetWidth();
				unsigned int h = App->GetHeight();
				glPixelStorei(GL_PACK_ALIGNMENT, 1);
				dest = (unsigned char *) malloc( sizeof(unsigned char)*w*h*3);
				glReadPixels(0, 0, w, h, GL_RGB, GL_UNSIGNED_BYTE, dest);
				
				FILE *file;
				file = fopen("_program1.ppm", "wb");
				fprintf(file, "P6\n%i %i\n%i\n", w, h, 255);
				for(int i=h-1; i>=0; i--)
					fwrite(&dest[i*w*3], sizeof(unsigned char), w*3, file);
				fclose(file);
				free(dest);
			}

			if(Event.Type == sf::Event::KeyPressed && Event.Key.Code == sf::Key::N){
				board->newGame();
			}
			//handle mouse pressed
			if(Event.Type == sf::Event::MouseButtonPressed)
			{
				if(Event.MouseButton.Button == sf::Mouse::Right) board->cancelPickup();
				if(Event.MouseButton.Button == sf::Mouse::Left) {
					int x = Event.MouseButton.X;
					int y = Event.MouseButton.Y;
					y = RESOLUTION - y;

					board->display(true);
					glFlush();
					glFinish();
				
					float clickColor[4];
					glPixelStorei(GL_PACK_ALIGNMENT, 1);
					glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
					glReadPixels(x, y, 1, 1, GL_RGBA, GL_FLOAT, clickColor);

					GLuint clickId = 0;
					clickId = clickId | ((unsigned int)(clickColor[0] * 255.0f) << 0);
					clickId = clickId | ((unsigned int)(clickColor[1] * 255.0f) << 8);
					clickId = clickId | ((unsigned int)(clickColor[2] * 255.0f) << 16);
					clickId = clickId | ((unsigned int)(clickColor[3] * 255.0f) << 24);

					
					unsigned int objectId = clickId;

					//printf("Selected: %02X %02X %02X %02X\n", (objectId >> 24) & 0xFF, (objectId >> 16) & 0xFF, (objectId >> 8) & 0xFF, objectId & 0xFF );
					if(!board->piecePlace(objectId)){
						board->piecePickUp(objectId);
					}
				}
			}
		}
	}
	void handleEvents()
	{
		const sf::Input& Input = App->GetInput();
		bool shiftDown = Input.IsKeyDown(sf::Key::LShift) || Input.IsKeyDown(sf::Key::RShift);
		sf::Event Event;
		while (App->GetEvent(Event))
		{
			// Close window : exit
			if (Event.Type == sf::Event::Closed)
				App->Close();
			
			// Escape key : exit
			if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Escape))
				App->Close();
			
			if((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::W)) {
				tiltX-=cos(cameraTheta*M_PI/180)*TILTSPEED;
				tiltZ-=sin(cameraTheta*M_PI/180)*TILTSPEED;
			}
			if((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::S)) {
				tiltX+=cos(cameraTheta*M_PI/180)*TILTSPEED;
				tiltZ+=sin(cameraTheta*M_PI/180)*TILTSPEED;
			}
			if((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::A)) {
				tiltX-=sin(cameraTheta*M_PI/180)*TILTSPEED;
				tiltZ+=cos(cameraTheta*M_PI/180)*TILTSPEED;
			}
			if((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::D)) {
				tiltX+=sin(cameraTheta*M_PI/180)*TILTSPEED;
				tiltZ-=cos(cameraTheta*M_PI/180)*TILTSPEED;
			}
			if(tiltX*tiltX+tiltZ*tiltZ>MAXTILT*MAXTILT) {
				double size = sqrt(tiltX*tiltX+tiltZ*tiltZ);
				tiltX*=MAXTILT/size;
				tiltZ*=MAXTILT/size;
			}
			
			if (cameraLookMode && Event.Type == sf::Event::MouseMoved)
			{
				int deltaX = Event.MouseMove.X - lastPos[0];
				int deltaY = Event.MouseMove.Y - lastPos[1];

				/*glPushMatrix();
				glLoadIdentity();
				glRotated(deltaY, 1, 0, 0);
				glRotated(deltaX, 0, 1, 0);
				glMultMatrixd(rotationMatrix);
				glGetDoublev(GL_MODELVIEW_MATRIX, (GLdouble*) &rotationMatrix);
				glPopMatrix();*/

				cameraTheta += deltaX*CAMERASPEED;
				//cameraPhi -= deltaY*CAMERASPEED;

				if (cameraPhi > 180)
					cameraPhi = 180;
				if (cameraPhi < 0.01)
					cameraPhi = 0.01;

				lastPos[0] = Event.MouseMove.X;
				lastPos[1] = Event.MouseMove.Y;
			}

			if (Event.Type == sf::Event::MouseButtonPressed
				  && Event.MouseButton.Button == sf::Mouse::Left)
			{
				lastPos[0] = Event.MouseButton.X;
				lastPos[1] = Event.MouseButton.Y;
				cameraLookMode = !cameraLookMode;
			}
		}
		ball.accelerate(tiltX*0.0001,0.0001,0.0001*tiltZ);
		ball.testCollision(level[0]);
	}
Esempio n. 9
0
void handleInput() {
    //////////////////////////////////////////////////////////////////////////
    // TODO: ADD YOUR INPUT HANDLING HERE.
    //////////////////////////////////////////////////////////////////////////

    // Event loop, for processing user input, etc.  For more info, see:
    // http://www.sfml-dev.org/tutorials/1.6/window-events.php
    sf::Event evt;
    while (window.GetEvent(evt)) {
        switch (evt.Type) {
        case sf::Event::KeyPressed:
            switch(evt.Key.Code)
            {
            case sf::Key::A:
                left = true;
                break;
            case sf::Key::W:
                forward = true;
                break;
            case sf::Key::S:
                backward = true;
                break;
            case sf::Key::D:
                right = true;
                break;
            case sf::Key::Up:
                lightUp = true;
                break;
            case sf::Key::Left:
                lightLeft = true;
                break;
            case sf::Key::Down:
                lightDown = true;
                break;
            case sf::Key::Right:
                lightRight = true;
                break;
            case sf::Key::T:
                test = !test;
                break;
            default:
                break;
            }
            break;
        case sf::Event::KeyReleased:
            switch(evt.Key.Code)
            {
            case sf::Key::A:
                left = false;
                break;
            case sf::Key::W:
                forward = false;
                break;
            case sf::Key::S:
                backward = false;
                break;
            case sf::Key::D:
                right = false;
                break;
            case sf::Key::Up:
                lightUp = false;
                break;
            case sf::Key::Left:
                lightLeft = false;
                break;
            case sf::Key::Down:
                lightDown = false;
                break;
            case sf::Key::Right:
                lightRight = false;
                break;
            default:
                break;
            }
            break;
        case sf::Event::MouseMoved:
            static float rotation_sensitivity = 0.01;
            static float prev_mouse_x = evt.MouseMove.X;
            static float prev_mouse_y = evt.MouseMove.Y;
            yaw -= rotation_sensitivity * (prev_mouse_x - evt.MouseMove.X);
            pitch += rotation_sensitivity * (prev_mouse_y - evt.MouseMove.Y);

            if (pitch < -M_PI / 2.0f) pitch = -M_PI / 2.0f;
            if (pitch > M_PI / 2.0f) pitch = M_PI / 2.0f;

            prev_mouse_x = evt.MouseMove.X;
            prev_mouse_y = evt.MouseMove.Y;
            break;
        case sf::Event::Closed:
            // Close the window.  This will cause the game loop to exit,
            // because the IsOpened() function will no longer return true.
            window.Close();
            break;
        case sf::Event::Resized:
            // If the window is resized, then we need to change the perspective
            // transformation and viewport
            glViewport(0, 0, evt.Size.Width, evt.Size.Height);
            break;
        default:
            break;
        }
    }
}