From ae12379711b1f791b34910d92ba203c1b0e28b16 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Branimir=20Karad=C5=BEi=C4=87?= Date: Sat, 14 Jan 2017 19:24:56 -0800 Subject: [PATCH] Cleanup. --- include/bx/easing.h | 289 +++++++++++++----------------------------- include/bx/easing.inl | 256 +++++++++++++++++++++++++++++++++++++ 2 files changed, 342 insertions(+), 203 deletions(-) create mode 100644 include/bx/easing.inl diff --git a/include/bx/easing.h b/include/bx/easing.h index 3db6eec..9efbc51 100644 --- a/include/bx/easing.h +++ b/include/bx/easing.h @@ -14,6 +14,7 @@ namespace bx { + /// struct Easing { enum Enum @@ -64,252 +65,134 @@ namespace bx }; }; + /// typedef float (*EaseFn)(float _t); - template - float easeOut(float _t) - { - return 1.0f - ease(1.0f - _t); - } + /// + float easeLinear(float _t); - template - float easeMix(float _t) - { - return _t < 0.5f - ? easeFrom0toH(2.0f*_t)*0.5f - : easeFromHto1(2.0f*_t - 1.0f)*0.5f + 0.5f - ; - } + /// + float easeInQuad(float _t); - inline float easeLinear(float _t) - { - return _t; - } + /// + float easeOutQuad(float _t); - inline float easeInQuad(float _t) - { - return fsq(_t); - } + /// + float easeInOutQuad(float _t); - inline float easeOutQuad(float _t) - { - return easeOut(_t); - } + /// + float easeOutInQuad(float _t); - inline float easeInOutQuad(float _t) - { - return easeMix(_t); - } + /// + float easeInCubic(float _t); - inline float easeOutInQuad(float _t) - { - return easeMix(_t); - } + /// + float easeOutCubic(float _t); - inline float easeInCubic(float _t) - { - return _t*_t*_t; - } + /// + float easeInOutCubic(float _t); - inline float easeOutCubic(float _t) - { - return easeOut(_t); - } + /// + float easeOutInCubic(float _t); - inline float easeInOutCubic(float _t) - { - return easeMix(_t); - } + /// + float easeInQuart(float _t); - inline float easeOutInCubic(float _t) - { - return easeMix(_t); - } + /// + float easeOutQuart(float _t); - inline float easeInQuart(float _t) - { - return _t*_t*_t*_t; - } + /// + float easeInOutQuart(float _t); - inline float easeOutQuart(float _t) - { - return easeOut(_t); - } + /// + float easeOutInQuart(float _t); - inline float easeInOutQuart(float _t) - { - return easeMix(_t); - } + /// + float easeInQuint(float _t); - inline float easeOutInQuart(float _t) - { - return easeMix(_t); - } + /// + float easeOutQuint(float _t); - inline float easeInQuint(float _t) - { - return _t*_t*_t*_t*_t; - } + /// + float easeInOutQuint(float _t); - inline float easeOutQuint(float _t) - { - return easeOut(_t); - } + /// + float easeOutInQuint(float _t); - inline float easeInOutQuint(float _t) - { - return easeMix(_t); - } + /// + float easeInSine(float _t); - inline float easeOutInQuint(float _t) - { - return easeMix(_t); - } + /// + float easeOutSine(float _t); - inline float easeInSine(float _t) - { - return 1.0f - fcos(_t*piHalf); - } + /// + float easeInOutSine(float _t); - inline float easeOutSine(float _t) - { - return easeOut(_t); - } + /// + float easeOutInSine(float _t); - inline float easeInOutSine(float _t) - { - return easeMix(_t); - } + /// + float easeInExpo(float _t); - inline float easeOutInSine(float _t) - { - return easeMix(_t); - } + /// + float easeOutExpo(float _t); - inline float easeInExpo(float _t) - { - return fpow(2.0f, 10.0f * (_t - 1.0f) ) - 0.001f; - } + /// + float easeInOutExpo(float _t); - inline float easeOutExpo(float _t) - { - return easeOut(_t); - } + /// + float easeOutInExpo(float _t); - inline float easeInOutExpo(float _t) - { - return easeMix(_t); - } + /// + float easeInCirc(float _t); - inline float easeOutInExpo(float _t) - { - return easeMix(_t); - } + /// + float easeOutCirc(float _t); - inline float easeInCirc(float _t) - { - return -(fsqrt(1.0f - _t*_t) - 1.0f); - } + /// + float easeInOutCirc(float _t); - inline float easeOutCirc(float _t) - { - return easeOut(_t); - } + /// + float easeOutInCirc(float _t); - inline float easeInOutCirc(float _t) - { - return easeMix(_t); - } + /// + float easeOutElastic(float _t); - inline float easeOutInCirc(float _t) - { - return easeMix(_t); - } + /// + float easeInElastic(float _t); - inline float easeOutElastic(float _t) - { - return fpow(2.0f, -10.0f*_t)*fsin( (_t-0.3f/4.0f)*(2.0f*pi)/0.3f) + 1.0f; - } + /// + float easeInOutElastic(float _t); - inline float easeInElastic(float _t) - { - return easeOut(_t); - } + /// + float easeOutInElastic(float _t); - inline float easeInOutElastic(float _t) - { - return easeMix(_t); - } + /// + float easeInBack(float _t); - inline float easeOutInElastic(float _t) - { - return easeMix(_t); - } + /// + float easeOutBack(float _t); - inline float easeInBack(float _t) - { - return easeInCubic(_t) - _t*fsin(_t*pi); - } + /// + float easeInOutBack(float _t); - inline float easeOutBack(float _t) - { - return easeOut(_t); - } + /// + float easeOutInBack(float _t); - inline float easeInOutBack(float _t) - { - return easeMix(_t); - } + /// + float easeOutBounce(float _t); - inline float easeOutInBack(float _t) - { - return easeMix(_t); - } + /// + float easeInBounce(float _t); - inline float easeOutBounce(float _t) - { - if (4.0f/11.0f > _t) - { - return 121.0f/16.0f*_t*_t; - } + /// + float easeInOutBounce(float _t); - if (8.0f/11.0f > _t) - { - return 363.0f/40.0f*_t*_t - - 99.0f/10.0f*_t - + 17.0f/ 5.0f - ; - } - - if (9.0f/10.0f > _t) - { - return 4356.0f/ 361.0f*_t*_t - - 35442.0f/1805.0f*_t - + 16061.0f/1805.0f - ; - } - - return 54.0f/ 5.0f*_t*_t - - 513.0f/25.0f*_t - + 268.0f/25.0f - ; - } - - inline float easeInBounce(float _t) - { - return easeOut(_t); - } - - inline float easeInOutBounce(float _t) - { - return easeMix(_t); - } - - inline float easeOutInBounce(float _t) - { - return easeMix(_t); - } + /// + float easeOutInBounce(float _t); } // namespace bx +#include "easing.inl" + #endif // BX_EASING_H_HEADER_GUARD diff --git a/include/bx/easing.inl b/include/bx/easing.inl new file mode 100644 index 0000000..b23edb1 --- /dev/null +++ b/include/bx/easing.inl @@ -0,0 +1,256 @@ +/* + * Copyright 2011-2017 Branimir Karadzic. All rights reserved. + * License: https://github.com/bkaradzic/bx#license-bsd-2-clause + */ + +#ifndef BX_EASING_H_HEADER_GUARD +# error "Must be included from bx/easing.h!" +#endif // BX_EASING_H_HEADER_GUARD + +namespace bx +{ + template + float easeOut(float _t) + { + return 1.0f - ease(1.0f - _t); + } + + template + float easeMix(float _t) + { + return _t < 0.5f + ? easeFrom0toH(2.0f*_t)*0.5f + : easeFromHto1(2.0f*_t - 1.0f)*0.5f + 0.5f + ; + } + + inline float easeLinear(float _t) + { + return _t; + } + + inline float easeInQuad(float _t) + { + return fsq(_t); + } + + inline float easeOutQuad(float _t) + { + return easeOut(_t); + } + + inline float easeInOutQuad(float _t) + { + return easeMix(_t); + } + + inline float easeOutInQuad(float _t) + { + return easeMix(_t); + } + + inline float easeInCubic(float _t) + { + return _t*_t*_t; + } + + inline float easeOutCubic(float _t) + { + return easeOut(_t); + } + + inline float easeInOutCubic(float _t) + { + return easeMix(_t); + } + + inline float easeOutInCubic(float _t) + { + return easeMix(_t); + } + + inline float easeInQuart(float _t) + { + return _t*_t*_t*_t; + } + + inline float easeOutQuart(float _t) + { + return easeOut(_t); + } + + inline float easeInOutQuart(float _t) + { + return easeMix(_t); + } + + inline float easeOutInQuart(float _t) + { + return easeMix(_t); + } + + inline float easeInQuint(float _t) + { + return _t*_t*_t*_t*_t; + } + + inline float easeOutQuint(float _t) + { + return easeOut(_t); + } + + inline float easeInOutQuint(float _t) + { + return easeMix(_t); + } + + inline float easeOutInQuint(float _t) + { + return easeMix(_t); + } + + inline float easeInSine(float _t) + { + return 1.0f - fcos(_t*piHalf); + } + + inline float easeOutSine(float _t) + { + return easeOut(_t); + } + + inline float easeInOutSine(float _t) + { + return easeMix(_t); + } + + inline float easeOutInSine(float _t) + { + return easeMix(_t); + } + + inline float easeInExpo(float _t) + { + return fpow(2.0f, 10.0f * (_t - 1.0f) ) - 0.001f; + } + + inline float easeOutExpo(float _t) + { + return easeOut(_t); + } + + inline float easeInOutExpo(float _t) + { + return easeMix(_t); + } + + inline float easeOutInExpo(float _t) + { + return easeMix(_t); + } + + inline float easeInCirc(float _t) + { + return -(fsqrt(1.0f - _t*_t) - 1.0f); + } + + inline float easeOutCirc(float _t) + { + return easeOut(_t); + } + + inline float easeInOutCirc(float _t) + { + return easeMix(_t); + } + + inline float easeOutInCirc(float _t) + { + return easeMix(_t); + } + + inline float easeOutElastic(float _t) + { + return fpow(2.0f, -10.0f*_t)*fsin( (_t-0.3f/4.0f)*(2.0f*pi)/0.3f) + 1.0f; + } + + inline float easeInElastic(float _t) + { + return easeOut(_t); + } + + inline float easeInOutElastic(float _t) + { + return easeMix(_t); + } + + inline float easeOutInElastic(float _t) + { + return easeMix(_t); + } + + inline float easeInBack(float _t) + { + return easeInCubic(_t) - _t*fsin(_t*pi); + } + + inline float easeOutBack(float _t) + { + return easeOut(_t); + } + + inline float easeInOutBack(float _t) + { + return easeMix(_t); + } + + inline float easeOutInBack(float _t) + { + return easeMix(_t); + } + + inline float easeOutBounce(float _t) + { + if (4.0f/11.0f > _t) + { + return 121.0f/16.0f*_t*_t; + } + + if (8.0f/11.0f > _t) + { + return 363.0f/40.0f*_t*_t + - 99.0f/10.0f*_t + + 17.0f/ 5.0f + ; + } + + if (9.0f/10.0f > _t) + { + return 4356.0f/ 361.0f*_t*_t + - 35442.0f/1805.0f*_t + + 16061.0f/1805.0f + ; + } + + return 54.0f/ 5.0f*_t*_t + - 513.0f/25.0f*_t + + 268.0f/25.0f + ; + } + + inline float easeInBounce(float _t) + { + return easeOut(_t); + } + + inline float easeInOutBounce(float _t) + { + return easeMix(_t); + } + + inline float easeOutInBounce(float _t) + { + return easeMix(_t); + } + +} // namespace bx