metaforce/Runtime/GuiSys/COrbitPointMarker.cpp

97 lines
4.4 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"
2018-12-08 05:30:43 +00:00
namespace urde {
2017-10-29 06:21:52 +00:00
2018-12-08 05:30:43 +00:00
COrbitPointMarker::COrbitPointMarker() {
x0_zOffset = g_tweakTargeting->GetOrbitPointZOffset();
x28_orbitPointModel = g_SimplePool->GetObj("CMDL_OrbitPoint");
2017-10-29 06:21:52 +00:00
}
bool COrbitPointMarker::CheckLoadComplete() const { return x28_orbitPointModel.IsLoaded(); }
2017-10-29 06:21:52 +00:00
2018-12-08 05:30:43 +00:00
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
x10_lagTargetPos = zeus::CVector3f(orbitTargetPosition.x(), orbitTargetPosition.y(),
curCam->GetTranslation().z() + x0_zOffset);
x8_lagAzimuth = zeus::CEulerAngles(zeus::CQuaternion(curCam->GetTransform().basis)).z() + zeus::degToRad(45.f);
} else {
ResetInterpolationTimer(g_tweakTargeting->GetOrbitPointOutTime());
2017-10-29 06:21:52 +00:00
}
2018-12-08 05:30:43 +00:00
x1c_lastFreeOrbit = !x1c_lastFreeOrbit;
}
2017-10-29 06:21:52 +00:00
2018-12-08 05:30:43 +00:00
if (x20_interpTimer > 0.f)
x20_interpTimer = std::max(0.f, x20_interpTimer - dt);
2017-10-29 06:21:52 +00:00
2018-12-08 05:30:43 +00:00
if (!x4_camRelZPos) {
zeus::CVector3f orbitTargetPosition = mgr.GetPlayer().GetHUDOrbitTargetPosition();
if ((orbitTargetPosition.z() + x0_zOffset) - x10_lagTargetPos.z() < 0.1f)
x10_lagTargetPos = orbitTargetPosition + zeus::CVector3f(0.f, 0.f, x0_zOffset);
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 05:30:43 +00:00
x10_lagTargetPos = zeus::CVector3f(orbitTargetPosition.x(), orbitTargetPosition.y(), x10_lagTargetPos.z() + 0.1f);
} else {
zeus::CVector3f orbitTargetPosition = mgr.GetPlayer().GetHUDOrbitTargetPosition();
x10_lagTargetPos =
zeus::CVector3f(orbitTargetPosition.x(), orbitTargetPosition.y(), x0_zOffset + orbitTargetPosition.z());
}
2017-10-29 06:21:52 +00:00
2018-12-08 05:30:43 +00:00
if (x1c_lastFreeOrbit) {
float newAzimuth = zeus::CEulerAngles(zeus::CQuaternion(curCam->GetTransform().basis)).z() + zeus::degToRad(45.f);
float aziDelta = newAzimuth - xc_azimuth;
if (mgr.GetPlayer().IsInFreeLook())
x8_lagAzimuth += aziDelta;
xc_azimuth = newAzimuth;
}
2017-10-29 06:21:52 +00:00
}
2018-12-08 05:30:43 +00:00
void COrbitPointMarker::Draw(const CStateManager& mgr) const {
if ((x1c_lastFreeOrbit || x20_interpTimer > 0.f) && g_tweakTargeting->DrawOrbitPoint() &&
x28_orbitPointModel.IsLoaded()) {
2019-07-21 08:42:52 +00:00
SCOPED_GRAPHICS_DEBUG_GROUP("COrbitPointMarker::Draw", zeus::skCyan);
2018-12-08 05:30:43 +00:00
const CGameCamera* curCam = mgr.GetCameraManager()->GetCurrentCamera(mgr);
zeus::CTransform camXf = mgr.GetCameraManager()->GetCurrentCameraTransform(mgr);
CGraphics::SetViewPointMatrix(camXf);
zeus::CFrustum frustum = mgr.SetupDrawFrustum(g_Viewport);
frustum.updatePlanes(camXf, zeus::SProjPersp(zeus::degToRad(curCam->GetFov()),
2019-01-23 07:52:19 +00:00
g_Viewport.aspect, 1.f, 100.f));
2018-12-08 05:30:43 +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();
color.a() *= scale;
CModelFlags flags(7, 0, 0, color);
x28_orbitPointModel->Draw(flags);
}
2017-10-29 06:21:52 +00:00
}
2018-12-08 05:30:43 +00:00
} // namespace urde