2020-01-15 12:07:48 +00:00
|
|
|
#include "Runtime/Camera/CCameraManager.hpp"
|
|
|
|
|
2020-01-20 17:57:21 +00:00
|
|
|
#include <algorithm>
|
|
|
|
|
2020-01-15 12:07:48 +00:00
|
|
|
#include "Runtime/CStateManager.hpp"
|
|
|
|
#include "Runtime/GameGlobalObjects.hpp"
|
|
|
|
#include "Runtime/Camera/CBallCamera.hpp"
|
|
|
|
#include "Runtime/Camera/CCameraShakeData.hpp"
|
|
|
|
#include "Runtime/Camera/CCinematicCamera.hpp"
|
|
|
|
#include "Runtime/Camera/CFirstPersonCamera.hpp"
|
|
|
|
#include "Runtime/Camera/CInterpolationCamera.hpp"
|
|
|
|
#include "Runtime/Camera/CPathCamera.hpp"
|
|
|
|
#include "Runtime/World/CExplosion.hpp"
|
|
|
|
#include "Runtime/World/CPlayer.hpp"
|
|
|
|
#include "Runtime/World/CScriptCameraHint.hpp"
|
|
|
|
#include "Runtime/World/CScriptSpindleCamera.hpp"
|
|
|
|
#include "Runtime/World/CScriptWater.hpp"
|
|
|
|
|
2019-09-21 13:07:13 +00:00
|
|
|
#include "TCastTo.hpp" // Generated file, do not modify include path
|
2017-01-15 03:07:01 +00:00
|
|
|
|
2021-04-10 08:42:06 +00:00
|
|
|
namespace metaforce {
|
2016-10-31 22:56:44 +00:00
|
|
|
float CCameraManager::sFirstPersonFOV = 55.f;
|
2016-04-16 21:49:47 +00:00
|
|
|
|
2020-04-21 07:22:41 +00:00
|
|
|
CCameraManager::CCameraManager(TUniqueId curCameraId) : x0_curCameraId(curCameraId) {
|
2020-04-10 19:03:05 +00:00
|
|
|
CSfxManager::AddListener(CSfxManager::ESfxChannels::Game, zeus::skZero3f, zeus::skZero3f, {1.f, 0.f, 0.f},
|
|
|
|
{0.f, 0.f, 1.f}, 50.f, 50.f, 1000.f, 1, 1.f);
|
2018-12-08 05:30:43 +00:00
|
|
|
sFirstPersonFOV = g_tweakGame->GetFirstPersonFOV();
|
2016-04-17 02:50:45 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
bool CCameraManager::IsInFirstPersonCamera() const { return x7c_fpCamera->GetUniqueId() == x0_curCameraId; }
|
2016-04-17 02:50:45 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
zeus::CVector3f CCameraManager::GetGlobalCameraTranslation(const CStateManager& stateMgr) const {
|
|
|
|
const CGameCamera* camera = GetCurrentCamera(stateMgr);
|
|
|
|
return camera->GetTransform().rotate(x30_shakeOffset);
|
2016-04-17 02:50:45 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
zeus::CTransform CCameraManager::GetCurrentCameraTransform(const CStateManager& stateMgr) const {
|
|
|
|
const CGameCamera* camera = GetCurrentCamera(stateMgr);
|
|
|
|
return camera->GetTransform() * zeus::CTransform::Translate(x30_shakeOffset);
|
2016-04-17 02:50:45 +00:00
|
|
|
}
|
|
|
|
|
2020-01-20 17:51:50 +00:00
|
|
|
void CCameraManager::RemoveCameraShaker(u32 id) {
|
2020-01-20 17:57:21 +00:00
|
|
|
const auto iter = std::find_if(x14_shakers.cbegin(), x14_shakers.cend(),
|
|
|
|
[id](const auto& shaker) { return shaker.xbc_shakerId == id; });
|
|
|
|
if (iter == x14_shakers.cend()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
x14_shakers.erase(iter);
|
2016-04-17 02:50:45 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
int CCameraManager::AddCameraShaker(const CCameraShakeData& data, bool sfx) {
|
2020-03-13 20:32:24 +00:00
|
|
|
x14_shakers.emplace_back(data).xbc_shakerId = ++x2c_lastShakeId;
|
2018-12-08 05:30:43 +00:00
|
|
|
if (!xa0_24_pendingRumble) {
|
|
|
|
xa0_24_pendingRumble = true;
|
|
|
|
x90_rumbleCooldown = 0.5f;
|
|
|
|
}
|
|
|
|
if (sfx && data.x0_duration > 0.f) {
|
|
|
|
float vol = zeus::clamp(100.f, std::max(data.GetMaxAMComponent(), data.GetMaxFMComponent()) * 9.f + 100.f, 127.f);
|
|
|
|
CSfxHandle sfxHandle;
|
|
|
|
if (data.xc0_flags & 0x1)
|
2021-06-07 19:29:18 +00:00
|
|
|
sfxHandle = CSfxManager::AddEmitter(SFXamb_x_rumble_lp_00, data.xc4_sfxPos, zeus::skZero3f, vol / 127.f, false,
|
|
|
|
false, 0x7f, kInvalidAreaId);
|
2018-12-08 05:30:43 +00:00
|
|
|
else
|
|
|
|
sfxHandle = CSfxManager::SfxStart(SFXamb_x_rumble_lp_00, vol / 127.f, 0.f, false, 0x7f, false, kInvalidAreaId);
|
|
|
|
sfxHandle->SetTimeRemaining(data.x0_duration);
|
|
|
|
}
|
|
|
|
return x2c_lastShakeId;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CCameraManager::EnterCinematic(CStateManager& mgr) {
|
|
|
|
mgr.GetPlayer().GetPlayerGun()->CancelFiring(mgr);
|
|
|
|
mgr.GetPlayer().UnFreeze(mgr);
|
|
|
|
|
2020-04-05 05:01:54 +00:00
|
|
|
for (const CEntity* ent : mgr.GetAllObjectList()) {
|
|
|
|
if (const TCastToConstPtr<CExplosion> explo = ent) {
|
2018-12-08 05:30:43 +00:00
|
|
|
mgr.FreeScriptObject(explo->GetUniqueId());
|
2020-04-05 05:01:54 +00:00
|
|
|
} else if (const TCastToConstPtr<CWeapon> weap = ent) {
|
2018-12-08 05:30:43 +00:00
|
|
|
if (weap->GetActive()) {
|
2019-04-03 04:32:31 +00:00
|
|
|
if (False(weap->GetAttribField() & EProjectileAttrib::KeepInCinematic)) {
|
2018-12-08 05:30:43 +00:00
|
|
|
if (TCastToConstPtr<CAi>(mgr.GetObjectById(weap->GetOwnerId())) ||
|
|
|
|
TCastToConstPtr<CPlayer>(mgr.GetObjectById(weap->GetOwnerId())))
|
|
|
|
mgr.FreeScriptObject(weap->GetUniqueId());
|
2017-11-24 08:23:28 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
2017-11-24 08:23:28 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
2017-11-24 08:23:28 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CCameraManager::AddCinemaCamera(TUniqueId id, CStateManager& stateMgr) {
|
2020-04-05 05:01:54 +00:00
|
|
|
if (x4_cineCameras.empty()) {
|
2018-12-08 05:30:43 +00:00
|
|
|
EnterCinematic(stateMgr);
|
2020-04-05 05:01:54 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
RemoveCinemaCamera(id, stateMgr);
|
|
|
|
x4_cineCameras.push_back(id);
|
2020-04-05 05:01:54 +00:00
|
|
|
|
|
|
|
if (const TCastToPtr<CCinematicCamera> cam = stateMgr.ObjectById(id)) {
|
|
|
|
// Into player eye
|
|
|
|
if ((cam->GetFlags() & 0x4) != 0) {
|
2018-12-08 05:30:43 +00:00
|
|
|
float time = 4.f;
|
|
|
|
float delayTime = cam->GetDuration() - 4.f;
|
|
|
|
if (delayTime < 0.f) {
|
|
|
|
delayTime = 0.f;
|
|
|
|
time = cam->GetDuration();
|
|
|
|
}
|
|
|
|
cam->SetFovInterpolation(cam->GetFov(), 55.f, time, delayTime);
|
2017-11-24 08:23:28 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
2017-11-24 08:23:28 +00:00
|
|
|
}
|
2016-04-17 02:50:45 +00:00
|
|
|
|
2020-03-25 06:33:32 +00:00
|
|
|
void CCameraManager::SetInsideFluid(bool isInside, TUniqueId fluidId) {
|
|
|
|
if (isInside) {
|
2018-12-08 05:30:43 +00:00
|
|
|
++x74_fluidCounter;
|
|
|
|
x78_fluidId = fluidId;
|
2020-03-25 06:33:32 +00:00
|
|
|
} else {
|
2018-12-08 05:30:43 +00:00
|
|
|
--x74_fluidCounter;
|
2020-03-25 06:33:32 +00:00
|
|
|
}
|
2016-04-17 02:50:45 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CCameraManager::Update(float dt, CStateManager& stateMgr) {
|
|
|
|
UpdateCameraHints(dt, stateMgr);
|
|
|
|
ThinkCameras(dt, stateMgr);
|
|
|
|
UpdateListener(stateMgr);
|
|
|
|
UpdateRumble(dt, stateMgr);
|
|
|
|
UpdateFog(dt, stateMgr);
|
2016-04-17 02:50:45 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
CGameCamera* CCameraManager::GetCurrentCamera(CStateManager& stateMgr) const {
|
|
|
|
CObjectList* camList = stateMgr.ObjectListById(EGameObjectList::GameCamera);
|
|
|
|
return static_cast<CGameCamera*>(camList->GetObjectById(GetCurrentCameraId()));
|
2016-04-17 02:50:45 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
const CGameCamera* CCameraManager::GetCurrentCamera(const CStateManager& stateMgr) const {
|
|
|
|
const CObjectList* camList = stateMgr.GetObjectListById(EGameObjectList::GameCamera);
|
|
|
|
return static_cast<const CGameCamera*>(camList->GetObjectById(GetCurrentCameraId()));
|
2016-04-16 21:49:47 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CCameraManager::CreateStandardCameras(CStateManager& stateMgr) {
|
|
|
|
TUniqueId fpId = stateMgr.AllocateUniqueId();
|
|
|
|
x7c_fpCamera =
|
2019-02-24 07:15:54 +00:00
|
|
|
new CFirstPersonCamera(fpId, zeus::CTransform(), stateMgr.Player()->GetUniqueId(),
|
2019-09-28 02:46:56 +00:00
|
|
|
g_tweakPlayer->GetOrbitCameraSpeed(), sFirstPersonFOV, NearPlane(), FarPlane(), Aspect());
|
2018-12-08 05:30:43 +00:00
|
|
|
stateMgr.AddObject(x7c_fpCamera);
|
|
|
|
stateMgr.Player()->SetCameraState(CPlayer::EPlayerCameraState::FirstPerson, stateMgr);
|
|
|
|
SetCurrentCameraId(fpId, stateMgr);
|
2017-03-24 05:30:16 +00:00
|
|
|
|
2019-09-28 02:46:56 +00:00
|
|
|
x80_ballCamera = new CBallCamera(stateMgr.AllocateUniqueId(), stateMgr.Player()->GetUniqueId(), zeus::CTransform(),
|
|
|
|
ThirdPersonFOV(), NearPlane(), FarPlane(), Aspect());
|
2018-12-08 05:30:43 +00:00
|
|
|
stateMgr.AddObject(x80_ballCamera);
|
2017-03-24 05:30:16 +00:00
|
|
|
|
2019-02-24 07:15:54 +00:00
|
|
|
x88_interpCamera = new CInterpolationCamera(stateMgr.AllocateUniqueId(), zeus::CTransform());
|
2018-12-08 05:30:43 +00:00
|
|
|
stateMgr.AddObject(x88_interpCamera);
|
2017-03-24 05:30:16 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CCameraManager::SkipCinematic(CStateManager& stateMgr) {
|
2020-04-05 05:01:54 +00:00
|
|
|
const TUniqueId camId = GetCurrentCameraId();
|
|
|
|
auto* ent = static_cast<CCinematicCamera*>(stateMgr.ObjectById(camId));
|
2018-12-08 05:30:43 +00:00
|
|
|
while (ent) {
|
|
|
|
ent->SetActive(false);
|
|
|
|
ent->WasDeactivated(stateMgr);
|
|
|
|
ent = TCastToPtr<CCinematicCamera>(GetCurrentCamera(stateMgr)).GetPtr();
|
|
|
|
}
|
|
|
|
stateMgr.GetPlayer().UpdateCinematicState(stateMgr);
|
|
|
|
x7c_fpCamera->SkipCinematic();
|
2017-02-18 02:19:50 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CCameraManager::SetPathCamera(TUniqueId id, CStateManager& mgr) {
|
|
|
|
xa4_pathCamId = id;
|
2020-04-05 05:01:54 +00:00
|
|
|
if (const TCastToPtr<CPathCamera> cam = mgr.ObjectById(id)) {
|
2018-12-08 05:30:43 +00:00
|
|
|
cam->Reset(GetCurrentCameraTransform(mgr), mgr);
|
|
|
|
x80_ballCamera->TeleportCamera(cam->GetTransform(), mgr);
|
|
|
|
}
|
2017-10-06 07:29:56 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CCameraManager::SetSpindleCamera(TUniqueId id, CStateManager& mgr) {
|
|
|
|
xa2_spindleCamId = id;
|
2020-04-05 05:01:54 +00:00
|
|
|
if (const TCastToPtr<CScriptSpindleCamera> cam = mgr.ObjectById(id)) {
|
2018-12-08 05:30:43 +00:00
|
|
|
cam->Reset(GetCurrentCameraTransform(mgr), mgr);
|
|
|
|
x80_ballCamera->TeleportCamera(cam->GetTransform(), mgr);
|
|
|
|
}
|
2017-10-06 07:29:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CCameraManager::InterpolateToBallCamera(const zeus::CTransform& xf, TUniqueId camId,
|
2018-06-28 01:17:01 +00:00
|
|
|
const zeus::CVector3f& lookPos, float maxTime, float positionSpeed,
|
2018-12-08 05:30:43 +00:00
|
|
|
float rotationSpeed, bool sinusoidal, CStateManager& mgr) {
|
|
|
|
if (!IsInFirstPersonCamera()) {
|
|
|
|
x88_interpCamera->SetInterpolation(xf, lookPos, maxTime, positionSpeed, rotationSpeed, camId, sinusoidal, mgr);
|
|
|
|
if (!ShouldBypassInterpolation())
|
|
|
|
SetCurrentCameraId(x88_interpCamera->GetUniqueId(), mgr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CCameraManager::RestoreHintlessCamera(CStateManager& mgr) {
|
2020-04-05 05:01:54 +00:00
|
|
|
const TCastToConstPtr<CScriptCameraHint> hint = mgr.ObjectById(xa6_camHintId);
|
|
|
|
const zeus::CTransform ballCamXf = x80_ballCamera->GetTransform();
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
xa6_camHintId = kInvalidUniqueId;
|
|
|
|
xa8_hintPriority = 1000;
|
2020-04-05 05:01:54 +00:00
|
|
|
|
|
|
|
if (!hint) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
zeus::CVector3f camToPlayerFlat = mgr.GetPlayer().GetTranslation() - ballCamXf.origin;
|
|
|
|
camToPlayerFlat.z() = 0.f;
|
|
|
|
if (camToPlayerFlat.canBeNormalized()) {
|
|
|
|
camToPlayerFlat.normalize();
|
|
|
|
} else {
|
|
|
|
camToPlayerFlat = mgr.GetPlayer().GetMoveDir();
|
|
|
|
}
|
|
|
|
|
|
|
|
x80_ballCamera->ResetToTweaks(mgr);
|
|
|
|
x80_ballCamera->UpdateLookAtPosition(0.f, mgr);
|
|
|
|
if (!mgr.GetPlayer().IsMorphBallTransitioning() &&
|
|
|
|
hint->GetHint().GetBehaviourType() != CBallCamera::EBallCameraBehaviour::Default) {
|
|
|
|
if ((hint->GetHint().GetOverrideFlags() & 0x1000) != 0) {
|
|
|
|
x80_ballCamera->SetClampVelRange(hint->GetHint().GetClampVelRange());
|
|
|
|
x80_ballCamera->SetClampVelTimer(hint->GetHint().GetClampVelTime());
|
|
|
|
} else {
|
|
|
|
x80_ballCamera->TeleportCamera(x80_ballCamera->UpdateLookDirection(camToPlayerFlat, mgr), mgr);
|
|
|
|
InterpolateToBallCamera(ballCamXf, x80_ballCamera->GetUniqueId(), x80_ballCamera->GetLookPos(),
|
|
|
|
hint->GetHint().GetClampVelTime(), hint->GetHint().GetClampVelRange(),
|
|
|
|
hint->GetHint().GetClampRotRange(), (hint->GetHint().GetOverrideFlags() & 0x800) != 0,
|
|
|
|
mgr);
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CCameraManager::SkipBallCameraCinematic(CStateManager& mgr) {
|
|
|
|
if (IsInCinematicCamera()) {
|
|
|
|
x80_ballCamera->TeleportCamera(GetLastCineCamera(mgr)->GetTransform(), mgr);
|
|
|
|
x80_ballCamera->SetFovInterpolation(GetLastCineCamera(mgr)->GetFov(), x80_ballCamera->GetFov(), 1.f, 0.f);
|
|
|
|
SkipCinematic(mgr);
|
|
|
|
SetCurrentCameraId(x80_ballCamera->GetUniqueId(), mgr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CCameraManager::ApplyCameraHint(const CScriptCameraHint& hint, CStateManager& mgr) {
|
|
|
|
if (x80_ballCamera->GetState() == CBallCamera::EBallCameraState::ToBall) {
|
|
|
|
x80_ballCamera->SetState(CBallCamera::EBallCameraState::Default, mgr);
|
|
|
|
mgr.GetPlayer().SetCameraState(CPlayer::EPlayerCameraState::Ball, mgr);
|
|
|
|
}
|
|
|
|
|
2020-04-05 05:01:54 +00:00
|
|
|
const TCastToConstPtr<CScriptCameraHint> oldHint = mgr.ObjectById(xa6_camHintId);
|
2018-12-08 05:30:43 +00:00
|
|
|
xa6_camHintId = hint.GetUniqueId();
|
|
|
|
xa8_hintPriority = hint.GetPriority();
|
|
|
|
|
2020-04-05 05:01:54 +00:00
|
|
|
const zeus::CTransform camXf = GetCurrentCameraTransform(mgr);
|
2018-12-08 05:30:43 +00:00
|
|
|
x80_ballCamera->ApplyCameraHint(mgr);
|
|
|
|
|
2020-04-05 05:01:54 +00:00
|
|
|
if ((hint.GetHint().GetOverrideFlags() & 0x20) != 0) {
|
2018-12-08 05:30:43 +00:00
|
|
|
x80_ballCamera->ResetPosition(mgr);
|
2020-04-05 05:01:54 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
|
|
|
|
switch (hint.GetHint().GetBehaviourType()) {
|
|
|
|
case CBallCamera::EBallCameraBehaviour::PathCameraDesiredPos:
|
|
|
|
case CBallCamera::EBallCameraBehaviour::PathCamera:
|
|
|
|
SetPathCamera(hint.GetDelegatedCamera(), mgr);
|
|
|
|
break;
|
|
|
|
case CBallCamera::EBallCameraBehaviour::SpindleCamera:
|
|
|
|
SetSpindleCamera(hint.GetDelegatedCamera(), mgr);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
SetPathCamera(kInvalidUniqueId, mgr);
|
|
|
|
SetSpindleCamera(kInvalidUniqueId, mgr);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2020-04-05 05:01:54 +00:00
|
|
|
if ((hint.GetHint().GetOverrideFlags() & 0x2000) != 0) {
|
2018-12-08 05:30:43 +00:00
|
|
|
SkipBallCameraCinematic(mgr);
|
2020-04-05 05:01:54 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
|
|
|
|
x80_ballCamera->UpdateLookAtPosition(0.f, mgr);
|
|
|
|
|
|
|
|
if ((hint.GetHint().GetOverrideFlags() & 0x20) == 0 &&
|
|
|
|
(hint.GetHint().GetBehaviourType() != CBallCamera::EBallCameraBehaviour::Default ||
|
|
|
|
(oldHint && oldHint->GetHint().GetBehaviourType() != CBallCamera::EBallCameraBehaviour::Default))) {
|
|
|
|
InterpolateToBallCamera(camXf, x80_ballCamera->GetUniqueId(), x80_ballCamera->GetLookPos(),
|
|
|
|
hint.GetHint().GetInterpolateTime(), hint.GetHint().GetClampVelRange(),
|
|
|
|
hint.GetHint().GetClampRotRange(), (hint.GetHint().GetOverrideFlags() & 0x400) != 0, mgr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CCameraManager::UpdateCameraHints(float, CStateManager& mgr) {
|
|
|
|
bool invalidHintRemoved = false;
|
|
|
|
for (auto it = xac_cameraHints.begin(); it != xac_cameraHints.end();) {
|
2020-04-05 05:01:54 +00:00
|
|
|
if (!TCastToConstPtr<CScriptCameraHint>(mgr.ObjectById(it->second))) {
|
2018-12-08 05:30:43 +00:00
|
|
|
invalidHintRemoved = true;
|
|
|
|
it = xac_cameraHints.erase(it);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
++it;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool inactiveHintRemoved = false;
|
2020-09-18 21:04:50 +00:00
|
|
|
for (const auto& id : x2b0_inactiveCameraHints) {
|
2020-04-05 05:01:54 +00:00
|
|
|
if (const TCastToConstPtr<CScriptCameraHint> hint = mgr.GetObjectById(id)) {
|
2018-12-08 05:30:43 +00:00
|
|
|
if (hint->GetHelperCount() == 0 || hint->GetInactive()) {
|
|
|
|
for (auto it = xac_cameraHints.begin(); it != xac_cameraHints.end(); ++it) {
|
|
|
|
if (it->second == id) {
|
|
|
|
xac_cameraHints.erase(it);
|
|
|
|
if (xa6_camHintId == id) {
|
|
|
|
inactiveHintRemoved = true;
|
|
|
|
SetPathCamera(kInvalidUniqueId, mgr);
|
|
|
|
SetSpindleCamera(kInvalidUniqueId, mgr);
|
2017-10-06 07:29:56 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
break;
|
|
|
|
}
|
2017-10-06 07:29:56 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
x2b0_inactiveCameraHints.clear();
|
|
|
|
|
|
|
|
bool activeHintAdded = false;
|
2020-09-18 21:04:50 +00:00
|
|
|
for (const auto& id : x334_activeCameraHints) {
|
2020-04-05 05:01:54 +00:00
|
|
|
if (const TCastToConstPtr<CScriptCameraHint> hint = mgr.GetObjectById(id)) {
|
2018-12-08 05:30:43 +00:00
|
|
|
bool activeHintPresent = false;
|
|
|
|
for (auto it = xac_cameraHints.begin(); it != xac_cameraHints.end(); ++it) {
|
|
|
|
if (it->second == id) {
|
|
|
|
activeHintPresent = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2017-10-06 07:29:56 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
if (!activeHintPresent) {
|
|
|
|
activeHintAdded = true;
|
|
|
|
xac_cameraHints.emplace_back(hint->GetPriority(), id);
|
|
|
|
}
|
2017-10-06 07:29:56 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
|
|
|
x334_activeCameraHints.clear();
|
2017-10-06 07:29:56 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
if (inactiveHintRemoved || activeHintAdded || invalidHintRemoved) {
|
|
|
|
std::sort(xac_cameraHints.begin(), xac_cameraHints.end(),
|
|
|
|
[](const auto& a, const auto& b) { return a.first < b.first; });
|
|
|
|
zeus::CTransform ballCamXf = x80_ballCamera->GetTransform();
|
|
|
|
if ((inactiveHintRemoved || invalidHintRemoved) && xac_cameraHints.empty()) {
|
|
|
|
RestoreHintlessCamera(mgr);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
bool foundHint = false;
|
2020-04-05 05:01:54 +00:00
|
|
|
const CScriptCameraHint* bestHint = nullptr;
|
2018-12-08 05:30:43 +00:00
|
|
|
for (auto& h : xac_cameraHints) {
|
2020-04-05 05:01:54 +00:00
|
|
|
if (const TCastToConstPtr<CScriptCameraHint> hint = mgr.ObjectById(h.second)) {
|
2018-12-08 05:30:43 +00:00
|
|
|
bestHint = hint.GetPtr();
|
|
|
|
foundHint = true;
|
2017-10-06 07:29:56 +00:00
|
|
|
break;
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
|
|
|
}
|
2020-04-05 05:01:54 +00:00
|
|
|
if (!foundHint) {
|
2018-12-08 05:30:43 +00:00
|
|
|
RestoreHintlessCamera(mgr);
|
2020-04-05 05:01:54 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
|
|
|
|
bool changeHint = false;
|
|
|
|
if (bestHint && foundHint) {
|
|
|
|
if ((bestHint->GetHint().GetOverrideFlags() & 0x80) != 0 && xac_cameraHints.size() > 1) {
|
|
|
|
zeus::CVector3f ballPos = mgr.GetPlayer().GetBallPosition();
|
|
|
|
if ((bestHint->GetHint().GetOverrideFlags() & 0x100) != 0) {
|
|
|
|
zeus::CVector3f camToBall = ballPos - ballCamXf.origin;
|
2020-04-05 05:01:54 +00:00
|
|
|
if (camToBall.canBeNormalized()) {
|
2018-12-08 05:30:43 +00:00
|
|
|
camToBall.normalize();
|
2020-04-05 05:01:54 +00:00
|
|
|
} else {
|
2018-12-08 05:30:43 +00:00
|
|
|
camToBall = ballCamXf.basis[1];
|
2020-04-05 05:01:54 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
|
|
|
|
for (auto it = xac_cameraHints.begin() + 1; it != xac_cameraHints.end(); ++it) {
|
2020-04-05 05:01:54 +00:00
|
|
|
if (const TCastToConstPtr<CScriptCameraHint> hint = mgr.ObjectById(it->second)) {
|
2018-12-08 05:30:43 +00:00
|
|
|
if ((hint->GetHint().GetOverrideFlags() & 0x80) != 0 && hint->GetPriority() == bestHint->GetPriority() &&
|
|
|
|
hint->GetAreaIdAlways() == bestHint->GetAreaIdAlways()) {
|
|
|
|
zeus::CVector3f hintToBall = ballPos - bestHint->GetTranslation();
|
2020-04-05 05:01:54 +00:00
|
|
|
if (hintToBall.canBeNormalized()) {
|
2018-12-08 05:30:43 +00:00
|
|
|
hintToBall.normalize();
|
2020-04-05 05:01:54 +00:00
|
|
|
} else {
|
2018-12-08 05:30:43 +00:00
|
|
|
hintToBall = bestHint->GetTransform().basis[1];
|
2020-04-05 05:01:54 +00:00
|
|
|
}
|
2017-10-06 07:29:56 +00:00
|
|
|
|
2020-04-05 05:01:54 +00:00
|
|
|
const float camHintDot = zeus::clamp(-1.f, camToBall.dot(hintToBall), 1.f);
|
2017-10-06 07:29:56 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
zeus::CVector3f thisHintToBall = ballPos - hint->GetTranslation();
|
2020-04-05 05:01:54 +00:00
|
|
|
if (thisHintToBall.canBeNormalized()) {
|
2018-12-08 05:30:43 +00:00
|
|
|
thisHintToBall.normalize();
|
2020-04-05 05:01:54 +00:00
|
|
|
} else {
|
2018-12-08 05:30:43 +00:00
|
|
|
thisHintToBall = hint->GetTransform().basis[1];
|
2020-04-05 05:01:54 +00:00
|
|
|
}
|
2017-10-06 07:29:56 +00:00
|
|
|
|
2020-04-05 05:01:54 +00:00
|
|
|
const float camThisHintDot = zeus::clamp(-1.f, camToBall.dot(thisHintToBall), 1.f);
|
2017-10-06 07:29:56 +00:00
|
|
|
|
2020-04-05 05:01:54 +00:00
|
|
|
if (camThisHintDot > camHintDot) {
|
2018-12-08 05:30:43 +00:00
|
|
|
bestHint = hint.GetPtr();
|
2020-04-05 05:01:54 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
} else {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
break;
|
2017-10-06 07:29:56 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
|
|
|
} else {
|
2020-04-05 05:01:54 +00:00
|
|
|
if (const TCastToConstPtr<CActor> act = mgr.GetObjectById(bestHint->GetFirstHelper())) {
|
2020-04-10 17:43:52 +00:00
|
|
|
const zeus::CVector3f f26 = act->GetTranslation() - mgr.GetPlayer().GetBallPosition();
|
2018-12-08 05:30:43 +00:00
|
|
|
zeus::CVector3f ballToHelper = f26;
|
2020-04-05 05:01:54 +00:00
|
|
|
if (ballToHelper.canBeNormalized()) {
|
2018-12-08 05:30:43 +00:00
|
|
|
ballToHelper.normalize();
|
2020-04-05 05:01:54 +00:00
|
|
|
} else {
|
2018-12-08 05:30:43 +00:00
|
|
|
ballToHelper = bestHint->GetTransform().basis[1];
|
2020-04-05 05:01:54 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
|
|
|
|
for (auto it = xac_cameraHints.begin() + 1; it != xac_cameraHints.end(); ++it) {
|
2020-04-05 05:01:54 +00:00
|
|
|
if (const TCastToConstPtr<CScriptCameraHint> hint = mgr.ObjectById(it->second)) {
|
2018-12-08 05:30:43 +00:00
|
|
|
if ((hint->GetHint().GetOverrideFlags() & 0x80) != 0 &&
|
|
|
|
hint->GetPriority() == bestHint->GetPriority() &&
|
|
|
|
hint->GetAreaIdAlways() == bestHint->GetAreaIdAlways()) {
|
|
|
|
zeus::CVector3f hintToHelper = act->GetTranslation() - bestHint->GetTranslation();
|
2020-04-05 05:01:54 +00:00
|
|
|
if (hintToHelper.canBeNormalized()) {
|
2018-12-08 05:30:43 +00:00
|
|
|
hintToHelper.normalize();
|
2020-04-05 05:01:54 +00:00
|
|
|
} else {
|
2018-12-08 05:30:43 +00:00
|
|
|
hintToHelper = bestHint->GetTransform().basis[1];
|
2020-04-05 05:01:54 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
|
2020-04-05 05:01:54 +00:00
|
|
|
const float ballHintDot = zeus::clamp(-1.f, ballToHelper.dot(hintToHelper), 1.f);
|
2018-12-08 05:30:43 +00:00
|
|
|
|
|
|
|
zeus::CVector3f thisBallToHelper = f26;
|
2020-04-05 05:01:54 +00:00
|
|
|
if (thisBallToHelper.canBeNormalized()) {
|
2018-12-08 05:30:43 +00:00
|
|
|
thisBallToHelper.normalize();
|
2020-04-05 05:01:54 +00:00
|
|
|
} else {
|
2018-12-08 05:30:43 +00:00
|
|
|
thisBallToHelper = hint->GetTransform().basis[1];
|
2020-04-05 05:01:54 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
|
|
|
|
zeus::CVector3f thisHintToHelper = act->GetTranslation() - hint->GetTranslation();
|
2020-04-05 05:01:54 +00:00
|
|
|
if (thisHintToHelper.canBeNormalized()) {
|
2018-12-08 05:30:43 +00:00
|
|
|
thisHintToHelper.normalize();
|
2020-04-05 05:01:54 +00:00
|
|
|
} else {
|
2018-12-08 05:30:43 +00:00
|
|
|
thisHintToHelper = hint->GetTransform().basis[1];
|
2020-04-05 05:01:54 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
|
2020-04-05 05:01:54 +00:00
|
|
|
const float thisBallHintDot = zeus::clamp(-1.f, thisBallToHelper.dot(thisHintToHelper), 1.f);
|
2018-12-08 05:30:43 +00:00
|
|
|
|
2020-04-05 05:01:54 +00:00
|
|
|
if (thisBallHintDot > ballHintDot) {
|
2018-12-08 05:30:43 +00:00
|
|
|
bestHint = hint.GetPtr();
|
2020-04-05 05:01:54 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
} else {
|
|
|
|
break;
|
2017-10-06 07:29:56 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
} else {
|
2017-10-06 07:29:56 +00:00
|
|
|
break;
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
2017-10-06 07:29:56 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
2017-10-06 07:29:56 +00:00
|
|
|
}
|
|
|
|
|
2020-04-05 05:01:54 +00:00
|
|
|
if (bestHint->GetUniqueId() != xa6_camHintId) {
|
2018-12-08 05:30:43 +00:00
|
|
|
changeHint = true;
|
2020-04-05 05:01:54 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
} else if (xa6_camHintId != bestHint->GetUniqueId()) {
|
|
|
|
if (bestHint->GetHint().GetBehaviourType() == CBallCamera::EBallCameraBehaviour::HintInitializePosition) {
|
|
|
|
if ((bestHint->GetHint().GetOverrideFlags() & 0x20) != 0) {
|
|
|
|
x80_ballCamera->TeleportCamera(zeus::lookAt(bestHint->GetTranslation(), x80_ballCamera->GetLookPos()), mgr);
|
|
|
|
}
|
|
|
|
DeleteCameraHint(bestHint->GetUniqueId(), mgr);
|
2020-04-05 05:01:54 +00:00
|
|
|
if ((bestHint->GetHint().GetOverrideFlags() & 0x2000) != 0) {
|
2018-12-08 05:30:43 +00:00
|
|
|
SkipBallCameraCinematic(mgr);
|
2020-04-05 05:01:54 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
changeHint = false;
|
|
|
|
} else {
|
|
|
|
changeHint = true;
|
2017-10-06 07:29:56 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
|
|
|
|
2020-04-05 05:01:54 +00:00
|
|
|
if (changeHint) {
|
2018-12-08 05:30:43 +00:00
|
|
|
ApplyCameraHint(*bestHint, mgr);
|
2020-04-05 05:01:54 +00:00
|
|
|
}
|
2017-10-06 07:29:56 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
2016-10-31 22:56:44 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CCameraManager::ThinkCameras(float dt, CStateManager& mgr) {
|
|
|
|
CGameCameraList gcList = mgr.GetCameraObjectList();
|
2016-10-31 22:56:44 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
for (CEntity* ent : gcList) {
|
2020-04-05 05:01:54 +00:00
|
|
|
if (const TCastToPtr<CGameCamera> gc = ent) {
|
2018-12-08 05:30:43 +00:00
|
|
|
gc->Think(dt, mgr);
|
|
|
|
gc->UpdatePerspective(dt);
|
2016-10-31 22:56:44 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
2016-10-31 22:56:44 +00:00
|
|
|
|
2020-04-05 05:01:54 +00:00
|
|
|
if (IsInCinematicCamera()) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return;
|
2020-04-05 05:01:54 +00:00
|
|
|
}
|
2016-10-31 22:56:44 +00:00
|
|
|
|
2020-04-05 05:01:54 +00:00
|
|
|
const TUniqueId camId = GetLastCameraId();
|
|
|
|
if (const CGameCamera* cam = TCastToConstPtr<CGameCamera>(mgr.GetObjectById(camId))) {
|
2018-12-08 05:30:43 +00:00
|
|
|
x3bc_curFov = cam->GetFov();
|
2020-04-05 05:01:54 +00:00
|
|
|
}
|
2016-10-31 22:56:44 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CCameraManager::UpdateFog(float dt, CStateManager& mgr) {
|
|
|
|
if (x98_fogDensitySpeed != 0.f) {
|
|
|
|
x94_fogDensityFactor += dt * x98_fogDensitySpeed;
|
|
|
|
if ((x98_fogDensitySpeed > 0.f) ? x94_fogDensityFactor > x9c_fogDensityFactorTarget
|
|
|
|
: x94_fogDensityFactor < x9c_fogDensityFactorTarget) {
|
|
|
|
x94_fogDensityFactor = x9c_fogDensityFactorTarget;
|
|
|
|
x98_fogDensitySpeed = 0.f;
|
2017-10-06 07:29:56 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
2017-10-06 07:29:56 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
if (x74_fluidCounter) {
|
2020-04-05 05:01:54 +00:00
|
|
|
if (const TCastToConstPtr<CScriptWater> water = mgr.GetObjectById(x78_fluidId)) {
|
|
|
|
const zeus::CVector2f zRange(GetCurrentCamera(mgr)->GetNearClipDistance(),
|
|
|
|
CalculateFogDensity(mgr, water.GetPtr()));
|
2018-12-08 05:30:43 +00:00
|
|
|
x3c_fog.SetFogExplicit(ERglFogMode::PerspExp, water->GetInsideFogColor(), zRange);
|
2020-04-05 05:01:54 +00:00
|
|
|
if (mgr.GetPlayerState()->GetActiveVisor(mgr) == CPlayerState::EPlayerVisor::Thermal) {
|
2017-10-06 07:29:56 +00:00
|
|
|
mgr.GetCameraFilterPass(4).DisableFilter(0.f);
|
2020-04-05 05:01:54 +00:00
|
|
|
} else {
|
2018-12-08 05:30:43 +00:00
|
|
|
mgr.GetCameraFilterPass(4).SetFilter(EFilterType::Multiply, EFilterShape::Fullscreen, 0.f,
|
|
|
|
water->GetInsideFogColor(), {});
|
2020-04-05 05:01:54 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
|
|
|
xa0_26_inWater = true;
|
|
|
|
} else if (xa0_26_inWater) {
|
|
|
|
mgr.GetCameraManager()->x3c_fog.DisableFog();
|
|
|
|
mgr.GetCameraFilterPass(4).DisableFilter(0.f);
|
|
|
|
xa0_26_inWater = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
x3c_fog.Update(dt);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CCameraManager::UpdateRumble(float dt, CStateManager& mgr) {
|
2019-02-24 07:15:54 +00:00
|
|
|
x30_shakeOffset = zeus::skZero3f;
|
2018-12-08 05:30:43 +00:00
|
|
|
for (auto it = x14_shakers.begin(); it != x14_shakers.end();) {
|
|
|
|
CCameraShakeData& shaker = *it;
|
|
|
|
shaker.Update(dt, mgr);
|
|
|
|
if (shaker.x4_curTime >= shaker.x0_duration) {
|
|
|
|
it = x14_shakers.erase(it);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
x30_shakeOffset += shaker.GetPoint();
|
|
|
|
++it;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!x14_shakers.empty() && !xa0_25_rumbling && xa0_24_pendingRumble) {
|
|
|
|
mgr.GetRumbleManager().Rumble(mgr, ERumbleFxId::CameraShake, 1.f, ERumblePriority::Two);
|
|
|
|
xa0_25_rumbling = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (x90_rumbleCooldown > 0.f) {
|
|
|
|
x90_rumbleCooldown -= dt;
|
|
|
|
} else if (xa0_25_rumbling) {
|
|
|
|
xa0_24_pendingRumble = false;
|
|
|
|
xa0_25_rumbling = false;
|
|
|
|
}
|
|
|
|
|
2020-04-05 05:01:54 +00:00
|
|
|
if (mgr.GetPlayer().GetCameraState() != CPlayer::EPlayerCameraState::FirstPerson && !IsInCinematicCamera()) {
|
2019-02-24 07:15:54 +00:00
|
|
|
x30_shakeOffset = zeus::skZero3f;
|
2020-04-05 05:01:54 +00:00
|
|
|
}
|
2016-10-31 22:56:44 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CCameraManager::UpdateListener(CStateManager& mgr) {
|
|
|
|
const zeus::CTransform xf = GetCurrentCameraTransform(mgr);
|
2019-02-24 07:15:54 +00:00
|
|
|
CSfxManager::UpdateListener(xf.origin, zeus::skZero3f, xf.frontVector(), xf.upVector(), 1.f);
|
2016-10-31 22:56:44 +00:00
|
|
|
}
|
|
|
|
|
2019-08-14 10:04:11 +00:00
|
|
|
float CCameraManager::CalculateFogDensity(CStateManager& mgr, const CScriptWater* water) const {
|
2020-04-05 05:01:54 +00:00
|
|
|
const float distanceFactor = 1.f - water->GetFluidPlane().GetAlpha();
|
2018-12-08 05:30:43 +00:00
|
|
|
float distance = 0;
|
2020-04-05 05:01:54 +00:00
|
|
|
if (mgr.GetPlayerState()->HasPowerUp(CPlayerState::EItemType::GravitySuit)) {
|
2018-12-08 05:30:43 +00:00
|
|
|
distance =
|
|
|
|
g_tweakGame->GetGravityWaterFogDistanceRange() * distanceFactor + g_tweakGame->GetGravityWaterFogDistanceBase();
|
2020-04-05 05:01:54 +00:00
|
|
|
} else {
|
2018-12-08 05:30:43 +00:00
|
|
|
distance = g_tweakGame->GetWaterFogDistanceRange() * distanceFactor + g_tweakGame->GetWaterFogDistanceBase();
|
2020-04-05 05:01:54 +00:00
|
|
|
}
|
2016-10-31 22:56:44 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
return distance * x94_fogDensityFactor;
|
2016-10-31 22:56:44 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CCameraManager::ResetCameras(CStateManager& mgr) {
|
|
|
|
zeus::CTransform xf = mgr.GetPlayer().CreateTransformFromMovementDirection();
|
|
|
|
xf.origin = mgr.GetPlayer().GetEyePosition();
|
2016-08-15 01:19:04 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
for (CEntity* ent : mgr.GetCameraObjectList()) {
|
2020-04-05 05:01:54 +00:00
|
|
|
const TCastToPtr<CGameCamera> camObj(ent);
|
2018-12-08 05:30:43 +00:00
|
|
|
camObj->Reset(xf, mgr);
|
|
|
|
}
|
2016-08-15 01:19:04 +00:00
|
|
|
}
|
2016-10-15 19:18:50 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CCameraManager::SetSpecialCameras(CFirstPersonCamera& fp, CBallCamera& ball) {
|
|
|
|
x7c_fpCamera = &fp;
|
|
|
|
x80_ballCamera = &ball;
|
2016-10-15 19:18:50 +00:00
|
|
|
}
|
2017-03-24 05:30:16 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CCameraManager::ProcessInput(const CFinalInput& input, CStateManager& stateMgr) {
|
|
|
|
for (CEntity* ent : stateMgr.GetCameraObjectList()) {
|
2020-04-05 05:01:54 +00:00
|
|
|
if (ent == nullptr) {
|
2018-12-08 05:30:43 +00:00
|
|
|
continue;
|
2020-04-05 05:01:54 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
auto& cam = static_cast<CGameCamera&>(*ent);
|
2020-04-05 05:01:54 +00:00
|
|
|
if (input.ControllerIdx() != cam.x16c_controllerIdx) {
|
2018-12-08 05:30:43 +00:00
|
|
|
continue;
|
2020-04-05 05:01:54 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
cam.ProcessInput(input, stateMgr);
|
|
|
|
}
|
2017-03-24 05:30:16 +00:00
|
|
|
}
|
2017-03-26 19:36:07 +00:00
|
|
|
|
2020-04-09 17:28:20 +00:00
|
|
|
void CCameraManager::RenderCameras(CStateManager& mgr) {
|
|
|
|
for (CEntity* cam : mgr.GetCameraObjectList()) {
|
2018-12-08 05:30:43 +00:00
|
|
|
static_cast<CGameCamera*>(cam)->Render(mgr);
|
2020-04-09 17:28:20 +00:00
|
|
|
}
|
2017-03-26 19:36:07 +00:00
|
|
|
}
|
2017-08-02 07:13:11 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CCameraManager::SetupBallCamera(CStateManager& mgr) {
|
2020-04-05 05:01:54 +00:00
|
|
|
if (const TCastToConstPtr<CScriptCameraHint> hint = mgr.ObjectById(xa6_camHintId)) {
|
2018-12-08 05:30:43 +00:00
|
|
|
if (hint->GetHint().GetBehaviourType() == CBallCamera::EBallCameraBehaviour::HintInitializePosition) {
|
2020-04-05 05:01:54 +00:00
|
|
|
if ((hint->GetHint().GetOverrideFlags() & 0x20) != 0) {
|
2018-12-08 05:30:43 +00:00
|
|
|
x80_ballCamera->TeleportCamera(hint->GetTransform(), mgr);
|
2020-04-05 05:01:54 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
AddInactiveCameraHint(xa6_camHintId, mgr);
|
|
|
|
} else {
|
|
|
|
ApplyCameraHint(*hint, mgr);
|
2017-10-07 05:32:11 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
2017-08-02 07:13:11 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CCameraManager::SetPlayerCamera(CStateManager& mgr, TUniqueId newCamId) {
|
|
|
|
if (x88_interpCamera->GetActive()) {
|
|
|
|
x88_interpCamera->SetActive(false);
|
|
|
|
x80_ballCamera->SkipFovInterpolation();
|
|
|
|
if (!ShouldBypassInterpolation())
|
|
|
|
SetCurrentCameraId(newCamId, mgr);
|
|
|
|
}
|
2017-08-02 07:13:11 +00:00
|
|
|
}
|
2017-08-16 05:34:02 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
float CCameraManager::GetCameraBobMagnitude() const {
|
2021-06-07 19:29:18 +00:00
|
|
|
return 1.f - zeus::clamp(-1.f,
|
|
|
|
std::fabs(zeus::clamp(-1.f, x7c_fpCamera->GetTransform().basis[1].dot(zeus::skUp), 1.f)) /
|
|
|
|
std::cos(2.f * M_PIF / 12.f),
|
|
|
|
1.f);
|
2017-08-16 05:34:02 +00:00
|
|
|
}
|
2017-08-18 01:30:15 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
bool CCameraManager::HasBallCameraInitialPositionHint(CStateManager& mgr) const {
|
|
|
|
if (HasCameraHint(mgr)) {
|
|
|
|
switch (mgr.GetCameraManager()->GetCameraHint(mgr)->GetHint().GetBehaviourType()) {
|
|
|
|
case CBallCamera::EBallCameraBehaviour::HintBallToCam:
|
|
|
|
case CBallCamera::EBallCameraBehaviour::HintFixedPosition:
|
|
|
|
case CBallCamera::EBallCameraBehaviour::HintFixedTransform:
|
|
|
|
case CBallCamera::EBallCameraBehaviour::PathCamera:
|
|
|
|
case CBallCamera::EBallCameraBehaviour::SpindleCamera:
|
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
return false;
|
2018-06-28 01:17:01 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
|
|
|
return false;
|
2017-08-18 01:30:15 +00:00
|
|
|
}
|
2017-08-29 13:17:52 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CCameraManager::RemoveCinemaCamera(TUniqueId uid, CStateManager& mgr) {
|
2020-04-05 05:25:52 +00:00
|
|
|
const auto search = std::find(x4_cineCameras.cbegin(), x4_cineCameras.cend(), uid);
|
2020-04-05 05:01:54 +00:00
|
|
|
|
2020-04-05 05:25:52 +00:00
|
|
|
if (search == x4_cineCameras.cend()) {
|
2020-04-05 05:01:54 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
x4_cineCameras.erase(search);
|
2017-08-29 13:17:52 +00:00
|
|
|
}
|
2017-10-05 05:40:44 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CCameraManager::DeleteCameraHint(TUniqueId id, CStateManager& mgr) {
|
2020-04-05 05:01:54 +00:00
|
|
|
const TCastToPtr<CScriptCameraHint> hint = mgr.ObjectById(id);
|
|
|
|
|
|
|
|
if (!hint) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-04-05 05:25:52 +00:00
|
|
|
const auto search = std::find_if(x2b0_inactiveCameraHints.cbegin(), x2b0_inactiveCameraHints.cend(),
|
2020-04-05 05:01:54 +00:00
|
|
|
[id](TUniqueId tid) { return tid == id; });
|
|
|
|
|
2020-04-05 05:25:52 +00:00
|
|
|
if (search != x2b0_inactiveCameraHints.cend()) {
|
2020-04-05 05:01:54 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
hint->ClearIdList();
|
|
|
|
hint->SetInactive(true);
|
|
|
|
if (x2b0_inactiveCameraHints.size() != 64) {
|
|
|
|
x2b0_inactiveCameraHints.push_back(id);
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
2017-10-05 05:40:44 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CCameraManager::AddInactiveCameraHint(TUniqueId id, CStateManager& mgr) {
|
2020-04-05 05:01:54 +00:00
|
|
|
if (const TCastToConstPtr<CScriptCameraHint> hint = mgr.ObjectById(id)) {
|
2020-04-05 05:25:52 +00:00
|
|
|
const auto search = std::find_if(x2b0_inactiveCameraHints.cbegin(), x2b0_inactiveCameraHints.cend(),
|
2020-04-05 05:01:54 +00:00
|
|
|
[id](TUniqueId tid) { return tid == id; });
|
2020-04-05 05:25:52 +00:00
|
|
|
if (search == x2b0_inactiveCameraHints.cend() && x2b0_inactiveCameraHints.size() != 64) {
|
2018-12-08 05:30:43 +00:00
|
|
|
x2b0_inactiveCameraHints.push_back(id);
|
2020-04-05 05:01:54 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
2017-10-05 05:40:44 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CCameraManager::AddActiveCameraHint(TUniqueId id, CStateManager& mgr) {
|
2020-04-05 05:01:54 +00:00
|
|
|
if (const TCastToConstPtr<CScriptCameraHint> hint = mgr.ObjectById(id)) {
|
2020-04-05 05:25:52 +00:00
|
|
|
const auto search = std::find_if(x334_activeCameraHints.cbegin(), x334_activeCameraHints.cend(),
|
2020-04-05 05:01:54 +00:00
|
|
|
[id](TUniqueId tid) { return tid == id; });
|
2021-06-07 19:29:18 +00:00
|
|
|
if (search == x334_activeCameraHints.cend() && xac_cameraHints.size() != 64 &&
|
|
|
|
x334_activeCameraHints.size() != 64) {
|
2018-12-08 05:30:43 +00:00
|
|
|
x334_activeCameraHints.push_back(id);
|
2020-04-05 05:01:54 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
2017-10-05 05:40:44 +00:00
|
|
|
}
|
2017-10-06 07:29:56 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
TUniqueId CCameraManager::GetLastCineCameraId() const {
|
2020-04-05 05:01:54 +00:00
|
|
|
if (x4_cineCameras.empty()) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return kInvalidUniqueId;
|
2020-04-05 05:01:54 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
return x4_cineCameras.back();
|
2017-10-06 07:29:56 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
const CCinematicCamera* CCameraManager::GetLastCineCamera(CStateManager& mgr) const {
|
|
|
|
return static_cast<const CCinematicCamera*>(mgr.GetObjectById(GetLastCineCameraId()));
|
2017-10-06 07:29:56 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
const CScriptCameraHint* CCameraManager::GetCameraHint(CStateManager& mgr) const {
|
|
|
|
return TCastToConstPtr<CScriptCameraHint>(mgr.GetObjectById(xa6_camHintId)).GetPtr();
|
2017-10-06 07:29:56 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
bool CCameraManager::HasCameraHint(CStateManager& mgr) const {
|
|
|
|
if (xac_cameraHints.empty() || xa6_camHintId == kInvalidUniqueId)
|
|
|
|
return false;
|
|
|
|
return mgr.GetObjectById(xa6_camHintId) != nullptr;
|
2017-10-06 07:29:56 +00:00
|
|
|
}
|
2017-10-10 03:50:48 +00:00
|
|
|
|
|
|
|
bool CCameraManager::IsInterpolationCameraActive() const { return x88_interpCamera->GetActive(); }
|
2018-11-19 05:00:33 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CCameraManager::SetFogDensity(float fogDensityTarget, float fogDensitySpeed) {
|
|
|
|
x9c_fogDensityFactorTarget = fogDensityTarget;
|
|
|
|
x98_fogDensitySpeed = (x9c_fogDensityFactorTarget >= x94_fogDensityFactor ? fogDensitySpeed : -fogDensitySpeed);
|
2016-04-16 21:49:47 +00:00
|
|
|
}
|
2021-04-10 08:42:06 +00:00
|
|
|
} // namespace metaforce
|