Expand description
§Multi-touch gesture recognizer
Converts raw TouchContact events into high-level camera
InputEvents (pan, pinch-zoom, two-finger rotate, two-finger
pitch).
§Design
The recognizer follows the same architecture as MapLibre GL JS / Mapbox GL JS:
- Single touch → pan (averaged delta when multiple fingers are down).
- Two-finger pinch → zoom, using
log₂(distance / last_distance)for smooth proportional zoom. - Two-finger rotation → yaw, with an adaptive threshold that scales with finger distance (smaller circle = higher threshold in degrees).
- Two-finger vertical drag → pitch, detected when both fingers move predominantly vertically in the same direction.
§Gesture disambiguation
Pinch-zoom activates after |log₂(distance / start_distance)| ≥ 0.1.
Rotation activates after the bearing delta exceeds a threshold
derived from ROTATION_THRESHOLD_PX / circumference × 360°.
Pitch requires both finger vectors to be vertical and same-direction.
All three can be active simultaneously (zoom+rotate is common during
a two-finger gesture).
§Usage
use rustial_engine::gesture::GestureRecognizer;
use rustial_engine::{InputEvent, TouchContact, TouchPhase};
let mut gesture = GestureRecognizer::new();
// Finger 0 touches down at (100, 200).
let events = gesture.process(TouchContact {
id: 0, phase: TouchPhase::Started, x: 100.0, y: 200.0,
});
assert!(events.is_empty()); // no gesture from a single touch-down
// Finger 0 drags to (110, 200) → pan.
let events = gesture.process(TouchContact {
id: 0, phase: TouchPhase::Moved, x: 110.0, y: 200.0,
});
assert_eq!(events.len(), 1);
assert!(events[0].is_pan());Structs§
- Gesture
Recognizer - Stateful multi-touch gesture recognizer.