More accurate recent mouse velocity
This commit is contained in:
parent
ee0ad02717
commit
c3d3bc0c07
2 changed files with 8 additions and 3 deletions
|
@ -180,8 +180,7 @@ impl MouseInput {
|
|||
// the user tried to throw
|
||||
}
|
||||
|
||||
// TODO: pass current time as argument so we don't have a velocity after mouse up
|
||||
let velocity = self.pos_tracker.velocity().unwrap_or_default();
|
||||
let velocity = self.pos_tracker.velocity_noew(new.time).unwrap_or_default();
|
||||
|
||||
MouseInput {
|
||||
down: new.mouse_down && new.mouse_pos.is_some(),
|
||||
|
|
|
@ -104,8 +104,14 @@ where
|
|||
T: std::ops::Sub<Output = Vel>,
|
||||
Vel: std::ops::Div<f32, Output = Vel>,
|
||||
{
|
||||
/// Calculate a smooth velocity (per second) from start until now
|
||||
pub fn velocity_noew(&mut self, now: f64) -> Option<Vel> {
|
||||
self.flush(now);
|
||||
self.velocity_all()
|
||||
}
|
||||
|
||||
/// Calculate a smooth velocity (per second) over the entire time span
|
||||
pub fn velocity(&self) -> Option<Vel> {
|
||||
pub fn velocity_all(&self) -> Option<Vel> {
|
||||
if let (Some(first), Some(last)) = (self.values.front(), self.values.back()) {
|
||||
let dt = (last.0 - first.0) as f32;
|
||||
if dt > 0.0 {
|
||||
|
|
Loading…
Reference in a new issue