Fix Motion Pak emulation axes

This commit is contained in:
Adrian Siekierka 2024-10-31 15:46:43 +01:00
parent f9a426bba6
commit 742cff5dbc
2 changed files with 26 additions and 3 deletions

View File

@ -113,7 +113,8 @@ u8 CartMotionPakHomebrew::SRAMRead(u32 addr)
return 0; return 0;
case 8: case 8:
// Read Z rotation // Read Z rotation
ShiftVal = RotationToMotionPak(Platform::Addon_MotionQuery(Platform::MotionRotationZ, UserData)) << 4; // CHECKME: This is a guess, compare with real hardware
ShiftVal = RotationToMotionPak(-Platform::Addon_MotionQuery(Platform::MotionRotationZ, UserData)) << 4;
return 0; return 0;
case 10: case 10:
// Identify cart // Identify cart

View File

@ -140,13 +140,35 @@ float EmuInstance::inputMotionQuery(melonDS::Platform::MotionQueryType type)
{ {
if (controller && hasAccelerometer) if (controller && hasAccelerometer)
if (SDL_GameControllerGetSensorData(controller, SDL_SENSOR_ACCEL, values, 3) == 0) if (SDL_GameControllerGetSensorData(controller, SDL_SENSOR_ACCEL, values, 3) == 0)
return values[type % 3]; {
// Map values from DS console orientation to SDL controller orientation.
switch (type)
{
case melonDS::Platform::MotionAccelerationX:
return values[0];
case melonDS::Platform::MotionAccelerationY:
return -values[2];
case melonDS::Platform::MotionAccelerationZ:
return values[1];
}
}
} }
else if (type <= melonDS::Platform::MotionRotationZ) else if (type <= melonDS::Platform::MotionRotationZ)
{ {
if (controller && hasGyroscope) if (controller && hasGyroscope)
if (SDL_GameControllerGetSensorData(controller, SDL_SENSOR_GYRO, values, 3) == 0) if (SDL_GameControllerGetSensorData(controller, SDL_SENSOR_GYRO, values, 3) == 0)
return values[type % 3]; {
// Map values from DS console orientation to SDL controller orientation.
switch (type)
{
case melonDS::Platform::MotionRotationX:
return values[0];
case melonDS::Platform::MotionRotationY:
return -values[2];
case melonDS::Platform::MotionRotationZ:
return values[1];
}
}
} }
return 0.0f; return 0.0f;
} }