Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

1411526 Posts in 69381 Topics- by 58436 Members - Latest Member: GlitchyPSI

May 01, 2024, 11:49:48 PM

Need hosting? Check out Digital Ocean
(more details in this thread)
TIGSource ForumsDeveloperTechnical (Moderator: ThemsAllTook)Gamepad HAT switch, how does it work?
Pages: [1]
Print
Author Topic: Gamepad HAT switch, how does it work?  (Read 12724 times)
Ben_Hurr
Level 10
*****


nom nom nom


View Profile
« on: October 20, 2013, 08:23:59 AM »

This is probably a dum question, but how do HAT Switches on gamepads work (The D-Pad if you're not familiar)?

Like, is their output continuous (0.0-1.0, 0-360), or do they just spit out discrete values (UP,UP/RIGHT,RIGHT,etc)?
I ask because with the libraries I'm working with plus my own gamepad it seems to spit out discrete floating point values, and that's really annoying to deal with when you just want UP/RIGHT/DOWN/LEFT with overlapping diagonals.  Roll Eyes

...That and there doesn't seem to be anything on the internet about this either.  WTF
Logged
nikki
Level 10
*****


View Profile
« Reply #1 on: October 20, 2013, 08:31:05 AM »

I've recently set up an controller and saw xaxis yaxis values pop op, I thus assume a dpad send out x axis y axis values (probably between 0 and 1.0, or maybe -1, 1)

I hope someone with more knowledge drops in this thread though
Logged
ThemsAllTook
Administrator
Level 10
******



View Profile WWW
« Reply #2 on: October 20, 2013, 08:48:57 AM »

The way I've dealt with hat switches in my gamepad library has been to report them as pairs of axes, essentially treating them as d-pads. The underlying APIs for Mac OS X and Windows both report integer values from 0-8 (Mac OS X provides facilities for arbitrary ranges, but as I recall 0-8 is the only one I've seen), with each number representing one of eight directions, and another for the neutral position. 0 is up, 1 is up-right, and it proceeds clockwise as you'd expect. 8 represents the neutral position. Interestingly, Linux just reports them as axes in the first place, so no additional translation was necessary there.

It's a little bit gross, but here's the function I use on Windows to translate from a hat switch input value to a pair of axes:

Code:
static void povToXY(DWORD pov, int * outX, int * outY) {
if (pov == JOY_POVCENTERED) {
*outX = *outY = 0;

} else {
if (pov > JOY_POVFORWARD && pov < JOY_POVBACKWARD) {
*outX = 1;

} else if (pov > JOY_POVBACKWARD) {
*outX = -1;

} else {
*outX = 0;
}

if (pov > JOY_POVLEFT || pov < JOY_POVRIGHT) {
*outY = -1;

} else if (pov > JOY_POVRIGHT && pov < JOY_POVLEFT) {
*outY = 1;

} else {
*outY = 0;
}
}
}
Logged

Ben_Hurr
Level 10
*****


nom nom nom


View Profile
« Reply #3 on: October 20, 2013, 09:25:48 AM »

If what you say is true, and all HAT type devices only spit out discrete number ranges like 0-8, then that makes things much easier.

For starts, I don't have to worry about a magical POV switchs that return 1-360 degrees!
Logged
zacaj
Level 3
***


void main()


View Profile WWW
« Reply #4 on: October 20, 2013, 10:05:52 AM »

SDL's HAT switch api also reports integers like that
Logged

My twitter: @zacaj_

Quote from: mcc
Well let's just take a look at this "getting started" page and see--
Quote
Download and install cmake
Noooooooo
Ben_Hurr
Level 10
*****


nom nom nom


View Profile
« Reply #5 on: October 20, 2013, 11:23:53 AM »

Welp, I managed to get hat switches to work perfectly.
Thanks for the help guys!  Tears of Joy
Logged
Average Software
Level 10
*****

Fleeing all W'rkncacnter


View Profile WWW
« Reply #6 on: October 21, 2013, 04:43:23 AM »

