forked from Kolyah35/minecraft-pe-0.6.1
the whole game
This commit is contained in:
37
src/util/SmoothFloat.h
Executable file
37
src/util/SmoothFloat.h
Executable file
@@ -0,0 +1,37 @@
|
||||
#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__*/
|
||||
Reference in New Issue
Block a user