From 50c9b1d57738baf8125d4a9f711658d5b6fbfd0b Mon Sep 17 00:00:00 2001 From: Huon Imberger Date: Mon, 12 Feb 2024 18:37:42 +1100 Subject: [PATCH] Remove built-in roll controls (#51) --- examples/advanced.rs | 7 ---- examples/roll_axis.rs | 81 +++++++++++++++++++++++++++++++++++++++ examples/touch/Cargo.lock | 2 +- examples/touch/src/lib.rs | 8 +--- src/input.rs | 57 ++------------------------- src/lib.rs | 71 ++++------------------------------ 6 files changed, 95 insertions(+), 131 deletions(-) create mode 100644 examples/roll_axis.rs diff --git a/examples/advanced.rs b/examples/advanced.rs index 34a26d8..a0263ca 100644 --- a/examples/advanced.rs +++ b/examples/advanced.rs @@ -5,7 +5,6 @@ //! Orbit: Middle click //! Pan: Shift + Middle click //! Zoom: Mousewheel -//! Roll: A (roll left) and D (roll right) use bevy::prelude::*; use bevy_panorbit_camera::{PanOrbitCamera, PanOrbitCameraPlugin}; @@ -79,12 +78,6 @@ fn setup( modifier_pan: Some(KeyCode::ShiftLeft), // Reverse the zoom direction reversed_zoom: true, - // Enable roll in addition to orbit. - // Note: when enabling roll you probably also want to set `allow_upside_down` to `true` - // because upside down loses its meaning when you can roll freely. - key_roll_left: Some(KeyCode::A), - key_roll_right: Some(KeyCode::D), - roll_sensitivity: 0.5, ..default() }, )); diff --git a/examples/roll_axis.rs b/examples/roll_axis.rs new file mode 100644 index 0000000..2a79327 --- /dev/null +++ b/examples/roll_axis.rs @@ -0,0 +1,81 @@ +//! Demonstrates how to 'roll' the camera, thus control the 3rd axis of rotation + +use bevy::prelude::*; +use bevy_panorbit_camera::{PanOrbitCamera, PanOrbitCameraPlugin}; +use std::f32::consts::TAU; + +fn main() { + App::new() + .add_plugins(DefaultPlugins) + .add_plugins(PanOrbitCameraPlugin) + .add_systems(Startup, setup) + .add_systems(Update, roll_controls) + .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 { + transform: Transform::from_translation(Vec3::new(0.0, 1.5, 5.0)), + ..default() + }, + PanOrbitCamera { + // Changing the up vector (which rolling does) changes what 'up' means, so you likely + // want to allow upside down when rolling. + allow_upside_down: true, + ..default() + }, + )); +} + +/// Use left/right arrow keys to roll the camera +fn roll_controls( + mut pan_orbit_q: Query<(&mut PanOrbitCamera, &Transform)>, + time: Res