mirror of
https://github.com/AxioDL/metaforce.git
synced 2025-12-09 19:47:43 +00:00
CCameraManager imps
This commit is contained in:
@@ -7,14 +7,25 @@
|
||||
#include "Input/CRumbleManager.hpp"
|
||||
#include "World/CScriptWater.hpp"
|
||||
#include "World/CPlayer.hpp"
|
||||
|
||||
#include "World/CScriptWater.hpp"
|
||||
#include "CPlayerState.hpp"
|
||||
#include "GameGlobalObjects.hpp"
|
||||
#include "Graphics/CGraphics.hpp"
|
||||
#include "CObjectList.hpp"
|
||||
namespace urde
|
||||
{
|
||||
float CCameraManager::sAspect = 1.42f;
|
||||
float CCameraManager::sFarPlane = 750.f;
|
||||
float CCameraManager::sNearPlane = 0.2f;
|
||||
float CCameraManager::sFirstPersonFOV = 55.f;
|
||||
float CCameraManager::sThirdPersonFOV = 60.f;
|
||||
|
||||
CCameraManager::CCameraManager(TUniqueId curCameraId) : x0_curCameraId(curCameraId)
|
||||
{
|
||||
CSfxManager::AddListener(CSfxManager::ESfxChannels::One, zeus::CVector3f::skZero, zeus::CVector3f::skZero,
|
||||
{1.f, 0.f, 0.f}, {0.f, 0.f, 1.f}, 50.f, 50.f, 1000.f, 1, 0x7f);
|
||||
sAspect = float(gViewport.x8_width / gViewport.xc_height);
|
||||
sFirstPersonFOV = g_tweakGame->GetFirstPersonFOV();
|
||||
}
|
||||
|
||||
zeus::CVector3f CCameraManager::GetGlobalCameraTranslation(const CStateManager& stateMgr) const
|
||||
@@ -61,6 +72,13 @@ void CCameraManager::SetInsideFluid(bool val, TUniqueId fluidId)
|
||||
|
||||
void CCameraManager::Update(float dt, CStateManager& stateMgr)
|
||||
{
|
||||
sub800097AC(dt, stateMgr);
|
||||
ThinkCameras(dt, stateMgr);
|
||||
UpdateListener(stateMgr);
|
||||
UpdateRumble(dt, stateMgr);
|
||||
UpdateFog(dt, stateMgr);
|
||||
|
||||
#if 0
|
||||
const CGameCamera* camera = GetCurrentCamera(stateMgr);
|
||||
zeus::CVector3f heading = camera->GetTransform().basis * zeus::CVector3f{0.f, 1.f, 0.f};
|
||||
CSfxManager::UpdateListener(camera->GetTransform().origin, zeus::CVector3f::skZero, heading, {0.f, 0.f, 1.f}, 0x7f);
|
||||
@@ -79,15 +97,15 @@ void CCameraManager::Update(float dt, CStateManager& stateMgr)
|
||||
|
||||
if (x18_shakers.size())
|
||||
{
|
||||
if (!x86_25_rumbling || x86_24_)
|
||||
if (!xa0_25_rumbling || xa0_24_)
|
||||
{
|
||||
stateMgr.GetRumbleManager().Rumble(ERumbleFxId::Seven, stateMgr, ERumblePriority::Two);
|
||||
x86_25_rumbling = true;
|
||||
xa0_25_rumbling = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
x86_25_rumbling = false;
|
||||
xa0_25_rumbling = false;
|
||||
if (x84_rumbleId != -1)
|
||||
{
|
||||
stateMgr.GetRumbleManager().StopRumble(x84_rumbleId);
|
||||
@@ -107,16 +125,17 @@ void CCameraManager::Update(float dt, CStateManager& stateMgr)
|
||||
stateMgr.GetCameraFilterPass(4).SetFilter(CCameraFilterPass::EFilterType::Multiply,
|
||||
CCameraFilterPass::EFilterShape::Fullscreen, 0.f, tmpColor, -1);
|
||||
}
|
||||
x86_26_inWater = true;
|
||||
xa0_26_inWater = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
x86_26_inWater = false;
|
||||
xa0_26_inWater = false;
|
||||
x3c_fog.DisableFog();
|
||||
stateMgr.GetCameraFilterPass(4).DisableFilter(dt);
|
||||
}
|
||||
|
||||
x3c_fog.Update(dt);
|
||||
#endif
|
||||
}
|
||||
|
||||
CGameCamera* CCameraManager::GetCurrentCamera(CStateManager& stateMgr) const
|
||||
@@ -138,6 +157,61 @@ float CCameraManager::sub80009148() const
|
||||
1.f);
|
||||
}
|
||||
|
||||
void CCameraManager::sub800097AC(float, CStateManager& mgr)
|
||||
{
|
||||
}
|
||||
|
||||
void CCameraManager::ThinkCameras(float dt, CStateManager& mgr)
|
||||
{
|
||||
CGameCameraList gcList = mgr.GetCameraObjectList();
|
||||
|
||||
for (CEntity* ent : gcList)
|
||||
{
|
||||
CGameCamera* gc = dynamic_cast<CGameCamera*>(ent);
|
||||
if (gc)
|
||||
{
|
||||
gc->Think(dt, mgr);
|
||||
gc->UpdatePerspective(dt);
|
||||
}
|
||||
}
|
||||
|
||||
if (IsInCinematicCamera())
|
||||
return;
|
||||
|
||||
TUniqueId camId = GetLastCameraId();
|
||||
const CGameCamera* cam = dynamic_cast<const CGameCamera*>(mgr.GetObjectById(camId));
|
||||
|
||||
if (cam)
|
||||
x3bc_curFov = cam->GetFov();
|
||||
}
|
||||
|
||||
void CCameraManager::UpdateFog(float, CStateManager&)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void CCameraManager::UpdateRumble(float, CStateManager&)
|
||||
{
|
||||
}
|
||||
|
||||
void CCameraManager::UpdateListener(CStateManager& mgr)
|
||||
{
|
||||
const zeus::CTransform xf = GetCurrentCameraTransform(mgr);
|
||||
CSfxManager::UpdateListener(xf.origin, zeus::CVector3f::skZero, xf.frontVector(), xf.upVector(), 127);
|
||||
}
|
||||
|
||||
float CCameraManager::CalculateFogDensity(CStateManager& mgr, const CScriptWater* water)
|
||||
{
|
||||
float f31 = 1.f /* 1.f - water->x1b4_->x40_; */;
|
||||
float f1 = 0;
|
||||
if (mgr.GetPlayerState()->HasPowerUp(CPlayerState::EItemType::GravitySuit))
|
||||
f1 = (g_tweakPlayer->GetX54() * g_tweakPlayer->GetX50()) + f31;
|
||||
else
|
||||
f1 = (g_tweakPlayer->GetX5C() * g_tweakPlayer->GetX58()) + f31;
|
||||
|
||||
return f1 * x94_;
|
||||
}
|
||||
|
||||
void CCameraManager::ResetCameras(CStateManager& mgr)
|
||||
{
|
||||
zeus::CTransform xf = mgr.GetPlayer().CreateTransformFromMovementDirection();
|
||||
|
||||
@@ -12,9 +12,15 @@ class CBallCamera;
|
||||
class CStateManager;
|
||||
class CGameCamera;
|
||||
class CCameraShakeData;
|
||||
class CScriptWater;
|
||||
|
||||
class CCameraManager
|
||||
{
|
||||
static float sAspect;
|
||||
static float sFarPlane;
|
||||
static float sNearPlane;
|
||||
static float sFirstPersonFOV;
|
||||
static float sThirdPersonFOV;
|
||||
TUniqueId x0_curCameraId;
|
||||
std::vector<TUniqueId> x4_cineCameras;
|
||||
std::list<CCameraShakeData> x18_shakers;
|
||||
@@ -26,26 +32,44 @@ class CCameraManager
|
||||
CFirstPersonCamera* x7c_fpCamera = nullptr;
|
||||
CBallCamera* x80_ballCamera = nullptr;
|
||||
s16 x84_rumbleId = -1;
|
||||
float x94_;
|
||||
|
||||
union
|
||||
{
|
||||
struct
|
||||
{
|
||||
bool x86_24_ : 1;
|
||||
bool x86_25_rumbling : 1;
|
||||
bool x86_26_inWater : 1;
|
||||
bool xa0_24_ : 1;
|
||||
bool xa0_25_rumbling : 1;
|
||||
bool xa0_26_inWater : 1;
|
||||
};
|
||||
u8 _dummy = 0;
|
||||
u8 _dummy1 = 0;
|
||||
};
|
||||
|
||||
TUniqueId xa2_ = kInvalidUniqueId;
|
||||
TUniqueId xa4_ = kInvalidUniqueId;
|
||||
TUniqueId xa6_ = kInvalidUniqueId;
|
||||
u32 xa8_ = 1000;
|
||||
u32 xac_ = 0;
|
||||
|
||||
union
|
||||
{
|
||||
struct
|
||||
{
|
||||
bool x3b8_24_ : 1;
|
||||
bool x3b8_25_ : 1;
|
||||
};
|
||||
u8 _dummy2;
|
||||
};
|
||||
|
||||
float x3bc_curFov = 60.f;
|
||||
public:
|
||||
CCameraManager(TUniqueId curCameraId=kInvalidUniqueId);
|
||||
|
||||
static float DefaultAspect() {return 1.42f;}
|
||||
static float DefaultFarPlane() {return 750.0f;}
|
||||
static float DefaultNearPlane() {return 0.2f;}
|
||||
static float DefaultFirstPersonFOV() {return 55.0f;}
|
||||
static float DefaultThirdPersonFOV() {return 60.0f;}
|
||||
static float Aspect() {return sAspect;}
|
||||
static float FarPlane() {return sFarPlane;}
|
||||
static float NearPlane() {return sNearPlane;}
|
||||
static float FirstPersonFOV() {return sFirstPersonFOV;}
|
||||
static float ThirdPersonFOV() {return sThirdPersonFOV;}
|
||||
|
||||
void ResetCameras(CStateManager& mgr);
|
||||
void SetSpecialCameras(CFirstPersonCamera& fp, CBallCamera& ball);
|
||||
@@ -66,6 +90,12 @@ public:
|
||||
return x4_cineCameras.back();
|
||||
return x0_curCameraId;
|
||||
}
|
||||
TUniqueId GetLastCameraId() const
|
||||
{
|
||||
if (x4_cineCameras.size())
|
||||
return x4_cineCameras.back();
|
||||
return kInvalidUniqueId;
|
||||
}
|
||||
|
||||
CFirstPersonCamera* GetFirstPersonCamera() { return x7c_fpCamera; }
|
||||
CBallCamera* GetBallCamera() { return x80_ballCamera; }
|
||||
@@ -73,6 +103,14 @@ public:
|
||||
CGameArea::CAreaFog Fog() { return x3c_fog; }
|
||||
|
||||
float sub80009148() const;
|
||||
|
||||
void sub800097AC(float, CStateManager&);
|
||||
void ThinkCameras(float, CStateManager&);
|
||||
void UpdateFog(float, CStateManager&);
|
||||
void UpdateRumble(float, CStateManager&);
|
||||
void UpdateListener(CStateManager&);
|
||||
|
||||
float CalculateFogDensity(CStateManager&, const CScriptWater*);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -75,13 +75,13 @@ void CFirstPersonCamera::UpdateTransform(CStateManager& mgr, float dt)
|
||||
if (player->x3dc_)
|
||||
{
|
||||
float angle = player->x3ec_;
|
||||
if (std::fabs(player->x3ec_) > (g_tweakPlayer->GetPlayerSomething4() - std::fabs(x1c0_)))
|
||||
if (std::fabs(player->x3ec_) > (g_tweakPlayer->GetX124() - std::fabs(x1c0_)))
|
||||
angle = (player->x3ec_ > -0.f ? -1.f : 1.f);
|
||||
zeus::CVector3f vec;
|
||||
vec.z = std::sin(angle);
|
||||
vec.y = std::cos(-player->x3e4_) * std::cos(angle);
|
||||
vec.x = std::sin(-player->x3e4_) * std::cos(angle);
|
||||
if (g_tweakPlayer->GetPlayerSomething5() && !zeus::close_enough(vec, zeus::CVector3f::skZero))
|
||||
if (g_tweakPlayer->GetX228_24() && !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);
|
||||
@@ -112,10 +112,10 @@ void CFirstPersonCamera::UpdateTransform(CStateManager& mgr, float dt)
|
||||
{
|
||||
if (player->x294_ > 0.f)
|
||||
{
|
||||
float angle = zeus::clamp(0.f, (player->x294_ - g_tweakPlayer->GetPlayerSomething6()) /
|
||||
g_tweakPlayer->GetPlayerSomething7(),
|
||||
float angle = zeus::clamp(0.f, (player->x294_ - g_tweakPlayer->GetX288()) /
|
||||
g_tweakPlayer->GetX28c(),
|
||||
1.f) *
|
||||
g_tweakPlayer->GetPlayerSomething8();
|
||||
g_tweakPlayer->GetX290();
|
||||
angle += x1c0_;
|
||||
rVec.x = 0.f;
|
||||
rVec.y = std::cos(angle);
|
||||
@@ -125,10 +125,10 @@ void CFirstPersonCamera::UpdateTransform(CStateManager& mgr, float dt)
|
||||
}
|
||||
else if (player->x29c_ > 0.f)
|
||||
{
|
||||
float angle = zeus::clamp(0.f, (player->x29c_ - g_tweakPlayer->GetPlayerSomething9()) /
|
||||
g_tweakPlayer->GetPlayerSomething10(),
|
||||
float angle = zeus::clamp(0.f, (player->x29c_ - g_tweakPlayer->GetX294()) /
|
||||
g_tweakPlayer->GetX298(),
|
||||
1.f) *
|
||||
g_tweakPlayer->GetPlayerSomething11();
|
||||
g_tweakPlayer->GetX29C();
|
||||
rVec.x = 0.f;
|
||||
rVec.y = std::cos(angle);
|
||||
rVec.z = -std::sin(angle);
|
||||
@@ -152,7 +152,7 @@ void CFirstPersonCamera::UpdateTransform(CStateManager& mgr, float dt)
|
||||
if (gunFrontVec.canBeNormalized())
|
||||
gunFrontVec.normalize();
|
||||
|
||||
float scaledDt = (dt * g_tweakPlayer->GetPlayerSomething14());
|
||||
float scaledDt = (dt * g_tweakPlayer->GetX184());
|
||||
float angle = gunFrontVec.dot(rVec);
|
||||
if (std::fabs(angle) > 1.f)
|
||||
angle = (angle > -0.f ? -1.f : 1.f);
|
||||
@@ -183,7 +183,7 @@ void CFirstPersonCamera::UpdateTransform(CStateManager& mgr, float dt)
|
||||
|
||||
/* BUG: This is exactly what the runtime is doing, should we restore the intended behavior? */
|
||||
float angle = gunFrontVec.dot(rVec);
|
||||
float sdt = dt * g_tweakPlayer->GetPlayerSomething13();
|
||||
float sdt = dt * g_tweakPlayer->GetX2B0();
|
||||
|
||||
if (std::fabs(angle) > 1.0f)
|
||||
angle = (angle > -0.f ? -1.f : 1.f);
|
||||
@@ -194,17 +194,17 @@ void CFirstPersonCamera::UpdateTransform(CStateManager& mgr, float dt)
|
||||
}
|
||||
else if (player->x304_ == 2 || player->x304_ == 3)
|
||||
{
|
||||
dt *= g_tweakPlayer->GetPlayerSomething14();
|
||||
dt *= g_tweakPlayer->GetX184();
|
||||
CalculateGunFollowOrientationAndTransform(gunXf, qGun, dt, rVec);
|
||||
}
|
||||
else if (player->x304_ == 5)
|
||||
{
|
||||
dt *= g_tweakPlayer->GetPlayerSomething13();
|
||||
dt *= g_tweakPlayer->GetX2B0();
|
||||
CalculateGunFollowOrientationAndTransform(gunXf, qGun, dt, rVec);
|
||||
}
|
||||
else
|
||||
{
|
||||
dt *= g_tweakPlayer->GetPlayerSomething12();
|
||||
dt *= g_tweakPlayer->GetX280();
|
||||
CalculateGunFollowOrientationAndTransform(gunXf, qGun, dt, rVec);
|
||||
}
|
||||
}
|
||||
@@ -227,9 +227,9 @@ void CFirstPersonCamera::UpdateTransform(CStateManager& mgr, float dt)
|
||||
float angle = gunFront.dot(rVec);
|
||||
if (std::fabs(angle) > 1.f)
|
||||
angle = (angle > -0.f ? -1.f : 1.f);
|
||||
float sdt = dt * g_tweakPlayer->GetPlayerSomething15();
|
||||
float sdt = dt * g_tweakPlayer->GetX138();
|
||||
qGun = zeus::CQuaternion::lookAt(
|
||||
rVec, gunFront, sdt * zeus::clamp(0.f, g_tweakPlayer->GetPlayerSomething16() * (std::acos(angle) / sdt), 1.f));
|
||||
rVec, gunFront, sdt * zeus::clamp(0.f, g_tweakPlayer->GetX14C() * (std::acos(angle) / sdt), 1.f));
|
||||
}
|
||||
zeus::CTransform bobXf = player->GetCameraBob()->GetCameraBobTransformation();
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ CGameCamera::CGameCamera(TUniqueId uid, bool active, const std::string& name, co
|
||||
CActorParameters::None(), kInvalidUniqueId)
|
||||
, xe8_watchedObject(uid2)
|
||||
, x12c_(xf)
|
||||
, x15c_fov(fovy)
|
||||
, x15c_currentFov(fovy)
|
||||
, x160_znear(znear)
|
||||
, x164_zfar(zfar)
|
||||
, x168_aspect(aspect)
|
||||
@@ -21,7 +21,7 @@ CGameCamera::CGameCamera(TUniqueId uid, bool active, const std::string& name, co
|
||||
, x170_24_perspDirty(true)
|
||||
, x170_25_disablesInput(b1)
|
||||
, x180_(fovy)
|
||||
, x184_(fovy)
|
||||
, x184_fov(fovy)
|
||||
{
|
||||
|
||||
xe7_29_ = false;
|
||||
@@ -54,7 +54,7 @@ zeus::CMatrix4f CGameCamera::GetPerspectiveMatrix() const
|
||||
if (x170_24_perspDirty)
|
||||
{
|
||||
const_cast<CGameCamera*>(this)->xec_perspectiveMatrix =
|
||||
CGraphics::CalculatePerspectiveMatrix(x15c_fov, x168_aspect, x160_znear, x164_zfar, false);
|
||||
CGraphics::CalculatePerspectiveMatrix(x15c_currentFov, x168_aspect, x160_znear, x164_zfar, false);
|
||||
const_cast<CGameCamera*>(this)->x170_24_perspDirty = false;
|
||||
}
|
||||
|
||||
@@ -108,40 +108,40 @@ float CGameCamera::GetAspectRatio() const { return x168_aspect; }
|
||||
|
||||
TUniqueId CGameCamera::GetWatchedObject() const { return xe8_watchedObject; }
|
||||
|
||||
float CGameCamera::GetFov() const { return x15c_fov; }
|
||||
float CGameCamera::GetFov() const { return x15c_currentFov; }
|
||||
|
||||
void CGameCamera::sub8005AE3C(float f1)
|
||||
void CGameCamera::UpdatePerspective(float dt)
|
||||
{
|
||||
if (x174_ > 0.f)
|
||||
{
|
||||
x174_ -= f1;
|
||||
x174_ -= dt;
|
||||
return;
|
||||
}
|
||||
|
||||
if (x178_ <= 0.f)
|
||||
return;
|
||||
|
||||
x178_ -= f1;
|
||||
x178_ -= dt;
|
||||
if (x178_ > 0.f)
|
||||
{
|
||||
x15c_fov = x184_;
|
||||
x15c_currentFov = x184_fov;
|
||||
x170_24_perspDirty = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
x15c_fov = zeus::clamp(0.f, (f1 / x17c_), 1.f) + ((x180_ - x184_) * x184_);
|
||||
x15c_currentFov = zeus::clamp(0.f, (dt / x17c_), 1.f) + ((x180_ - x184_fov) * x184_fov);
|
||||
x170_24_perspDirty = true;
|
||||
}
|
||||
}
|
||||
|
||||
void CGameCamera::sub8005AF18(float f1, float f2, float f3, float f4)
|
||||
void CGameCamera::sub8005AF18(float f1, float fov, float f3, float f4)
|
||||
{
|
||||
if (f3 < 0.f)
|
||||
{
|
||||
x15c_fov = f2;
|
||||
x15c_currentFov = fov;
|
||||
x170_24_perspDirty = true;
|
||||
x184_ = f2;
|
||||
x184_ = x174_ = 0.f;
|
||||
x184_fov = fov;
|
||||
x178_ = x174_ = 0.f;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -149,8 +149,8 @@ void CGameCamera::sub8005AF18(float f1, float f2, float f3, float f4)
|
||||
x17c_ = f3;
|
||||
x178_ = f3;
|
||||
x180_ = f1;
|
||||
x184_ = f2;
|
||||
x15c_fov = f1;
|
||||
x184_fov = fov;
|
||||
x15c_currentFov = f1;
|
||||
x170_24_perspDirty = true;
|
||||
}
|
||||
}
|
||||
@@ -159,7 +159,7 @@ void CGameCamera::sub8005AF88()
|
||||
{
|
||||
if (x178_ > 0)
|
||||
{
|
||||
x15c_fov = x184_;
|
||||
x15c_currentFov = x184_fov;
|
||||
x170_24_perspDirty = true;
|
||||
}
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ class CGameCamera : public CActor
|
||||
TUniqueId xe8_watchedObject;
|
||||
zeus::CMatrix4f xec_perspectiveMatrix;
|
||||
zeus::CTransform x12c_;
|
||||
float x15c_fov;
|
||||
float x15c_currentFov;
|
||||
float x160_znear;
|
||||
float x164_zfar;
|
||||
float x168_aspect;
|
||||
@@ -30,7 +30,7 @@ class CGameCamera : public CActor
|
||||
float x178_ = 0.f;
|
||||
float x17c_ = 0.f;
|
||||
float x180_;
|
||||
float x184_;
|
||||
float x184_fov;
|
||||
public:
|
||||
CGameCamera(TUniqueId, bool active, const std::string& name, const CEntityInfo& info, const zeus::CTransform& xf,
|
||||
float fov, float nearz, float farz, float aspect, TUniqueId, bool, u32);
|
||||
@@ -51,7 +51,7 @@ public:
|
||||
float GetFov() const;
|
||||
void GetControllerNumber() const;
|
||||
bool DisablesInput() const;
|
||||
void sub8005AE3C(float);
|
||||
void UpdatePerspective(float);
|
||||
void sub8005AF18(float, float, float, float);
|
||||
void sub8005AF88();
|
||||
};
|
||||
|
||||
@@ -9,10 +9,10 @@ CPathCamera::CPathCamera(TUniqueId uid, const std::string& name, const CEntityIn
|
||||
float, float, float, float, float, float, float, u32,
|
||||
EInitialSplinePosition)
|
||||
: CGameCamera(uid, active, name, info, xf,
|
||||
CCameraManager::DefaultThirdPersonFOV(),
|
||||
CCameraManager::DefaultNearPlane(),
|
||||
CCameraManager::DefaultFarPlane(),
|
||||
CCameraManager::DefaultAspect(), kInvalidUniqueId, 0, 0)
|
||||
CCameraManager::ThirdPersonFOV(),
|
||||
CCameraManager::NearPlane(),
|
||||
CCameraManager::FarPlane(),
|
||||
CCameraManager::Aspect(), kInvalidUniqueId, 0, 0)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user