metaforce/Runtime/GuiSys/COrbitPointMarker.cpp

113 lines
4.7 KiB
C++
Raw Normal View History

2017-10-29 06:21:52 +00:00
#include "COrbitPointMarker.hpp"
#include "GameGlobalObjects.hpp"
#include "CSimplePool.hpp"
#include "CStateManager.hpp"
#include "World/CPlayer.hpp"
#include "Camera/CGameCamera.hpp"
#include "zeus/CEulerAngles.hpp"
#include "Graphics/CBooRenderer.hpp"
namespace urde
{
COrbitPointMarker::COrbitPointMarker()
{
x0_zOffset = g_tweakTargeting->GetOrbitPointZOffset();
x28_orbitPointModel = g_SimplePool->GetObj("CMDL_OrbitPoint");
}
bool COrbitPointMarker::CheckLoadComplete()
{
return x28_orbitPointModel.IsLoaded();
}
void COrbitPointMarker::Update(float dt, const CStateManager& mgr)
{
x24_curTime += dt;
const CGameCamera* curCam = mgr.GetCameraManager()->GetCurrentCamera(mgr);
CPlayer::EPlayerOrbitState orbitState = mgr.GetPlayer().GetOrbitState();
bool freeOrbit = orbitState >= CPlayer::EPlayerOrbitState::OrbitPoint;
if (freeOrbit != x1c_lastFreeOrbit)
{
if (orbitState == CPlayer::EPlayerOrbitState::OrbitPoint ||
orbitState == CPlayer::EPlayerOrbitState::OrbitCarcass)
{
ResetInterpolationTimer(g_tweakTargeting->GetOrbitPointInTime());
zeus::CVector3f orbitTargetPosition = mgr.GetPlayer().GetHUDOrbitTargetPosition();
if (!x4_camRelZPos)
x10_lagTargetPos = orbitTargetPosition + zeus::CVector3f(0.f, 0.f, x0_zOffset);
else
2018-12-08 01:49:15 +00:00
x10_lagTargetPos = zeus::CVector3f(orbitTargetPosition.x(), orbitTargetPosition.y(),
curCam->GetTranslation().z() + x0_zOffset);
2017-10-29 06:21:52 +00:00
x8_lagAzimuth =
2018-12-08 01:49:15 +00:00
zeus::CEulerAngles(zeus::CQuaternion(curCam->GetTransform().basis)).z() + zeus::degToRad(45.f);
2017-10-29 06:21:52 +00:00
}
else
{
ResetInterpolationTimer(g_tweakTargeting->GetOrbitPointOutTime());
}
x1c_lastFreeOrbit = !x1c_lastFreeOrbit;
}
if (x20_interpTimer > 0.f)
x20_interpTimer = std::max(0.f, x20_interpTimer - dt);
if (!x4_camRelZPos)
{
zeus::CVector3f orbitTargetPosition = mgr.GetPlayer().GetHUDOrbitTargetPosition();
2018-12-08 01:49:15 +00:00
if ((orbitTargetPosition.z() + x0_zOffset) - x10_lagTargetPos.z() < 0.1f)
2017-10-29 06:21:52 +00:00
x10_lagTargetPos = orbitTargetPosition + zeus::CVector3f(0.f, 0.f, x0_zOffset);
2018-12-08 01:49:15 +00:00
else if ((orbitTargetPosition.z() + x0_zOffset) - x10_lagTargetPos.z() < 0.f)
x10_lagTargetPos = zeus::CVector3f(orbitTargetPosition.x(), orbitTargetPosition.y(), x10_lagTargetPos.z() - 0.1f);
2017-10-29 06:21:52 +00:00
else
2018-12-08 01:49:15 +00:00
x10_lagTargetPos = zeus::CVector3f(orbitTargetPosition.x(), orbitTargetPosition.y(), x10_lagTargetPos.z() + 0.1f);
2017-10-29 06:21:52 +00:00
}
else
{
zeus::CVector3f orbitTargetPosition = mgr.GetPlayer().GetHUDOrbitTargetPosition();
2018-12-08 01:49:15 +00:00
x10_lagTargetPos = zeus::CVector3f(orbitTargetPosition.x(), orbitTargetPosition.y(),
x0_zOffset + orbitTargetPosition.z());
2017-10-29 06:21:52 +00:00
}
if (x1c_lastFreeOrbit)
{
2018-12-08 01:49:15 +00:00
float newAzimuth = zeus::CEulerAngles(zeus::CQuaternion(curCam->GetTransform().basis)).z() + zeus::degToRad(45.f);
2017-10-29 06:21:52 +00:00
float aziDelta = newAzimuth - xc_azimuth;
if (mgr.GetPlayer().IsInFreeLook())
x8_lagAzimuth += aziDelta;
xc_azimuth = newAzimuth;
}
}
void COrbitPointMarker::Draw(const CStateManager& mgr) const
{
if ((x1c_lastFreeOrbit || x20_interpTimer > 0.f) && g_tweakTargeting->DrawOrbitPoint() &&
x28_orbitPointModel.IsLoaded())
{
const CGameCamera* curCam = mgr.GetCameraManager()->GetCurrentCamera(mgr);
zeus::CTransform camXf = mgr.GetCameraManager()->GetCurrentCameraTransform(mgr);
CGraphics::SetViewPointMatrix(camXf);
2018-02-05 06:56:09 +00:00
zeus::CFrustum frustum = mgr.SetupDrawFrustum(g_Viewport);
2017-10-29 06:21:52 +00:00
frustum.updatePlanes(camXf, zeus::SProjPersp(zeus::degToRad(curCam->GetFov()),
2018-02-05 06:56:09 +00:00
g_Viewport.x8_width / float(g_Viewport.xc_height), 1.f, 100.f));
2017-10-29 06:21:52 +00:00
g_Renderer->SetClippingPlanes(frustum);
g_Renderer->SetPerspective(curCam->GetFov(), g_Viewport.x8_width, g_Viewport.xc_height,
curCam->GetNearClipDistance(), curCam->GetFarClipDistance());
float scale;
if (x1c_lastFreeOrbit)
scale = 1.f - x20_interpTimer / g_tweakTargeting->GetOrbitPointInTime();
else
scale = x20_interpTimer / g_tweakTargeting->GetOrbitPointOutTime();
zeus::CTransform modelXf = zeus::CTransform::RotateZ(x8_lagAzimuth);
modelXf.scaleBy(scale);
modelXf.origin += x10_lagTargetPos;
CGraphics::SetModelMatrix(modelXf);
zeus::CColor color = g_tweakTargeting->GetOrbitPointColor();
2018-12-08 01:49:15 +00:00
color.a() *= scale;
2017-10-29 06:21:52 +00:00
CModelFlags flags(7, 0, 0, color);
x28_orbitPointModel->Draw(flags);
}
}
}