Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: SFML 2.0, handling multiple inputs at the same time in screen  (Read 3994 times)

0 Members and 1 Guest are viewing this topic.

Syntactic Fructose

  • Jr. Member
  • **
  • Posts: 80
  • Overflowing stacks and eating snacks
    • View Profile
I read up on sf::Input in the 1.6 documentation, but I can't seem to find it in 2.0RC. Was sf::Input removed? I'm trying to fix my event handling function to be able to handle multiple types of input at once(e.g. moving mouse and pressing w to go forward and also look around at the same time). How should I go about doing this? Thanks for any help!

victorlevasseur

  • Full Member
  • ***
  • Posts: 206
    • View Profile
Re: SFML 2.0, handling multiple inputs at the same time in screen
« Reply #1 on: April 11, 2013, 07:28:52 pm »
Hello, you can use sf::Mouse, sf::Joystick, sf::Keyboard static methods to get the same result as sf::Input.

G.

  • Hero Member
  • *****
  • Posts: 1593
    • View Profile
Re: SFML 2.0, handling multiple inputs at the same time in screen
« Reply #2 on: April 11, 2013, 08:19:02 pm »
Take a look at the related tutorial for more information.

Syntactic Fructose

  • Jr. Member
  • **
  • Posts: 80
  • Overflowing stacks and eating snacks
    • View Profile
Re: SFML 2.0, handling multiple inputs at the same time in screen
« Reply #3 on: April 12, 2013, 07:05:34 pm »
Thanks for the reply guys, Just have another question regarding my input. I have my keyboard input working perfectly, and very responsive. Only problem is using my mouse in conjunction with my keys, at the moment I can only do one or the other, move with my keyboard or move with my mouse. Here is my controls function i use for the program
void computeMatricesFromInputs(sf::RenderWindow& window, float time){
        //get mouse position
        sf::Vector2i mousePos = sf::Mouse::getPosition(window);
                //set position of mouse so it does not move at all
        sf::Mouse::setPosition(sf::Vector2i(400, 300), window);
        //since the mouse position is always set to the center of the screen, any slight movements
        //      are added to the horizontal and vertical angle. (400,300) must also equal zero for the
        //      cube to remain still at origin, so that's why the mouse position is the subtractor to
        //      the center of the screen
        horizontalAngle += mouseSpeed * (800/2 - mousePos.x);
        verticalAngle   += mouseSpeed * (600/2 - mousePos.y);

        // Direction : Spherical coordinates to Cartesian coordinates conversion
        direction = glm::vec3(
                cos(verticalAngle) * sin(horizontalAngle),
                sin(verticalAngle),
                cos(verticalAngle) * cos(horizontalAngle)
        );
       
        // Right vector
        right = glm::vec3(
                sin(horizontalAngle - 3.14f/2.0f),
                0,
                cos(horizontalAngle - 3.14f/2.0f)
        );
        // Up vector
        glm::vec3 up = glm::cross( right, direction );
        // Projection matrix : 45° Field of View, 4:3 ratio, display range : 0.1 unit <-> 100 units
        ProjectionMatrix = glm::perspective(45.0f, 4.0f / 3.0f, 0.1f, 100.0f);
        // Camera matrix
        ViewMatrix = glm::lookAt(
                position,       //camera position
                position+direction,     //look at origin
                up      //head up
        );

        if (sf::Keyboard::isKeyPressed(sf::Keyboard::W)){
                position += direction * time * speed;
        }else if(sf::Keyboard::isKeyPressed(sf::Keyboard::S)){
                position -= direction * time * speed;
        }else if(sf::Keyboard::isKeyPressed(sf::Keyboard::D)){
                position += right * time * speed;
        }else if(sf::Keyboard::isKeyPressed(sf::Keyboard::A)){
                position -= right * time * speed;
        }
}

what I can notice right now is that I check for keyboard function before my mouse, do I need to use threading in order to have these inputs work in conjunction? Thanks!

 

anything