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

Author Topic: Joystick Programming  (Read 8376 times)

0 Members and 1 Guest are viewing this topic.

mateandmetal

  • Full Member
  • ***
  • Posts: 171
  • The bird is the word
    • View Profile
    • my blog
Joystick Programming
« on: March 29, 2012, 01:13:32 am »
Hi

Started joystick programming today.... I have some doubts..  :-\


1) I have discovered that some buttons of my wired X360 controller are not detected as pressed (the buttons are LT and RT)... sf::Joystick::getButtonCount is returning 10..... Using my generic usb gamepad getButtonCount returns 12 buttons (and they all count as pressed when I press them) ... is this a bug?


2) I´m getting some errors trying to get the joystick moved with the events system. This is my code:

        sf::Event event;
        while (window.pollEvent (event)) {

             // Close window : exit
            if (event.type == sf::Event::Closed)
                window.close();

            // HERE I want to know the joystick number, the axis, and the new position
            if (event.type == sf::Event::JoystickMoved) {

               // error: expected primary expression before ´.´ token
               unsigned int njoy = sf::Event::JoystickMoveEvent.joystickId;

               // trying this way.. error: invalid use of ´struct sf::Event::JoystickMoveEvent´
               unsigned int njoy = event.JoystickMoveEvent.joystickId;
 

what is the correct way of getting the joy number, the axis moved, and the new position (using the event system) ?

win7 x64, codeblocks, sfml 2 updated
thanks
- Mate (beverage) addict
- Heavy metal addict _lml
- SFML 2 addict
- My first (and free) game: BichingISH!

mateandmetal

  • Full Member
  • ***
  • Posts: 171
  • The bird is the word
    • View Profile
    • my blog
Re: Joystick Programming
« Reply #1 on: March 29, 2012, 02:47:11 am »
i figured it out:

1) LT and RT are not detected as buttons... They are detected as axis  ??? ... Why?

2) correct code:

         if (event.type == sf::Event::JoystickMoved) {

                unsigned int njoy = event.joystickMove.joystickId; // Joy Number
                sf::Joystick::Axis eje = event.joystickMove.axis;  // Axis moved

                float pos = event.joystickMove.position; // New position
 


But now I have a 3rd question.... Is SFML axis handling code very bug? or Joystick programming is just a pain in the ...  ;D ?

Generic USB gamepad uses diferent axes with analog mode on and off
X360 controller uses the same axes for left stick, right stick, LT and RT button, and digital pad  :o (the controller works fine with most commercial games)
- Mate (beverage) addict
- Heavy metal addict _lml
- SFML 2 addict
- My first (and free) game: BichingISH!

thePyro_13

  • Full Member
  • ***
  • Posts: 156
    • View Profile
Re: Joystick Programming
« Reply #2 on: March 29, 2012, 04:59:58 am »
i figured it out:

1) LT and RT are not detected as buttons... They are detected as axis  ??? ... Why?
All the newer controllers(Xbox 360, so on...) seem to expose them as axis these days. Probably so that they can be used as accelerators in racing(and flight sim) games.
But now I have a 3rd question.... Is SFML axis handling code very bug? or Joystick programming is just a pain in the ...  ;D ?
Have you tried using sf::Joystick rather than SFML events? I find getting the input from the input objects to make far more sense then using the event system.
Generic USB gamepad uses diferent axes with analog mode on and off
X360 controller uses the same axes for left stick, right stick, LT and RT button, and digital pad  :o (the controller works fine with most commercial games)
The 360 controller should have 4 sets of  axis. One for each normal joystick, one for the POV(d-pad). And one shared between the two triggers.

In SFML:
POVx, POVy are probably the d-pad.
X, Y are probably the left most controller
Z, R are either the right joystick or the triggers.
U, V are whichever one Z, R isn't.
« Last Edit: March 29, 2012, 05:04:05 am by thePyro_13 »

mateandmetal

  • Full Member
  • ***
  • Posts: 171
  • The bird is the word
    • View Profile
    • my blog
Re: Joystick Programming
« Reply #3 on: March 30, 2012, 12:42:02 am »
Have you tried using sf::Joystick rather than SFML events?

Thanks thePyro_13... Im using sf::Joystick interface now... I wrote a new app that shows the axis positions on the window... I see everything much clearer now:




Quote from: thePyro_13
In SFML:
POVx, POVy are probably the d-pad.
X, Y are probably the left most controller
Z, R are either the right joystick or the triggers.
U, V are whichever one Z, R isn't.

Generic gamepad with analog ON and X360: yes.... PovX, PovY have the same behavior
X, Y ... left stick (analog ON)
the right stick is not the same .. Generic gamepad is Z, R ... 360 is U, R  ???

LT and RT on the 360 controller is the Z axis going from -99 to 99 aprox.

Perhaps with the PS3 controller is all different  :o :)
- Mate (beverage) addict
- Heavy metal addict _lml
- SFML 2 addict
- My first (and free) game: BichingISH!