├── .github └── workflows │ └── main.yml ├── .gitignore ├── CHANGELOG.md ├── Cargo.toml ├── LICENSE-APACHE ├── LICENSE-MIT ├── README.md ├── examples ├── advanced.rs ├── animate.rs ├── basic.rs ├── egui.rs ├── egui_multiple_windows.rs ├── focus_bounds.rs ├── follow_target.rs ├── keyboard_controls.rs ├── multiple_viewports.rs ├── multiple_windows.rs ├── orthographic.rs ├── render_to_texture.rs ├── swapped_axis.rs └── trackpad.rs └── src ├── egui.rs ├── input.rs ├── lib.rs ├── touch.rs ├── traits.rs └── util.rs /.github/workflows/main.yml: -------------------------------------------------------------------------------- 1 | on: 2 | push: 3 | branches: 4 | - master 5 | pull_request: 6 | branches: 7 | - master 8 | 9 | name: Continuous integration 10 | 11 | jobs: 12 | build: 13 | name: Build 14 | runs-on: ubuntu-latest 15 | steps: 16 | - uses: actions/checkout@v4 17 | - uses: dtolnay/rust-toolchain@stable 18 | - run: cargo build 19 | 20 | test: 21 | name: Test 22 | runs-on: ubuntu-latest 23 | steps: 24 | - uses: actions/checkout@v4 25 | - uses: dtolnay/rust-toolchain@stable 26 | - name: Install alsa and udev 27 | run: sudo apt-get update; sudo apt-get install --no-install-recommends libasound2-dev libudev-dev 28 | if: runner.os == 'linux' 29 | - run: cargo test 30 | 31 | build-examples: 32 | name: Build Examples 33 | runs-on: ubuntu-latest 34 | steps: 35 | - uses: actions/checkout@v4 36 | - uses: dtolnay/rust-toolchain@stable 37 | - name: Install alsa and udev 38 | run: sudo apt-get update; sudo apt-get install --no-install-recommends libasound2-dev libudev-dev 39 | if: runner.os == 'linux' 40 | - run: cargo build --examples 41 | 42 | fmt: 43 | name: Rustfmt 44 | runs-on: ubuntu-latest 45 | steps: 46 | - uses: actions/checkout@v4 47 | - uses: dtolnay/rust-toolchain@stable 48 | - run: rustup component add rustfmt 49 | - run: cargo fmt --all -- --check 50 | 51 | clippy: 52 | name: Clippy 53 | runs-on: ubuntu-latest 54 | steps: 55 | - uses: actions/checkout@v4 56 | - uses: dtolnay/rust-toolchain@stable 57 | - run: rustup component add clippy 58 | - run: cargo clippy -- -D warnings 59 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | /Cargo.lock 3 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ## 0.26 2 | 3 | - Update to Bevy 0.16 4 | 5 | ## 0.25 6 | 7 | - Adds better trackpad support, with Blender-style controls (thanks @natepiano) 8 | 9 | ## 0.24 10 | 11 | - Add ability to change the base axes, e.g. to make Z up instead of Y up 12 | 13 | ## 0.23 14 | 15 | - Update `bevy_egui` to 0.33 16 | 17 | ## 0.22.2 18 | 19 | - Fix initial calculation of yaw from the camera's transform (translation) 20 | 21 | ## 0.22.1 22 | 23 | - Add ability to limit the cameras `focus` to a cube or sphere shape (thanks @bytemunch) 24 | 25 | ## 0.22 26 | 27 | - Update `bevy_egui` to 0.32 28 | 29 | ## 0.21.2 30 | 31 | - Derive `Reflect` on `PanOrbitCamera` 32 | 33 | ## 0.21.1 34 | 35 | - Add `Camera3d` as a required component (new feature of Bevy 0.15) of `PanOrbitCamera`, so it doesn't need to be added 36 | manually 37 | 38 | ## 0.21 39 | 40 | - Update to Bevy 0.15 41 | 42 | ## 0.20.1 43 | 44 | - Update docs, explaining that setting sensitivity values to 0 will disable the respective control 45 | 46 | ## 0.20 47 | 48 | - Change `zoom_lower_limit` from `Option` to `f32`, defaulting to `0.05`, and remove the hard coded lower zoom 49 | limit of `0.05`. 50 | This allows the lower limit to be lowered below 0.05, in case there is a need to work at very small scales. 51 | 52 | ## 0.19.5 53 | 54 | - Update `bevy_egui` to 0.30 in order to resolve an issue with `bevy-inspector-egui` 55 | 0.27 ([#85](https://github.com/Plonq/bevy_panorbit_camera/pull/85)) 56 | 57 | ## 0.19.4 58 | 59 | - Re-fix bug that was fixed in 0.19.1 (see below for explanation). 60 | 61 | ## 0.19.3 62 | 63 | - Update `bevy_egui` dependency to 0.29 64 | 65 | ## 0.19.2 66 | 67 | - Fix bug with how egui feature deals with egui side panels and immovable windows. It should now act more 68 | naturally - if you start dragging in the viewport, dragging over egui will continue to control the camera. 69 | If you start the drag in any egui area, the camera won't be affected, even if the cursor leaves the egui area. 70 | Thanks @thmxv! 71 | 72 | ## 0.19.1 73 | 74 | - Fix panic if egui context for window doesn't exist. For example if a new window is created after startup. 75 | 76 | ## 0.19 77 | 78 | - Update to Bevy 0.14 79 | 80 | ## 0.18 and older 81 | 82 | Check [GitHub releases](https://github.com/Plonq/bevy_panorbit_camera/releases) for details 83 | -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "bevy_panorbit_camera" 3 | version = "0.26.0" 4 | authors = ["Plonq"] 5 | edition = "2021" 6 | description = "A basic pan and orbit camera in Bevy" 7 | keywords = ["gamedev", "bevy", "orbit", "camera"] 8 | categories = ["game-development"] 9 | license = "MIT OR Apache-2.0" 10 | repository = "https://github.com/Plonq/bevy_panorbit_camera" 11 | homepage = "https://github.com/Plonq/bevy_panorbit_camera" 12 | readme = "README.md" 13 | 14 | [features] 15 | bevy_egui = ["dep:bevy_egui"] 16 | 17 | [dependencies] 18 | bevy = { version = "0.16", default-features = false, features = [ 19 | "bevy_core_pipeline", 20 | "bevy_render", 21 | "bevy_window", 22 | ] } 23 | bevy_egui = { version = "0.34", optional = true, default-features = false } 24 | 25 | [dev-dependencies] 26 | bevy = { version = "0.16" } 27 | float-cmp = "0.10.0" 28 | bevy_egui = { version = "0.34", default-features = false, features = [ 29 | "render", 30 | "default_fonts", 31 | ] } 32 | 33 | [[example]] 34 | name = "egui" 35 | required-features = ["bevy_egui"] 36 | 37 | [[example]] 38 | name = "egui_multiple_windows" 39 | required-features = ["bevy_egui"] 40 | -------------------------------------------------------------------------------- /LICENSE-APACHE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | -------------------------------------------------------------------------------- /LICENSE-MIT: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in all 11 | copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | SOFTWARE. 20 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![Crates.io](https://img.shields.io/crates/v/bevy_panorbit_camera)](https://crates.io/crates/bevy_panorbit_camera) 2 | [![docs.rs](https://docs.rs/bevy_panorbit_camera/badge.svg)](https://docs.rs/bevy_panorbit_camera) 3 | [![Bevy tracking](https://img.shields.io/badge/Bevy%20tracking-released%20version-lightblue)](https://github.com/bevyengine/bevy/blob/main/docs/plugins_guidelines.md#main-branch-tracking) 4 | 5 |
6 |

