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

Author Topic: Joystick enum Axis  (Read 493 times)

0 Members and 1 Guest are viewing this topic.

infrared511

  • Newbie
  • *
  • Posts: 5
    • View Profile
    • Email
Joystick enum Axis
« on: October 06, 2019, 10:52:00 pm »
Is it possible to change the enumerator numbers in the Joystick.hpp Axis? I know you can edit and change it, but does that affect the rest of the Joystick implementation? My issue is the axis numbers and button numbers are often the same and causes conflict with my bindings when checking the joystick with a constant update, not the event. For instance, PovY = 7 while the right trigger(Dinput) also = 7. Both trigger it's the joystick, but then the ints are the same. With Events, this is kept separate as the events separate Axis and buttons. If I could change the Axis enumerator to start at 12 instead of 0 there will be no int clashes between buttons and Axis's while checking real time.

I hope this made sense and
Thanks.

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6222
  • Thor Developer
    • View Profile
    • Bromeon
Re: Joystick enum Axis
« Reply #1 on: October 06, 2019, 11:28:18 pm »
Each Axis is represented with a different enumerator, with a unique number:
    enum Axis
    {
        X,    ///< The X axis
        Y,    ///< The Y axis
        Z,    ///< The Z axis
        R,    ///< The R axis
        U,    ///< The U axis
        V,    ///< The V axis
        PovX, ///< The X axis of the point-of-view hat
        PovY  ///< The Y axis of the point-of-view hat
    };

Joystick buttons on the other hand are integers, indexed starting from 0. You can easily solve your problem by not mixing Axis and Button -- this is the reason why different types are used to represent both in SFML.

Of course, if you need to have a single address space to represent both axis and button (e.g. for serialization), it should be an easy exercise to achieve that in client code :)

By the way, in case you use Thor, I'm providing functions to serialize joystick axes from/to strings. This would allow you to display this in the game's UI. The documentation can be found here.
« Last Edit: October 06, 2019, 11:30:42 pm by Nexus »
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development: first SFML book

infrared511

  • Newbie
  • *
  • Posts: 5
    • View Profile
    • Email
Re: Joystick enum Axis
« Reply #2 on: October 07, 2019, 02:19:14 am »
Right, but button RT = 7 and so does Axis PovY, they are both integers. I understand keeping them separate, and they are as events. I guess I do not know how to accomplish real time updates while keeping them separate in my code. My original question still stands, will changing the Axis enumeration affect the rest of the code?  To ask further on your solution, how using a Switch Case can I separate real time axis and buttons?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32417
    • View Profile
    • SFML's website
    • Email
Re: Joystick enum Axis
« Reply #3 on: October 07, 2019, 08:45:16 am »
Real-time check of axis position is done with Joystick::getAxisPosition.
Real-time check of button state is done with Joystick::isButtonPressed.

There's no way you can have a conflict.

If you still have troubles, please give more details about (or show) the code you've written.
Laurent Gomila - SFML developer

infrared511

  • Newbie
  • *
  • Posts: 5
    • View Profile
    • Email
Re: Joystick enum Axis
« Reply #4 on: October 07, 2019, 06:56:34 pm »
Real-time check of axis position is done with Joystick::getAxisPosition.
Real-time check of button state is done with Joystick::isButtonPressed.

This is Specific. I can not see if ANY button/axis is registering a press, only a specific button/axis.

If I am updating to see if any button or axis is pressed, like sf::Event::JoystickButtonPressed, then there is a conflict as there is nothing in SFML to allow me to real time check this(Unless I am wrong). I can however check in real time if ANY axis/button is pressed by using the enum values, which as I said overlap. Simply starting axis enum at a higher number would fix this. I am not sure why nobody will answer my question asked so I will just do it and see.

  Thank you anyway.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 9558
    • View Profile
    • development blog
    • Email
Re: Joystick enum Axis
« Reply #5 on: October 07, 2019, 07:27:37 pm »
I think there's a fundamental misunderstand of either what you're trying to do (thus Laurent asked for some code, so we can understand), or your understanding of how SFML operates.

I can however check in real time if ANY axis/button is pressed by using the enum values, which as I said overlap.
That's the part we're not understanding here, as SFML doesn't provide such a functionality, how would you go about doing this?
Official FAQ: https://www.sfml-dev.org/faq.php
Nightly Builds: https://www.nightlybuilds.ch/
——————————————————————
Dev Blog: https://dev.my-gate.net/
Thor: http://www.bromeon.ch/libraries/thor/