1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153
//! This library provides a simple, lightweight way of having a "flycam" style camera for
//! debugging. It's confirgurable, letting you easily enable the system locally for a camera or
//! globally for all cameras with a component and resource.
//!
//! # Bevy compatibility
//!
//! | Bevy Version | bevy-debug-camera version |
//! |--------------|---------------------------|
//! | 0.9.1 | ^0.1.0 |
//!
//! # Examples
//!
//! You can look at the examples folder for
//! practical uses of this crate, but to get started you can simply do the following when setting
//! up your app:
//!
//! ```no_run
//! use bevy::prelude::*;
//! use bevy_debug_camera::{DebugCamera, DebugCameraPlugin};
//!
//! fn main() {
//! App::new()
//! .add_plugins(DefaultPlugins)
//! .add_plugin(DebugCameraPlugin::default())
//! .add_startup_system(setup)
//! .run();
//! }
//!
//! fn setup(mut commands: Commands) {
//! // ... other setup code
//! commands
//! .spawn(Camera3dBundle::default())
//! .insert(DebugCamera {
//! position: Vec3::new(-5., 1., 0.),
//! ..default()
//! });
//! }
//! ```
//!
//! # Bindings
//!
//! The default bindings are as follows:
//!
//! ## Mouse + Keyboard
//!
//! | Action | Binding |
//! |---------------|----------|
//! | Move forward | `W` |
//! | Move backward | `S` |
//! | Move left | `A` |
//! | Move right | `D` |
//! | Move up | `Lshift` |
//! | Move down | `Space` |
//! | Yaw | Mouse X |
//! | pitch | Mouse Y |
//! | Roll left | `Q` |
//! | Roll right | `E` |
//!
//! ## Controller
//!
//! | Action | Binding |
//! |-----------------|------------|
//! | Move fwd/bwd | Lstick Y |
//! | Move left/right | Lstick X |
//! | Move up | `RTrigger` |
//! | Move down | `LTrigger` |
//! | Yaw | Rstick X |
//! | pitch | Lstick Y |
//! | Roll left | `LBumper` |
//! | Roll right | `RBumper` |
//!
//! # Configuring Plugin
//!
//! The plugin comes with some configuration options you can set on startup that use to customise
//! behaviour of the cameras in use. You can configure:
//!
//! * Keyboard bindings
//! * Gamepad bindings
//! * Accepted input
//!
//! All these customisation are exposed as resources, which are constantly read and can be modified
//! during runtime as well An example using all configuration options can be seen below and in the
//! `configuration` example:
//!
//! ```no_run
//! use bevy::prelude::*;
//! use bevy_debug_camera::{
//! DebugCamera, DebugCameraPlugin, GamepadBindings, KeyboardBindings, DebugCameraActive,
//! };
//!
//! fn main() {
//! App::new()
//! .add_plugins(DefaultPlugins)
//! // Each field in `DebugCameraPlugin` can be set directly or picked up from
//! // default.
//! .add_plugin(DebugCameraPlugin {
//! gamepad_bindings: GamepadBindings {
//! // Overrides only the roll buttons
//! roll_left: GamepadButtonType::West,
//! roll_right: GamepadButtonType::East,
//! ..default()
//! },
//! keyboard_bindings: KeyboardBindings {
//! // Override WASD with arrows
//! fwd: KeyCode::Up,
//! bwd: KeyCode::Down,
//! left: KeyCode::Left,
//! right: KeyCode::Right,
//! ..default()
//! },
//! debug_camera_active: DebugCameraActive {
//! // Disable keyboard + mouse only
//! keymouse: false,
//! ..default()
//! },
//! })
//! .add_startup_system(setup)
//! .run();
//! }
//!
//! fn setup() {
//! // Setup logic here...
//! }
//! ```
mod components;
mod resources;
mod systems;
pub use components::DebugCamera;
pub use resources::{ActiveGamepad, DebugCameraActive, GamepadBindings, KeyboardBindings};
use bevy::prelude::*;
#[derive(Debug, Default)]
pub struct DebugCameraPlugin {
pub gamepad_bindings: resources::GamepadBindings,
pub keyboard_bindings: resources::KeyboardBindings,
pub debug_camera_active: resources::DebugCameraActive,
}
impl Plugin for DebugCameraPlugin {
fn build(&self, app: &mut App) {
app.insert_resource(resources::ActiveGamepad::default())
.insert_resource(self.debug_camera_active.clone())
.insert_resource(self.gamepad_bindings.clone())
.insert_resource(self.keyboard_bindings.clone())
.add_system(systems::camera_movement_system)
.add_system(systems::camera_update_system)
.add_system(systems::cursor_grab_system)
.add_system(systems::gamepad_connections);
}
}