forked from Kolyah35/minecraft-pe-0.6.1
38 lines
867 B
C++
Executable File
38 lines
867 B
C++
Executable File
#ifndef UTIL__SmoothFloat_H__
|
|
#define UTIL__SmoothFloat_H__
|
|
|
|
//package util;
|
|
|
|
class SmoothFloat
|
|
{
|
|
float targetValue;
|
|
float remainingValue;
|
|
float lastAmount;
|
|
|
|
public:
|
|
SmoothFloat()
|
|
: targetValue(0),
|
|
remainingValue(0),
|
|
lastAmount(0)
|
|
{}
|
|
|
|
float getNewDeltaValue(float deltaValue, float accelerationAmount) {
|
|
targetValue += deltaValue;
|
|
|
|
deltaValue = (targetValue - remainingValue) * accelerationAmount;
|
|
lastAmount = lastAmount + (deltaValue - lastAmount) * .5f;
|
|
if ((deltaValue > 0 && deltaValue > lastAmount) || (deltaValue < 0 && deltaValue < lastAmount)) {
|
|
deltaValue = lastAmount;
|
|
}
|
|
remainingValue += deltaValue;
|
|
|
|
return deltaValue;
|
|
}
|
|
|
|
float getTargetValue() {
|
|
return targetValue;
|
|
}
|
|
};
|
|
|
|
#endif /*UTIL__SmoothFloat_H__*/
|