axmol/cocos/math/MathUtil.cpp

28 lines
582 B
C++
Raw Normal View History

2014-04-02 10:33:07 +08:00
#include "MathUtil.h"
2014-04-02 11:06:37 +08:00
#include "ccMacros.h"
2014-04-02 10:33:07 +08:00
2014-04-02 12:09:51 +08:00
NS_CC_MATH_BEGIN
2014-04-02 10:33:07 +08:00
void MathUtil::smooth(float* x, float target, float elapsedTime, float responseTime)
{
GP_ASSERT(x);
if (elapsedTime > 0)
{
*x += (target - *x) * elapsedTime / (elapsedTime + responseTime);
}
}
void MathUtil::smooth(float* x, float target, float elapsedTime, float riseTime, float fallTime)
{
GP_ASSERT(x);
if (elapsedTime > 0)
{
float delta = target - *x;
*x += delta * elapsedTime / (elapsedTime + (delta > 0 ? riseTime : fallTime));
}
}
2014-04-02 12:09:51 +08:00
NS_CC_MATH_END