From c09c6006b7b2aaef69742ecf38767e6e74c6ece1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Branimir=20Karad=C5=BEi=C4=87?= Date: Sun, 19 Jul 2015 21:51:18 -0700 Subject: [PATCH] Added bias and gain functions. --- include/bx/fpumath.h | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/include/bx/fpumath.h b/include/bx/fpumath.h index 5050246..deaaa1d 100644 --- a/include/bx/fpumath.h +++ b/include/bx/fpumath.h @@ -121,6 +121,25 @@ namespace bx return result; } + // References: + // - Bias And Gain Are Your Friend + // http://blog.demofox.org/2012/09/24/bias-and-gain-are-your-friend/ + // - http://demofox.org/biasgain.html + inline float fbias(float _time, float _bias) + { + return _time / ( ( (1.0f/_bias - 2.0f)*(1.0f - _time) ) + 1.0f); + } + + inline float fgain(float _time, float _gain) + { + if (_time < 0.5f) + { + return fbias(_time * 2.0f, _gain) * 0.5f; + } + + return fbias(_time * 2.0f - 1.0f, 1.0f - _gain) * 0.5f + 0.5f; + } + inline void vec3Move(float* __restrict _result, const float* __restrict _a) { _result[0] = _a[0];