Add missing joystick handling

This commit is contained in:
Christian Semmler 2026-03-10 20:41:29 -07:00
parent be65af4550
commit 33436ef00f
No known key found for this signature in database
GPG Key ID: 086DAA1360BEEE5C

View File

@ -606,7 +606,7 @@ MxBool ThirdPersonCamera::HandleCameraRelativeMovement(
float p_deltaTime float p_deltaTime
) )
{ {
// Read keyboard state // Read keyboard and touch/joystick state
LegoInputManager* inputManager = InputManager(); LegoInputManager* inputManager = InputManager();
MxU32 keyFlags = 0; MxU32 keyFlags = 0;
if (!inputManager || inputManager->GetNavigationKeyStates(keyFlags) == FAILURE) { if (!inputManager || inputManager->GetNavigationKeyStates(keyFlags) == FAILURE) {
@ -640,6 +640,27 @@ MxBool ThirdPersonCamera::HandleCameraRelativeMovement(
moveDirZ += camRightZ; moveDirZ += camRightZ;
} }
// Mirror CalculateNewPosDir priority: only read joystick/virtual thumbstick
// when no keyboard or e_arrowKeys touch input is active.
if (keyFlags == 0 && inputManager) {
MxU32 joystickX, joystickY, povPosition;
if (inputManager->GetJoystickState(&joystickX, &joystickY, &povPosition) == SUCCESS) {
// Convert 0-100 range (center=50) to -1..1, applying deadzone
float jx = (joystickX - 50.0f) / 50.0f;
float jy = -(joystickY - 50.0f) / 50.0f; // negate: low Y = forward
if (SDL_fabsf(jx) < 0.1f) {
jx = 0.0f;
}
if (SDL_fabsf(jy) < 0.1f) {
jy = 0.0f;
}
moveDirX += camForwardX * jy + camRightX * jx;
moveDirZ += camForwardZ * jy + camRightZ * jx;
}
}
// Normalize movement direction // Normalize movement direction
float moveDirLen = SDL_sqrtf(moveDirX * moveDirX + moveDirZ * moveDirZ); float moveDirLen = SDL_sqrtf(moveDirX * moveDirX + moveDirZ * moveDirZ);
bool hasInput = moveDirLen > 0.001f; bool hasInput = moveDirLen > 0.001f;