• Login
  • Register
  • Dolphin Forums
  • Home
  • FAQ
  • Download
  • Wiki
  • Code


Dolphin, the GameCube and Wii emulator - Forums › Dolphin Emulator Discussion and Support › Development Discussion v
« Previous 1 ... 26 27 28 29 30 ... 117 Next »

Normalized analog stick input
View New Posts | View Today's Posts

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Thread Modes
Normalized analog stick input
10-05-2016, 06:51 PM
#1
BlueWanderer
Unregistered
 
It seems that at least for Xbox 360 controllers the input from an analog stick should be normalized. That is, for example, if I push the stick to the "corners", the magnitude should be 1 instead of square root of 2.

There are games where this is problematic that I either cannot walk in diagonal directions or cannot run in perpendicular directions.

I changed the GetState function of AnalogStick class, on the "stable" branch. There ought to be a switch for this I think, but I don't want to find out where to add it. So I guess it's a good idea for some else to deal with the repository.

Code:
        void GetState(ControlState* const x, ControlState* const y)
        {
            ControlState yy = controls[0]->control_ref->State() - controls[1]->control_ref->State();
            ControlState xx = controls[3]->control_ref->State() - controls[2]->control_ref->State();

            ControlState radius = settings[SETTING_RADIUS]->value;
            ControlState deadzone = settings[SETTING_DEADZONE]->value;
            ControlState m = controls[4]->control_ref->State();

            if (m)
            {
                radius *= 0.5;
            }

            ControlState max_a = std::max(std::abs(xx), std::abs(yy));

            // Short circuit if within deadzone
            // max_a == 0 check is not required if deadzone is alway non-negtive, but I don't know
            if (max_a <= deadzone || max_a == 0)
            {
                *x = 0;
                *y = 0;
            }
            // Scale down the value by the maximum magnitude on the current direction (distance(xx, yy) / max(abs(xx), abs(yy)))
            else
            {
                ControlState dead_x = deadzone * (xx / max_a);
                ControlState dead_y = deadzone * (yy / max_a);

                xx = (xx > 0 ? xx - dead_x : xx + dead_x) / (1 - deadzone);
                yy = (yy > 0 ? yy - dead_y : yy + dead_y) / (1 - deadzone);

                ControlState scale = radius * max_a / std::sqrt(xx * xx + yy * yy);

                *x = xx * scale;
                *y = yy * scale;
            }
        }

----

Guess I forgot to clamp the final results...
Reply
10-05-2016, 09:04 PM
#2
leolam Offline
Developer
**********
Developers (Some Administrators and Super Moderators)
Posts: 1,478
Threads: 5
Joined: Sep 2015
The stable branch is pretty much out-of-date (though there haven't been huge changes to the input code since the 5.0 RCs). A real patch to the master branch would be more useful, so that people can figure out what you changed instantly

By the way, you may want to discuss this on IRC (#dolphin-dev on freenode) and maybe submit a PR? Wink
Website Find
Reply
10-06-2016, 12:09 PM
#3
BlueWanderer
Unregistered
 
(10-05-2016, 09:04 PM)leolam Wrote: The stable branch is pretty much out-of-date (though there haven't been huge changes to the input code since the 5.0 RCs). A real patch to the master branch would be more useful, so that people can figure out what you changed instantly

By the way, you may want to discuss this on IRC (#dolphin-dev on freenode) and maybe submit a PR? Wink
I couldn't get the current head of master branch working Sad But I located the release version of 5.0, and that function is unmodified. In the head version, only difference is "settings" renamed to "numeric_settings".

I'm not an open source project guy (for example, I don't really know what a PR is _(:з)∠)_), and holiday ends tomorrow... So much I can do I think.

----

Ah, I guess PR means Pull Request. I don't know this is good to be pushed to server, for I don't know the protocols in an open source project Sad And there'd be a lot more work to do to make it a function.
Reply
10-07-2016, 04:22 AM
#4
Aleron Ives Offline
Senior Member
****
Posts: 662
Threads: 7
Joined: Apr 2014
That's sort of the point of a pull request. You suggest a change to the other developers, then you discuss it with the other developers and make improvements until they decide the change is ready to be merged into the master branch.
Find
Reply
10-16-2016, 06:18 AM (This post was last modified: 10-16-2016, 06:18 AM by akyryz.)
#5
akyryz Offline
Junior Member
**
Posts: 37
Threads: 4
Joined: Aug 2010
same issue with this https://forums.dolphin-emu.org/Thread-wii-classic-controller-not-normalized

a picture showing:

[Image: attachment.php?aid=14837]
Find
Reply
10-19-2016, 03:15 AM
#6
BlueWanderer
Unregistered
 
(10-07-2016, 04:22 AM)Aleron Ives Wrote: That's sort of the point of a pull request. You suggest a change to the other developers, then you discuss it with the other developers and make improvements until they decide the change is ready to be merged into the master branch.

I failed even push the change Sad Actually I can't login this forum for the past one week. So I post it here in case someone would like to update it.
Reply
10-19-2016, 04:27 AM
#7
BlueWanderer
Unregistered
 
(10-16-2016, 06:18 AM)akyryz Wrote: same issue with this https://forums.dolphin-emu.org/Thread-wii-classic-controller-not-normalized

a picture showing:

[Image: attachment.php?aid=14837]

If you have the environment you can paste my code. Classic controllers and GC controllers use the same routine.
Reply
« Next Oldest | Next Newest »


  • View a Printable Version
  • Subscribe to this thread
Forum Jump:


Users browsing this thread: 2 Guest(s)



Powered By MyBB | Theme by Fragma

Linear Mode
Threaded Mode