2019-12-22 20:04:07 +00:00
|
|
|
#include "Runtime/World/CFluidUVMotion.hpp"
|
|
|
|
|
|
|
|
#include <cmath>
|
|
|
|
|
|
|
|
#include <zeus/Math.hpp>
|
2016-04-20 05:44:08 +00:00
|
|
|
|
2021-04-10 08:42:06 +00:00
|
|
|
namespace metaforce {
|
2016-04-20 05:44:08 +00:00
|
|
|
|
2020-04-17 01:10:48 +00:00
|
|
|
CFluidUVMotion::CFluidUVMotion(float timeToWrap, float orientation, const SFluidLayerMotion& colorLayer,
|
|
|
|
const SFluidLayerMotion& pattern1Layer, const SFluidLayerMotion& pattern2Layer)
|
|
|
|
: x0_fluidLayers{{colorLayer, pattern1Layer, pattern2Layer}}
|
|
|
|
, x4c_ooTimeToWrap(1.f / timeToWrap)
|
|
|
|
, x50_orientation(orientation) {}
|
2016-04-20 05:44:08 +00:00
|
|
|
|
2017-08-13 07:56:35 +00:00
|
|
|
CFluidUVMotion::CFluidUVMotion(float timeToWrap, float orientation)
|
2018-12-08 05:30:43 +00:00
|
|
|
: 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-08-13 07:56:35 +00:00
|
|
|
}
|
2017-07-30 11:00:30 +00:00
|
|
|
|
2020-04-12 13:20:22 +00:00
|
|
|
CFluidUVMotion::FluidOffsets CFluidUVMotion::CalculateFluidTextureOffset(float t) const {
|
|
|
|
FluidOffsets offsets;
|
|
|
|
const float totalYOffset = t * x4c_ooTimeToWrap * std::cos(x50_orientation);
|
|
|
|
const float totalXOffset = t * x4c_ooTimeToWrap * std::sin(x50_orientation);
|
2018-12-08 05:30:43 +00:00
|
|
|
|
2020-04-12 13:20:22 +00:00
|
|
|
for (size_t i = 0; i < x0_fluidLayers.size(); ++i) {
|
2018-12-08 05:30:43 +00:00
|
|
|
const SFluidLayerMotion& layer = x0_fluidLayers[i];
|
|
|
|
|
2020-04-12 13:20:22 +00:00
|
|
|
const float speedT = t * layer.x4_ooTimeToWrap;
|
|
|
|
const float cycleT = speedT - std::floor(speedT);
|
2018-12-08 05:30:43 +00:00
|
|
|
float localY;
|
|
|
|
float localX;
|
|
|
|
switch (layer.x0_motion) {
|
|
|
|
case EFluidUVMotion::Linear: {
|
|
|
|
localX = speedT;
|
|
|
|
localY = 0.f;
|
|
|
|
} break;
|
|
|
|
case EFluidUVMotion::Circular: {
|
2020-04-12 13:20:22 +00:00
|
|
|
const float angle = (M_PIF * 2) * cycleT;
|
2018-12-08 05:30:43 +00:00
|
|
|
localY = layer.xc_magnitude * std::sin(angle);
|
|
|
|
localX = layer.xc_magnitude * std::cos(angle);
|
|
|
|
} break;
|
|
|
|
case EFluidUVMotion::Oscillate: {
|
|
|
|
localY = 0.f;
|
|
|
|
localX = layer.xc_magnitude * std::cos((M_PIF * 2) * cycleT);
|
|
|
|
} break;
|
|
|
|
default:
|
|
|
|
localY = localX = 0.f;
|
|
|
|
break;
|
|
|
|
}
|
2017-07-30 11:00:30 +00:00
|
|
|
|
2020-04-12 13:20:22 +00:00
|
|
|
const float x = localX * std::sin(layer.x8_orientation) + localY * std::cos(layer.x8_orientation) + totalXOffset;
|
|
|
|
const float y = localY * std::sin(layer.x8_orientation) + localX * std::cos(layer.x8_orientation) + totalYOffset;
|
2017-08-04 13:48:48 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
offsets[i][0] = x - std::floor(x);
|
|
|
|
offsets[i][1] = y - std::floor(y);
|
|
|
|
}
|
2020-04-12 13:20:22 +00:00
|
|
|
|
|
|
|
return offsets;
|
2016-04-20 05:44:08 +00:00
|
|
|
}
|
2021-04-10 08:42:06 +00:00
|
|
|
} // namespace metaforce
|