2016-04-17 02:50:45 +00:00
|
|
|
#include "CCameraShakeData.hpp"
|
2017-03-18 05:12:27 +00:00
|
|
|
#include "World/ScriptLoader.hpp"
|
2017-10-10 03:50:48 +00:00
|
|
|
#include "CStateManager.hpp"
|
|
|
|
#include "World/CPlayer.hpp"
|
2016-04-17 02:50:45 +00:00
|
|
|
|
|
|
|
namespace urde
|
|
|
|
{
|
|
|
|
|
2017-03-18 05:12:27 +00:00
|
|
|
SCameraShakePoint SCameraShakePoint::LoadCameraShakePoint(CInputStream& in)
|
|
|
|
{
|
2017-10-10 03:50:48 +00:00
|
|
|
u32 useEnvelope = ScriptLoader::LoadParameterFlags(in);
|
|
|
|
float attackTime = in.readFloatBig();
|
|
|
|
float sustainTime = in.readFloatBig();
|
|
|
|
float duration = in.readFloatBig();
|
|
|
|
float magnitude = in.readFloatBig();
|
|
|
|
return {useEnvelope != 0, attackTime, sustainTime, duration, magnitude};
|
2017-03-18 05:12:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CCameraShakerComponent CCameraShakerComponent::LoadNewCameraShakerComponent(CInputStream& in)
|
|
|
|
{
|
2017-10-10 03:50:48 +00:00
|
|
|
u32 useModulation = ScriptLoader::LoadParameterFlags(in);
|
|
|
|
SCameraShakePoint am = SCameraShakePoint::LoadCameraShakePoint(in);
|
|
|
|
SCameraShakePoint fm = SCameraShakePoint::LoadCameraShakePoint(in);
|
|
|
|
return {useModulation != 0, am, fm};
|
2017-03-18 05:12:27 +00:00
|
|
|
}
|
|
|
|
|
2017-10-10 03:50:48 +00:00
|
|
|
CCameraShakeData::CCameraShakeData(float duration, float sfxDist, u32 flags, const zeus::CVector3f& sfxPos,
|
2017-03-18 05:12:27 +00:00
|
|
|
const CCameraShakerComponent& shaker1, const CCameraShakerComponent& shaker2,
|
|
|
|
const CCameraShakerComponent& shaker3)
|
2017-10-10 03:50:48 +00:00
|
|
|
: x0_duration(duration), x8_shakerX(shaker1), x44_shakerY(shaker2), x80_shakerZ(shaker3),
|
|
|
|
xc0_flags(flags), xc4_sfxPos(sfxPos), xd0_sfxDist(sfxDist)
|
2017-03-18 05:12:27 +00:00
|
|
|
{}
|
|
|
|
|
2017-07-30 01:06:06 +00:00
|
|
|
CCameraShakeData::CCameraShakeData(float duration, float magnitude)
|
|
|
|
: CCameraShakeData(duration, 100.f, 0, zeus::CVector3f::skZero, CCameraShakerComponent{}, CCameraShakerComponent{},
|
2017-03-26 05:53:04 +00:00
|
|
|
CCameraShakerComponent{1,
|
2017-07-30 01:06:06 +00:00
|
|
|
SCameraShakePoint{0, 0.25f * duration, 0.f, 0.75f * duration, magnitude},
|
|
|
|
SCameraShakePoint{1, 0.f, 0.f, 0.5f * duration, 2.f}})
|
2017-03-26 05:53:04 +00:00
|
|
|
{}
|
|
|
|
|
2018-07-08 23:03:35 +00:00
|
|
|
CCameraShakeData::CCameraShakeData(CInputStream& in)
|
|
|
|
{
|
|
|
|
in.readUint32Big();
|
|
|
|
in.readFloatBig();
|
|
|
|
in.readFloatBig();
|
|
|
|
in.readFloatBig();
|
|
|
|
in.readFloatBig();
|
|
|
|
in.readFloatBig();
|
|
|
|
in.readFloatBig();
|
|
|
|
in.readBool();
|
|
|
|
BuildProjectileCameraShake(0.5f, 0.75f);
|
|
|
|
}
|
|
|
|
|
2017-07-30 01:06:06 +00:00
|
|
|
CCameraShakeData CCameraShakeData::BuildLandingCameraShakeData(float duration, float magnitude)
|
2017-06-12 04:23:34 +00:00
|
|
|
{
|
2017-07-30 01:06:06 +00:00
|
|
|
return {duration, 100.f, 0, zeus::CVector3f::skZero,
|
|
|
|
CCameraShakerComponent(1,
|
|
|
|
SCameraShakePoint(0, 0.15f * duration, 0.f, 0.85f * duration, magnitude),
|
|
|
|
SCameraShakePoint(1, 0.f, 0.f, 0.4f * duration, 1.5f)),
|
|
|
|
CCameraShakerComponent(),
|
|
|
|
CCameraShakerComponent(1,
|
|
|
|
SCameraShakePoint(0, 0.25f * duration, 0.f, 0.75f * duration, magnitude),
|
|
|
|
SCameraShakePoint(1, 0.f, 0.f, 0.5f * duration, 2.f))};
|
2017-06-12 04:23:34 +00:00
|
|
|
}
|
|
|
|
|
2017-07-30 01:06:06 +00:00
|
|
|
CCameraShakeData CCameraShakeData::BuildProjectileCameraShake(float duration, float magnitude)
|
2017-06-12 04:23:34 +00:00
|
|
|
{
|
2017-07-30 01:06:06 +00:00
|
|
|
return {duration, 100.f, 0, zeus::CVector3f::skZero,
|
|
|
|
CCameraShakerComponent(1,
|
|
|
|
SCameraShakePoint(0, 0.f, 0.f, duration, magnitude),
|
|
|
|
SCameraShakePoint(1, 0.f, 0.f, 0.5f * duration, 3.f)),
|
|
|
|
CCameraShakerComponent(),
|
|
|
|
CCameraShakerComponent()};
|
|
|
|
}
|
|
|
|
|
2017-09-10 00:36:21 +00:00
|
|
|
CCameraShakeData CCameraShakeData::BuildMissileCameraShake(float duration, float magnitude, float sfxDistance,
|
|
|
|
const zeus::CVector3f& sfxPos)
|
|
|
|
{
|
|
|
|
CCameraShakeData ret(duration, magnitude);
|
|
|
|
ret.SetSfxPositionAndDistance(sfxPos, sfxDistance);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2017-07-30 01:06:06 +00:00
|
|
|
CCameraShakeData CCameraShakeData::BuildPhazonCameraShakeData(float duration, float magnitude)
|
|
|
|
{
|
|
|
|
return {duration, 100.f, 0, zeus::CVector3f::skZero,
|
|
|
|
CCameraShakerComponent(1,
|
|
|
|
SCameraShakePoint(0, 0.15f * duration, 0.f, 0.25f * duration, magnitude),
|
|
|
|
SCameraShakePoint(1, 0.f, 0.f, 0.4f * duration, 0.3f)),
|
|
|
|
CCameraShakerComponent(),
|
|
|
|
CCameraShakerComponent(1,
|
|
|
|
SCameraShakePoint(0, 0.25f * duration, 0.f, 0.25f * duration, magnitude),
|
|
|
|
SCameraShakePoint(1, 0.f, 0.f, 0.5f * duration, 0.5f))};
|
2017-06-12 04:23:34 +00:00
|
|
|
}
|
|
|
|
|
2017-10-10 03:50:48 +00:00
|
|
|
void SCameraShakePoint::Update(float curTime)
|
|
|
|
{
|
|
|
|
float offTimePoint = xc_attackTime + x10_sustainTime;
|
|
|
|
float factor = 1.f;
|
|
|
|
if (curTime < xc_attackTime && xc_attackTime > 0.f)
|
|
|
|
factor = zeus::clamp(0.f, curTime / xc_attackTime, 1.f);
|
|
|
|
if (curTime >= offTimePoint && x14_duration > 0.f)
|
|
|
|
factor = 1.f - (curTime - offTimePoint) / x14_duration;
|
|
|
|
x4_value = x8_magnitude * factor;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CCameraShakerComponent::Update(float curTime, float duration, float distAtt)
|
2017-10-06 07:29:56 +00:00
|
|
|
{
|
2017-10-10 03:50:48 +00:00
|
|
|
if (std::fabs(duration) < 0.00001f || !x4_useModulation)
|
|
|
|
{
|
|
|
|
x38_value = 0.f;
|
|
|
|
return;
|
|
|
|
}
|
2017-10-06 07:29:56 +00:00
|
|
|
|
2017-10-10 03:50:48 +00:00
|
|
|
x20_fm.Update(curTime);
|
|
|
|
float freq = 1.f + x20_fm.GetValue();
|
|
|
|
x8_am.Update(curTime);
|
|
|
|
x38_value = x8_am.GetValue() * std::sin(2.f * M_PIF * (duration - curTime) * freq);
|
|
|
|
x38_value *= distAtt;
|
2017-10-06 07:29:56 +00:00
|
|
|
}
|
|
|
|
|
2017-10-10 03:50:48 +00:00
|
|
|
void CCameraShakeData::Update(float dt, CStateManager& mgr)
|
2017-10-06 07:29:56 +00:00
|
|
|
{
|
2017-10-10 03:50:48 +00:00
|
|
|
x4_curTime += dt;
|
|
|
|
float distAtt = 1.f;
|
|
|
|
if (xc0_flags & 0x1)
|
|
|
|
distAtt = 1.f - zeus::clamp(0.f, (xc4_sfxPos - mgr.GetPlayer().GetTranslation()).magnitude() / xd0_sfxDist, 1.f);
|
|
|
|
x8_shakerX.Update(x4_curTime, x0_duration, distAtt);
|
|
|
|
x44_shakerY.Update(x4_curTime, x0_duration, distAtt);
|
|
|
|
x80_shakerZ.Update(x4_curTime, x0_duration, distAtt);
|
2017-10-06 07:29:56 +00:00
|
|
|
}
|
|
|
|
|
2017-10-10 03:50:48 +00:00
|
|
|
zeus::CVector3f CCameraShakeData::GetPoint() const
|
2017-03-18 05:12:27 +00:00
|
|
|
{
|
2017-10-10 03:50:48 +00:00
|
|
|
return {x8_shakerX.GetValue(), x44_shakerY.GetValue(), x80_shakerZ.GetValue()};
|
2017-03-18 05:12:27 +00:00
|
|
|
}
|
2016-04-17 02:50:45 +00:00
|
|
|
|
2017-10-10 03:50:48 +00:00
|
|
|
float CCameraShakeData::GetMaxAMComponent() const
|
2017-03-18 05:12:27 +00:00
|
|
|
{
|
|
|
|
float ret = 0.f;
|
2017-10-10 03:50:48 +00:00
|
|
|
if (x8_shakerX.x4_useModulation)
|
|
|
|
ret = x8_shakerX.x8_am.GetValue();
|
|
|
|
if (x44_shakerY.x4_useModulation)
|
|
|
|
ret = std::max(ret, x44_shakerY.x8_am.GetValue());
|
|
|
|
if (x80_shakerZ.x4_useModulation)
|
|
|
|
ret = std::max(ret, x80_shakerZ.x8_am.GetValue());
|
2017-03-18 05:12:27 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2017-10-10 03:50:48 +00:00
|
|
|
float CCameraShakeData::GetMaxFMComponent() const
|
2016-04-17 02:50:45 +00:00
|
|
|
{
|
2017-10-10 03:50:48 +00:00
|
|
|
float ret = 0.f;
|
|
|
|
if (x8_shakerX.x4_useModulation)
|
|
|
|
ret = x8_shakerX.x20_fm.GetValue();
|
|
|
|
if (x44_shakerY.x4_useModulation)
|
|
|
|
ret = std::max(ret, x44_shakerY.x20_fm.GetValue());
|
|
|
|
if (x80_shakerZ.x4_useModulation)
|
|
|
|
ret = std::max(ret, x80_shakerZ.x20_fm.GetValue());
|
|
|
|
return ret;
|
2016-04-17 02:50:45 +00:00
|
|
|
}
|
2017-03-18 05:12:27 +00:00
|
|
|
|
|
|
|
CCameraShakeData CCameraShakeData::LoadCameraShakeData(CInputStream& in)
|
|
|
|
{
|
2017-10-10 03:50:48 +00:00
|
|
|
float xMag = in.readFloatBig();
|
2018-05-25 06:39:38 +00:00
|
|
|
in.readFloatBig();
|
2017-10-10 03:50:48 +00:00
|
|
|
float yMag = in.readFloatBig();
|
2018-05-25 06:39:38 +00:00
|
|
|
in.readFloatBig();
|
2017-10-10 03:50:48 +00:00
|
|
|
float zMag = in.readFloatBig();
|
2018-05-25 06:39:38 +00:00
|
|
|
in.readFloatBig();
|
2017-03-18 05:12:27 +00:00
|
|
|
float duration = in.readFloatBig();
|
|
|
|
|
2017-10-10 03:50:48 +00:00
|
|
|
SCameraShakePoint xAM(0, 0.f, 0.f, duration, 2.f * xMag);
|
|
|
|
SCameraShakePoint yAM(0, 0.f, 0.f, duration, 2.f * yMag);
|
|
|
|
SCameraShakePoint zAM(0, 0.f, 0.f, duration, 2.f * zMag);
|
|
|
|
SCameraShakePoint xFM(0, 0.f, 0.f, 0.5f * duration, 3.f);
|
|
|
|
SCameraShakePoint yFM(0, 0.f, 0.f, 0.5f * duration, 0.f);
|
|
|
|
SCameraShakePoint zFM(0, 0.f, 0.f, 0.5f * duration, 3.f);
|
2017-03-18 05:12:27 +00:00
|
|
|
|
2017-10-10 03:50:48 +00:00
|
|
|
CCameraShakerComponent shakerX(1, xAM, xFM);
|
|
|
|
CCameraShakerComponent shakerY;
|
|
|
|
CCameraShakerComponent shakerZ(1, zAM, zFM);
|
2017-03-18 05:12:27 +00:00
|
|
|
|
2017-10-10 03:50:48 +00:00
|
|
|
return {duration, 100.f, 0, zeus::CVector3f::skZero, shakerX, shakerY, shakerZ};
|
2017-03-18 05:12:27 +00:00
|
|
|
}
|
2016-04-17 02:50:45 +00:00
|
|
|
|
2017-09-10 00:36:21 +00:00
|
|
|
const CCameraShakeData CCameraShakeData::skChargedShotCameraShakeData =
|
2017-09-05 03:00:19 +00:00
|
|
|
{0.3f, 100.f, 0, zeus::CVector3f::skZero, CCameraShakerComponent(),
|
|
|
|
CCameraShakerComponent(1, {0, 0.f, 0.f, 0.3f, -1.f}, {1, 0.f, 0.f, 0.05f, 0.3f}),
|
|
|
|
CCameraShakerComponent()};
|
|
|
|
|
2016-04-17 02:50:45 +00:00
|
|
|
}
|