diff --git a/examples/ios/src/lib.rs b/examples/ios/src/lib.rs index eff06174682d2..e7b15c5984aa7 100644 --- a/examples/ios/src/lib.rs +++ b/examples/ios/src/lib.rs @@ -32,8 +32,37 @@ fn main() { .add_plugin(AudioPlugin) .add_startup_system(setup_scene) .add_startup_system(setup_music) + .add_system(touch_camera) .run(); } + +fn touch_camera( + windows: ResMut, + mut touches: EventReader, + mut camera: Query<&mut Transform, With>, + mut last_position: Local>, +) { + for touch in touches.iter() { + match touch.phase { + TouchPhase::Started => *last_position = None, + _ => (), + } + if let Some(last_position) = *last_position { + let window = windows.get_primary().unwrap(); + let mut transform = camera.single_mut(); + *transform = Transform::from_xyz( + transform.translation.x + + (touch.position.x - last_position.x) / window.width() * 5.0, + transform.translation.y, + transform.translation.z + + (touch.position.y - last_position.y) / window.height() * 5.0, + ) + .looking_at(Vec3::ZERO, Vec3::Y); + } + *last_position = Some(touch.position); + } +} + /// set up a simple 3D scene fn setup_scene( mut commands: Commands,