Merge pull request #2714 from lioncash/clamp

Core: Use clamps for nunchuk and wiimote x,y,z values
This commit is contained in:
skidau 2015-07-20 14:08:00 +10:00
commit 654c44b870
2 changed files with 8 additions and 24 deletions

View File

@ -2,6 +2,7 @@
// Licensed under GPLv2+
// Refer to the license.txt file included.
#include "Common/MathUtil.h"
#include "Core/HW/WiimoteEmu/WiimoteEmu.h"
#include "Core/HW/WiimoteEmu/Attachment/Nunchuk.h"
@ -93,18 +94,9 @@ void Nunchuk::GetState(u8* const data)
s16 accel_y = (s16)(4 * (accel.y * ACCEL_RANGE + ACCEL_ZERO_G));
s16 accel_z = (s16)(4 * (accel.z * ACCEL_RANGE + ACCEL_ZERO_G));
if (accel_x > 1024)
accel_x = 1024;
else if (accel_x < 0)
accel_x = 0;
if (accel_y > 1024)
accel_y = 1024;
else if (accel_y < 0)
accel_y = 0;
if (accel_z > 1024)
accel_z = 1024;
else if (accel_z < 0)
accel_z = 0;
accel_x = MathUtil::Clamp<s16>(accel_x, 0, 1024);
accel_y = MathUtil::Clamp<s16>(accel_y, 0, 1024);
accel_z = MathUtil::Clamp<s16>(accel_z, 0, 1024);
ncdata->ax = (accel_x >> 2) & 0xFF;
ncdata->ay = (accel_y >> 2) & 0xFF;

View File

@ -6,6 +6,7 @@
#include "Common/ChunkFile.h"
#include "Common/CommonTypes.h"
#include "Common/MathUtil.h"
#include "Common/Timer.h"
#include "Core/ConfigManager.h"
#include "Core/Host.h"
@ -404,18 +405,9 @@ void Wiimote::GetAccelData(u8* const data, const ReportFeatures& rptf)
s16 y = (s16)(4 * (m_accel.y * ACCEL_RANGE + ACCEL_ZERO_G));
s16 z = (s16)(4 * (m_accel.z * ACCEL_RANGE + ACCEL_ZERO_G));
if (x > 1024)
x = 1024;
else if (x < 0)
x = 0;
if (y > 1024)
y = 1024;
else if (y < 0)
y = 0;
if (z > 1024)
z = 1024;
else if (z < 0)
z = 0;
x = MathUtil::Clamp<s16>(x, 0, 1024);
y = MathUtil::Clamp<s16>(y, 0, 1024);
z = MathUtil::Clamp<s16>(z, 0, 1024);
accel.x = (x >> 2) & 0xFF;
accel.y = (y >> 2) & 0xFF;