Simplify Motion Pak acceleration conversion formula

This commit is contained in:
Adrian Siekierka 2024-10-31 14:34:30 +01:00
parent f8af7b98c8
commit 10c308a6a4
1 changed files with 11 additions and 15 deletions

View File

@ -59,15 +59,23 @@ u16 CartMotionPakHomebrew::ROMRead(u32 addr) const
static int AccelerationToMotionPak(float accel) static int AccelerationToMotionPak(float accel)
{ {
const float GRAVITY_M_S2 = 9.80665f; const float GRAVITY_M_S2 = 9.80665f;
const int COUNTS_PER_G = 819;
const int CENTER = 2048;
return std::clamp( return std::clamp(
(int) ((accel / GRAVITY_M_S2 * COUNTS_PER_G) + CENTER + 0.5), (int) ((accel / (5 * GRAVITY_M_S2) + 0.5) * 4096),
0, 4095 0, 4095
); );
} }
static int AccelerationToMotionPakRetail(float accel)
{
const float GRAVITY_M_S2 = 9.80665f;
return std::clamp(
(int) ((accel / (5 * GRAVITY_M_S2) + 0.5) * 256),
0, 254
);
}
static int RotationToMotionPak(float rot) static int RotationToMotionPak(float rot)
{ {
const float DEGREES_PER_RAD = 180 / M_PI; const float DEGREES_PER_RAD = 180 / M_PI;
@ -129,18 +137,6 @@ u8 CartMotionPakHomebrew::SRAMRead(u32 addr)
return val; return val;
} }
static int AccelerationToMotionPakRetail(float accel)
{
// Formula provided by xperia64 (melonDS/#74)
const float GRAVITY_M_S2 = 9.80665f;
const float VOLTAGE = 3.3f;
return std::clamp(
(int) ((accel * (VOLTAGE / 5) / GRAVITY_M_S2 + (VOLTAGE / 2)) * 256 / VOLTAGE),
0, 254
);
}
CartMotionPakRetail::CartMotionPakRetail(void* userdata) : CartMotionPakRetail::CartMotionPakRetail(void* userdata) :
CartCommon(MotionPakRetail), CartCommon(MotionPakRetail),
UserData(userdata) UserData(userdata)