-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsmooth.cpp
More file actions
35 lines (33 loc) · 1.09 KB
/
Copy pathsmooth.cpp
File metadata and controls
35 lines (33 loc) · 1.09 KB
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
template <typename Type>
void Smooth<Type>::set(this auto& self, Type value) {
if (self.changed(value)) {
self.dirty = true;
}
self.value = value;
self.target = value;
}
template <typename Type>
bool Smooth<Type>::changed(this const auto& self, Type new_value) {
if constexpr (std::is_same_v<Type, f32>) {
return f32_cmp(new_value, self.value, 0.0) == false;
} else if constexpr (std::is_same_v<Type, f64>) {
return f64_cmp(new_value, self.value, 0.0) == false;
} else {
return Type::cmp(new_value, self.value, 0.0) == false;
}
}
template <typename Type>
bool Smooth<Type>::update(this auto& self, f64 rate, f64 delta_time) {
Type new_value;
if constexpr (std::is_same_v<Type, f32>) {
new_value = f32_smooth_step(self.value, self.target, rate, delta_time);
} else if constexpr (std::is_same_v<Type, f64>) {
new_value = f64_smooth_step(self.value, self.target, rate, delta_time);
} else {
new_value = Type::smooth_step(self.value, self.target, rate, delta_time);
}
bool changed = self.dirty || self.changed(new_value);
self.value = new_value;
self.dirty = false;
return changed;
}