mirror of
https://github.com/luanti-org/luanti.git
synced 2025-06-27 16:36:03 +00:00
Smoothed yaw rotation for objects (#6825)
This commit is contained in:
parent
741e3efaf5
commit
f3997025fd
4 changed files with 89 additions and 52 deletions
|
@ -376,3 +376,22 @@ inline u32 npot2(u32 orig) {
|
|||
orig |= orig >> 16;
|
||||
return orig + 1;
|
||||
}
|
||||
|
||||
// Gradual steps towards the target value in a wrapped (circular) system
|
||||
// using the shorter of both ways
|
||||
template<typename T>
|
||||
inline void wrappedApproachShortest(T ¤t, const T target, const T stepsize,
|
||||
const T maximum)
|
||||
{
|
||||
T delta = target - current;
|
||||
if (delta < 0)
|
||||
delta += maximum;
|
||||
|
||||
if (delta > stepsize && maximum - delta > stepsize) {
|
||||
current += (delta < maximum / 2) ? stepsize : -stepsize;
|
||||
if (current >= maximum)
|
||||
current -= maximum;
|
||||
} else {
|
||||
current = target;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue