2016-08-14 21:11:44 +00:00
|
|
|
#include "CPlayerCameraBob.hpp"
|
2016-09-16 00:56:46 +00:00
|
|
|
#include "World/CPlayer.hpp"
|
|
|
|
#include "CStateManager.hpp"
|
|
|
|
#include "Camera/CCameraManager.hpp"
|
|
|
|
#include "zeus/Math.hpp"
|
2017-02-12 04:43:33 +00:00
|
|
|
#include "Particle/CGenDescription.hpp"
|
2016-08-14 21:11:44 +00:00
|
|
|
|
|
|
|
namespace urde
|
|
|
|
{
|
2016-09-15 07:26:35 +00:00
|
|
|
float CPlayerCameraBob::kCameraBobExtentX = 0.071f;
|
|
|
|
float CPlayerCameraBob::kCameraBobExtentY = 0.142f;
|
|
|
|
float CPlayerCameraBob::kCameraBobPeriod = 0.47f;
|
|
|
|
float CPlayerCameraBob::kOrbitBobScale = 0.769f;
|
|
|
|
float CPlayerCameraBob::kMaxOrbitBobScale = 0.8f;
|
|
|
|
float CPlayerCameraBob::kSlowSpeedPeriodScale = 0.3f;
|
|
|
|
float CPlayerCameraBob::kTargetMagnitudeTrackingRate = 0.1f;
|
|
|
|
float CPlayerCameraBob::kLandingBobSpringConstant = 150.f;
|
|
|
|
float CPlayerCameraBob::kViewWanderRadius = 2.9f;
|
|
|
|
float CPlayerCameraBob::kViewWanderSpeedMin = 0.1f;
|
|
|
|
float CPlayerCameraBob::kViewWanderSpeedMax = 0.3f;
|
|
|
|
float CPlayerCameraBob::kViewWanderRollVariation = 0.3f;
|
|
|
|
float CPlayerCameraBob::kGunBobMagnitude = 0.3f;
|
|
|
|
float CPlayerCameraBob::kHelmetBobMagnitude = 2.f;
|
2016-09-16 00:56:46 +00:00
|
|
|
const float CPlayerCameraBob::kLandingBobDamping = 2.f * zeus::sqrtF(150.f);
|
2016-08-14 21:11:44 +00:00
|
|
|
|
2016-09-15 07:26:35 +00:00
|
|
|
CPlayerCameraBob::CPlayerCameraBob(ECameraBobType type, const zeus::CVector2f& vec, float f1)
|
2016-09-16 00:56:46 +00:00
|
|
|
: x0_type(type), x4_vec(vec), xc_(f1)
|
2016-08-14 21:11:44 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-09-16 00:56:46 +00:00
|
|
|
zeus::CTransform CPlayerCameraBob::GetViewWanderTransform() const { return xd0_viewWanderXf; }
|
|
|
|
|
|
|
|
zeus::CVector3f CPlayerCameraBob::GetHelmetBobTranslation() const
|
|
|
|
{
|
|
|
|
|
|
|
|
return {kHelmetBobMagnitude * x2c_cameraBobTransform.origin.x,
|
|
|
|
kHelmetBobMagnitude * x2c_cameraBobTransform.origin.y,
|
|
|
|
kHelmetBobMagnitude * (x2c_cameraBobTransform.origin.z - x78_)};
|
|
|
|
}
|
|
|
|
|
|
|
|
zeus::CTransform CPlayerCameraBob::GetGunBobTransformation() const
|
|
|
|
{
|
|
|
|
return zeus::CTransform::Translate((1.f + kGunBobMagnitude) * x2c_cameraBobTransform.origin);
|
|
|
|
}
|
|
|
|
|
|
|
|
zeus::CTransform CPlayerCameraBob::GetCameraBobTransformation() const { return x2c_cameraBobTransform; }
|
|
|
|
|
|
|
|
void CPlayerCameraBob::SetPlayerVelocity(const zeus::CVector3f& velocity)
|
|
|
|
{
|
|
|
|
x5c_playerVelocity = velocity;
|
|
|
|
x68_ = zeus::min(x68_, velocity.z);
|
|
|
|
}
|
|
|
|
|
2017-01-15 03:59:37 +00:00
|
|
|
void CPlayerCameraBob::SetBobMagnitude(float magnitude)
|
|
|
|
{
|
|
|
|
#if 0
|
|
|
|
/* Retro Original (This is why underpaid (re: unpaid) interns make crappy programmers) */
|
|
|
|
x10_bobMagnitude = magnitude;
|
|
|
|
x10_bobMagnitude = std::max(0.f, x10_bobMagnitude);
|
|
|
|
x10_bobMagnitude = std::max(1.f, x10_bobMagnitude);
|
|
|
|
#else
|
|
|
|
/* Should fix lightshow */
|
|
|
|
x10_bobMagnitude = zeus::clamp(0.f, magnitude, 1.f);
|
|
|
|
#endif
|
|
|
|
}
|
2016-09-16 00:56:46 +00:00
|
|
|
|
|
|
|
void CPlayerCameraBob::SetBobTimeScale(float ts) { x18_bobTimeScale = zeus::clamp(0.f, ts, 1.f); }
|
|
|
|
|
|
|
|
void CPlayerCameraBob::ResetCameraBobTime() { x1c_bobTime = 0.f; }
|
|
|
|
|
2016-09-16 22:21:19 +00:00
|
|
|
void CPlayerCameraBob::SetCameraBobTransform(const zeus::CTransform& xf) { x2c_cameraBobTransform = xf; }
|
|
|
|
|
2016-09-16 00:56:46 +00:00
|
|
|
void CPlayerCameraBob::SetState(CPlayerCameraBob::ECameraBobState state, CStateManager& mgr)
|
|
|
|
{
|
|
|
|
if (x24_curState == state)
|
|
|
|
return;
|
|
|
|
|
|
|
|
x20_oldState = x24_curState;
|
|
|
|
x24_curState = state;
|
2017-08-19 06:52:13 +00:00
|
|
|
if (x20_oldState == ECameraBobState::InAir)
|
2016-09-16 00:56:46 +00:00
|
|
|
{
|
|
|
|
x28_applyLandingTrans = true;
|
|
|
|
x68_ = std::min(x68_, -35.f);
|
|
|
|
x29_ = (x68_ >= -30.f);
|
|
|
|
if (x29_)
|
|
|
|
x74_ += x68_;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
x6c_ += x68_;
|
|
|
|
x68_ = 0.f;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-19 06:52:13 +00:00
|
|
|
if (x24_curState == ECameraBobState::WalkNoBob && x100_ != 0.f)
|
2016-09-16 00:56:46 +00:00
|
|
|
InitViewWander(mgr);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CPlayerCameraBob::InitViewWander(CStateManager& mgr)
|
|
|
|
{
|
|
|
|
x7c_wanderPoints[0] = {0.f, 1.f, 0.f};
|
|
|
|
x7c_wanderPoints[1] = x7c_wanderPoints[0];
|
|
|
|
x7c_wanderPoints[2] = x7c_wanderPoints[0];
|
|
|
|
x7c_wanderPoints[3] = CalculateRandomViewWanderPosition(mgr);
|
|
|
|
xb0_wanderPitches[0] = 0.f;
|
|
|
|
xb0_wanderPitches[1] = xb0_wanderPitches[0];
|
|
|
|
xb0_wanderPitches[2] = xb0_wanderPitches[0];
|
|
|
|
xb0_wanderPitches[3] = CalculateRandomViewWanderPitch(mgr);
|
|
|
|
|
|
|
|
xc8_viewWanderSpeed =
|
|
|
|
(kViewWanderSpeedMax - kViewWanderRadius) * kViewWanderRadius + mgr.GetActiveRandom()->Float();
|
|
|
|
xc4_wanderTime = 0.f;
|
|
|
|
xcc_wanderIndex = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CPlayerCameraBob::UpdateViewWander(float dt, CStateManager& mgr)
|
|
|
|
{
|
|
|
|
zeus::CVector3f pt = zeus::getCatmullRomSplinePoint(
|
|
|
|
x7c_wanderPoints[xcc_wanderIndex], x7c_wanderPoints[(xcc_wanderIndex + 1) & 3],
|
|
|
|
x7c_wanderPoints[(xcc_wanderIndex + 2) & 3], x7c_wanderPoints[(xcc_wanderIndex + 3) & 3], dt);
|
|
|
|
|
|
|
|
pt.x *= x100_;
|
|
|
|
pt.z *= x100_;
|
|
|
|
zeus::CTransform orient = zeus::CTransform::RotateY((
|
|
|
|
zeus::getCatmullRomSplinePoint(xb0_wanderPitches[xcc_wanderIndex], xb0_wanderPitches[(xcc_wanderIndex + 1) & 3],
|
|
|
|
xb0_wanderPitches[(xcc_wanderIndex + 2) & 3],
|
|
|
|
xb0_wanderPitches[(xcc_wanderIndex + 3) & 3], dt) *
|
|
|
|
x100_));
|
2017-02-12 03:51:59 +00:00
|
|
|
xd0_viewWanderXf = zeus::lookAt(pt, zeus::CVector3f::skZero, zeus::CVector3f::skUp) * orient;
|
2016-09-16 00:56:46 +00:00
|
|
|
|
|
|
|
xc4_wanderTime = (xc8_viewWanderSpeed * xc4_wanderTime) + dt;
|
|
|
|
if (xc4_wanderTime > 1.f)
|
|
|
|
{
|
|
|
|
x7c_wanderPoints[xcc_wanderIndex] = CalculateRandomViewWanderPosition(mgr);
|
|
|
|
xb0_wanderPitches[xcc_wanderIndex] = CalculateRandomViewWanderPitch(mgr);
|
|
|
|
xc8_viewWanderSpeed =
|
|
|
|
((kViewWanderSpeedMax - kViewWanderSpeedMin) * kViewWanderSpeedMin) + mgr.GetActiveRandom()->Float();
|
|
|
|
xcc_wanderIndex = (xcc_wanderIndex + 1) & 3;
|
|
|
|
xc4_wanderTime -= 1.f;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CPlayerCameraBob::Update(float dt, CStateManager& mgr)
|
|
|
|
{
|
2017-08-04 13:48:48 +00:00
|
|
|
x1c_bobTime = (dt * x18_bobTimeScale) + x1c_bobTime;
|
2016-09-16 00:56:46 +00:00
|
|
|
float landSpring = kLandingBobSpringConstant;
|
|
|
|
float landDampen = kLandingBobDamping;
|
|
|
|
if (x28_applyLandingTrans)
|
|
|
|
{
|
|
|
|
landDampen = 4.f * zeus::sqrtF(40.f);
|
|
|
|
landSpring = 40.f;
|
|
|
|
}
|
|
|
|
|
2017-08-04 13:48:48 +00:00
|
|
|
x6c_ = (dt * -((landSpring * x70_landingTranslation) + -(landDampen * x6c_))) + x6c_;
|
|
|
|
x70_landingTranslation = x6c_ * dt + x70_landingTranslation;
|
|
|
|
x74_ = dt * (-(80.f * x78_) + -((6.f * zeus::sqrtF(80.f)) * x74_)) + x74_;
|
|
|
|
x78_ = x74_ * dt + x78_;
|
|
|
|
|
2016-09-16 00:56:46 +00:00
|
|
|
if (std::fabs(x6c_) < 0.0049f && std::fabs(x70_landingTranslation) < 0.0049f && std::fabs(x78_) < 0.0049f)
|
|
|
|
{
|
|
|
|
x28_applyLandingTrans = false;
|
2017-08-16 05:34:02 +00:00
|
|
|
x70_landingTranslation = 0.f;
|
2016-09-16 00:56:46 +00:00
|
|
|
x78_ = 0.f;
|
|
|
|
}
|
|
|
|
|
2017-08-19 06:52:13 +00:00
|
|
|
if (x24_curState == ECameraBobState::WalkNoBob)
|
2016-09-16 00:56:46 +00:00
|
|
|
x104_ = 1.f;
|
|
|
|
else
|
|
|
|
x104_ = 0.f;
|
|
|
|
|
2017-10-07 05:32:11 +00:00
|
|
|
float f1 = mgr.GetCameraManager()->GetCameraBobMagnitude();
|
2016-09-16 00:56:46 +00:00
|
|
|
x70_landingTranslation *= f1;
|
|
|
|
x78_ *= f1;
|
|
|
|
x104_ *= f1;
|
2017-08-16 05:34:02 +00:00
|
|
|
if (mgr.GetPlayer().x38c_doneSidewaysDashing)
|
2016-09-16 00:56:46 +00:00
|
|
|
{
|
|
|
|
x70_landingTranslation *= 0.2f;
|
|
|
|
x78_ *= 0.2f;
|
|
|
|
x104_ *= 0.4f;
|
|
|
|
}
|
|
|
|
|
2017-08-04 13:48:48 +00:00
|
|
|
x100_ = kTargetMagnitudeTrackingRate * (x104_ - x100_) + x100_;
|
2016-09-16 00:56:46 +00:00
|
|
|
x100_ = std::max(x100_, 0.f);
|
|
|
|
float tmp = x14_;
|
2017-08-04 13:48:48 +00:00
|
|
|
x14_ = kTargetMagnitudeTrackingRate * (x10_bobMagnitude - x14_) + x14_;
|
2016-09-16 00:56:46 +00:00
|
|
|
UpdateViewWander(dt, mgr);
|
|
|
|
x78_ = tmp;
|
|
|
|
|
|
|
|
x2c_cameraBobTransform = GetViewWanderTransform() * CalculateCameraBobTransformation() *
|
2017-02-12 03:51:59 +00:00
|
|
|
zeus::lookAt(zeus::CVector3f::skZero, {0.f, 2.f, x78_}, zeus::CVector3f::skUp);
|
2016-09-16 00:56:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
zeus::CVector3f CPlayerCameraBob::CalculateRandomViewWanderPosition(CStateManager& mgr)
|
|
|
|
{
|
|
|
|
const float angle = (2.f * (M_PIF * mgr.GetActiveRandom()->Float()));
|
|
|
|
const float bias = kViewWanderRadius * mgr.GetActiveRandom()->Float();
|
|
|
|
return {(bias * std::sin(angle)), 1.f, (bias * std::cos(angle))};
|
|
|
|
}
|
|
|
|
|
|
|
|
float CPlayerCameraBob::CalculateRandomViewWanderPitch(CStateManager& mgr)
|
|
|
|
{
|
|
|
|
return zeus::degToRad((2.f * (mgr.GetActiveRandom()->Float() - 0.5f)) * kViewWanderRollVariation);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CPlayerCameraBob::CalculateMovingTranslation(float& x, float& y) const
|
|
|
|
{
|
|
|
|
if (x0_type == ECameraBobType::Zero)
|
|
|
|
{
|
|
|
|
double c = ((M_PIF * 2.f) * std::fmod(x1c_bobTime, 2.0f * xc_) / xc_);
|
2017-08-04 13:48:48 +00:00
|
|
|
x = (x14_ * x4_vec.x) * float(std::sin(c));
|
|
|
|
y = (x14_ * x4_vec.y) * float(std::fabs(std::cos(c * .5)) * std::cos(c * .5));
|
2016-09-16 00:56:46 +00:00
|
|
|
}
|
|
|
|
else if (x0_type == ECameraBobType::One)
|
|
|
|
{
|
|
|
|
float fX = std::fmod(x1c_bobTime, 2.f * xc_);
|
|
|
|
if (fX > xc_)
|
|
|
|
x = (2.f - (fX / xc_)) * (x14_ * x4_vec.x);
|
|
|
|
else
|
|
|
|
x = ((fX / xc_)) * (x14_ * x4_vec.x);
|
|
|
|
|
2017-08-16 05:34:02 +00:00
|
|
|
auto sY = float(std::sin(std::fmod((M_PI * fX) / xc_, M_PI)));
|
2017-08-04 13:48:48 +00:00
|
|
|
y = (1.f - sY) * (x14_ * x4_vec.y) * 0.5f + (0.5f * -((sY * sY) - 1.f) * (x14_ * x4_vec.y));
|
2016-09-16 00:56:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
float CPlayerCameraBob::CalculateLandingTranslation() const { return x70_landingTranslation; }
|
|
|
|
|
|
|
|
zeus::CTransform CPlayerCameraBob::CalculateCameraBobTransformation() const
|
|
|
|
{
|
|
|
|
float x = 0.f;
|
|
|
|
float y = 0.f;
|
|
|
|
CalculateMovingTranslation(x, y);
|
|
|
|
if (x28_applyLandingTrans)
|
|
|
|
y += CalculateLandingTranslation();
|
|
|
|
|
|
|
|
return zeus::CTransform::Translate(x, 0.f, y);
|
|
|
|
}
|
|
|
|
|
2016-09-15 07:26:35 +00:00
|
|
|
void CPlayerCameraBob::ReadTweaks(CInputStream& in)
|
|
|
|
{
|
|
|
|
if (in.hasError())
|
|
|
|
return;
|
|
|
|
|
|
|
|
kCameraBobExtentX = in.readFloatBig();
|
|
|
|
kCameraBobExtentY = in.readFloatBig();
|
|
|
|
kCameraBobPeriod = in.readFloatBig();
|
|
|
|
kOrbitBobScale = in.readFloatBig();
|
|
|
|
kMaxOrbitBobScale = in.readFloatBig();
|
|
|
|
kSlowSpeedPeriodScale = in.readFloatBig();
|
|
|
|
kTargetMagnitudeTrackingRate = in.readFloatBig();
|
|
|
|
kLandingBobSpringConstant = in.readFloatBig();
|
|
|
|
kViewWanderRadius = in.readFloatBig();
|
|
|
|
kViewWanderSpeedMin = in.readFloatBig();
|
|
|
|
kViewWanderSpeedMax = in.readFloatBig();
|
|
|
|
kViewWanderRollVariation = in.readFloatBig();
|
|
|
|
kGunBobMagnitude = in.readFloatBig();
|
|
|
|
kHelmetBobMagnitude = in.readFloatBig();
|
|
|
|
}
|
2016-08-14 21:11:44 +00:00
|
|
|
}
|