This commit is contained in:
Henrik Rydgård
2012-10-30 00:03:07 +01:00
parent ef01fc2121
commit ea11d9d492
3 changed files with 80 additions and 0 deletions
+1
View File
@@ -3,6 +3,7 @@ set(SRCS
lin/vec3.cpp
lin/quat.cpp
lin/aabb.cpp
curves.cpp
)
set(SRCS ${SRCS})
+57
View File
@@ -0,0 +1,57 @@
#include <math.h>
#include "math/math_util.h"
#include "curves.h"
float linearInOut(int t, int fadeInLength, int solidLength, int fadeOutLength) {
if (t < 0) return 0;
if (t < fadeInLength) {
return (float)t / fadeInLength;
}
t -= fadeInLength;
if (t < solidLength) {
return 1.0f;
}
t -= solidLength;
if (t < fadeOutLength) {
return 1.0f - (float)t / fadeOutLength;
}
return 0.0f;
}
float linearIn(int t, int fadeInLength) {
if (t < 0) return 0;
if (t < fadeInLength) {
return (float)t / fadeInLength;
}
return 1.0f;
}
float linearOut(int t, int fadeOutLength) {
return 1.0f - linearIn(t, fadeOutLength);
}
float ease(float val) {
return ((-cosf(val * PI)) + 1.0f) * 0.5;
}
float sawtooth(int t, int period) {
return (t % period) * (1.0f / (period - 1));
}
float passWithPause(int t, int fadeInLength, int pauseLength, int fadeOutLength)
{
if (t < fadeInLength) {
return -1.0f + (float)t / fadeInLength;
}
t -= fadeInLength;
if (t < pauseLength) {
return 0.0f;
}
t -= pauseLength;
if (t < fadeOutLength) {
return (float)t / fadeOutLength;
}
return 1.0f;
}
+22
View File
@@ -0,0 +1,22 @@
#pragma once
#include <base/basictypes.h>
// Easy curve computation for fades etc.
// output range: [0.0, 1.0]
float linearInOut(int t, int fadeInLength, int solidLength, int fadeOutLength);
float linearIn(int t, int fadeInLength);
float linearOut(int t, int fadeInLength);
// smooth operator [0, 1] -> [0, 1]
float ease(float val);
// need a bouncy ease
// waveforms [0, 1]
float sawtooth(int t, int period);
// output range: -1.0 to 1.0
float passWithPause(int t, int fadeInLength, int pauseLength, int fadeOutLength);