diff options
| author | Aaron Franke <arnfranke@yahoo.com> | 2022-09-18 18:07:24 -0500 |
|---|---|---|
| committer | Aaron Franke <arnfranke@yahoo.com> | 2022-09-19 03:09:59 -0500 |
| commit | 9a2e8d907b86b974c1644ae6e75eb7adefa384b2 (patch) | |
| tree | 8f794587438e8b76d791ca23a0554fe7a81d4696 /include | |
| parent | b11ff9d87662b4cd5582cc721d2e1d1d5f4f369f (diff) | |
| download | redot-cpp-9a2e8d907b86b974c1644ae6e75eb7adefa384b2.tar.gz | |
Add pingpong and fract methods to Math
https://github.com/godotengine/godot/pull/53819
Diffstat (limited to 'include')
| -rw-r--r-- | include/godot_cpp/core/math.hpp | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/include/godot_cpp/core/math.hpp b/include/godot_cpp/core/math.hpp index ca1e6e9..e864ee1 100644 --- a/include/godot_cpp/core/math.hpp +++ b/include/godot_cpp/core/math.hpp @@ -583,6 +583,22 @@ inline float wrapf(real_t value, real_t min, real_t max) { return is_zero_approx(range) ? min : value - (range * floor((value - min) / range)); } +inline float fract(float value) { + return value - floor(value); +} + +inline double fract(double value) { + return value - floor(value); +} + +inline float pingpong(float value, float length) { + return (length != 0.0f) ? abs(fract((value - length) / (length * 2.0f)) * length * 2.0f - length) : 0.0f; +} + +inline double pingpong(double value, double length) { + return (length != 0.0) ? abs(fract((value - length) / (length * 2.0)) * length * 2.0 - length) : 0.0; +} + inline unsigned int next_power_of_2(unsigned int x) { if (x == 0) return 0; |