This is probably a dum question, but how do HAT Switches on gamepads work (The D-Pad if you're not familiar)?

Just in case you don't know, the vast majority of d-pads are not hatswitches.  The XBox 360 pad is the only one I'm aware of.  This is part of the reason why that d-pad generally sucks for fighting games.
Logged



What would John Carmack do?
Ben_Hurr
Level 10
*****


nom nom nom


View Profile
« Reply #7 on: October 21, 2013, 10:28:55 AM »

Oh boy.  Sad
Logged
InfiniteStateMachine
Level 10
*****



View Profile
« Reply #8 on: October 21, 2013, 10:49:33 AM »

This is probably a dum question, but how do HAT Switches on gamepads work (The D-Pad if you're not familiar)?

Just in case you don't know, the vast majority of d-pads are not hatswitches.  The XBox 360 pad is the only one I'm aware of.  This is part of the reason why that d-pad generally sucks for fighting games.

can you elaborate? Do you mean internally they return non-discrete values?

Ultimately when the other option is a analog stick then you are kind of screwed for fighting games in general.
Logged

zacaj
Level 3
***


void main()


View Profile WWW
« Reply #9 on: October 21, 2013, 10:50:56 AM »

Aren't fighting games played on joysticks usually?  0-8 would work just fine for an arcade joystick
Logged

My twitter: @zacaj_

Quote from: mcc
Well let's just take a look at this "getting started" page and see--
Quote
Download and install cmake
Noooooooo
InfiniteStateMachine
Level 10
*****



View Profile
« Reply #10 on: October 21, 2013, 11:11:36 AM »

yeah I'm not exactly sure about that. Gamepads in general are bad for fighting games but the dpad is the best option (except for the 360 dpad which is an abomination).
Logged

Average Software
Level 10
*****

Fleeing all W'rkncacnter


View Profile WWW
« Reply #11 on: October 21, 2013, 01:03:11 PM »

This is probably a dum question, but how do HAT Switches on gamepads work (The D-Pad if you're not familiar)?

Just in case you don't know, the vast majority of d-pads are not hatswitches.  The XBox 360 pad is the only one I'm aware of.  This is part of the reason why that d-pad generally sucks for fighting games.

can you elaborate? Do you mean internally they return non-discrete values?

Most d-pads are implemented as four contact points and report as two axes with three positions each (high, low, neutral).  There is no 'diagonal' input from the pad, diagonal is just a combination of two independent axis values.

The 360 d-pad actually reports diagonals as a separate input because it's a true hat switch.

Quote from: InfiniteStateMachine
yeah I'm not exactly sure about that. Gamepads in general are bad for fighting games but the dpad is the best option (except for the 360 dpad which is an abomination).

The Sega Saturn pads were fantastic for fighting games, better than sticks for many games.  A lot of serious fighting gamers like myself consider them to be the finest pads ever made.  The 6-button Street Fighter layout helps too.

The reason hats suck for fighters is that it's usually more difficult to hit a diagonal on them.  With a sticks it usually isn't a problem, but for pads it's actually really annoying.
Logged



What would John Carmack do?
InfiniteStateMachine
Level 10
*****



View Profile
« Reply #12 on: October 21, 2013, 01:23:28 PM »

Interesting. So under the 360's terrible jacket there's something good under there.

I do remember those saturn pads. They kind of defaulted as the best for me at the time mainly because of the 6 buttons (I'm a big SF player too).

I guess I've never noticed because I use joysticks for fighting games so I never really noticed when using a dpad.
Logged

Ben_Hurr
Level 10
*****


nom nom nom


View Profile
« Reply #13 on: October 23, 2013, 03:59:57 PM »

...

The reason hats suck for fighters is that it's usually more difficult to hit a diagonal on them.  With a sticks it usually isn't a problem, but for pads it's actually really annoying.
Well lucky for you I got it so you can nicely slide your thumb around the DPad and have it register diagonals reliably then!  Corny Laugh
Logged
Sik
Level 10
*****


View Profile WWW
« Reply #14 on: October 23, 2013, 05:05:59 PM »

Just in case somebody gets confused:
SDL's HAT switch api also reports integers like that
It actually reports a bitfield, i.e. one bit for each direction (the constants for the diagonals are just values that have two of the bits set).

The Sega Saturn pads were fantastic for fighting games, better than sticks for many games.  A lot of serious fighting gamers like myself consider them to be the finest pads ever made.  The 6-button Street Fighter layout helps too.
Well, it was based on the 6-button controller for the Mega Drive, which in turn was made specifically for fighting games (and more specifically, Street Fighter II), so it's not surprising it's actually good for those.

Also something that Mega Drive controller did extremely well was the D-pad responsiveness. Actually, it's pretty much the same as the one in the 3-button controller, but it has way more spacing around it (you can even see under the D-pad), but that means that pressing in any direction pretty much takes zero effort, while the D-pad still won't be overly sensitive and trigger directions that weren't supposed to be pressed. The best part is that the design is so simple that even cheap Chinese clone knock-offs tend to be good o.O (at least in my experience)

The reason hats suck for fighters is that it's usually more difficult to hit a diagonal on them.  With a sticks it usually isn't a problem, but for pads it's actually really annoying.
Something the Mega Drive and the Saturn controllers avert. It looks like the XBox One controller is using that kind of D-pad too, but it could be just the looks for all I know =P
Logged
Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic