From 7cd3e8f502d0a6ea032a841a568fc0c44ffe6e1b Mon Sep 17 00:00:00 2001 From: Jack Andersen Date: Wed, 29 Nov 2017 15:22:46 -1000 Subject: [PATCH] Various bug fixes --- Runtime/Camera/CFirstPersonCamera.cpp | 163 ++++++++++++++++---------- Runtime/Character/CActorLights.cpp | 16 ++- Runtime/Character/CActorLights.hpp | 2 +- Runtime/Input/ControlMapper.cpp | 2 +- Runtime/MP1/CLogBookScreen.cpp | 2 +- Runtime/MP1/COptionsScreen.cpp | 2 +- Runtime/MP1/CPauseScreen.cpp | 10 +- Runtime/World/CPhysicsActor.cpp | 7 +- specter | 2 +- 9 files changed, 125 insertions(+), 81 deletions(-) diff --git a/Runtime/Camera/CFirstPersonCamera.cpp b/Runtime/Camera/CFirstPersonCamera.cpp index a0a7aef5b..4765fce48 100644 --- a/Runtime/Camera/CFirstPersonCamera.cpp +++ b/Runtime/Camera/CFirstPersonCamera.cpp @@ -95,8 +95,8 @@ void CFirstPersonCamera::CalculateGunFollowOrientationAndTransform(zeus::CTransf if (rVecNoZ.canBeNormalized()) rVecNoZ.normalize(); - gunXf = zeus::CQuaternion::lookAt(rVecNoZ, gunFrontVec, zeus::CRelAngle::FromDegrees(360.f)).toTransform() * - gunXf.getRotation(); + gunXf = zeus::CQuaternion::lookAt(gunFrontVec, rVecNoZ, zeus::CRelAngle::FromDegrees(360.f)).toTransform() * + x190_gunFollowXf.getRotation(); zeus::CVector3f newgunFront = gunXf.frontVector(); @@ -104,9 +104,8 @@ void CFirstPersonCamera::CalculateGunFollowOrientationAndTransform(zeus::CTransf newgunFront.normalize(); float angle = newgunFront.dot(rVec); - if (std::fabs(angle) > 0.f) - angle = (angle > -0.f ? -1.f : 1.f); - gunQ = zeus::CQuaternion::lookAt(rVec, newgunFront, zeus::clamp(0.f, std::acos(angle) / dt, 1.f)); + angle = std::min(angle, 1.f); + gunQ = zeus::CQuaternion::lookAt(newgunFront, rVec, zeus::clamp(0.f, std::acos(angle) / dt, 1.f) * dt); } void CFirstPersonCamera::UpdateTransform(CStateManager& mgr, float dt) @@ -130,8 +129,12 @@ void CFirstPersonCamera::UpdateTransform(CStateManager& mgr, float dt) vec.z = std::sin(angle); vec.y = std::cos(-player->x3e4_freeLookYawAngle) * std::cos(angle); vec.x = std::sin(-player->x3e4_freeLookYawAngle) * std::cos(angle); - if (g_tweakPlayer->GetFreeLookTurnsPlayer() && !zeus::close_enough(vec, zeus::CVector3f::skZero)) - vec.normalize(); + if (g_tweakPlayer->GetFreeLookTurnsPlayer()) + { + vec.x = 0.f; + if (!zeus::close_enough(vec, zeus::CVector3f::skZero)) + vec.normalize(); + } rVec = zeus::CQuaternion::lookAt({0.f, 1.f, 0.f}, rVec, zeus::CRelAngle::FromDegrees(360.f)).transform(vec); } @@ -144,11 +147,13 @@ void CFirstPersonCamera::UpdateTransform(CStateManager& mgr, float dt) player->GetCameraBob()->SetCameraBobTransform(zeus::CTransform::Identity()); } - if (player->GetOrbitState() == CPlayer::EPlayerOrbitState::ForcedOrbitObject || - player->GetOrbitState() == CPlayer::EPlayerOrbitState::OrbitObject) + switch (player->GetOrbitState()) + { + case CPlayer::EPlayerOrbitState::ForcedOrbitObject: + case CPlayer::EPlayerOrbitState::OrbitObject: { const CActor* act = TCastToConstPtr(mgr.GetObjectById(player->x310_orbitTargetId)); - if (act && act->GetMaterialList().Intersection(CMaterialList(EMaterialTypes::Lava)) != 0) + if (act && act->GetMaterialList().HasMaterial(EMaterialTypes::Orbit)) { zeus::CVector3f v = player->x314_orbitPoint.y - eyePos; if (v.canBeNormalized()) @@ -156,34 +161,54 @@ void CFirstPersonCamera::UpdateTransform(CStateManager& mgr, float dt) rVec = v; } + else + { + rVec = player->x314_orbitPoint - eyePos; + } + break; } - else if (player->GetOrbitState() == CPlayer::EPlayerOrbitState::NoOrbit && - player->GetMorphballTransitionState() == CPlayer::EPlayerMorphBallState::Unmorphed && - !player->x3dc_inFreeLook && x1c4_pitchId == kInvalidUniqueId) + case CPlayer::EPlayerOrbitState::OrbitPoint: + case CPlayer::EPlayerOrbitState::OrbitCarcass: { - if (player->x294_jumpCameraTimer > 0.f) + if (!player->x3dd_lookButtonHeld) { - float angle = zeus::clamp(0.f, (player->x294_jumpCameraTimer - g_tweakPlayer->GetJumpCameraPitchDownStart()) / - g_tweakPlayer->GetJumpCameraPitchDownFull(), 1.f) * - g_tweakPlayer->GetJumpCameraPitchDownAngle(); - angle += x1c0_pitch; - rVec.x = 0.f; - rVec.y = std::cos(angle); - rVec.z = -std::sin(angle); - - rVec = playerXf.rotate(rVec); + rVec = player->x314_orbitPoint - eyePos; } - else if (player->x29c_fallCameraTimer > 0.f) + break; + } + case CPlayer::EPlayerOrbitState::NoOrbit: + { + if (player->GetMorphballTransitionState() == CPlayer::EPlayerMorphBallState::Unmorphed && + !player->x3dc_inFreeLook && x1c4_pitchId == kInvalidUniqueId) { - float angle = zeus::clamp(0.f, (player->x29c_fallCameraTimer - g_tweakPlayer->GetFallCameraPitchDownStart()) / - g_tweakPlayer->GetFallCameraPitchDownFull(), 1.f) * - g_tweakPlayer->GetFallCameraPitchDownAngle(); - rVec.x = 0.f; - rVec.y = std::cos(angle); - rVec.z = -std::sin(angle); + if (player->x294_jumpCameraTimer > 0.f) + { + float angle = zeus::clamp(0.f, (player->x294_jumpCameraTimer - g_tweakPlayer->GetJumpCameraPitchDownStart()) / + g_tweakPlayer->GetJumpCameraPitchDownFull(), 1.f) * + g_tweakPlayer->GetJumpCameraPitchDownAngle(); + angle += x1c0_pitch; + rVec.x = 0.f; + rVec.y = std::cos(angle); + rVec.z = -std::sin(angle); - rVec = playerXf.rotate(rVec); + rVec = playerXf.rotate(rVec); + } + else if (player->x29c_fallCameraTimer > 0.f) + { + float angle = zeus::clamp(0.f, (player->x29c_fallCameraTimer - g_tweakPlayer->GetFallCameraPitchDownStart()) / + g_tweakPlayer->GetFallCameraPitchDownFull(), 1.f) * + g_tweakPlayer->GetFallCameraPitchDownAngle(); + //rVec.x = 0.f; + //rVec.y = std::cos(angle); + //rVec.z = -std::sin(angle); + + //rVec = playerXf.rotate(rVec); + } } + break; + } + default: + break; } if (rVec.canBeNormalized()) @@ -192,12 +217,33 @@ void CFirstPersonCamera::UpdateTransform(CStateManager& mgr, float dt) zeus::CTransform gunXf = x190_gunFollowXf; zeus::CQuaternion qGun = zeus::CQuaternion::skNoRotation; - if (player->x3dc_inFreeLook) + if (!player->x3dc_inFreeLook) { - if (player->GetOrbitState() == CPlayer::EPlayerOrbitState::ForcedOrbitObject || - player->GetOrbitState() == CPlayer::EPlayerOrbitState::OrbitObject) + switch (player->GetOrbitState()) { - zeus::CVector3f gunFrontVec = gunXf.frontVector(); + default: + { + CalculateGunFollowOrientationAndTransform(gunXf, qGun, + dt * g_tweakPlayer->GetFirstPersonCameraSpeed(), rVec); + break; + } + case CPlayer::EPlayerOrbitState::Grapple: + { + CalculateGunFollowOrientationAndTransform(gunXf, qGun, + dt * g_tweakPlayer->GetGrappleCameraSpeed(), rVec); + break; + } + case CPlayer::EPlayerOrbitState::OrbitPoint: + case CPlayer::EPlayerOrbitState::OrbitCarcass: + { + CalculateGunFollowOrientationAndTransform(gunXf, qGun, + dt * g_tweakPlayer->GetOrbitCameraSpeed() * 0.25f, rVec); + break; + } + case CPlayer::EPlayerOrbitState::ForcedOrbitObject: + case CPlayer::EPlayerOrbitState::OrbitObject: + { + zeus::CVector3f gunFrontVec = x190_gunFollowXf.frontVector(); if (gunFrontVec.canBeNormalized()) gunFrontVec.normalize(); @@ -206,10 +252,10 @@ void CFirstPersonCamera::UpdateTransform(CStateManager& mgr, float dt) float angle = gunFrontVec.dot(rVec); angle = zeus::clamp(-1.f, angle, 1.f); float clampedAngle = zeus::clamp(0.f, std::acos(angle) / scaledDt, 1.f); - if (angle > 0.999f && x18c_lockCamera && !player->x374_orbitLockEstablished) - qGun = zeus::CQuaternion::lookAt(rVec, gunFrontVec, zeus::CRelAngle::FromDegrees(360.f)); + if (angle > 0.999f || x18c_lockCamera || player->x374_orbitLockEstablished) + qGun = zeus::CQuaternion::lookAt(gunFrontVec, rVec, zeus::CRelAngle::FromDegrees(360.f)); else - qGun = zeus::CQuaternion::lookAt(rVec, gunFrontVec, scaledDt * clampedAngle); + qGun = zeus::CQuaternion::lookAt(gunFrontVec, rVec, scaledDt * clampedAngle); const CScriptGrapplePoint* gPoint = TCastToConstPtr(mgr.GetObjectById(player->x310_orbitTargetId)); @@ -220,53 +266,42 @@ void CFirstPersonCamera::UpdateTransform(CStateManager& mgr, float dt) gunFrontVec.normalize(); zeus::CVector3f rVecCpy = rVec; + rVecCpy.z = 0.f; if (rVecCpy.canBeNormalized()) rVecCpy.normalize(); gunXf = - zeus::CQuaternion::lookAt(rVecCpy, gunFrontVec, zeus::CRelAngle::FromDegrees(360.f)).toTransform() * + zeus::CQuaternion::lookAt(gunFrontVec, rVecCpy, zeus::CRelAngle::FromDegrees(360.f)).toTransform() * x190_gunFollowXf.getRotation(); gunFrontVec = gunXf.frontVector(); if (gunFrontVec.canBeNormalized()) gunFrontVec.normalize(); - float angle = gunFrontVec.dot(rVec); - float sdt = dt * g_tweakPlayer->GetGrappleCameraSpeed(); + //float angle = gunFrontVec.dot(rVec); + //float sdt = dt * g_tweakPlayer->GetGrappleCameraSpeed(); - angle = zeus::clamp(-1.f, angle, 1.f); - angle = zeus::clamp(0.f, std::acos(angle) / sdt, 1.f) * sdt; - qGun = zeus::CQuaternion::lookAt(rVec, gunFrontVec, angle); + //angle = zeus::clamp(-1.f, angle, 1.f); + //angle = zeus::clamp(0.f, std::acos(angle) / sdt, 1.f); + qGun = zeus::CQuaternion::lookAt(gunFrontVec, rVecCpy, zeus::CRelAngle::FromDegrees(360.f)); } + break; } - else if (player->GetOrbitState() == CPlayer::EPlayerOrbitState::OrbitPoint || - player->GetOrbitState() == CPlayer::EPlayerOrbitState::OrbitCarcass) - { - dt *= g_tweakPlayer->GetOrbitCameraSpeed(); - CalculateGunFollowOrientationAndTransform(gunXf, qGun, dt, rVec); - } - else if (player->GetOrbitState() == CPlayer::EPlayerOrbitState::Grapple) - { - dt *= g_tweakPlayer->GetGrappleCameraSpeed(); - CalculateGunFollowOrientationAndTransform(gunXf, qGun, dt, rVec); - } - else - { - dt *= g_tweakPlayer->GetFirstPersonCameraSpeed(); - CalculateGunFollowOrientationAndTransform(gunXf, qGun, dt, rVec); } } else { zeus::CVector3f gunFront = x190_gunFollowXf.frontVector(); + gunFront.z = 0.f; if (gunFront.canBeNormalized()) gunFront.normalize(); zeus::CVector3f rVecCpy = rVec; + rVecCpy.z = 0.f; if (rVecCpy.canBeNormalized()) rVecCpy.normalize(); - gunXf = zeus::CQuaternion::lookAt(rVecCpy, gunFront, zeus::CRelAngle::FromDegrees(360.f)).toTransform() * + gunXf = zeus::CQuaternion::lookAt(gunFront, rVecCpy, zeus::CRelAngle::FromDegrees(360.f)).toTransform() * x190_gunFollowXf.getRotation(); gunFront = gunXf.frontVector(); if (gunFront.canBeNormalized()) @@ -276,7 +311,7 @@ void CFirstPersonCamera::UpdateTransform(CStateManager& mgr, float dt) angle = zeus::clamp(-1.f, angle, 1.f); float sdt = dt * g_tweakPlayer->GetFreeLookSpeed(); qGun = zeus::CQuaternion::lookAt( - rVec, gunFront, sdt * zeus::clamp(0.f, g_tweakPlayer->GetFreeLookDampenFactor() * + gunFront, rVec, sdt * zeus::clamp(0.f, g_tweakPlayer->GetFreeLookDampenFactor() * (std::acos(angle) / sdt), 1.f)); } zeus::CTransform bobXf = player->GetCameraBob()->GetCameraBobTransformation(); @@ -285,14 +320,16 @@ void CFirstPersonCamera::UpdateTransform(CStateManager& mgr, float dt) player->GetOrbitState() == CPlayer::EPlayerOrbitState::Grapple || player->GetGrappleState() == CPlayer::EGrappleState::None || mgr.GetGameState() == CStateManager::EGameState::SoftPaused || - mgr.GetCameraManager()->IsInCinematicCamera()) + mgr.GetCameraManager()->IsInCinematicCamera() || + x1d4_closeInTimer > 0.f) { bobXf = zeus::CTransform::Identity(); player->GetCameraBob()->SetCameraBobTransform(bobXf); } x190_gunFollowXf = qGun.toTransform() * gunXf; - SetTransform(x190_gunFollowXf * bobXf.getRotation()); + //SetTransform(x190_gunFollowXf * bobXf.getRotation()); + SetTransform(playerXf); x190_gunFollowXf.origin = eyePos; CActor::SetTranslation(eyePos + player->GetTransform().rotate(bobXf.origin)); x190_gunFollowXf.orthonormalize(); diff --git a/Runtime/Character/CActorLights.cpp b/Runtime/Character/CActorLights.cpp index ee3fb3fed..af41f6e0c 100644 --- a/Runtime/Character/CActorLights.cpp +++ b/Runtime/Character/CActorLights.cpp @@ -36,7 +36,7 @@ CActorLights::CActorLights(u32 areaUpdateFramePeriod, const zeus::CVector3f& act void CActorLights::BuildConstantAmbientLighting() { - x299_26_ = true; + x299_26_ambientOnly = true; x298_24_dirty = true; x29c_shadowLightArrIdx = -1; x2a0_shadowLightIdx = -1; @@ -44,7 +44,7 @@ void CActorLights::BuildConstantAmbientLighting() void CActorLights::BuildConstantAmbientLighting(const zeus::CColor& color) { - x299_26_ = false; + x299_26_ambientOnly = false; x288_ambientColor = color; x294_aid = kInvalidAreaId; x298_24_dirty = true; @@ -454,7 +454,7 @@ bool CActorLights::BuildAreaLightList(const CStateManager& mgr, const CGameArea& void CActorLights::BuildDynamicLightList(const CStateManager& mgr, const zeus::CAABox& aabb) { UpdateBrightLight(); - x299_26_ = false; + x299_26_ambientOnly = false; x144_dynamicLights.clear(); if (!x29a_findNearestDynamicLights) @@ -506,7 +506,10 @@ void CActorLights::BuildDynamicLightList(const CStateManager& mgr, const zeus::C std::vector CActorLights::BuildLightVector() const { std::vector lights; - lights.push_back(CLight::BuildLocalAmbient(zeus::CVector3f::skZero, x288_ambientColor)); + + zeus::CColor ambColor = x288_ambientColor; + ambColor.a = 1.f; + lights.push_back(CLight::BuildLocalAmbient(zeus::CVector3f::skZero, ambColor)); if (x0_areaLights.size()) { @@ -543,9 +546,10 @@ void CActorLights::ActivateLights(CBooModel& model) const if (x298_28_inArea) { - if (!x298_26_hasAreaLights || !x299_26_) + if (!x298_26_hasAreaLights || x299_26_ambientOnly) { - g_Renderer->SetAmbientColor(zeus::CColor::skWhite); + //g_Renderer->SetAmbientColor(zeus::CColor::skWhite); + lights.push_back(CLight::BuildLocalAmbient(zeus::CVector3f::skZero, zeus::CColor::skWhite)); model.ActivateLights(lights); return; } diff --git a/Runtime/Character/CActorLights.hpp b/Runtime/Character/CActorLights.hpp index 44d6763c1..f3401de91 100644 --- a/Runtime/Character/CActorLights.hpp +++ b/Runtime/Character/CActorLights.hpp @@ -35,7 +35,7 @@ class CActorLights bool x298_31_disableWorldLights : 1; bool x299_24_inBrightLight : 1; bool x299_25_useBrightLightLag : 1; - bool x299_26_ : 1; + bool x299_26_ambientOnly : 1; }; u16 _dummy = 0; }; diff --git a/Runtime/Input/ControlMapper.cpp b/Runtime/Input/ControlMapper.cpp index 84f211c7a..5074d7dd6 100644 --- a/Runtime/Input/ControlMapper.cpp +++ b/Runtime/Input/ControlMapper.cpp @@ -188,7 +188,7 @@ static FloatReturnFn skAnalogFuncs[] = nullptr }; -#define kCommandFilterCount 65 +#define kCommandFilterCount 67 static bool skCommandFilterFlag[kCommandFilterCount] = {true}; void ControlMapper::SetCommandFiltered(ECommands cmd, bool filtered) diff --git a/Runtime/MP1/CLogBookScreen.cpp b/Runtime/MP1/CLogBookScreen.cpp index 8b9f69476..f06f2d40f 100644 --- a/Runtime/MP1/CLogBookScreen.cpp +++ b/Runtime/MP1/CLogBookScreen.cpp @@ -77,7 +77,7 @@ void CLogBookScreen::UpdateRightTitles() { std::vector>& category = x19c_scanCompletes[x70_tablegroup_leftlog->GetUserSelection()]; - for (int i=0 ; xd8_textpane_titles.size() ; ++i) + for (int i=0 ; i(); + x1a0_gameCube = std::make_unique(); x2a0_24_inOptionBody = false; } diff --git a/Runtime/MP1/CPauseScreen.cpp b/Runtime/MP1/CPauseScreen.cpp index e4fc1e625..37a58a208 100644 --- a/Runtime/MP1/CPauseScreen.cpp +++ b/Runtime/MP1/CPauseScreen.cpp @@ -28,6 +28,7 @@ CPauseScreen::CPauseScreen(ESubScreen subscreen, x5c_frmePauseScreenBuf.reset(new u8[x58_frmePauseScreenBufSz]); x60_loadTok = g_ResFactory->LoadResourceAsync(frmeTag, x5c_frmePauseScreenBuf.get()); CSfxManager::SfxStart(1435, 1.f, 0.f, false, 0x7f, false, kInvalidAreaId); + x7c_screens.resize(2); } std::unique_ptr CPauseScreen::BuildPauseSubScreen(ESubScreen subscreen, @@ -113,11 +114,12 @@ void CPauseScreen::StartTransition(float time, const CStateManager& mgr, ESubScr return; xc_nextSubscreen = subscreen; x4_ = b; - std::unique_ptr& newScreenSlot = x7c_screens[x78_activeIdx]; - std::unique_ptr& newScreenInst = x64_frameInsts[x78_activeIdx]; + x10_alphaInterp = time; + std::unique_ptr& newScreenSlot = x7c_screens[1 - x78_activeIdx]; + std::unique_ptr& newScreenInst = x64_frameInsts[1 - x78_activeIdx]; newScreenSlot = BuildPauseSubScreen(xc_nextSubscreen, mgr, *newScreenInst); - if (x7c_screens[1 - x78_activeIdx]) - x7c_screens[1 - x78_activeIdx]->TransitioningAway(); + if (x7c_screens[x78_activeIdx]) + x7c_screens[x78_activeIdx]->TransitioningAway(); x91_initialTransition = false; } diff --git a/Runtime/World/CPhysicsActor.cpp b/Runtime/World/CPhysicsActor.cpp index 7ba600b60..bbd1e695e 100644 --- a/Runtime/World/CPhysicsActor.cpp +++ b/Runtime/World/CPhysicsActor.cpp @@ -100,7 +100,8 @@ void CPhysicsActor::AddMotionState(const CMotionState& mst) { zeus::CNUQuaternion q{x34_transform.buildMatrix3f()}; q += mst.xc_orientation; - SetTransform(zeus::CTransform(zeus::CQuaternion::fromNUQuaternion(q), x34_transform.origin)); + zeus::CQuaternion quat = zeus::CQuaternion::fromNUQuaternion(q); + SetTransform(zeus::CTransform(quat, x34_transform.origin)); SetTranslation(x34_transform.origin + mst.x0_translation); @@ -241,7 +242,7 @@ void CPhysicsActor::ComputeDerivedQuantities() { x138_velocity = xec_massRecip * xfc_constantForce; x114_ = x34_transform.buildMatrix3f(); - x144_angularVelocity = xf0_inertiaTensor * x108_angularMomentum; + x144_angularVelocity = xf4_inertiaTensorRecip * x108_angularMomentum; } bool CPhysicsActor::WillMove(const CStateManager&) @@ -311,7 +312,7 @@ CMotionState CPhysicsActor::PredictLinearMotion(float dt) const CMotionState CPhysicsActor::PredictAngularMotion(float dt) const { const zeus::CVector3f v1 = xf4_inertiaTensorRecip * (x180_angularImpulse + x198_moveAngularImpulse); - zeus::CNUQuaternion q = 0.5f * zeus::CNUQuaternion(0.f, x144_angularVelocity + v1); + zeus::CNUQuaternion q = 0.5f * zeus::CNUQuaternion(0.f, x144_angularVelocity.getVector() + v1); CMotionState ret = {zeus::CVector3f::skZero, q * zeus::CNUQuaternion(x34_transform.buildMatrix3f()) * dt, zeus::CVector3f::skZero, (x174_torque * dt) + x180_angularImpulse}; return ret; diff --git a/specter b/specter index 410ab94d7..d78b1bf64 160000 --- a/specter +++ b/specter @@ -1 +1 @@ -Subproject commit 410ab94d7f5d5d6c5081af90ae9c217b10978db1 +Subproject commit d78b1bf64087bf82133b1de71bfca9f9128fbf78