From c0603295930dad4847b1be8b5866669852d5fc02 Mon Sep 17 00:00:00 2001 From: MelonSpeedruns Date: Sun, 27 Mar 2022 19:30:48 -0400 Subject: [PATCH] Almost done, needs collision still --- libultraship/libultraship/SDLController.cpp | 14 +- soh/src/code/z_camera.c | 193 +++++--------------- 2 files changed, 50 insertions(+), 157 deletions(-) diff --git a/libultraship/libultraship/SDLController.cpp b/libultraship/libultraship/SDLController.cpp index ad9d1e699..b2d5670ac 100644 --- a/libultraship/libultraship/SDLController.cpp +++ b/libultraship/libultraship/SDLController.cpp @@ -183,13 +183,6 @@ namespace Ship { wCamX = SDL_GameControllerGetAxis(Cont, SDL_CONTROLLER_AXIS_RIGHTX) / 25; wCamY = SDL_GameControllerGetAxis(Cont, SDL_CONTROLLER_AXIS_RIGHTY) / 25; - if (abs(wCamX) <= 255) { - wCamX = 0; - } - if (abs(wCamY) <= 255) { - wCamY = 0; - } - if (SDL_GameControllerHasSensor(Cont, SDL_SENSOR_GYRO)) { float gyroData[3]; @@ -362,11 +355,12 @@ namespace Ship { void SDLController::CreateDefaultBinding() { std::string ConfSection = GetBindingConfSection(); std::shared_ptr pConf = GlobalCtx2::GetInstance()->GetConfig(); + ConfigFile& Conf = *pConf.get(); - Conf[ConfSection][STR(BTN_CRIGHT)] = std::to_string((SDL_CONTROLLER_AXIS_RIGHTX + AXIS_SCANCODE_BIT)); - Conf[ConfSection][STR(BTN_CLEFT)] = std::to_string(-(SDL_CONTROLLER_AXIS_RIGHTX + AXIS_SCANCODE_BIT)); - Conf[ConfSection][STR(BTN_CDOWN)] = std::to_string((SDL_CONTROLLER_AXIS_RIGHTY + AXIS_SCANCODE_BIT)); + Conf[ConfSection][STR(BTN_CRIGHT)] = std::to_string(SDL_CONTROLLER_BUTTON_RIGHTSHOULDER); + Conf[ConfSection][STR(BTN_CLEFT)] = std::to_string(SDL_CONTROLLER_BUTTON_Y); + Conf[ConfSection][STR(BTN_CDOWN)] = std::to_string(SDL_CONTROLLER_BUTTON_X); Conf[ConfSection][STR(BTN_CUP)] = std::to_string(SDL_CONTROLLER_BUTTON_RIGHTSTICK); //Conf[ConfSection][STR(BTN_CRIGHT + "_2")] = std::to_string(SDL_CONTROLLER_BUTTON_X); //Conf[ConfSection][STR(BTN_CLEFT + "_2")] = std::to_string(SDL_CONTROLLER_BUTTON_Y); diff --git a/soh/src/code/z_camera.c b/soh/src/code/z_camera.c index 095cd5a12..b950d678c 100644 --- a/soh/src/code/z_camera.c +++ b/soh/src/code/z_camera.c @@ -1408,30 +1408,29 @@ s32 Camera_Noop(Camera* camera) { return true; } +f32 camX; +f32 camY; + s32 Camera_Free(Camera* camera) { - Vec3f* eye = &camera->eye; - Vec3f* at = &camera->at; - Vec3f* eyeNext = &camera->eyeNext; - f32 spA0; - f32 sp9C; - f32 sp98; - f32 sp94; - Vec3f sp88; - s16 wiggleAdj; - s16 t; - VecSph eyeAdjustment; - VecSph atEyeGeo; - VecSph atEyeNextGeo; - PosRot* playerPosRot = &camera->playerPosRot; Normal1* norm1 = (Normal1*)camera->paramData; - Normal1Anim* anim = &norm1->anim; - f32 playerHeight; - f32 rate = 0.1f; - osSyncPrintf("\nCam Val X: %d\n", D_8015BD7C->state.input[0].cur.cam_x); + f32 playerHeight = Player_GetHeight(camera->player); + f32 sp94; + + sCameraInterfaceFlags = norm1->interfaceFlags; - playerHeight = Player_GetHeight(camera->player); if (RELOAD_PARAMS) { + VecSph eyeAdjustment1; + Vec3f oldCamRot; + oldCamRot.x = camera->player->actor.world.pos.x; + oldCamRot.y = camera->player->actor.world.pos.y + Player_GetHeight(camera->player); + oldCamRot.z = camera->player->actor.world.pos.z; + OLib_Vec3fDiffToVecSphGeo(&eyeAdjustment1, &oldCamRot, &camera->eye); + OLib_Vec3fDiffToVecSphGeo(&eyeAdjustment1, &oldCamRot, &camera->eyeNext); + + camX = eyeAdjustment1.yaw; + camY = eyeAdjustment1.pitch; + CameraModeValue* values = sCameraSettings[camera->setting].cameraModes[camera->mode].values; f32 yNormal = (1.0f + PCT(R_CAM_YOFFSET_NORM) - PCT(R_CAM_YOFFSET_NORM) * (68.0f / playerHeight)); sp94 = yNormal * PCT(playerHeight); @@ -1452,145 +1451,45 @@ s32 Camera_Free(Camera* camera) { Camera_CopyPREGToModeValues(camera); } - sCameraInterfaceFlags = norm1->interfaceFlags; - - OLib_Vec3fDiffToVecSphGeo(&atEyeGeo, at, eye); - OLib_Vec3fDiffToVecSphGeo(&atEyeNextGeo, at, eyeNext); - - switch (camera->animState) { - case 0x14: - camera->yawUpdateRateInv = OREG(27); - camera->pitchUpdateRateInv = OREG(27); - default: - break; - } + VecSph eyeAdjustment; + const f32 camSpeed = 0.5f; camera->animState = 1; - sUpdateCameraDirection = 1; - if (anim->unk_28 != 0) { - anim->unk_28--; + camera->at.x = Camera_LERPCeilF(camera->player->actor.world.pos.x, camera->at.x, camSpeed, 1.0f); + camera->at.y = Camera_LERPCeilF(camera->player->actor.world.pos.y + Player_GetHeight(camera->player), camera->at.y, + camSpeed, 1.0f); + camera->at.z = Camera_LERPCeilF(camera->player->actor.world.pos.z, camera->at.z, camSpeed, 1.0f); + + OLib_Vec3fDiffToVecSphGeo(&eyeAdjustment, &camera->at, &camera->eye); + OLib_Vec3fDiffToVecSphGeo(&eyeAdjustment, &camera->at, &camera->eyeNext); + + camera->dist = eyeAdjustment.r = 200; + + f32 newCamX = -D_8015BD7C->state.input[0].cur.cam_x; + f32 newCamY = D_8015BD7C->state.input[0].cur.cam_y; + + if (fabsf(newCamX) >= 100.0f) { + camX += newCamX; } - spA0 = camera->speedRatio * PCT(OREG(25)); - sp9C = camera->speedRatio * PCT(OREG(26)); - sp98 = anim->swing.unk_18 != 0 ? PCT(OREG(25)) : spA0; - - sp94 = (camera->xzSpeed - anim->unk_20) * (0.333333f); - if (sp94 > 1.0f) { - sp94 = 1.0f; - } - if (sp94 > -1.0f) { - sp94 = -1.0f; + if (fabsf(newCamY) >= 100.0f) { + camY += newCamY; } - anim->unk_20 = camera->xzSpeed; - - - camera->yawUpdateRateInv = - Camera_LERPCeilF(anim->swing.swingUpdateRate + (f32)(anim->swing.swingUpdateRateTimer * 2), - camera->yawUpdateRateInv, sp98, rate); - camera->pitchUpdateRateInv = - Camera_LERPCeilF((f32)R_CAM_DEFA_PHI_UPDRATE + (f32)(anim->swing.swingUpdateRateTimer * 2), - camera->pitchUpdateRateInv, sp9C, rate); - - camera->pitchUpdateRateInv = Camera_LERPCeilF(R_CAM_DEFA_PHI_UPDRATE, camera->pitchUpdateRateInv, sp9C, rate); - camera->xzOffsetUpdateRate = Camera_LERPCeilF(PCT(OREG(2)), camera->xzOffsetUpdateRate, spA0, rate); - camera->yOffsetUpdateRate = Camera_LERPCeilF(PCT(OREG(3)), camera->yOffsetUpdateRate, sp9C, rate); - camera->fovUpdateRate = Camera_LERPCeilF(PCT(OREG(4)), camera->yOffsetUpdateRate, camera->speedRatio * 0.05f, rate); - - if (norm1->interfaceFlags & 1) { - t = func_80044ADC(camera, BINANG_ROT180(atEyeGeo.yaw), 0); - sp9C = ((1.0f / norm1->unk_10) * 0.5f) * (1.0f - camera->speedRatio); - anim->slopePitchAdj = Camera_LERPCeilS(t, anim->slopePitchAdj, ((1.0f / norm1->unk_10) * 0.5f) + sp9C, 0xF); - } else { - anim->slopePitchAdj = 0; - if (camera->playerGroundY == camera->playerPosRot.pos.y) { - anim->yOffset = camera->playerPosRot.pos.y; - } + if (camY > 0x38A4) { + camY = 0x38A4; + } + if (camY < -0x3C8C) { + camY = -0x3C8C; } - spA0 = ((anim->swing.unk_18 != 0) && (norm1->yOffset > -40.0f)) - ? (sp9C = Math_SinS(anim->swing.unk_14), ((-40.0f * sp9C) + (norm1->yOffset * (1.0f - sp9C)))) - : norm1->yOffset; + eyeAdjustment.yaw = camX; + eyeAdjustment.pitch = camY; - if (norm1->interfaceFlags & 0x80) { - func_800458D4(camera, &atEyeNextGeo, spA0, &anim->yOffset, norm1->interfaceFlags & 1); - } else if (norm1->interfaceFlags & 0x20) { - func_80045B08(camera, &atEyeNextGeo, spA0, anim->slopePitchAdj); - } else { - Camera_CalcAtDefault(camera, &atEyeNextGeo, spA0, norm1->interfaceFlags & 1); - } + Camera_Vec3fVecSphGeoAdd(&camera->eye, &camera->at, &eyeAdjustment); + Camera_Vec3fVecSphGeoAdd(&camera->eyeNext, &camera->at, &eyeAdjustment); - OLib_Vec3fDiffToVecSphGeo(&eyeAdjustment, at, eyeNext); - - camera->dist = eyeAdjustment.r = - Camera_ClampDist(camera, eyeAdjustment.r, norm1->distMin, norm1->distMax, anim->unk_28); - - // rotate yaw to follow player. - float newCamX = -D_8015BD7C->state.input[0].cur.cam_x; - float newCamY = D_8015BD7C->state.input[0].cur.cam_y; - eyeAdjustment.yaw += newCamX; - eyeAdjustment.pitch += newCamY; - - // set eyeAdjustment pitch from 79.65 degrees to -85 degrees - if (eyeAdjustment.pitch > 0x38A4) { - eyeAdjustment.pitch = 0x38A4; - } - if (eyeAdjustment.pitch < -0x3C8C) { - eyeAdjustment.pitch = -0x3C8C; - } - - Camera_Vec3fVecSphGeoAdd(eyeNext, at, &eyeAdjustment); - if ((camera->status == CAM_STAT_ACTIVE) && (!(norm1->interfaceFlags & 0x10))) { - anim->swingYawTarget = BINANG_ROT180(camera->playerPosRot.rot.y); - if (anim->startSwingTimer > 0) { - func_80046E20(camera, &eyeAdjustment, norm1->distMin, norm1->unk_0C, &sp98, &anim->swing); - } else { - sp88 = *eyeNext; - anim->swing.swingUpdateRate = camera->yawUpdateRateInv = norm1->unk_0C * 2.0f; - if (Camera_BGCheck(camera, at, &sp88)) { - anim->swingYawTarget = atEyeNextGeo.yaw; - anim->startSwingTimer = -1; - } else { - *eye = *eyeNext; - } - anim->swing.unk_18 = 0; - } - - if (anim->swing.unk_18 != 0) { - camera->inputDir.y = - Camera_LERPCeilS(camera->inputDir.y + BINANG_SUB(BINANG_ROT180(anim->swing.unk_16), camera->inputDir.y), - camera->inputDir.y, 1.0f - (0.99f * sp98), 0xA); - } - - if (norm1->interfaceFlags & 4) { - camera->inputDir.x = -atEyeGeo.pitch; - camera->inputDir.y = BINANG_ROT180(atEyeGeo.yaw); - camera->inputDir.z = 0; - } else { - OLib_Vec3fDiffToVecSphGeo(&eyeAdjustment, eye, at); - camera->inputDir.x = eyeAdjustment.pitch; - camera->inputDir.y = eyeAdjustment.yaw; - camera->inputDir.z = 0; - } - - // crit wiggle - if (gSaveContext.health <= 16 && ((camera->globalCtx->state.frames % 256) == 0)) { - wiggleAdj = Rand_ZeroOne() * 10000.0f; - camera->inputDir.y = wiggleAdj + camera->inputDir.y; - } - } else { - anim->swing.swingUpdateRate = norm1->unk_0C; - anim->swing.unk_18 = 0; - sUpdateCameraDirection = 0; - *eye = *eyeNext; - } - - spA0 = (gSaveContext.health <= 16 ? 0.8f : 1.0f); - camera->fov = Camera_LERPCeilF(norm1->fovTarget * spA0, camera->fov, camera->fovUpdateRate, 1.0f); - camera->roll = Camera_LERPCeilS(0, camera->roll, 0.5f, 0xA); - camera->atLERPStepScale = Camera_ClampLERPScale(camera, norm1->atLERPScaleMax); return 1; }