-
Notifications
You must be signed in to change notification settings - Fork 4
Open
Description
Hi and thanks for the work on this crate.
I was wondering if there was any plan on supporting touch events in this crate?
If not, maybe I can work on a PR to add this?
I can already see that in WASM on Firefox I can use one finger to rotate the camera, but I can't pan/move the camera with two fingers.
FYI, here's what Claude Code suggests:
Plan: Add Touch Events Support to Bevy Blendy Cameras
Current State Analysis
The codebase already has partial touch support:
- Touches resource is imported and used in active_viewport_data_system (src/lib.rs:287)
- Basic touch position detection is implemented for viewport detection (src/lib.rs:219-228)
- Touch activation detection exists (src/lib.rs:338-340) but only for initial camera selection
- However, actual touch gesture handling for camera controls is completely missing
Proposed Implementation
- Extend MouseKeyTracker for Touch Events
File: src/input.rs
- Add touch-specific fields to MouseKeyTracker struct:
- touch_orbit: Vec2 - single finger orbit gestures
- touch_pan: Vec2 - two-finger pan gestures
- touch_zoom: f32 - pinch-to-zoom gestures
- active_touches: u8 - count of active touches
- Import TouchInput events from Bevy
- Implement Touch Gesture Recognition
File: src/input.rs - Update mouse_key_tracker_system
- Single touch: Orbit camera (equivalent to middle mouse drag)
- Two touches:
- Pan camera when moving together
- Zoom camera when distance changes (pinch gesture)
- Three+ touches: Ignore to avoid conflicts
- Handle touch lifecycle (Started, Moved, Ended, Cancelled)
- Add Touch Configuration Options
Files: src/orbit.rs and src/fly.rs
- Add touch sensitivity settings:
- touch_orbit_sensitivity: f32
- touch_pan_sensitivity: f32
- touch_zoom_sensitivity: f32
- Add touch enable/disable flags:
- enable_touch_controls: bool (default: true)
- Update Camera Controllers
Files: src/orbit.rs and src/fly.rs
- Modify orbit/fly systems to consume touch input from MouseKeyTracker
- Implement touch-specific behavior:
- Orbit mode: Single finger orbit, two finger pan/zoom
- Fly mode: Single finger rotate, two finger forward/backward movement
- Handle Touch-Mouse Conflicts
File: src/input.rs
- Implement priority system: active touches disable mouse input
- Ensure smooth transitions between touch and mouse input
- Reset gesture state when switching input methods
- Update Dependencies
File: Cargo.toml
- Ensure Bevy touch features are enabled (already included in bevy_window/bevy_winit)
Technical Considerations
- Gesture Detection: Use touch position deltas and distances for pan/zoom calculations
- Multi-touch Handling: Track individual touch IDs to maintain gesture consistency
- Platform Compatibility: Support iOS, Android, and touch-enabled desktop platforms
- Performance: Efficient touch tracking without impacting frame rates
- Backward Compatibility: All existing mouse/keyboard controls remain unchanged
Expected Outcome
Users will be able to:
- Single finger: Orbit camera around focus point
- Two fingers: Pan camera view and pinch-to-zoom
- Seamless switching: Between touch and mouse/keyboard controls
- Full compatibility: On mobile, tablet, and touch-enabled desktop devices
Metadata
Metadata
Assignees
Labels
No labels