Skip to content

Commit

Permalink
Fix Motion Pak emulation axes
Browse files Browse the repository at this point in the history
  • Loading branch information
asiekierka committed Oct 31, 2024
1 parent f9a426b commit 742cff5
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/GBACartMotionPak.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@ u8 CartMotionPakHomebrew::SRAMRead(u32 addr)
return 0;
case 8:
// 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;
case 10:
// Identify cart
Expand Down
26 changes: 24 additions & 2 deletions src/frontend/qt_sdl/EmuInstanceInput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,13 +140,35 @@ float EmuInstance::inputMotionQuery(melonDS::Platform::MotionQueryType type)
{
if (controller && hasAccelerometer)
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)
{
if (controller && hasGyroscope)
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;
}
Expand Down

0 comments on commit 742cff5

Please sign in to comment.