2025-01-07 23:43:54 -08:00

29 lines
594 B
Rust

use crate::integer::Time;
#[derive(Clone,Debug)]
pub struct MouseState<T>{
pub pos:glam::IVec2,
pub time:Time<T>,
}
impl<T> Default for MouseState<T>{
fn default()->Self{
Self{
time:Time::ZERO,
pos:glam::IVec2::ZERO,
}
}
}
impl<T> MouseState<T>
where Time<T>:Copy,
{
pub fn lerp(&self,target:&MouseState<T>,time:Time<T>)->glam::IVec2{
let m0=self.pos.as_i64vec2();
let m1=target.pos.as_i64vec2();
//these are deltas
let t1t=(target.time-time).nanos();
let tt0=(time-self.time).nanos();
let dt=(target.time-self.time).nanos();
((m0*t1t+m1*tt0)/dt).as_ivec2()
}
}