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

Author Topic: A Concern About Joystick Axises  (Read 3624 times)

0 Members and 1 Guest are viewing this topic.

anthnich

  • Newbie
  • *
  • Posts: 34
    • View Profile
    • Long Division LLC
A Concern About Joystick Axises
« on: June 12, 2014, 08:03:15 pm »
Hi.

I have a tiny concern that I want to put forward, just to clear up if I am screwing something up or I found a quirk.

I have a Playstation 2 -> USB converter and your standard dual shock plugged into it.

In a game I am programming, I have an InputManager written which loads binds and the like and handles all input. The InputManager is initialized before anything happens in the engine. So, since there is no window created yet, I need to call sf::Joystick::update() to update the joystick first. Here is where I found a problem.

In my gamepad, it detect all axises (using hasAxis()) as available, although my pad uses only 4 of them. The axises that are "unavailable" have a constant position value of either -100 or 100. No big deal, I just check to see if those values are constant when setting up binds and disallow use of those axises. With that workaround, everything works fine. Now, here is where I have run into a quirk.

Axis::U is one axis that is unavailable to me. So, if I call sf::Joystick::update(), that axis should give back a value of either 100 or -100 on getAxisPosition(). Except, this axis returns the value of Axis::R UNTIL I create a window and update the joystick again.

Here is the test code that demonstrates. It may or may not work for you, depending on which axis does this for you.

int main() {

        // no window, so update joystick.
        sf::Joystick::update();

        // U is "(un)available" on my pad, so check value. value will be the same as Axis::R, which is a problem.
        std::cout << "Axis U Value:" << sf::Joystick::getAxisPosition(0, sf::Joystick::Axis::U) << std::endl;

        // now, we'll open a window --
        sf::RenderWindow window;
        window.create(sf::VideoMode(640, 480), "A Window", sf::Style::Close);

        // -- and reupdate the joystick. If I don't reupdate, the value will be the same as above.
        sf::Joystick::update();

        // value is now -100, since it's technically not available to me.
        std::cout << "Axis U Value:" << sf::Joystick::getAxisPosition(0, sf::Joystick::Axis::U) << std::endl;

        bool done = false;

        while (!done) {

                if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::Escape))
                        done = true;

        }

}

It is my understanding that once I call the first sf::Joystick::update(), the joystick should be ready to go, but it isn't.

EDIT: This is the build I am using: https://github.com/SFML/SFML/tree/265c411c39f498f95a03517818167b47b754c440
« Last Edit: June 12, 2014, 08:06:10 pm by anthnich »

anthnich

  • Newbie
  • *
  • Posts: 34
    • View Profile
    • Long Division LLC
Re: A Concern About Joystick Axises
« Reply #1 on: June 14, 2014, 05:42:33 pm »
Can anyone reproduce this on their end with their gamepad axises?

Hiura

  • SFML Team
  • Hero Member
  • *****
  • Posts: 4321
    • View Profile
    • Email
Re: A Concern About Joystick Axises
« Reply #2 on: June 14, 2014, 07:09:10 pm »
OS?
SFML / OS X developer

anthnich

  • Newbie
  • *
  • Posts: 34
    • View Profile
    • Long Division LLC
Re: A Concern About Joystick Axises
« Reply #3 on: June 15, 2014, 01:57:32 am »
Windows 7.

Jesper Juhl

  • Hero Member
  • *****
  • Posts: 1405
    • View Profile
    • Email
Re: A Concern About Joystick Axises
« Reply #4 on: June 15, 2014, 09:19:30 pm »
Although you are not on Linux I feel the following may be relevant to this (or other people reading this) thread, so I'm just going to leave it here (my point is the Sony ps4 bits): http://www.phoronix.com/scan.php?page=news_item&px=MTY1MjQ
« Last Edit: June 15, 2014, 09:25:11 pm by Jesper Juhl »

anthnich

  • Newbie
  • *
  • Posts: 34
    • View Profile
    • Long Division LLC
Re: A Concern About Joystick Axises
« Reply #5 on: September 05, 2014, 09:19:21 pm »
Sorry about the necro-bump, but I was curious if there is any updates on this? I still have the problem.

While rewriting portions of my engine, I changed around Init() order, so I just open the window before handling Input initialization. But, I figure the parent post will still be a problem if someone uses SFML & a gamepad w/o a window.

Tank

  • SFML Team
  • Hero Member
  • *****
  • Posts: 1486
    • View Profile
    • Blog
    • Email
Re: A Concern About Joystick Axises
« Reply #6 on: September 06, 2014, 09:29:03 am »
I will try to reproduce this with my Logitech game pad and see what I can do next week.

anthnich

  • Newbie
  • *
  • Posts: 34
    • View Profile
    • Long Division LLC
Re: A Concern About Joystick Axises
« Reply #7 on: September 09, 2014, 05:57:04 pm »
Thanks. Hopefully it's not too large of a problem.

 

anything