mirror of
https://github.com/hrydgard/ppsspp.git
synced 2026-07-11 01:25:07 +02:00
curves
This commit is contained in:
@@ -3,6 +3,7 @@ set(SRCS
|
||||
lin/vec3.cpp
|
||||
lin/quat.cpp
|
||||
lin/aabb.cpp
|
||||
curves.cpp
|
||||
)
|
||||
|
||||
set(SRCS ${SRCS})
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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);
|
||||
Reference in New Issue
Block a user