2016-04-20 05:44:08 +00:00
|
|
|
#include "CFluidUVMotion.hpp"
|
2017-07-30 11:00:30 +00:00
|
|
|
#include "zeus/Math.hpp"
|
2016-04-20 05:44:08 +00:00
|
|
|
|
|
|
|
namespace urde
|
|
|
|
{
|
|
|
|
|
2017-08-13 07:56:35 +00:00
|
|
|
CFluidUVMotion::CFluidUVMotion(float timeToWrap, float orientation,
|
|
|
|
const CFluidUVMotion::SFluidLayerMotion& colorLayer,
|
|
|
|
const CFluidUVMotion::SFluidLayerMotion& pattern1Layer,
|
|
|
|
const CFluidUVMotion::SFluidLayerMotion& pattern2Layer)
|
|
|
|
: x4c_ooTimeToWrap(1.f / timeToWrap)
|
|
|
|
, x50_orientation(orientation)
|
2016-04-20 05:44:08 +00:00
|
|
|
{
|
|
|
|
x0_fluidLayers.resize(3);
|
2017-08-13 07:56:35 +00:00
|
|
|
x0_fluidLayers[0] = colorLayer;
|
|
|
|
x0_fluidLayers[1] = pattern1Layer;
|
|
|
|
x0_fluidLayers[2] = pattern2Layer;
|
2016-04-20 05:44:08 +00:00
|
|
|
}
|
|
|
|
|
2017-08-13 07:56:35 +00:00
|
|
|
CFluidUVMotion::CFluidUVMotion(float timeToWrap, float orientation)
|
|
|
|
: x4c_ooTimeToWrap(1.f / timeToWrap), x50_orientation(orientation)
|
|
|
|
{
|
|
|
|
x0_fluidLayers.resize(3);
|
|
|
|
x0_fluidLayers[0].x4_ooTimeToWrap = 0.001f;
|
|
|
|
x0_fluidLayers[1].x4_ooTimeToWrap = 0.33333334f;
|
|
|
|
x0_fluidLayers[2].x4_ooTimeToWrap = 0.2f;
|
|
|
|
x0_fluidLayers[2].x8_orientation = 0.78539819f;
|
|
|
|
}
|
2017-07-30 11:00:30 +00:00
|
|
|
|
2017-08-13 07:56:35 +00:00
|
|
|
void CFluidUVMotion::CalculateFluidTextureOffset(float t, float offsets[3][2]) const
|
2017-07-30 11:00:30 +00:00
|
|
|
{
|
2017-08-13 07:56:35 +00:00
|
|
|
float totalYOffset = (t * x4c_ooTimeToWrap) * zeus::fastCosF(x50_orientation);
|
|
|
|
float totalXOffset = (t * x4c_ooTimeToWrap) * zeus::fastSinF(x50_orientation);
|
2017-07-30 11:00:30 +00:00
|
|
|
|
|
|
|
for (u32 i = 0 ; i<x0_fluidLayers.size() ; ++i)
|
|
|
|
{
|
|
|
|
const SFluidLayerMotion& layer = x0_fluidLayers[i];
|
2017-08-04 13:48:48 +00:00
|
|
|
|
2017-08-13 07:56:35 +00:00
|
|
|
float speedT = t * layer.x4_ooTimeToWrap;
|
|
|
|
float cycleT = speedT - std::floor(speedT);
|
|
|
|
float localY;
|
|
|
|
float localX;
|
2017-07-30 11:00:30 +00:00
|
|
|
switch(layer.x0_motion)
|
|
|
|
{
|
|
|
|
case EFluidUVMotion::One:
|
2017-08-04 13:48:48 +00:00
|
|
|
{
|
2017-08-13 07:56:35 +00:00
|
|
|
float angle = (M_PIF * 2) * cycleT;
|
|
|
|
localY = layer.xc_magnitude * zeus::fastSinF(angle);
|
|
|
|
localX = layer.xc_magnitude * zeus::fastCosF(angle);
|
2017-08-04 13:48:48 +00:00
|
|
|
}
|
|
|
|
break;
|
2017-07-30 11:00:30 +00:00
|
|
|
case EFluidUVMotion::Two:
|
2017-08-04 13:48:48 +00:00
|
|
|
{
|
2017-08-13 07:56:35 +00:00
|
|
|
localY = 0.f;
|
|
|
|
localX = layer.xc_magnitude * zeus::fastCosF((M_PIF * 2) * cycleT);
|
2017-08-04 13:48:48 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
2017-08-13 07:56:35 +00:00
|
|
|
localY = localX = 0.f;
|
2017-07-30 11:00:30 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2017-08-13 07:56:35 +00:00
|
|
|
float x = localX * zeus::fastSinF(layer.x8_orientation) +
|
|
|
|
localY * zeus::fastCosF(layer.x8_orientation) + totalXOffset;
|
|
|
|
float y = localY * zeus::fastSinF(layer.x8_orientation) +
|
|
|
|
localX * zeus::fastCosF(layer.x8_orientation) + totalYOffset;
|
2017-08-04 13:48:48 +00:00
|
|
|
|
2017-08-13 07:56:35 +00:00
|
|
|
offsets[i][0] = x - std::floor(x);
|
|
|
|
offsets[i][1] = y - std::floor(y);
|
2017-07-30 11:00:30 +00:00
|
|
|
}
|
|
|
|
}
|
2016-04-20 05:44:08 +00:00
|
|
|
}
|