Add trun, cubic, and quintic lerp methods
This commit is contained in:
parent
d2c174f2e1
commit
6305261270
18
lerp.cpp
18
lerp.cpp
@ -31,6 +31,10 @@ lerp::sigmoid (double val) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
double lerp::trunc (double a, double, double)
|
||||||
|
{ return a; }
|
||||||
|
|
||||||
|
|
||||||
double
|
double
|
||||||
lerp::linear (double a, double b, double weight) {
|
lerp::linear (double a, double b, double weight) {
|
||||||
CHECK (weight >= 0 && weight <= 1.0);
|
CHECK (weight >= 0 && weight <= 1.0);
|
||||||
@ -47,3 +51,17 @@ lerp::cosine (double a, double b, double weight) {
|
|||||||
return a * (1.0 - f) + b * f;
|
return a * (1.0 - f) + b * f;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
double
|
||||||
|
lerp::cubic (double a, double b, double weight) {
|
||||||
|
CHECK (weight >= 0.0 && weight <= 1.0);
|
||||||
|
double t = weight * weight * (3.0 - 2.0 * weight);
|
||||||
|
return a * (1.0 - t) + b * t;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
double
|
||||||
|
lerp::quintic (double a, double b, double weight) {
|
||||||
|
double t = weight * weight * weight * (weight * (weight * 6.0 - 15.0) + 10.0);
|
||||||
|
return a * (1.0 - t) + b * t;
|
||||||
|
}
|
||||||
|
7
lerp.hpp
7
lerp.hpp
@ -23,8 +23,11 @@
|
|||||||
namespace lerp {
|
namespace lerp {
|
||||||
double sigmoid (double val);
|
double sigmoid (double val);
|
||||||
|
|
||||||
double linear (double a, double b, double weight);
|
double linear (double a, double b, double weight);
|
||||||
double cosine (double a, double b, double weight);
|
double cosine (double a, double b, double weight);
|
||||||
|
double cubic (double a, double b, double weight);
|
||||||
|
double quintic (double a, double b, double weight);
|
||||||
|
double trunc (double a, double b, double weight);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user