metaforce/Runtime/GuiSys/COrbitPointMarker.cpp

99 lines
4.5 KiB
C++
Raw Normal View History

#include "Runtime/GuiSys/COrbitPointMarker.hpp"
#include "Runtime/CSimplePool.hpp"
#include "Runtime/CStateManager.hpp"
#include "Runtime/GameGlobalObjects.hpp"
#include "Runtime/Camera/CGameCamera.hpp"
#include "Runtime/Graphics/CCubeRenderer.hpp"
#include "Runtime/World/CPlayer.hpp"
#include <zeus/CEulerAngles.hpp>
2017-10-29 06:21:52 +00:00
2021-04-10 08:42:06 +00:00
namespace metaforce {
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);
2022-02-27 22:46:15 +00:00
zeus::CFrustum frustum = mgr.SetupDrawFrustum(CGraphics::g_Viewport);
frustum.updatePlanes(
camXf, zeus::SProjPersp(zeus::degToRad(curCam->GetFov()), CGraphics::GetViewportAspect(), 1.f, 100.f));
2018-12-08 05:30:43 +00:00
g_Renderer->SetClippingPlanes(frustum);
2022-02-27 22:46:15 +00:00
g_Renderer->SetPerspective(curCam->GetFov(), CGraphics::GetViewportWidth(), CGraphics::GetViewportHeight(),
2018-12-08 05:30:43 +00:00
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
}
2021-04-10 08:42:06 +00:00
} // namespace metaforce