Struct anima_engine::math::Interpolator
[−]
[src]
pub struct Interpolator { pub start: f32, pub duration: f32, pub behavior: Behavior, }
A struct
useful to easily compute interpolation ratios.
Examples
let i = Interpolator::new(10.0, 5.0, Behavior::Linear); assert_eq!(i.ratio(12.5), 0.5);
let i = Interpolator::new(10.0, 5.0, Behavior::Linear); let v1 = Vector::new_unf(0.0); let v2 = Vector::new_unf(2.0); assert_eq!(v1.interpolate(v2, i.ratio(12.5)), Vector::new_unf(1.0));
let i = Interpolator::new(0.0, 2.0, Behavior::Linear); let q1 = Quaternion::ident(); let q2 = Quaternion::new_rot(Vector::right(), consts::PI / 2.0); let qi = q1.interpolate(q2, i.ratio(1.0)); const EPSILON: f32 = 0.00001; assert!((q1.angle(qi) - consts::PI / 4.0).abs() < EPSILON);
Fields
start |
|
duration |
|
behavior |
|
Methods
impl Interpolator
fn new(start: f32, duration: f32, behavior: Behavior) -> Interpolator
Creates an interpolator by defining its starting time, duration and behavior.
Examples
let i = Interpolator::new(0.0, 10.0, Behavior::Linear); assert_eq!(i, Interpolator { start: 0.0, duration: 10.0, behavior: Behavior::Linear });
fn ratio(&self, time: f32) -> f32
Computes the ratio (between 0.0
and 1.0
) for some given time.
Examples
let lin = Interpolator::new(0.0, 1.0, Behavior::Linear); let acc = Interpolator::new(0.0, 1.0, Behavior::Acc); let dec = Interpolator::new(0.0, 1.0, Behavior::Dec); let acd = Interpolator::new(0.0, 1.0, Behavior::AccDec); assert_eq!(lin.ratio(0.25), 0.25); assert_eq!(acc.ratio(0.25), 0.0625); assert_eq!(dec.ratio(0.25), 0.4375); assert_eq!(acd.ratio(0.25), 0.14644668);