evilC / UCR

Universal Control Remapper [ALPHA]
MIT License
197 stars 31 forks source link

Deadzone (and maybe other calcs?) are a box, not a circle #74

Open evilC opened 8 years ago

evilC commented 8 years ago

Maybe need circle deadzone etc for XBOX controller users, as the throw of an xbox stick is circular, not square like a flightstick.

EternalDahaka commented 8 years ago

Do you just need the calculations?

http://www.third-helix.com/2013/04/12/doing-thumbstick-dead-zones-right.html This is a good reference for that. Just use the distance from the center to make a circular deadzone(instead of from the axes which makes a square/axial), and rescale the values so you get the full range outside of the deadzone. You might need to translate the XInput values to a +-1 range if they aren't already.

It sort of looks like one of the things you're doing with this UCR program is input joystick > mouse output so you might want some other stuff for that. For the basic angles, you can just use some basic trig for that with something like angle = arctan(stickY/stickX)

and use the sine and cosine for the output movement outputVector(cos(angle), sin(angle))

Depending on the mouse functions you may need to invert the sine( I used a crude mouse.Position function which edits the pixel movement, but using an actual move function might be different- the angle alone might be sufficient [I'm not a programmer, so I'm ignorant of most things] )

If you already had the latter information, sorry for the fluff.

evilC commented 8 years ago

This is a great source of info, many thanks for bringing it to my attention.

evilC commented 8 years ago

This image from that guide is kind of misleading. DeadZone image The entire red area is not "dead". The vertical part is dead for the X axis, the horizontal part is dead for Y.

UCR's deadzone calcs, whilst "square", already re-scale the space outside the deadzone, so input "ramps up" as described in the "The High-Precision Problem" section. The math for that is here. I took it directly from UJR, and it seems to have stood the test of time well. If you can improve it, I am all ears though.

The only thing that UCR currently does not do is the circular deadzone. Currently, all UCR's axis remapping plugins are one axis per plugin, so in order to implement this, I would need to make two-axis versions of these plugins (So it has access to the X and Y values) and then implement new 2D deadzone code. I am currently holding off writing too many plugins, because the possibility of quite major changes still loom, and I do not want to burden myself with having to maintain too many plugins.

There is nothing, however, stopping anyone from writing such a plugin themselves - UCR would not need any modification itself in order to support this.

EternalDahaka commented 8 years ago

True, though the article mentions that the view "snaps" to the cardinals, which is accurate to how it works.

image

This however, would be a more accurate visual representation.

The code is fine, and is basically what the article advocates. The only difference would be to replace the "value" variable with the magnitude of both axes, simply gotten by the distance formula rather than the axis value. magntitude = root( [stickX]^2 + [stickY]^2 );

A square deadzone is fine though, depending on what it's used for. For single axis applications it's functionally the exact same, but for things like mouse movement, you'd get more intuitive and correct movements with a circular deadzone.