multi touch fixes

This commit is contained in:
2021-08-07 16:10:06 +02:00
parent bff41ecd89
commit b933a6dd35
2 changed files with 36 additions and 13 deletions

View File

@@ -354,6 +354,18 @@ impl InputState {
}
}
fn get_touch_drag_distance(&self) -> Vector2<f64> {
if let Some(old_pos) = self.pressed_touch_positions.values().next() {
if let Some(newest_input) = self.touch_inputs.iter().filter(|ti| ti.phase == TouchPhase::Started || ti.phase == TouchPhase::Moved).last() {
newest_input.touch_location - old_pos
} else {
vec2(0.0, 0.0)
}
} else {
vec2(0.0, 0.0)
}
}
pub fn get_axis(self: &Self, axis_code: &str) -> f32 {
if let Some(axis) = self.virtual_axes.get(axis_code) {
axis.axis_inputs.iter().map(|item| {
@@ -382,23 +394,15 @@ impl InputState {
&AxisInput::Touch(touch_axis) => {
match touch_axis {
TouchAxis::Horizontal => {
if let Some(old_pos) = self.pressed_touch_positions.values().next() {
if let Some(newest_input) = self.touch_inputs.last() {
(newest_input.touch_location.x - old_pos.x) as f32
} else {
0.0
}
if self.pressed_touch_positions.len() == 1 {
self.get_touch_drag_distance().x as f32
} else {
0.0
}
},
TouchAxis::Vertical => {
if let Some(old_pos) = self.pressed_touch_positions.values().next() {
if let Some(newest_input) = self.touch_inputs.last() {
(newest_input.touch_location.y - old_pos.y) as f32
} else {
0.0
}
if self.pressed_touch_positions.len() == 1 {
self.get_touch_drag_distance().y as f32
} else {
0.0
}