29 lines
594 B
Rust
Raw Normal View History

2024-08-02 13:45:52 -07:00
use crate::integer::Time;
#[derive(Clone,Debug)]
2025-01-07 22:36:21 -08:00
pub struct MouseState<T>{
2024-08-02 13:45:52 -07:00
pub pos:glam::IVec2,
2025-01-07 22:36:21 -08:00
pub time:Time<T>,
2024-08-02 13:45:52 -07:00
}
2025-01-07 22:36:21 -08:00
impl<T> Default for MouseState<T>{
2024-08-02 13:45:52 -07:00
fn default()->Self{
Self{
time:Time::ZERO,
pos:glam::IVec2::ZERO,
}
}
}
2025-01-07 22:36:21 -08:00
impl<T> MouseState<T>
where Time<T>:Copy,
{
pub fn lerp(&self,target:&MouseState<T>,time:Time<T>)->glam::IVec2{
2024-08-02 13:45:52 -07:00
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()
}
}