mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-03-09 23:40:42 +00:00
adds an mWrap and mWrapF method for cycling values to within a given range.
examples of usage would be say, keeping a rotation within 360 degrees, or hitting a tile boundary and resetting the offset
This commit is contained in:
parent
463cd50d0a
commit
cf98ef8350
2 changed files with 36 additions and 0 deletions
|
|
@ -237,6 +237,19 @@ inline F32 mClampF(F32 val, F32 low, F32 high)
|
|||
return (F32) getMax(getMin(val, high), low);
|
||||
}
|
||||
|
||||
inline S32 mWrap(S32 val, S32 low, S32 high)
|
||||
{
|
||||
int len = high - low;
|
||||
return low + (val >= 0 ? val % len : -val % len ? len - (-val % len) : 0);
|
||||
|
||||
}
|
||||
|
||||
inline F32 mWrapF(F32 val, F32 low, F32 high)
|
||||
{
|
||||
F32 t = fmod(val - low, high - low);
|
||||
return t < 0 ? t + high : t + low;
|
||||
}
|
||||
|
||||
/// Template function for doing a linear interpolation between any two
|
||||
/// types which implement operators for scalar multiply and addition.
|
||||
template <typename T>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue