Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix emulated wiimote shaking in Wario Land: Shake It, and probably ot…
…hers.

Fixes issue 5295. (probably issue 5017 and issue 5578 too)
  • Loading branch information
jordan-woyak committed Jan 18, 2013
1 parent d05d10d commit 69b1da9
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
23 changes: 17 additions & 6 deletions Source/Core/Core/Src/HW/WiimoteEmu/WiimoteEmu.cpp
Expand Up @@ -15,6 +15,8 @@
// Official SVN repository and contact information can be found at
// http://code.google.com/p/dolphin-emu/

#include <cmath>

#include "Attachment/Classic.h"
#include "Attachment/Nunchuk.h"
#include "Attachment/Guitar.h"
Expand Down Expand Up @@ -89,23 +91,32 @@ const ReportFeatures reporting_mode_features[] =
{ 0, 0, 0, 0, 23 },
};

void EmulateShake( AccelData* const accel
void EmulateShake(AccelData* const accel
, ControllerEmu::Buttons* const buttons_group
, u8* const shake_step )
{
static const double shake_data[] = { -2.5f, -5.0f, -2.5f, 0.0f, 2.5f, 5.0f, 2.5f, 0.0f };
// frame count of one up/down shake
// < 9 no shake detection in "Wario Land: Shake It"
auto const shake_step_max = 15;

// peak G-force
auto const shake_intensity = 3.f;

// shake is a bitfield of X,Y,Z shake button states
static const unsigned int btns[] = { 0x01, 0x02, 0x04 };
unsigned int shake = 0;

buttons_group->GetState( &shake, btns );
for ( unsigned int i=0; i<3; ++i )

for (int i = 0; i != 3; ++i)
{
if (shake & (1 << i))
{
(&(accel->x))[i] = shake_data[shake_step[i]++];
shake_step[i] %= sizeof(shake_data)/sizeof(double);
(&(accel->x))[i] = std::sin(TAU * shake_step[i] / shake_step_max) * shake_intensity;
shake_step[i] = (shake_step[i] + 1) % shake_step_max;
}
else
shake_step[i] = 0;
}
}

void EmulateTilt(AccelData* const accel
Expand Down
7 changes: 6 additions & 1 deletion Source/Core/Core/Src/HW/WiimoteEmu/WiimoteEmu.h
Expand Up @@ -30,7 +30,12 @@
#include <vector>
#include <queue>

#define PI 3.14159265358979323846
namespace
{
// :)
auto const TAU = 6.28318530717958647692;
auto const PI = TAU / 2.0;
}

// Registry sizes
#define WIIMOTE_EEPROM_SIZE (16*1024)
Expand Down

0 comments on commit 69b1da9

Please sign in to comment.