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

Author Topic: Strange things with Gamepad  (Read 5082 times)

0 Members and 1 Guest are viewing this topic.

Lo-X

  • Hero Member
  • *****
  • Posts: 618
    • View Profile
    • My personal website, with CV, portfolio and projects
Strange things with Gamepad
« on: August 15, 2011, 08:13:15 pm »
Hello

I tried the last build of SFML 2 with the new sf::Joystick and I saw a strange thing while using it with a gamepad, I don't know if it's normal or not.

If I Use this code :

Code: [Select]
int main(void)
{
      // App = sf::RenderWindow
     sf::Joystick::Update();
     int MyJoystickNumber = 0;
     for(int i = 0; i < 8; i++)    
          if(sf::Joystick::IsConnected(i)) {  
               MyJoystickNumber = i; break;
          }

     // Some code

     // Problematic code
     if(sf::Joystick::GetAxisPosition(MyJoystickNumber, sf::Joystick::X) < -40)
          cout << "Turn Left !" << endl;
}


In fact, "Turn Left !" just never appear, the Joystick number is not my gamepad number and I've nothing else than a mouse and a keyboard on the computer.

If I have a table of joystick's numbers and I check all these joysticks, the message appear.
So my game works well and the new interface is nice, but I'm obliged to check 2 Joysticks instead of one in a single game loop.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Strange things with Gamepad
« Reply #1 on: August 15, 2011, 08:41:51 pm »
Quote
the Joystick number is not my gamepad number

How do you know what your gamepad number is?

Quote
If I have a table of joystick's numbers and I check all these joysticks, the message appear.
So my game works well and the new interface is nice, but I'm obliged to check 2 Joysticks instead of one in a single game loop.

Sorry I don't get this part. Can you elaborate?
Laurent Gomila - SFML developer

Lo-X

  • Hero Member
  • *****
  • Posts: 618
    • View Profile
    • My personal website, with CV, portfolio and projects
Strange things with Gamepad
« Reply #2 on: August 15, 2011, 10:22:20 pm »
Quote from: "Laurent"
How do you know what your gamepad number is?

Je vais illustrer mon propos :

Je dois utiliser une boucle pour avoir tous les numéros de Joystick :
Code: [Select]
int JoystickNumberTable[8], j = 0;
for(int i = 0; i < 8; i++)  
     if(sf::Joystick::IsConnected(i)) {  
          JoystickNumberTable[j] = i;
          j++;
     }

(Chez moi, je récupère toujours deux nombres : 0 et 1)

Puis, lorsque je veux vérifier si le joystick est tourné ou non :

Code: [Select]
for(int i = 0; i < j; i++)
            {
                if(sf::Joystick::GetAxisPosition(JoystickNumberTable[i], sf::Joystick::X) < -40)
                        cout << "Turn Left !" << endl;
            }


Si je récupère le premier numéro de Joystick trouvé avec IsConnected(NUMERO), sf::Joystick::GetAxisPosition(   NUMERO   , ...) retourne des valeurs comprises entre -3 et 3 (à quelques décimales près).

Mais je viens de me dire que le premier numéro trouvé correspond au stick POV de la manette, même si en le tournant également, rien ne se passe.

Je ne sais pas si c'est clair ^^
Sorry for english speaking people :/

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Strange things with Gamepad
« Reply #3 on: August 15, 2011, 10:35:54 pm »
But how many joysticks do you have? I don't think that POV should be seen as a separate joystick.

Quote
Sorry for english speaking people :/

Hmm... there's a french forum you know ;)
Laurent Gomila - SFML developer

Lo-X

  • Hero Member
  • *****
  • Posts: 618
    • View Profile
    • My personal website, with CV, portfolio and projects
Strange things with Gamepad
« Reply #4 on: August 15, 2011, 10:59:43 pm »
Quote from: "Laurent"
But how many joysticks do you have? I don't think that POV should be seen as a separate joystick.


I've only one gamepad, so one joystick.
I've Linux (ubuntu 11.04)
Here is the pad :

(NGS Tanker, a Playstation 2/3 and PC compatible pad)

Quote from: "Laurent"
Hmm... there's a french forum you know ;)


I need to learn english, and there are more people to answer on english side :D

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Strange things with Gamepad
« Reply #5 on: August 15, 2011, 11:08:16 pm »
Ok. Is there a standard utility that you can run to see how your gamepad is detected and mapped? If it's the same as SFML, it's probably a problem with the gamepad's driver. Otherwise it's a bug in SFML :)

Quote
I need to learn english, and there are more people to answer on english side

So don't answer in french :lol:
Laurent Gomila - SFML developer

Lo-X

  • Hero Member
  • *****
  • Posts: 618
    • View Profile
    • My personal website, with CV, portfolio and projects
Strange things with Gamepad
« Reply #6 on: August 15, 2011, 11:19:05 pm »
Quote from: "Laurent"
Ok. Is there a standard utility that you can run to see how your gamepad is detected and mapped? If it's the same as SFML, it's probably a problem with the gamepad's driver. Otherwise it's a bug in SFML


I'll see that