diff --git a/README.md b/README.md index eeefb41..e21aeea 100644 --- a/README.md +++ b/README.md @@ -26,6 +26,7 @@ Default controls: - Works with orthographic camera projection in addition to perspective - Customisable controls, sensitivity, and more - Works with multiple viewports and/or windows +- Easy to animate, e.g. to slowly rotate around an object ## Quick Start diff --git a/examples/animate.rs b/examples/animate.rs new file mode 100644 index 0000000..0282ff3 --- /dev/null +++ b/examples/animate.rs @@ -0,0 +1,65 @@ +//! Demonstrates how you can animate the movement of the camera + +use bevy::prelude::*; +use bevy_panorbit_camera::{PanOrbitCamera, PanOrbitCameraPlugin}; +use std::f32::consts::TAU; + +fn main() { + App::new() + .add_plugins(DefaultPlugins) + .add_plugin(PanOrbitCameraPlugin) + .add_startup_system(setup) + .add_system(animate) + .run(); +} + +fn setup( + mut commands: Commands, + mut meshes: ResMut>, + mut materials: ResMut>, +) { + // Ground + commands.spawn(PbrBundle { + mesh: meshes.add(shape::Plane::from_size(5.0).into()), + material: materials.add(Color::rgb(0.3, 0.5, 0.3).into()), + ..default() + }); + // Cube + commands.spawn(PbrBundle { + mesh: meshes.add(Mesh::from(shape::Cube { size: 1.0 })), + material: materials.add(Color::rgb(0.8, 0.7, 0.6).into()), + transform: Transform::from_xyz(0.0, 0.5, 0.0), + ..default() + }); + // Light + commands.spawn(PointLightBundle { + point_light: PointLight { + intensity: 1500.0, + shadows_enabled: true, + ..default() + }, + transform: Transform::from_xyz(4.0, 8.0, 4.0), + ..default() + }); + // Camera + commands.spawn(( + Camera3dBundle::default(), + PanOrbitCamera { + // Optionally disable smoothing to have full control over the camera's position + // orbit_smoothness: 0.0, + // Might want to disable the controls + enabled: false, + ..default() + }, + )); +} + +// Animate the camera's position +fn animate(time: Res