metaforce/Runtime/Camera/CCameraManager.cpp

153 lines
4.6 KiB
C++
Raw Normal View History

#include "CCameraManager.hpp"
2016-04-16 23:48:29 +00:00
#include "CCameraShakeData.hpp"
2016-04-17 02:50:45 +00:00
#include "Audio/CSfxManager.hpp"
#include "CGameCamera.hpp"
#include "CStateManager.hpp"
#include "Input/CRumbleManager.hpp"
#include "World/CScriptWater.hpp"
#include "World/CPlayer.hpp"
namespace urde
{
2016-04-16 23:48:29 +00:00
CCameraManager::CCameraManager(TUniqueId curCameraId)
: x0_curCameraId(curCameraId)
{
2016-04-17 02:50:45 +00:00
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);
}
zeus::CVector3f CCameraManager::GetGlobalCameraTranslation(const CStateManager& stateMgr) const
{
const CGameCamera* camera = GetCurrentCamera(stateMgr);
return camera->GetTransform() * x30_shakeOffset;
}
zeus::CTransform CCameraManager::GetCurrentCameraTransform(const CStateManager& stateMgr) const
{
const CGameCamera* camera = GetCurrentCamera(stateMgr);
return camera->GetTransform() * zeus::CTransform::Translate(x30_shakeOffset);
}
void CCameraManager::RemoveCameraShaker(int id)
{
for (auto it=x18_shakers.begin() ; it != x18_shakers.end() ; ++it)
if (it->x20_shakerId == id)
{
x18_shakers.erase(it);
break;
}
}
int CCameraManager::AddCameraShaker(const CCameraShakeData& data)
{
x18_shakers.emplace_back(data);
x18_shakers.back().x20_shakerId = ++x2c_lastShakeId;
return x2c_lastShakeId;
}
void CCameraManager::AddCinemaCamera(TUniqueId id, CStateManager& stateMgr)
{
x4_cineCameras.push_back(id);
}
void CCameraManager::SetInsideFluid(bool val, TUniqueId fluidId)
{
if (val)
{
++x74_fluidCounter;
x78_fluidId = fluidId;
}
else
--x74_fluidCounter;
}
void CCameraManager::Update(float dt, CStateManager& stateMgr)
{
const CGameCamera* camera = GetCurrentCamera(stateMgr);
2016-04-29 10:08:46 +00:00
zeus::CVector3f heading = camera->GetTransform().basis * zeus::CVector3f{0.f, 1.f, 0.f};
CSfxManager::UpdateListener(camera->GetTransform().origin, zeus::CVector3f::skZero,
2016-04-17 02:50:45 +00:00
heading, {0.f, 0.f, 1.f}, 0x7f);
x30_shakeOffset = zeus::CVector3f::skZero;
for (auto it=x18_shakers.begin() ; it != x18_shakers.end() ;)
{
if (it->x1c_curTime >= it->x18_duration)
{
it = x18_shakers.erase(it);
continue;
}
2016-08-21 20:39:18 +00:00
x30_shakeOffset += it->GeneratePoint(dt, *stateMgr.GetActiveRandom());
2016-04-17 02:50:45 +00:00
++it;
}
if (x18_shakers.size())
{
if (!x86_25_rumbling || x86_24_)
{
stateMgr.GetRumbleManager().Rumble(ERumbleFxId::Seven, stateMgr, ERumblePriority::Two);
x86_25_rumbling = true;
}
}
else
{
x86_25_rumbling = false;
if (x84_rumbleId != -1)
{
stateMgr.GetRumbleManager().StopRumble(x84_rumbleId);
x84_rumbleId = -1;
}
}
if (x74_fluidCounter)
{
2016-04-17 05:35:32 +00:00
const CScriptWater* water = dynamic_cast<const CScriptWater*>(stateMgr.GetObjectById(x78_fluidId));
2016-04-17 02:50:45 +00:00
if (water)
{
// TODO: Finish
zeus::CColor tmpColor; // Get from water
zeus::CVector2f tmpVector; // Get from camera
2016-08-08 04:48:18 +00:00
x3c_fog.SetFogExplicit(ERglFogMode::PerspExp, tmpColor, tmpVector);
2016-08-20 04:22:13 +00:00
stateMgr.GetCameraFilterPass(4).SetFilter(CCameraFilterPass::EFilterType::Multiply,
CCameraFilterPass::EFilterShape::Fullscreen,
2016-04-17 02:50:45 +00:00
0.f, tmpColor, -1);
}
x86_26_inWater = true;
}
else
{
x86_26_inWater = false;
x3c_fog.DisableFog();
stateMgr.GetCameraFilterPass(4).DisableFilter(dt);
}
x3c_fog.Update(dt);
}
CGameCamera* CCameraManager::GetCurrentCamera(CStateManager& stateMgr) const
{
2016-04-17 05:35:32 +00:00
CObjectList* camList = stateMgr.ObjectListById(EGameObjectList::GameCamera);
2016-04-17 02:50:45 +00:00
return static_cast<CGameCamera*>(camList->GetObjectById(GetCurrentCameraId()));
}
const CGameCamera* CCameraManager::GetCurrentCamera(const CStateManager& stateMgr) const
{
const CObjectList* camList = stateMgr.GetObjectListById(EGameObjectList::GameCamera);
return static_cast<const CGameCamera*>(camList->GetObjectById(GetCurrentCameraId()));
}
void CCameraManager::ResetCameras(CStateManager& mgr)
{
zeus::CTransform xf = mgr.GetPlayer().CreateTransformFromMovementDirection();
xf.origin = mgr.GetPlayer().GetEyePosition();
2016-08-15 20:58:07 +00:00
for (CEntity* ent : mgr.GetCameraObjectList())
{
2016-08-15 20:58:07 +00:00
CGameCamera* camObj = static_cast<CGameCamera*>(ent);
camObj->Reset(xf, mgr);
}
}
}