axmol/cocos/math/MathUtil.cpp

29 lines
569 B
C++
Raw Normal View History

2014-04-02 10:33:07 +08:00
#include "Base.h"
#include "MathUtil.h"
namespace gameplay
{
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));
}
}
}