Need smart someone who knows XInput
Page 1 of 1
sTo0z
[Moderator] Babysitter



Posts: 7449
Location: USA
PostPosted: Wed, 10th May 2017 22:18    Post subject: Need smart someone who knows XInput
plz Crying or Very sad


Back to top
sTo0z
[Moderator] Babysitter



Posts: 7449
Location: USA
PostPosted: Fri, 12th May 2017 14:35    Post subject:
How about someone just smart at math? Very Happy

Got what I needed (mostly) working, but trying to implement a thing that I don't fully understand, need more math powers.


Back to top
paxsali
Banned



Posts: 18352

PostPosted: Fri, 12th May 2017 14:54    Post subject:
⁢⁢


Last edited by paxsali on Thu, 4th Jul 2024 21:13; edited 1 time in total
Back to top
garus
VIP Member



Posts: 34200

PostPosted: Fri, 12th May 2017 15:18    Post subject:
snip


Last edited by garus on Tue, 27th Aug 2024 21:33; edited 1 time in total
Back to top
Nui
VIP Member



Posts: 5720
Location: in a place with fluffy towels
PostPosted: Fri, 12th May 2017 15:56    Post subject:
Well, considering the current description, I would suggest taking the input x of your problem domain and to create a function f, so that f(x) = y assuming that y is the corresponding solution. You're welcome.


kogel mogel
Back to top
LeoNatan
Banned



Posts: 73193
Location: Ramat Gan, Israel 🇮🇱
PostPosted: Fri, 12th May 2017 16:20    Post subject:
Vote to close the question: unclear what you are asking
Back to top
paxsali
Banned



Posts: 18352

PostPosted: Fri, 12th May 2017 16:47    Post subject:
⁢⁢


Last edited by paxsali on Thu, 4th Jul 2024 21:13; edited 1 time in total
Back to top
sTo0z
[Moderator] Babysitter



Posts: 7449
Location: USA
PostPosted: Fri, 12th May 2017 19:10    Post subject:
LOL, true I guess. It was sort of a call for someone to reach out to me, but I guess we can do it this way. Wink

Trying to implement scaled dead zone on left joystick for driving games.

I have this basic implementation working in DirectInput:

https://msdn.microsoft.com/en-us/library/windows/desktop/ee417001(v=vs.85).aspx#dead_zone

DirectInput range goes from 0 to 65535, XInput goes from -32768 to 32767, so I just did a basic offset by subtracting 32767 from DirectInput, then followed the article above.

It's ok, but not good enough. Was trying to implement this:
http://www.third-helix.com/2013/04/12/doing-thumbstick-dead-zones-right.html

The section labeled "The Right Way — Scaled Radial Dead Zone"

Just need it for the X axis really, but when I tried to implement, I didn't quite follow. Maybe Unity is doing something I don't understand, trying to adapt this to C# SharpDX/DirectInput.

When I implemented, TINY inputs returned reverse direction and results that did't make sense.

For example, if 0 is the center, and deadzone is 7182, if I push joystick RIGHT just enough to return a 10,000, when I run that through the formula, tiny amounts come out to a negative value.

Full disclosure, I am awful at coding and I barely know C# and know less about DirectInput.


Back to top
PumpAction
[Schmadmin]



Posts: 26759

PostPosted: Sat, 13th May 2017 00:39    Post subject:
uhm.. maybe I didn't get your question properly but why don't you just:

deadx = 7182;
maxx = 32768;

absx = abs(x); // absolute value of x which is always positive

if (absx > deadx) // if your x is greater than your deadzone value

move(((maxx - deadx) / (absx - deadx)) * (absx / x) ); // move will be 1 if you are at the max position and at 0 if you are at the deadzone position. between deadzone and max it will scale linearly. (absx / x) makes sure that move will receive a negative value if x was negative.

