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

@@ -8,6 +8,25 @@
} }
], ],
"objects": [ "objects": [
{
"mesh_index": 0,
"position": [
0.0,
0.0,
0.0
],
"rotation": [
1.0,
0.0,
0.0,
0.0
],
"scale": [
1.0,
1.0,
1.0
]
},
{ {
"mesh_index": 1, "mesh_index": 1,
"position": [ "position": [
@@ -32,7 +51,7 @@
"mesh_index": null, "mesh_index": null,
"position": [ "position": [
0, 0,
0, 1.0,
5.0 5.0
], ],
"rotation": [ "rotation": [

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 { pub fn get_axis(self: &Self, axis_code: &str) -> f32 {
if let Some(axis) = self.virtual_axes.get(axis_code) { if let Some(axis) = self.virtual_axes.get(axis_code) {
axis.axis_inputs.iter().map(|item| { axis.axis_inputs.iter().map(|item| {
@@ -382,23 +394,15 @@ impl InputState {
&AxisInput::Touch(touch_axis) => { &AxisInput::Touch(touch_axis) => {
match touch_axis { match touch_axis {
TouchAxis::Horizontal => { TouchAxis::Horizontal => {
if let Some(old_pos) = self.pressed_touch_positions.values().next() { if self.pressed_touch_positions.len() == 1 {
if let Some(newest_input) = self.touch_inputs.last() { self.get_touch_drag_distance().x as f32
(newest_input.touch_location.x - old_pos.x) as f32
} else {
0.0
}
} else { } else {
0.0 0.0
} }
}, },
TouchAxis::Vertical => { TouchAxis::Vertical => {
if let Some(old_pos) = self.pressed_touch_positions.values().next() { if self.pressed_touch_positions.len() == 1 {
if let Some(newest_input) = self.touch_inputs.last() { self.get_touch_drag_distance().y as f32
(newest_input.touch_location.y - old_pos.y) as f32
} else {
0.0
}
} else { } else {
0.0 0.0
} }