Put boilerplate code into easing base class

This commit is contained in:
Tobias Loose
2013-12-05 23:27:28 +01:00
parent 93d1a637b6
commit 8bb58ca3b1
+20 -15
View File
@@ -28,7 +28,25 @@ public:
time_acc = 0; duration = 0;
}
virtual void update(float dt) = 0;
void update(float dt)
{
if(duration > 0)
{
time_acc += dt;
if(time_acc > duration)
{
time_acc = duration;
value = start_value + delta_value;
}
else
{
updateValue();
}
}
}
virtual void updateValue() = 0;
void start(float targetValue, float _duration)
{
@@ -55,18 +73,7 @@ class InOutQuadEasing : public Easing
public:
InOutQuadEasing(float val): Easing(val) {}
void update(float dt)
{
if(duration > 0)
{
time_acc += dt;
if(time_acc > duration)
{
time_acc = duration;
value = start_value + delta_value;
}
else
void updateValue()
{
float time_tmp = time_acc * 2 / duration;
if (time_tmp < 1)
@@ -79,8 +86,6 @@ public:
value = -delta_value/2 * (time_tmp*(time_tmp-2) - 1) + start_value;
}
}
}
}
};