Should work, no? I have never put in any deadzone stuff but I guess if you go for a linear scale AFTER passing the deadzone, this should work? Alternatively define a bezier function and pass it (((maxx - deadx) / (absx - deadx)) * (absx / x) to return a different -1 < d < 1 for your move function Smile


=> NFOrce GIF plugin <= - Ryzen 3800X, 16GB DDR4-3200, Sapphire 5700XT Pulse
Back to top
PumpAction
[Schmadmin]



Posts: 26759

PostPosted: Sun, 14th May 2017 02:04    Post subject:
btw take into account that this is only for one axis. if you implement this on x and y you will just have a rectangular shitty deadzone. To account for this implement that your distance is sqrt(x²+y²)


=> NFOrce GIF plugin <= - Ryzen 3800X, 16GB DDR4-3200, Sapphire 5700XT Pulse
Back to top
Nui
VIP Member



Posts: 5720
Location: in a place with fluffy towels
PostPosted: Sun, 14th May 2017 12:55    Post subject:
@sTo0z maybe you could just post the relevant dead zone code we'll check if that seems fine?


kogel mogel
Back to top
sTo0z
[Moderator] Babysitter



Posts: 7449
Location: USA
PostPosted: Sun, 14th May 2017 14:48    Post subject:
Ya I guess I forgot to ask a question, lol.

I guess I was focused on this guy's solution because I had the faith that he knew what he was talking about and came to this final solution. Wink

My question is:

Given a raw XInput value of 10,000 (very small right turn, just enough to escape deadzone), can someone run that through the formula and tell me what the result is supposed to be?

Here is my current DirectInput (offset to be XInput) code. Again, I'm bad, have mercy. Also, ignore the part where I offset by +1 and convert to 0 - 255 range... Razz



Code:
if (state.Offset == JoystickOffset.X)
                            {
                                // DEADZONE STUFF

                                // OFFSET VALUE FOR CALCULATIONS
                                int LX = state.Value - 32767;

                                // SETUP
                                double deadzone = 0.25f * 32767;
                                double magnitude = Math.Sqrt(LX * LX);
                                double normalizedLX = LX / magnitude;
                                double normalizedMagnitude = 0;

                                // CALCULATE
                                if (magnitude > deadzone)
                                {
                                    if (magnitude > 32767) magnitude = 32767;

                                    magnitude -= deadzone;
                                    normalizedMagnitude = (normalizedLX * (magnitude / (32767 - deadzone))) + 1;
                                    int oldRange = 2;
                                    int newRange = 255;
                                    normalizedMagnitude = (normalizedMagnitude * newRange) / oldRange;
                                }
                                else
                                {
                                    magnitude = 127.5;
                                    normalizedMagnitude = 127.5;
                                }

                                int finalMagnitude = Convert.ToInt32(normalizedMagnitude);
                                InputCode.Wheel = finalMagnitude;
                            }


So,
Question 1) Input 10,000, how would that go through the linked formula?
Question 2) How do I get that into my current code correctly?


Back to top
Nui
VIP Member



Posts: 5720
Location: in a place with fluffy towels
PostPosted: Sun, 14th May 2017 15:20    Post subject:
sTo0z wrote:

Question 1) Input 10,000, how would that go through the linked formula?
Question 2) How do I get that into my current code correctly?


1)
seems easier to calculate when normalizing values to be in -1, 1
with 10000 input and deadzone of 0.25
Code:

10000 / 32767 = 0.305 // normalize to -1,1
0.305 - 0.25 = 0.055 // subtract deadzone from magnitude
0.055 / (1-0.25) = 0.0733 // scale back up
0.0733 * 32767 = 2402.91 // reverse normalization if even needed


2)
sTo0z wrote:
Code:
                                    normalizedMagnitude = (normalizedLX * (magnitude / (32767 - deadzone)));

You need to subtract the deadzone from your magnitude and then scale back up correctly. This should be your problem.
If you want to follow the links formula but keep these non normalized values you need to muck around with the scaling factor
Code:
                                    normalizedMagnitude = (normalizedLX * (magnitude - deadzone) / ((32767 - deadzone) / 32767)));


Or if you keep deadzone at 0.25
Code:
                                    normalizedMagnitude = (normalizedLX * (magnitude - deadzone*32767) / (1 - deadzone)));


But can you not normalize to -1,1 for everything? Seems easier to deal with than these numbers.

And btw, why do you set the magnitude to 127.5 when in the deadzone?
Back to top
sTo0z
[Moderator] Babysitter



Posts: 7449
Location: USA
PostPosted: Sun, 14th May 2017 15:44    Post subject:
Yah seemed like the linked code enjoyed the "normalized" -1 to 1 range, that's why I offset initially to get away from the 0 through 65535 range.

Ok let me try and poke through your response to keep up, I am slow but I'll get there Very Happy

Nui wrote:
And btw, why do you set the magnitude to 127.5 when in the deadzone?


The final destination accepts a basic range from 0 to 255 Sad So if it's in the deadzone, my understanding is to just send true center instead. I realize 127.5 is foolish when I convert to int right after, but I liked to keep the "truth" in the code to improve later.


Back to top
Nui
VIP Member



Posts: 5720
Location: in a place with fluffy towels
PostPosted: Sun, 14th May 2017 15:48    Post subject:
I see. That seems strange, but oh well Smile


kogel mogel
Back to top
Page 1 of 1 All times are GMT + 1 Hour
NFOHump.com Forum Index - Programmers Corner
Signature/Avatar nuking: none (can be changed in your profile)  


Display posts from previous:   

Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB 2.0.8 © 2001, 2002 phpBB Group