Bevy Pan/Orbit Camera

7 |
8 | 9 | ![A screen recording showing camera movement](https://user-images.githubusercontent.com/7709415/230715348-eb19d9a8-4826-4a73-a039-02cacdcb3dc9.gif "Demo of bevy_panorbit_camera") 10 | 11 | ## Summary 12 | 13 | Bevy Pan/Orbit Camera provides orbit camera controls for Bevy Engine, designed with simplicity and flexibility in mind. 14 | Use it to quickly prototype, experiment, for model viewers, and more! 15 | 16 | ## Features: 17 | 18 | - Smoothed orbiting, panning, and zooming 19 | - Works with orthographic camera projection in addition to perspective 20 | - Customisable controls, sensitivity, and more 21 | - Touch support 22 | - Works with multiple viewports and/or windows 23 | - Easy to control manually, e.g. for keyboard control or animation 24 | - Can control cameras that render to a texture 25 | 26 | ## Controls 27 | 28 | Default mouse controls: 29 | 30 | - Left Mouse - Orbit 31 | - Right Mouse - Pan 32 | - Scroll Wheel - Zoom 33 | 34 | Default touch controls: 35 | 36 | - One finger - Orbit 37 | - Two fingers - Pan 38 | - Pinch - Zoom 39 | 40 | ## Quick Start 41 | 42 | Add the plugin: 43 | 44 | ```rust ignore 45 | .add_plugins(PanOrbitCameraPlugin) 46 | ``` 47 | 48 | Add `PanOrbitCamera` (this will automatically add a `Camera3d` but you can add it manually if necessary): 49 | 50 | ```rust ignore 51 | commands.spawn(( 52 | Transform::from_translation(Vec3::new(0.0, 1.5, 5.0)), 53 | PanOrbitCamera::default(), 54 | )); 55 | ``` 56 | 57 | This will set up a camera with good defaults. 58 | 59 | Check out the [advanced example](https://github.com/Plonq/bevy_panorbit_camera/tree/master/examples/advanced.rs) to see 60 | all the possible configuration options. 61 | 62 | ## Cargo Features 63 | 64 | - `bevy_egui` (optional): Makes `PanOrbitCamera` ignore any input that `egui` uses, thus preventing moving the camera 65 | when interacting with egui windows 66 | 67 | ## Version Compatibility 68 | 69 | | bevy | bevy_panorbit_camera | 70 | |------|----------------------| 71 | | 0.16 | 0.26 | 72 | | 0.15 | 0.21-0.25 | 73 | | 0.14 | 0.19-0.20 | 74 | | 0.13 | 0.14-0.18 | 75 | | 0.12 | 0.9-0.13 | 76 | | 0.11 | 0.6-0.8 | 77 | | 0.10 | 0.1-0.5 | 78 | 79 | ## Credits 80 | 81 | - [Bevy Cheat Book](https://bevy-cheatbook.github.io): For providing an example that I started from 82 | - [babylon.js](https://www.babylonjs.com): I referenced their arc rotate camera for some of this 83 | - [bevy_pancam](https://github.com/johanhelsing/bevy_pancam): For the egui feature idea 84 | 85 | ## License 86 | 87 | All code in this repository is dual-licensed under either: 88 | 89 | * MIT License ([LICENSE-MIT](LICENSE-MIT) or [http://opensource.org/licenses/MIT](http://opensource.org/licenses/MIT)) 90 | * Apache License, Version 2.0 ([LICENSE-APACHE](LICENSE-APACHE) 91 | or [http://www.apache.org/licenses/LICENSE-2.0](http://www.apache.org/licenses/LICENSE-2.0)) 92 | 93 | at your option. 94 | This means you can select the license you prefer! 95 | This dual-licensing approach is the de-facto standard in the Rust ecosystem and there 96 | are [very good reasons](https://github.com/bevyengine/bevy/issues/2373) to include both. 97 | -------------------------------------------------------------------------------- /examples/advanced.rs: -------------------------------------------------------------------------------- 1 | //! Demonstrates all common configuration options, 2 | //! and how to modify them at runtime 3 | //! 4 | //! Controls: 5 | //! Orbit: Middle click 6 | //! Pan: Shift + Middle click 7 | //! Zoom: Mousewheel 8 | 9 | use bevy::prelude::*; 10 | use bevy_panorbit_camera::{PanOrbitCamera, PanOrbitCameraPlugin, TouchControls}; 11 | use std::f32::consts::TAU; 12 | 13 | fn main() { 14 | App::new() 15 | .add_plugins(DefaultPlugins) 16 | .add_plugins(PanOrbitCameraPlugin) 17 | .add_systems(Startup, setup) 18 | .add_systems(Update, toggle_camera_controls_system) 19 | .run(); 20 | } 21 | 22 | fn setup( 23 | mut commands: Commands, 24 | mut meshes: ResMut>, 25 | mut materials: ResMut>, 26 | ) { 27 | // Ground 28 | commands.spawn(( 29 | Mesh3d(meshes.add(Plane3d::default().mesh().size(5.0, 5.0))), 30 | MeshMaterial3d(materials.add(Color::srgb(0.3, 0.5, 0.3))), 31 | )); 32 | // Cube 33 | commands.spawn(( 34 | Mesh3d(meshes.add(Cuboid::new(1.0, 1.0, 1.0))), 35 | MeshMaterial3d(materials.add(Color::srgb(0.8, 0.7, 0.6))), 36 | Transform::from_xyz(0.0, 0.5, 0.0), 37 | )); 38 | // Light 39 | commands.spawn(( 40 | PointLight { 41 | shadows_enabled: true, 42 | ..default() 43 | }, 44 | Transform::from_xyz(4.0, 8.0, 4.0), 45 | )); 46 | // Camera 47 | commands.spawn(( 48 | // Note we're setting the initial position below with yaw, pitch, and radius, hence 49 | // we don't set transform on the camera. 50 | PanOrbitCamera { 51 | // Set focal point (what the camera should look at) 52 | focus: Vec3::new(0.0, 1.0, 0.0), 53 | // Set the starting position, relative to focus (overrides camera's transform). 54 | yaw: Some(TAU / 8.0), 55 | pitch: Some(TAU / 8.0), 56 | radius: Some(5.0), 57 | // Set limits on rotation and zoom 58 | yaw_upper_limit: Some(TAU / 4.0), 59 | yaw_lower_limit: Some(-TAU / 4.0), 60 | pitch_upper_limit: Some(TAU / 3.0), 61 | pitch_lower_limit: Some(-TAU / 3.0), 62 | zoom_upper_limit: Some(5.0), 63 | zoom_lower_limit: 1.0, 64 | // Adjust sensitivity of controls 65 | orbit_sensitivity: 1.5, 66 | pan_sensitivity: 0.5, 67 | zoom_sensitivity: 0.5, 68 | // Allow the camera to go upside down 69 | allow_upside_down: true, 70 | // Change the controls (these match Blender) 71 | button_orbit: MouseButton::Middle, 72 | button_pan: MouseButton::Middle, 73 | modifier_pan: Some(KeyCode::ShiftLeft), 74 | // Reverse the zoom direction 75 | reversed_zoom: true, 76 | // Use alternate touch controls 77 | touch_controls: TouchControls::TwoFingerOrbit, 78 | ..default() 79 | }, 80 | )); 81 | } 82 | 83 | // This is how you can change config at runtime. 84 | // Press 'T' to toggle the camera controls. 85 | fn toggle_camera_controls_system( 86 | key_input: Res>, 87 | mut pan_orbit_query: Query<&mut PanOrbitCamera>, 88 | ) { 89 | if key_input.just_pressed(KeyCode::KeyT) { 90 | for mut pan_orbit in pan_orbit_query.iter_mut() { 91 | pan_orbit.enabled = !pan_orbit.enabled; 92 | } 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /examples/animate.rs: -------------------------------------------------------------------------------- 1 | //! Demonstrates how you can animate the movement of the camera 2 | 3 | use bevy::prelude::*; 4 | use bevy_panorbit_camera::{PanOrbitCamera, PanOrbitCameraPlugin}; 5 | use std::f32::consts::TAU; 6 | 7 | fn main() { 8 | App::new() 9 | .add_plugins(DefaultPlugins) 10 | .add_plugins(PanOrbitCameraPlugin) 11 | .add_systems(Startup, setup) 12 | .add_systems(Update, animate) 13 | .run(); 14 | } 15 | 16 | fn setup( 17 | mut commands: Commands, 18 | mut meshes: ResMut>, 19 | mut materials: ResMut>, 20 | ) { 21 | // Ground 22 | commands.spawn(( 23 | Mesh3d(meshes.add(Plane3d::default().mesh().size(5.0, 5.0))), 24 | MeshMaterial3d(materials.add(Color::srgb(0.3, 0.5, 0.3))), 25 | )); 26 | // Cube 27 | commands.spawn(( 28 | Mesh3d(meshes.add(Cuboid::new(1.0, 1.0, 1.0))), 29 | MeshMaterial3d(materials.add(Color::srgb(0.8, 0.7, 0.6))), 30 | Transform::from_xyz(0.0, 0.5, 0.0), 31 | )); 32 | // Light 33 | commands.spawn(( 34 | PointLight { 35 | shadows_enabled: true, 36 | ..default() 37 | }, 38 | Transform::from_xyz(4.0, 8.0, 4.0), 39 | )); 40 | // Camera 41 | commands.spawn(( 42 | Transform::from_translation(Vec3::new(0.0, 1.5, 5.0)), 43 | PanOrbitCamera { 44 | // Disable smoothing, since the animation takes care of that 45 | orbit_smoothness: 0.0, 46 | // Probably want to disable the controls 47 | enabled: false, 48 | ..default() 49 | }, 50 | )); 51 | } 52 | 53 | // Animate the camera's position 54 | fn animate(time: Res