Skip to content

Commit

Permalink
add new system to be able to move the camera
Browse files Browse the repository at this point in the history
  • Loading branch information
mockersf committed Nov 25, 2021
1 parent 06d365b commit 63fb5c2
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions examples/ios/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Windows>,
mut touches: EventReader<TouchInput>,
mut camera: Query<&mut Transform, With<Camera>>,
mut last_position: Local<Option<Vec2>>,
) {
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,
Expand Down

0 comments on commit 63fb5c2

Please sign in to comment.