-
Notifications
You must be signed in to change notification settings - Fork 0
/
Utility.cpp
62 lines (47 loc) · 1.32 KB
/
Utility.cpp
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
#include "Utility.hpp"
#include <algorithm>
float utility::increase(float start, float increment, float max)
{
auto result = start + increment;
while (result >= max)
result -= max;
while (result < 0)
result += max;
return result;
}
float utility::limit(float value, float min, float max)
{
return std::max(min, std::min(value, max));
}
float utility::rumbleWidth(float projectedRoadWidth, std::size_t lanes)
{
return projectedRoadWidth / std::max(6u, 2 * lanes);
}
float utility::laneMarkerWidth(float projectedRoadWidth, std::size_t lanes)
{
return projectedRoadWidth / std::max(32u, 8 * lanes);
}
float utility::exponentialFog(float distance, float density)
{
return static_cast<float>(1 / std::pow(M_E, (distance * distance * density)));
}
float utility::easeIn(float a, float b, float percent)
{
return a + (b - a) * std::pow(percent, 2.f);
}
float utility::easeOut(float a, float b, float percent)
{
return a + (b - a) * (1 - std::pow(1.f - percent, 2.f));
}
float utility::easeInOut(float a, float b, float percent)
{
return a + (b - a) * (static_cast<float>(-std::cos(percent * M_PI) / 2.f) + 0.5f);
}
float utility::interpolate(float a, float b, float percent)
{
return a + (b - a) * percent;
}
float utility::percentRemaining(float n, float total)
{
return (static_cast<int>(n) % static_cast<int>(total)) / total;
}