//! Demonstrates all common configuration options, //! and how to modify them at runtime //! //! Controls: //! Orbit: Middle click //! Pan: Shift + Middle click //! Zoom: Mousewheel use bevy::prelude::*; use bevy_panorbit_camera::{PanOrbitCamera, PanOrbitCameraPlugin, TouchControls}; use std::f32::consts::TAU; fn main() { App::new() .add_plugins(DefaultPlugins) .add_plugins(PanOrbitCameraPlugin) .add_systems(Startup, setup) .add_systems(Update, toggle_camera_controls_system) .run(); } fn setup( mut commands: Commands, mut meshes: ResMut>, mut materials: ResMut>, ) { // Ground commands.spawn(PbrBundle { mesh: meshes.add(Plane3d::default().mesh().size(5.0, 5.0)), material: materials.add(Color::srgb(0.3, 0.5, 0.3)), ..default() }); // Cube commands.spawn(PbrBundle { mesh: meshes.add(Cuboid::new(1.0, 1.0, 1.0)), material: materials.add(Color::srgb(0.8, 0.7, 0.6)), transform: Transform::from_xyz(0.0, 0.5, 0.0), ..default() }); // Light commands.spawn(PointLightBundle { point_light: PointLight { shadows_enabled: true, ..default() }, transform: Transform::from_xyz(4.0, 8.0, 4.0), ..default() }); // Camera commands.spawn(( // Note we're setting the initial position below with yaw, pitch, and radius, hence // we don't set transform on the camera. Camera3dBundle::default(), PanOrbitCamera { // Set focal point (what the camera should look at) focus: Vec3::new(0.0, 1.0, 0.0), // Set the starting position, relative to focus (overrides camera's transform). yaw: Some(TAU / 8.0), pitch: Some(TAU / 8.0), radius: Some(5.0), // Set limits on rotation and zoom yaw_upper_limit: Some(TAU / 4.0), yaw_lower_limit: Some(-TAU / 4.0), pitch_upper_limit: Some(TAU / 3.0), pitch_lower_limit: Some(-TAU / 3.0), zoom_upper_limit: Some(5.0), zoom_lower_limit: Some(1.0), // Adjust sensitivity of controls orbit_sensitivity: 1.5, pan_sensitivity: 0.5, zoom_sensitivity: 0.5, // Allow the camera to go upside down allow_upside_down: true, // Change the controls (these match Blender) button_orbit: MouseButton::Middle, button_pan: MouseButton::Middle, modifier_pan: Some(KeyCode::ShiftLeft), // Reverse the zoom direction reversed_zoom: true, // Use alternate touch controls touch_controls: TouchControls::TwoFingerOrbit, ..default() }, )); } // This is how you can change config at runtime. // Press 'T' to toggle the camera controls. fn toggle_camera_controls_system( key_input: Res>, mut pan_orbit_query: Query<&mut PanOrbitCamera>, ) { if key_input.just_pressed(KeyCode::KeyT) { for mut pan_orbit in pan_orbit_query.iter_mut() { pan_orbit.enabled = !pan_orbit.enabled; } } }