Created
March 14, 2022 16:29
-
-
Save SharpCoder/aedcb5456450b3f90a6298031ef15e9f to your computer and use it in GitHub Desktop.
Basic interpolation method written in rust
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pub fn interpolate(start: u32, end: u32, elapsed: u64, duration: u64) -> u32 { | |
// Calculate step | |
let x0 = 0f32; | |
let y0 = min(start, end) as f32; | |
let x1 = duration as f32; | |
let y1 = max(end, start) as f32; | |
let x = min(elapsed, duration) as f32; | |
let delta = (x * ((y1 - y0)/(x1 - x0))) as u32; | |
if start > end { | |
return start - delta; | |
} else { | |
return start + delta; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment