Simplify Motion Pak acceleration conversion formula
This commit is contained in:
parent
f8af7b98c8
commit
10c308a6a4
|
@ -59,15 +59,23 @@ u16 CartMotionPakHomebrew::ROMRead(u32 addr) const
|
|||
static int AccelerationToMotionPak(float accel)
|
||||
{
|
||||
const float GRAVITY_M_S2 = 9.80665f;
|
||||
const int COUNTS_PER_G = 819;
|
||||
const int CENTER = 2048;
|
||||
|
||||
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
|
||||
);
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
const float DEGREES_PER_RAD = 180 / M_PI;
|
||||
|
@ -129,18 +137,6 @@ u8 CartMotionPakHomebrew::SRAMRead(u32 addr)
|
|||
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) :
|
||||
CartCommon(MotionPakRetail),
|
||||
UserData(userdata)
|
||||
|
|
Loading…
Reference in New Issue