blob: 25eb2f97223e6dd9288762a2418dc2b2922ba44b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
#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
|