Added WIP mouse support to the free cam

This commit is contained in:
MelonSpeedruns 2022-05-22 11:41:41 -04:00
commit 9e48935186
6 changed files with 50 additions and 15 deletions

View file

@ -14,25 +14,27 @@ namespace Ship {
Attachment = nullptr;
}
SDL_Event ev;
void Controller::Read(OSContPad* pad) {
ReadFromSource();
// Mouse Inputs
// Touch Inputs
int x, y;
Uint32 buttons;
SDL_PumpEvents();
buttons = SDL_GetMouseState(&x, &y);
wTouchX = x;
wTouchY = y;
// Click Inputs
if ((buttons & SDL_BUTTON_LMASK) != 0) {
wLeftClick = 1;
}
else {
wLeftClick = 0;
}
if ((buttons & SDL_BUTTON_RMASK) != 0) {
wRightClick = 1;
}
@ -40,8 +42,18 @@ namespace Ship {
wRightClick = 0;
}
// Mouse Inputs
int x2, y2;
Uint32 buttons2;
SDL_PumpEvents();
buttons2 = SDL_GetRelativeMouseState(&x2, &y2);
wMouseMoveX = x2;
wMouseMoveY = y2;
// Button Inputs
pad->button |= dwPressedButtons & 0xFFFF;
// Stick Inputs
if (pad->stick_x == 0) {
if (dwPressedButtons & BTN_STICKLEFT) {
pad->stick_x = -128;
@ -66,16 +78,23 @@ namespace Ship {
}
}
// Gyro
pad->gyro_x = wGyroX;
pad->gyro_y = wGyroY;
// Right Stick
pad->cam_x = wCamX;
pad->cam_y = wCamY;
// Click/Touch
pad->touch_x = wTouchX;
pad->touch_y = wTouchY;
pad->left_click = wLeftClick;
pad->right_click = wRightClick;
// Mouse
pad->mouse_move_x = wMouseMoveX;
pad->mouse_move_y = wMouseMoveY;
}
void Controller::SetButtonMapping(const std::string& szButtonName, int32_t dwScancode) {

View file

@ -46,6 +46,9 @@ namespace Ship {
float wCamX;
float wCamY;
float wMouseMoveX;
float wMouseMoveY;
virtual std::string GetControllerType() = 0;
virtual std::string GetConfSection() = 0;
virtual std::string GetBindingConfSection() = 0;

View file

@ -118,9 +118,11 @@ typedef struct {
/* 0x0B */ u8 right_click;
/* 0x0C */ f32 touch_x;
/* 0x10 */ f32 touch_y;
/* 0x14 */ f32 cam_x;
/* 0x18 */ f32 cam_y;
} OSContPad; // size = 0x1C
/* 0x14 */ f32 mouse_move_x;
/* 0x18 */ f32 mouse_move_y;
/* 0x1C */ f32 cam_x;
/* 0x20 */ f32 cam_y;
} OSContPad; // size = 0x24
typedef struct {
/* 0x00 */ u8 rumble;

View file

@ -124,9 +124,11 @@ typedef struct {
/* 0x0B */ uint8_t right_click;
/* 0x0C */ float touch_x;
/* 0x10 */ float touch_y;
/* 0x14 */ float cam_x;
/* 0x18 */ float cam_y;
} OSContPad; // size = 0x1C
/* 0x14 */ float mouse_move_x;
/* 0x18 */ float mouse_move_y;
/* 0x1C */ float cam_x;
/* 0x20 */ float cam_y;
} OSContPad; // size = 0x24
typedef struct {
/* 0x00 */ uint8_t rumble;

View file

@ -4,7 +4,7 @@ void TitleSetup_InitImpl(GameState* gameState) {
osSyncPrintf("ゼルダ共通データ初期化\n"); // "Zelda common data initalization"
SaveContext_Init();
gameState->running = false;
SET_NEXT_GAMESTATE(gameState, FileChoose_Init, TitleContext);
SET_NEXT_GAMESTATE(gameState, Title_Init, TitleContext);
}
void TitleSetup_Destroy(GameState* gameState) {

View file

@ -1432,6 +1432,9 @@ s32 SetCameraManual(Camera* camera) {
return 0;
}
f32 lastMouseX;
f32 lastMouseY;
s32 Camera_Free(Camera* camera) {
Normal1* norm1 = (Normal1*)camera->paramData;
@ -1501,14 +1504,20 @@ s32 Camera_Free(Camera* camera) {
camera->dist = eyeAdjustment.r = Camera_LERPCeilF(150.0f, camera->dist, camSpeed / 4, 1.0f);
}
f32 newCamX = -D_8015BD7C->state.input[0].cur.cam_x;
f32 newCamY = D_8015BD7C->state.input[0].cur.cam_y;
// Mouse Free Camera
f32 mouseX = D_8015BD7C->state.input[0].cur.touch_x - lastMouseX;
lastMouseX = D_8015BD7C->state.input[0].cur.touch_x;
f32 mouseY = D_8015BD7C->state.input[0].cur.touch_y - lastMouseY;
lastMouseY = D_8015BD7C->state.input[0].cur.touch_y;
if (fabsf(newCamX) >= 250.0f) {
f32 newCamX = -D_8015BD7C->state.input[0].cur.cam_x + -(mouseX * 40.0f);
f32 newCamY = D_8015BD7C->state.input[0].cur.cam_y + (mouseY * 40.0f);
if (fabsf(newCamX) >= 200.0f) {
camX += newCamX;
}
if (fabsf(newCamY) >= 250.0f) {
if (fabsf(newCamY) >= 200.0f) {
camY += newCamY;
}