2017-08-06 07:15:42 +00:00
|
|
|
#include <Runtime/GameGlobalObjects.hpp>
|
2016-11-20 21:53:15 +00:00
|
|
|
#include "CFluidPlane.hpp"
|
2017-08-06 07:15:42 +00:00
|
|
|
#include "CSimplePool.hpp"
|
2017-08-14 03:55:06 +00:00
|
|
|
#include "CRipple.hpp"
|
|
|
|
#include "CScriptWater.hpp"
|
|
|
|
#include "CStateManager.hpp"
|
2016-11-20 21:53:15 +00:00
|
|
|
|
|
|
|
namespace urde
|
|
|
|
{
|
2017-08-06 07:15:42 +00:00
|
|
|
|
2017-08-13 08:19:33 +00:00
|
|
|
CFluidPlane::CFluidPlane(CAssetId texPattern1, CAssetId texPattern2, CAssetId texColor, float alpha,
|
|
|
|
EFluidType fluidType, float rippleIntensity, const CFluidUVMotion& motion)
|
2017-08-06 07:15:42 +00:00
|
|
|
: x4_texPattern1Id(texPattern1), x8_texPattern2Id(texPattern2), xc_texColorId(texColor), x40_alpha(alpha),
|
2017-08-13 07:56:35 +00:00
|
|
|
x44_fluidType(fluidType), x48_rippleIntensity(rippleIntensity), x4c_uvMotion(motion)
|
2016-11-20 21:53:15 +00:00
|
|
|
{
|
2017-08-06 07:15:42 +00:00
|
|
|
if (g_ResFactory->GetResourceTypeById(texPattern1) == FOURCC('TXTR'))
|
|
|
|
x10_texPattern1.emplace(g_SimplePool->GetObj(SObjectTag{FOURCC('TXTR'), texPattern1}));
|
|
|
|
if (g_ResFactory->GetResourceTypeById(texPattern2) == FOURCC('TXTR'))
|
|
|
|
x20_texPattern2.emplace(g_SimplePool->GetObj(SObjectTag{FOURCC('TXTR'), texPattern2}));
|
|
|
|
if (g_ResFactory->GetResourceTypeById(texColor) == FOURCC('TXTR'))
|
|
|
|
x30_texColor.emplace(g_SimplePool->GetObj(SObjectTag{FOURCC('TXTR'), texColor}));
|
2016-11-20 21:53:15 +00:00
|
|
|
}
|
|
|
|
|
2017-08-14 03:55:06 +00:00
|
|
|
float CFluidPlane::ProjectRippleVelocity(float baseI, float velDot) const
|
2017-03-30 22:36:18 +00:00
|
|
|
{
|
2017-08-14 03:55:06 +00:00
|
|
|
float tmp = 0.5f * baseI * velDot * velDot;
|
|
|
|
if (tmp != 0.f)
|
|
|
|
tmp = std::sqrt(tmp);
|
|
|
|
if (tmp >= 160.f)
|
|
|
|
return 1.f;
|
|
|
|
return tmp / 160.f;
|
|
|
|
}
|
|
|
|
|
|
|
|
float CFluidPlane::CalculateRippleIntensity(float baseI) const
|
|
|
|
{
|
|
|
|
float mul;
|
|
|
|
switch (x44_fluidType)
|
|
|
|
{
|
|
|
|
case EFluidType::NormalWater:
|
|
|
|
mul = g_tweakGame->GetRippleIntensityNormal();
|
|
|
|
break;
|
|
|
|
case EFluidType::PoisonWater:
|
|
|
|
mul = g_tweakGame->GetRippleIntensityPoison();
|
|
|
|
break;
|
|
|
|
case EFluidType::Lava:
|
|
|
|
mul = g_tweakGame->GetRippleIntensityLava();
|
|
|
|
break;
|
2017-08-16 05:34:02 +00:00
|
|
|
case EFluidType::PhazonFluid:
|
2017-08-14 03:55:06 +00:00
|
|
|
case EFluidType::Four:
|
|
|
|
mul = 0.8f;
|
|
|
|
break;
|
2017-08-16 05:34:02 +00:00
|
|
|
case EFluidType::ThickLava:
|
2017-08-14 03:55:06 +00:00
|
|
|
mul = 1.f;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return zeus::clamp(0.f, baseI * mul * (1.f - x48_rippleIntensity + 0.5f), 1.f);
|
|
|
|
}
|
2017-03-30 22:36:18 +00:00
|
|
|
|
2017-08-14 03:55:06 +00:00
|
|
|
void CFluidPlane::AddRipple(float mag, TUniqueId rippler, const zeus::CVector3f& center,
|
|
|
|
CScriptWater& water, CStateManager& mgr)
|
|
|
|
{
|
|
|
|
if (!water.CanRippleAtPoint(center))
|
|
|
|
return;
|
|
|
|
|
|
|
|
mag = CalculateRippleIntensity(mag);
|
|
|
|
mgr.GetFluidPlaneManager()->RippleManager().AddRipple(CRipple(rippler, center, mag));
|
2017-03-30 22:36:18 +00:00
|
|
|
}
|
|
|
|
|
2017-08-14 03:55:06 +00:00
|
|
|
void CFluidPlane::AddRipple(float intensity, TUniqueId rippler, const zeus::CVector3f& center,
|
|
|
|
const zeus::CVector3f& velocity, const CScriptWater& water, CStateManager& mgr,
|
|
|
|
const zeus::CVector3f& upVec)
|
2016-11-20 21:53:15 +00:00
|
|
|
{
|
2017-08-14 03:55:06 +00:00
|
|
|
if (!water.CanRippleAtPoint(center))
|
|
|
|
return;
|
2016-11-20 21:53:15 +00:00
|
|
|
|
2017-08-14 03:55:06 +00:00
|
|
|
intensity = CalculateRippleIntensity(ProjectRippleVelocity(intensity, upVec.dot(velocity)));
|
|
|
|
mgr.GetFluidPlaneManager()->RippleManager().AddRipple(CRipple(rippler, center, intensity));
|
|
|
|
}
|
|
|
|
|
|
|
|
void CFluidPlane::AddRipple(const CRipple& ripple, const CScriptWater& water, CStateManager& mgr)
|
|
|
|
{
|
|
|
|
if (!water.CanRippleAtPoint(ripple.GetCenter()))
|
|
|
|
return;
|
|
|
|
mgr.GetFluidPlaneManager()->RippleManager().AddRipple(ripple);
|
2016-11-20 21:53:15 +00:00
|
|
|
}
|
|
|
|
}
|