diff options
| author | robojumper <robojumper@gmail.com> | 2024-09-12 22:36:34 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-09-12 16:36:34 -0400 |
| commit | 1180e1f4860d62bccd64bfa2a29eaeebd2c4b019 (patch) | |
| tree | ce6e231ef46aacbdad52ad7f6cbcd9d02dba555e /src/m/m3d/m_calc_ratio.cpp | |
| parent | e2c4bb7be7fa731a335bce4bc22283d899133e39 (diff) | |
m3d (#13)
* Initial M3d Pass
* `m_bmdl` and `m_bline` left
---------
Co-authored-by: elijah-thomas774 <elijahthomas774@gmail.com>
Co-authored-by: Elijah Thomas <42302100+elijah-thomas774@users.noreply.github.com>
Diffstat (limited to 'src/m/m3d/m_calc_ratio.cpp')
| -rw-r--r-- | src/m/m3d/m_calc_ratio.cpp | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/src/m/m3d/m_calc_ratio.cpp b/src/m/m3d/m_calc_ratio.cpp new file mode 100644 index 00000000..f4ae81f6 --- /dev/null +++ b/src/m/m3d/m_calc_ratio.cpp @@ -0,0 +1,73 @@ +#include <m/m3d/m_calc_ratio.h> +#include <nw4r/math/math_arithmetic.h> + +namespace m3d { + +calcRatio_c::calcRatio_c() { + mf1 = 0.0f; + mf2 = 1.0f; + mf3 = 0.0f; + mf4 = 0.0f; + mf5 = 1.0f; + mb1 = 0; + mb2 = 0; +} + +calcRatio_c::~calcRatio_c() {} + +void calcRatio_c::remove() { + mb1 = 0; + reset(); +} + +void calcRatio_c::reset() { + mf1 = 0.0f; + mf2 = 1.0f; + mf4 = 0.0f; + mf5 = 1.0f; +} + +void calcRatio_c::offUpdate() { + mb1 = 1; + mb2 = 0; +} + +void calcRatio_c::set(f32 value) { + if (value == 0.0f) { + reset(); + return; + } + mf1 = 1.0f; + mf2 = 0.0f; + mf4 = 1.0f; + mf5 = 0.0f; + mb2 = 1; + mf3 = 1.0f / value; +} + +void calcRatio_c::calc() { + if (mf1 == 0.0f) { + return; + } + + mf2 += mf3; + if (mf2 >= 1.0f) { + reset(); + } else { + mb2 = 1; + f32 start = mf1; + f32 tmp = start - start * mf2 * mf2; + mf1 = tmp; + f32 max = 1.0f - mf1; + tmp = mf1 / start; + f32 inv = nw4r::math::FInv(tmp + max); + mf4 = tmp * inv; + mf5 = max * inv; + } +} + +bool calcRatio_c::isEnd() const { + return mf1 == 0.0f; +} + +} // namespace m3d |
