Skip to content

Commit

Permalink
Modify DInput and touch analog to not clamp to a circle. Tries to fix #…
Browse files Browse the repository at this point in the history
  • Loading branch information
hrydgard committed Jun 19, 2013
1 parent 61b510b commit fa335c8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
18 changes: 16 additions & 2 deletions Windows/DinputDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.

#include <limits.h>
#include <algorithm>

#include "Core/HLE/sceCtrl.h"
#include "DinputDevice.h"
#include "ControlMapping.h"
Expand All @@ -25,6 +27,11 @@
#include "Xinput.h"
#pragma comment(lib,"dinput8.lib")

#ifdef min
#undef min
#undef max
#endif

unsigned int dinput_ctrl_map[] = {
11, PAD_BUTTON_MENU, // Open PauseScreen
10, PAD_BUTTON_BACK, // Toggle PauseScreen & Back Setting Page
Expand Down Expand Up @@ -183,8 +190,15 @@ int DinputDevice::UpdateState(InputState &input_state)

if (analog)
{
input_state.pad_lstick_x += (float)js.lX / 10000.f;
input_state.pad_lstick_y += -((float)js.lY / 10000.f);
float x = (float)js.lX / 10000.f;
float y = -((float)js.lY / 10000.f);

// Expand and clamp. Hack to let us reach the corners on most pads.
x = std::min(1.0f, std::max(-1.0f, x * 1.2f));
y = std::min(1.0f, std::max(-1.0f, y * 1.2f));

input_state.pad_lstick_x += x;
input_state.pad_lstick_y += y;
}

for (u8 i = 0; i < sizeof(dinput_ctrl_map)/sizeof(dinput_ctrl_map[0]); i += 2)
Expand Down
2 changes: 1 addition & 1 deletion native
Submodule native updated 1 files
+9 −6 ui/virtual_input.cpp

3 comments on commit fa335c8

@Squall-Leonhart
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

peak range for corners is still far from the full square range,

seeing peak values of 104 - 106 on each axes when cornered.

Seemingly, all this hack has done is amplified the range values causing the stick to believe it is fully moved in any given direction before its even close to the physical limit of the pad.

@hrydgard
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed that's what it does, which is not really ideal but still seems to have fixed movements in those games that required it to go far out in the corners - or do you still have games with issues with that?

Can find a nicer "squaring the circle" method later that doesn't suffer from the "sudden max" problem that you mention.

@Squall-Leonhart
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Sin(atan) in that code example is to ensure the scaling is adjusted to angular input without boosting the cardinal inputs i assume.

I didn't do too well in math though, so i may be wrong.

Please sign in to comment.