summaryrefslogtreecommitdiffstats
path: root/content/browser/gamepad
diff options
context:
space:
mode:
authorscottmg@chromium.org <scottmg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-03-24 20:45:49 +0000
committerscottmg@chromium.org <scottmg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-03-24 20:45:49 +0000
commit9862082a9b4cf2affde748b230b2c2e0b3248d38 (patch)
tree62e178b64de9f3df2550e5475adf19fe2d0aeabe /content/browser/gamepad
parent1192339cc77909d203a40ce01919f55fec39413f (diff)
downloadchromium_src-9862082a9b4cf2affde748b230b2c2e0b3248d38.zip
chromium_src-9862082a9b4cf2affde748b230b2c2e0b3248d38.tar.gz
chromium_src-9862082a9b4cf2affde748b230b2c2e0b3248d38.tar.bz2
Fix range of gamepad axis values on Windows
Previously was being normalized via division by 32767, but the range is documented to be -32768..32767 so we need to bias to not exceed -1..1 and get the full range. Also inspected the Linux code expecting a similar bug, but the range there is documented to be -32767..32767 so simple division suffices. R=rsleevi BUG=119791 Review URL: http://codereview.chromium.org/9838078 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@128773 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content/browser/gamepad')
-rw-r--r--content/browser/gamepad/platform_data_fetcher_win.cc12
1 files changed, 7 insertions, 5 deletions
diff --git a/content/browser/gamepad/platform_data_fetcher_win.cc b/content/browser/gamepad/platform_data_fetcher_win.cc
index 8c30264..ce07b5f 100644
--- a/content/browser/gamepad/platform_data_fetcher_win.cc
+++ b/content/browser/gamepad/platform_data_fetcher_win.cc
@@ -33,7 +33,9 @@ static const BYTE kDeviceSubTypeDrumKit = 8;
static const BYTE kDeviceSubTypeGuitarBass = 11;
static const BYTE kDeviceSubTypeArcadePad = 19;
-const float kMaxWinAxisValue = 32767.0;
+float NormalizeAxis(SHORT value) {
+ return ((value + 32768.f) / 32767.5f) - 1.f;
+}
const WebUChar* const GamepadSubTypeName(BYTE sub_type) {
switch (sub_type) {
@@ -162,10 +164,10 @@ void GamepadPlatformDataFetcherWin::GetGamepadData(WebGamepads* pads,
#undef ADD
pad.axesLength = 0;
// XInput are +up/+right, -down/-left, we want -up/-left.
- pad.axes[pad.axesLength++] = state.Gamepad.sThumbLX / kMaxWinAxisValue;
- pad.axes[pad.axesLength++] = -state.Gamepad.sThumbLY / kMaxWinAxisValue;
- pad.axes[pad.axesLength++] = state.Gamepad.sThumbRX / kMaxWinAxisValue;
- pad.axes[pad.axesLength++] = -state.Gamepad.sThumbRY / kMaxWinAxisValue;
+ pad.axes[pad.axesLength++] = NormalizeAxis(state.Gamepad.sThumbLX);
+ pad.axes[pad.axesLength++] = -NormalizeAxis(state.Gamepad.sThumbLY);
+ pad.axes[pad.axesLength++] = NormalizeAxis(state.Gamepad.sThumbRX);
+ pad.axes[pad.axesLength++] = -NormalizeAxis(state.Gamepad.sThumbRY);
} else {
pad.connected = false;
}