From 26dc2ad3b8d01a2c7dbd327a7256aba1a4f536e7 Mon Sep 17 00:00:00 2001 From: Mikkel Rasmussen Date: Sun, 16 Jul 2023 13:30:15 +0200 Subject: [PATCH 01/19] Fixed links in README.md [skip ci] --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index c0ca594..7fe8778 100644 --- a/README.md +++ b/README.md @@ -11,8 +11,8 @@
-link to crates.io -link to docs.rs +link to crates.io +link to docs.rs link to license downloads/link to crates.io stars/github repo From 0eb6ddfa7b8a34d81dca310c6642308785a1ca7a Mon Sep 17 00:00:00 2001 From: Mikkel Rasmussen Date: Sun, 16 Jul 2023 13:31:03 +0200 Subject: [PATCH 02/19] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 7fe8778..2fe5b6b 100644 --- a/README.md +++ b/README.md @@ -11,8 +11,8 @@
-link to crates.io -link to docs.rs +link to crates.io +link to docs.rs link to license downloads/link to crates.io stars/github repo From 9a57a3dc5957743bcec9d9b1decddc90f9d5f973 Mon Sep 17 00:00:00 2001 From: BeastLe9enD Date: Thu, 23 Nov 2023 20:59:18 +0100 Subject: [PATCH 03/19] Update to bevy 0.12 --- Cargo.toml | 14 ++++++-------- examples/fpv.rs | 2 +- examples/orbit.rs | 4 ++-- examples/split.rs | 2 +- 4 files changed, 10 insertions(+), 12 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 8d72fbc..58d0ff3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "bevy_dolly" -version = "0.0.1" +version = "0.0.2" authors = ["Black Phlox "] license = "MIT OR Apache-2.0" edition = "2021" @@ -15,8 +15,6 @@ exclude = [ ".github/*", ] -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - [profile.dev] opt-level = 3 @@ -30,22 +28,22 @@ helpers = ["dep:leafwing-input-manager"] [dependencies] dolly = { path = "dolly", default-features = false } -leafwing-input-manager = { version = "0.10", optional = true } +leafwing-input-manager = { version = "0.11.1", optional = true } [dependencies.bevy] -version = "0.11.0" +version = "0.12.0" features = ["bevy_render", "bevy_asset", "bevy_pbr"] default-features = false [dev-dependencies] -leafwing-input-manager = "0.10" +leafwing-input-manager = "0.11.1" [dev-dependencies.bevy] -version = "0.11.0" +version = "0.12.0" features = ["bevy_core_pipeline", "bevy_asset", "bevy_scene", "bevy_pbr", "bevy_winit", "bevy_gltf", "bevy_sprite", "png", "ktx2", "zstd", "tonemapping_luts"] default-features = false [target.'cfg(target_os = "linux")'.dev-dependencies.bevy] -version = "0.11.0" +version = "0.12.0" features = ["x11", "wayland"] default-features = false diff --git a/examples/fpv.rs b/examples/fpv.rs index d25a452..0d3bcb8 100644 --- a/examples/fpv.rs +++ b/examples/fpv.rs @@ -140,7 +140,7 @@ fn update_camera( }; let mut delta = Vec2::ZERO; - for event in mouse_motion_events.iter() { + for event in mouse_motion_events.read() { delta += event.delta; } delta.x *= sensitivity.x; diff --git a/examples/orbit.rs b/examples/orbit.rs index 251df38..4ee78b1 100644 --- a/examples/orbit.rs +++ b/examples/orbit.rs @@ -197,7 +197,7 @@ fn handle_mouse_scroll( zoom: Res>, mut rig_q: Query<&mut Rig>, ) { - for mouse_wheel_event in mouse_wheel_events.iter() { + for mouse_wheel_event in mouse_wheel_events.read() { for mut projection in &mut q_main.iter_mut() { match &mut projection.as_mut() { Projection::Perspective(pers) => { @@ -235,7 +235,7 @@ fn update_camera( let sensitivity = Vec2::splat(2.0); let mut delta = Vec2::ZERO; - for event in mouse_motion_events.iter() { + for event in mouse_motion_events.read() { delta += event.delta; } diff --git a/examples/split.rs b/examples/split.rs index d2702c5..e773bb8 100644 --- a/examples/split.rs +++ b/examples/split.rs @@ -124,7 +124,7 @@ fn set_camera_viewports( mut left_camera: Query<&mut Camera, (With, Without)>, mut right_camera: Query<&mut Camera, With>, ) { - for resize_event in resize_events.iter() { + for resize_event in resize_events.read() { if let Ok((entity, window)) = windows.get_single() { if resize_event.window == entity { let mut left_camera = left_camera.single_mut(); From b2144239aa2fbda5be09fb25b631fd7420c61d6d Mon Sep 17 00:00:00 2001 From: Mikkel Rasmussen Date: Fri, 24 Nov 2023 01:24:57 +0100 Subject: [PATCH 04/19] Updated submodule to branch dolly bevy_0.12 --- dolly | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dolly b/dolly index c7d8118..3983dee 160000 --- a/dolly +++ b/dolly @@ -1 +1 @@ -Subproject commit c7d81183a0284083791f939d9056b0ff0954009c +Subproject commit 3983deee4105f6373cbf7c5630e68d171f5d7164 From f0f08d4ace728d6f21a7a470c02d6e50e02905e4 Mon Sep 17 00:00:00 2001 From: Mikkel Rasmussen Date: Fri, 24 Nov 2023 02:07:36 +0100 Subject: [PATCH 05/19] Updated submodule to branch dolly bevy_0.12 --- dolly | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dolly b/dolly index 3983dee..2ceea75 160000 --- a/dolly +++ b/dolly @@ -1 +1 @@ -Subproject commit 3983deee4105f6373cbf7c5630e68d171f5d7164 +Subproject commit 2ceea759e20ddfeb5f7abd5f22ecebb9dde77038 From dcd1f44df1f853244783e24d19cc338411c44308 Mon Sep 17 00:00:00 2001 From: Mikkel Rasmussen Date: Mon, 27 Nov 2023 00:23:49 +0100 Subject: [PATCH 06/19] Added gizmo and new example (wip) --- Cargo.toml | 2 +- examples/2d_fight_cam.rs | 133 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 134 insertions(+), 1 deletion(-) create mode 100644 examples/2d_fight_cam.rs diff --git a/Cargo.toml b/Cargo.toml index 58d0ff3..d024666 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -40,7 +40,7 @@ leafwing-input-manager = "0.11.1" [dev-dependencies.bevy] version = "0.12.0" -features = ["bevy_core_pipeline", "bevy_asset", "bevy_scene", "bevy_pbr", "bevy_winit", "bevy_gltf", "bevy_sprite", "png", "ktx2", "zstd", "tonemapping_luts"] +features = ["bevy_core_pipeline", "bevy_asset", "bevy_scene", "bevy_pbr", "bevy_winit", "bevy_gltf", "bevy_sprite", "png", "ktx2", "zstd", "tonemapping_luts", "bevy_gizmos"] default-features = false [target.'cfg(target_os = "linux")'.dev-dependencies.bevy] diff --git a/examples/2d_fight_cam.rs b/examples/2d_fight_cam.rs new file mode 100644 index 0000000..8254b14 --- /dev/null +++ b/examples/2d_fight_cam.rs @@ -0,0 +1,133 @@ +use bevy::prelude::*; +use bevy_dolly::prelude::*; + +fn main() { + App::new() + .add_plugins(DefaultPlugins) + .add_systems(Startup, setup) + .add_systems(PreUpdate, sprite_movement) + .add_systems(Update, update_camera) + .add_systems(Update, draw_gizmo) + .add_systems(Update, Dolly::::update_2d_active_continuous) + .run(); +} + +#[derive(Component)] +struct MainCamera; + +#[derive(Component)] +struct PlayerOne; + +#[derive(Component)] +struct PlayerTwo; + +#[derive(Component)] +enum Direction { + Left, + Right, +} + +fn setup(mut commands: Commands, asset_server: Res) { + commands + .spawn(SpriteBundle { + texture: asset_server.load("bevy_dolly.png"), + transform: Transform::from_xyz(100., 0., 0.1), + sprite: Sprite { + custom_size: Some(Vec2::new(128., 128.)), + ..Default::default() + }, + ..Default::default() + }) + .insert(Direction::Right) + .insert(PlayerOne); + + commands + .spawn(SpriteBundle { + texture: asset_server.load("bevy_dolly.png"), + transform: Transform::from_xyz(100., 0., 0.1), + sprite: Sprite { + custom_size: Some(Vec2::new(128., 128.)), + flip_x: true, + ..Default::default() + }, + ..Default::default() + }) + .insert(PlayerTwo); + + commands.spawn(SpriteBundle { + texture: asset_server.load("room.png"), + transform: Transform::from_xyz(100., 200., 0.), + sprite: Sprite { + custom_size: Some(Vec2::new(2.6 * 800., 800.)), + ..Default::default() + }, + ..Default::default() + }); + + commands.spawn(SpriteBundle { + texture: asset_server.load("room_end.png"), + transform: Transform::from_xyz(1116., -104.5, 0.2), + sprite: Sprite { + ..Default::default() + }, + ..Default::default() + }); + + commands.spawn(SpriteBundle { + texture: asset_server.load("room_end.png"), + transform: Transform::from_xyz(-916., -104.5, 0.2), + sprite: Sprite { + flip_x: true, + ..Default::default() + }, + ..Default::default() + }); + + commands.spawn(( + MainCamera, + Rig::builder() + .with(Position::new(Vec3::new(0., 0., 0.))) + .with(Smooth::new_position(1.2)) + .build(), + Camera2dBundle::default(), + )); +} + +fn draw_gizmo(mut gizmos: Gizmos, q0: Query<&Transform, With>) { + for a in &q0 { + gizmos.rect_2d( + a.translation.truncate(), + 0., + Vec2::splat(300.), + Color::BLACK, + ); + } +} + +/// The sprite is animated by changing its translation depending on the time that has passed since +/// the last frame. +fn sprite_movement(time: Res

-`bevy_dolly` is a prototype plugin using [h3r2tic](https://github.com/h3r2tic)'s powerful crate: [dolly](https://github.com/h3r2tic/dolly), implemented for bevy. +# Improving `bevy_dolly` Documentation -⚠ **Feedback** - _Bevy_dolly's API is still being revised, so feedback on ergonomics and DX is highly appreciated_ ⚠ +## Overview -It is important to note that dolly is a way to control the movement of the camera and thus, not the camera component itself.
+`bevy_dolly` is a prototype plugin built for the [Bevy](https://github.com/bevyengine/bevy) game engine. It leverages the powerful `dolly` crate, developed by [h3r2tic](https://github.com/h3r2tic), to control camera movement within a Bevy application. -Dolly requires two steps to function: +> [!WARNING] +> Be aware that `bevy_dolly`'s API is still undergoing revisions. Feedback on its ergonomics and developer experience (DX) is highly appreciated. -1. Creating a `Rig` we are able to define drivers on which the dolly can enact, these drivers can both be constraints and functionality. -2. A marker component that is registered on both the Camera and the Rig. +## Dolly and Camera Movement -## What are drivers? +It's important to know that `dolly` is all about controlling how the camera moves and not changing the camera itself. This means you can use it for other things, like making a turret and its cannon move around. -Explain what drivers are +Dolly operates in two essential steps: -To read more about the different drivers. +1. **Creating a Rig**: Define a `Rig` with drivers that the dolly can utilize. These drivers, which can control both translation, rotation, constraints and custom behavior as abstractions. These rigs serve as tools to shape the camera's behavior and provide additional functionality. -```rs +2. **Marker Component**: Register a marker component on both the Camera and the Rig (rig component tag). This allows you to easily switch the behavior of a camera entity by changing the associated rig component tag. To understand the process better, refer to the [examples](#example-showcase). + +## Understanding Drivers + +Drivers are mechanisms that influence the behavior of the camera. They can represent constraints or provide additional functionality. To explore the available drivers, refer to the [examples](example-showcase). + +In your `Cargo.toml`: + +```toml +[dependencies] +# Your bevy dependency here ... +# bevy = "0.12" +bevy_dolly = { version = "0.0.2" } +``` + +In your Bevy App: + +```rust +// The component tag used to parent to a Dolly Rig #[derive(Component)] struct MainCamera; @@ -54,76 +72,80 @@ fn main() { } ``` -```rs +In the setup system: + +```rust // In your setup system fn setup( mut commands: Commands, ) { commands.spawn(( - MainCamera, // The rig tag - Rig::builder() + MainCamera, // The rig component tag + Rig::builder() // The rig itself .with(Position::new(Vec3::ZERO)) .with(YawPitch::new().yaw_degrees(45.0).pitch_degrees(-30.0)) .with(Smooth::new_position(0.3)) .with(Smooth::new_rotation(0.3)) .with(Arm::new(Vec3::Z * 4.0)) .build(), - Camera3dBundle::default(), + Camera3dBundle::default(), // The camera which is related via the rig tag )); } ``` -Link to [examples readme](/examples/README.md) +## Helper Plugins -## Helpers - -This plugin currently also provides some helper plugins, which. -They are enabled by default but are not needed and can be removed when setting up bevy_dolly's dependency: +`bevy_dolly` provides some helper plugins by default, which can be removed if not needed when setting up `bevy_dolly` as a dependency: ```toml [dependencies] -bevy_dolly = { version = "0.0.1", default-features = false } +bevy_dolly = { version = "0.0.2", default-features = false } ``` -Note this will also remove the bevy_dolly's extended drivers and add `features = ["drivers"],` to include the drivers back. +To include the drivers back, add `features = ["drivers"],` to the dependency. -## Examples +## Example Showcase -To see how works in Bevy in practice, please look at this repository's [examples](/examples/). +Explore practical examples in the [examples repository](/examples/README.md). -### How to run +### Running Examples -`cargo run --release --example orbit` +If you've cloned the project and want to test, execute the following command to run the `orbit` example: -## Support +```bash +cargo run --release --example orbit +``` -[![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) +## Compatibility and Support |bevy|bevy_dolly| |---|---| -|0.11| 0.0.1 | +|0.12|0.0.2| +|0.11|0.0.1| ## Alternatives -There is a bunch of other bevy camera controllers that are worth checking out, especially if you are just starting out learning bevy: +Explore other Bevy camera controllers that might suit your needs: -- [bevy_fps_controller](https://github.com/qhdwight/bevy_fps_controller) - A Fps controller with crouching, sprinting, flymode and more -- [smooth-bevy-cameras](https://github.com/bonsairobo/smooth-bevy-cameras) - 3 Smooth Camera controllers: Fps, Orbit or Unreal -- [bevy_spectator](https://github.com/JonahPlusPlus/bevy_spectator) - A spectator camera controller -- [bevy_flycam](https://github.com/sburris0/bevy_flycam) - A simple fly camera -- [bevy_fly_camera](https://github.com/mcpar-land/bevy_fly_camera) - A advanced fly camera -- [bevy_pancam](https://github.com/johanhelsing/bevy_pancam) - 2D Click and Drag - Style camera movement -- [bevy_config_cam](https://github.com/BlackPhlox/bevy_config_cam) - Plugin that enables to use collection of different camera controllers at runtime, uses bevy_dolly as the backend +- [bevy_fps_controller](https://github.com/qhdwight/bevy_fps_controller) +- [smooth-bevy-cameras](https://github.com/bonsairobo/smooth-bevy-cameras) +- [bevy_spectator](https://github.com/JonahPlusPlus/bevy_spectator) +- [bevy_flycam](https://github.com/sburris0/bevy_flycam) +- [bevy_fly_camera](https://github.com/mcpar-land/bevy_fly_camera) +- [bevy_pancam](https://github.com/johanhelsing/bevy_pancam) +- [bevy_config_cam](https://github.com/BlackPhlox/bevy_config_cam) ## Licensing -The project is under dual license MIT and Apache 2.0, so joink to your hearts content, just remember the license agreements. +The project is under a dual license: MIT and Apache 2.0. Feel free to contribute within the bounds of these licenses. ## Contributing -Yes this project is still very much WIP, so PRs are very welcome. -The `dolly` dependency used is a slightly patched submodule, so to build the crate locally you must first run the following: +Yes this project is still a WIP, so PRs are very welcome. -```bash -git submodule update --init --recursive -``` +> [!NOTE] +> Note that the `dolly` dependency used is a slightly patched submodule to allow for native bevy transform types. To build the crate locally, run: +> +> ```bash +> git submodule update --init --recursive +> ``` From 026eb74fc3fa6d18bcac5573e5a6baf6e19dd3a5 Mon Sep 17 00:00:00 2001 From: Mikkel Rasmussen Date: Sun, 3 Dec 2023 11:47:42 +0100 Subject: [PATCH 10/19] Updated readme --- README.md | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index ef85d57..8bcebb1 100644 --- a/README.md +++ b/README.md @@ -82,17 +82,38 @@ fn setup( commands.spawn(( MainCamera, // The rig component tag Rig::builder() // The rig itself - .with(Position::new(Vec3::ZERO)) - .with(YawPitch::new().yaw_degrees(45.0).pitch_degrees(-30.0)) - .with(Smooth::new_position(0.3)) - .with(Smooth::new_rotation(0.3)) - .with(Arm::new(Vec3::Z * 4.0)) + .with(Position::new(Vec3::ZERO)) // Start position + // Adds a driver with method rotate_yaw_pitch + .with(YawPitch::new().yaw_degrees(45.0).pitch_degrees(-30.0)) + // Interpolation when the translation is updated, also known as smoothing + .with(Smooth::new_position(0.3)) + // Interpolation when the rotation is updated (updated via the YawPitch driver) + .with(Smooth::new_rotation(0.3)) + // Moves the camera point out in the Z direction and uses the position as the pivot + .with(Arm::new(Vec3::Z * 4.0)) .build(), Camera3dBundle::default(), // The camera which is related via the rig tag )); } ``` +And your runtime to update the rig: + +```rust +fn update_input( + mut commands: Commands, + keys: Res>, + mut rig_q: Query<&mut Rig>, +) { + let mut rig = rig_q.single_mut(); + if let Some(yaw_pitch) = rig.try_driver_mut::() { + if keys.just_pressed(KeyCode::Z) { + yaw_pitch.rotate_yaw_pitch(-90.0, 0.0); + } + } +} +``` + ## Helper Plugins `bevy_dolly` provides some helper plugins by default, which can be removed if not needed when setting up `bevy_dolly` as a dependency: From 6044d4843e8b48a94e6b3194f10ef5336ef8454e Mon Sep 17 00:00:00 2001 From: Mikkel Rasmussen Date: Sun, 3 Dec 2023 12:06:39 +0100 Subject: [PATCH 11/19] Added bevy_main ci check --- .github/workflows/bevy_main.yml | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 .github/workflows/bevy_main.yml diff --git a/.github/workflows/bevy_main.yml b/.github/workflows/bevy_main.yml new file mode 100644 index 0000000..2284eab --- /dev/null +++ b/.github/workflows/bevy_main.yml @@ -0,0 +1,25 @@ +name: check if code still compiles + +on: + schedule: + - cron: '0 8 * * 5' + +env: + CARGO_TERM_COLOR: always + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + + - name: Install Dependencies + run: sudo apt-get update && sudo apt-get install g++ pkg-config libx11-dev libasound2-dev libudev-dev + - uses: actions-rs/toolchain@v1 + with: + toolchain: stable + override: true + + - name: Check code + run: cargo update && cargo check --lib --examples From 7448699f645d48d4eefa8b8bde711bc3b509e9f3 Mon Sep 17 00:00:00 2001 From: Mikkel Rasmussen Date: Sun, 3 Dec 2023 12:07:39 +0100 Subject: [PATCH 12/19] Added comment --- .github/workflows/bevy_main.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/bevy_main.yml b/.github/workflows/bevy_main.yml index 2284eab..12b811b 100644 --- a/.github/workflows/bevy_main.yml +++ b/.github/workflows/bevy_main.yml @@ -1,3 +1,5 @@ +# From: +# https://bevy-cheatbook.github.io/setup/bevy-git.html#ci-setup name: check if code still compiles on: From 75ed08f6af1b0caf38b61f91a5137371eaf8d8df Mon Sep 17 00:00:00 2001 From: Mikkel Rasmussen Date: Sun, 3 Dec 2023 12:09:21 +0100 Subject: [PATCH 13/19] Removed header --- README.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/README.md b/README.md index 8bcebb1..284e45a 100644 --- a/README.md +++ b/README.md @@ -22,8 +22,6 @@

-# Improving `bevy_dolly` Documentation - ## Overview `bevy_dolly` is a prototype plugin built for the [Bevy](https://github.com/bevyengine/bevy) game engine. It leverages the powerful `dolly` crate, developed by [h3r2tic](https://github.com/h3r2tic), to control camera movement within a Bevy application. From ec07d2aea10d25544d73be54449583a2c587c65e Mon Sep 17 00:00:00 2001 From: Mikkel Rasmussen Date: Sun, 3 Dec 2023 12:19:13 +0100 Subject: [PATCH 14/19] Readded alternatives' comments --- README.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 284e45a..d86a7bd 100644 --- a/README.md +++ b/README.md @@ -146,13 +146,13 @@ cargo run --release --example orbit Explore other Bevy camera controllers that might suit your needs: -- [bevy_fps_controller](https://github.com/qhdwight/bevy_fps_controller) -- [smooth-bevy-cameras](https://github.com/bonsairobo/smooth-bevy-cameras) -- [bevy_spectator](https://github.com/JonahPlusPlus/bevy_spectator) -- [bevy_flycam](https://github.com/sburris0/bevy_flycam) -- [bevy_fly_camera](https://github.com/mcpar-land/bevy_fly_camera) -- [bevy_pancam](https://github.com/johanhelsing/bevy_pancam) -- [bevy_config_cam](https://github.com/BlackPhlox/bevy_config_cam) +- [bevy_fps_controller](https://github.com/qhdwight/bevy_fps_controller) - A Fps controller with crouching, sprinting, flymode and more +- [smooth-bevy-cameras](https://github.com/bonsairobo/smooth-bevy-cameras) - 3 Smooth Camera controllers: Fps, Orbit or Unreal +- [bevy_spectator](https://github.com/JonahPlusPlus/bevy_spectator) - A spectator camera controller +- [bevy_flycam](https://github.com/sburris0/bevy_flycam) - A simple fly camera +- [bevy_fly_camera](https://github.com/mcpar-land/bevy_fly_camera) - A advanced fly camera +- [bevy_pancam](https://github.com/johanhelsing/bevy_pancam) - 2D Click and Drag - Style camera movement +- [bevy_config_cam](https://github.com/BlackPhlox/bevy_config_cam) - Plugin that enables to use collection of different camera controllers at runtime, uses bevy_dolly as the backend ## Licensing From 889c396846edb4483c9cf31150a26091b6a1938a Mon Sep 17 00:00:00 2001 From: Mikkel Rasmussen Date: Sun, 3 Dec 2023 12:32:41 +0100 Subject: [PATCH 15/19] Update README.md --- README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index d86a7bd..d3aa7c8 100644 --- a/README.md +++ b/README.md @@ -64,7 +64,8 @@ fn main() { .add_plugins(DefaultPlugins) .add_startup_system(setup) //.. - .add_system(Dolly::::update_active) + .add_system(Update, Dolly::::update_active) + .add_system(Update, update_input) //.. .run(); } @@ -81,7 +82,7 @@ fn setup( MainCamera, // The rig component tag Rig::builder() // The rig itself .with(Position::new(Vec3::ZERO)) // Start position - // Adds a driver with method rotate_yaw_pitch + // Adds a driver with the method rotate_yaw_pitch .with(YawPitch::new().yaw_degrees(45.0).pitch_degrees(-30.0)) // Interpolation when the translation is updated, also known as smoothing .with(Smooth::new_position(0.3)) From 4a32cba4b3fbb865b4382024f8ec95ea1b6f35d3 Mon Sep 17 00:00:00 2001 From: Mikkel Rasmussen Date: Sun, 3 Dec 2023 12:33:39 +0100 Subject: [PATCH 16/19] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index d3aa7c8..32e0c4b 100644 --- a/README.md +++ b/README.md @@ -62,8 +62,8 @@ struct MainCamera; fn main() { App::new() .add_plugins(DefaultPlugins) - .add_startup_system(setup) //.. + .add_system(Startup, setup) .add_system(Update, Dolly::::update_active) .add_system(Update, update_input) //.. From c96c009b89a08fd2da2ec3b2b99f01fbe63f9def Mon Sep 17 00:00:00 2001 From: Mikkel Rasmussen Date: Sun, 3 Dec 2023 12:41:17 +0100 Subject: [PATCH 17/19] Fix main merge error --- src/dolly/driver.rs | 31 -------- src/dolly/drivers/arm.rs | 36 --------- src/dolly/drivers/lock_position.rs | 72 ------------------ src/dolly/drivers/look_at.rs | 83 -------------------- src/dolly/drivers/mod.rs | 11 --- src/dolly/drivers/position.rs | 41 ---------- src/dolly/drivers/rotation.rs | 35 --------- src/dolly/drivers/smooth.rs | 110 --------------------------- src/dolly/drivers/yaw_pitch.rs | 103 ------------------------- src/dolly/handedness.rs | 42 ----------- src/dolly/mod.rs | 6 -- src/dolly/prelude.rs | 1 - src/dolly/rig.rs | 117 ----------------------------- src/dolly/transform.rs | 52 ------------- src/dolly/util.rs | 70 ----------------- src/lib.rs | 2 +- 16 files changed, 1 insertion(+), 811 deletions(-) delete mode 100644 src/dolly/driver.rs delete mode 100644 src/dolly/drivers/arm.rs delete mode 100644 src/dolly/drivers/lock_position.rs delete mode 100644 src/dolly/drivers/look_at.rs delete mode 100644 src/dolly/drivers/mod.rs delete mode 100644 src/dolly/drivers/position.rs delete mode 100644 src/dolly/drivers/rotation.rs delete mode 100644 src/dolly/drivers/smooth.rs delete mode 100644 src/dolly/drivers/yaw_pitch.rs delete mode 100644 src/dolly/handedness.rs delete mode 100644 src/dolly/mod.rs delete mode 100644 src/dolly/prelude.rs delete mode 100644 src/dolly/rig.rs delete mode 100644 src/dolly/transform.rs delete mode 100644 src/dolly/util.rs diff --git a/src/dolly/driver.rs b/src/dolly/driver.rs deleted file mode 100644 index 8877e42..0000000 --- a/src/dolly/driver.rs +++ /dev/null @@ -1,31 +0,0 @@ -use bevy_transform::prelude::Transform; - -//use crate::{handedness::Handedness, rig::RigUpdateParams, transform::Transform}; -use crate::dolly::rig::RigUpdateParams; - -pub trait RigDriverTraits: RigDriver + Sync + Send + std::any::Any + std::fmt::Debug { - /// Returns `self` as `&dyn Any` - fn as_any(&self) -> &dyn std::any::Any; - - /// Returns `self` as `&mut dyn Any` - fn as_any_mut(&mut self) -> &mut dyn std::any::Any; -} - -pub trait RigDriver: std::any::Any + std::fmt::Debug { - /// Calculates the transform of this driver component based on the parent - /// provided in `params`. - fn update(&mut self, params: RigUpdateParams) -> Transform; -} - -impl RigDriverTraits for T -where - T: RigDriver + std::any::Any + Sync + Send + std::fmt::Debug, -{ - fn as_any(&self) -> &dyn std::any::Any { - self - } - - fn as_any_mut(&mut self) -> &mut dyn std::any::Any { - self - } -} diff --git a/src/dolly/drivers/arm.rs b/src/dolly/drivers/arm.rs deleted file mode 100644 index d30cccf..0000000 --- a/src/dolly/drivers/arm.rs +++ /dev/null @@ -1,36 +0,0 @@ -//use std::marker::PhantomData; - -//use glam::Vec3; -use bevy_math::Vec3; -use bevy_transform::prelude::Transform; - -use crate::dolly::{ - driver::RigDriver, - //handedness::Handedness, - rig::RigUpdateParams, - //transform::Transform, -}; - -/// Offsets the camera along a vector, in the coordinate space of the parent. -#[derive(Debug)] -pub struct Arm { - /// - pub offset: Vec3, -} - -impl Arm { - /// - pub fn new(offset: Vec3) -> Self { - Self { offset } - } -} - -impl RigDriver for Arm { - fn update(&mut self, params: RigUpdateParams) -> Transform { - Transform { - translation: params.parent.translation + params.parent.rotation * self.offset, - rotation: params.parent.rotation, - scale: Vec3::ONE, - } - } -} diff --git a/src/dolly/drivers/lock_position.rs b/src/dolly/drivers/lock_position.rs deleted file mode 100644 index 6ff9280..0000000 --- a/src/dolly/drivers/lock_position.rs +++ /dev/null @@ -1,72 +0,0 @@ -//use std::marker::PhantomData; - -use bevy_transform::prelude::Transform; - -use crate::dolly::{ - driver::RigDriver, - //handedness::Handedness, - rig::RigUpdateParams, - //transform::Transform, -}; - -/// Locks/constrains the position of the camera to one or more axes -#[derive(Debug)] -pub struct LockPosition { - x: Option, - y: Option, - z: Option, -} - -impl LockPosition { - pub fn new() -> Self { - Self { - x: None, - y: None, - z: None, - } - } - pub fn from(x: Option, y: Option, z: Option) -> Self { - Self { x, y, z } - } - pub fn x(&self, x: f32) -> Self { - Self { - x: Some(x), - y: self.y, - z: self.z, - } - } - pub fn y(&self, y: f32) -> Self { - Self { - x: self.x, - y: Some(y), - z: self.z, - } - } - pub fn z(&self, z: f32) -> Self { - Self { - x: self.x, - y: self.y, - z: Some(z), - } - } -} - -impl Default for LockPosition { - fn default() -> Self { - Self::new() - } -} - -impl RigDriver for LockPosition { - fn update(&mut self, params: RigUpdateParams) -> Transform { - let mut delta_pos = params.parent.translation; - delta_pos.x = self.x.unwrap_or(delta_pos.x); - delta_pos.y = self.y.unwrap_or(delta_pos.y); - delta_pos.z = self.z.unwrap_or(delta_pos.z); - Transform { - translation: delta_pos, - rotation: params.parent.rotation, - ..Default::default() - } - } -} diff --git a/src/dolly/drivers/look_at.rs b/src/dolly/drivers/look_at.rs deleted file mode 100644 index a1a2ce0..0000000 --- a/src/dolly/drivers/look_at.rs +++ /dev/null @@ -1,83 +0,0 @@ -//use std::marker::PhantomData; - -//use glam::Vec3; -use bevy_math::Vec3; -use bevy_transform::prelude::Transform; - -use crate::dolly::{ - driver::RigDriver, - //handedness::Handedness, - rig::RigUpdateParams, - //transform::Transform, - util::{ - //look_at, - ExpSmoothed, - ExpSmoothingParams, - }, -}; - -/// Rotates the camera to point at a world-space position. -/// -/// The target tracking can be additionally smoothed, and made to look ahead of it. -#[derive(Debug)] -pub struct LookAt { - /// Exponential smoothing factor - pub smoothness: f32, - - /// The world-space position to look at - pub target: Vec3, - - // The scale with which smoothing should be applied to the target position - output_offset_scale: f32, - - smoothed_target: ExpSmoothed, -} - -impl LookAt { - /// - pub fn new(target: Vec3) -> Self { - Self { - smoothness: 0.0, - output_offset_scale: 1.0, - target, - smoothed_target: Default::default(), - } - } - - /// Set the exponential smoothing factor for target position tracking. - pub fn tracking_smoothness(mut self, smoothness: f32) -> Self { - self.smoothness = smoothness; - self - } - - /// Reverse target position smoothing, causing the camera to look ahead of it. - /// This can then be chained with [`Smooth`], to create - /// a camera that smoothly follows an object, but doesn't lag far behind it. - /// - /// [`Smooth`]: struct.Smooth.html - pub fn tracking_predictive(mut self, predictive: bool) -> Self { - self.output_offset_scale = if predictive { -1.0 } else { 1.0 }; - self - } -} - -impl RigDriver for LookAt { - fn update(&mut self, params: RigUpdateParams) -> Transform { - let target = self.smoothed_target.exp_smooth_towards( - &self.target, - ExpSmoothingParams { - smoothness: self.smoothness, - output_offset_scale: self.output_offset_scale, - delta_time_seconds: params.delta_time_seconds, - }, - ); - - let rotation = params.parent.looking_at(target, Vec3::Y).rotation; - - Transform { - translation: params.parent.translation, - rotation, - ..Default::default() - } - } -} diff --git a/src/dolly/drivers/mod.rs b/src/dolly/drivers/mod.rs deleted file mode 100644 index 976ff46..0000000 --- a/src/dolly/drivers/mod.rs +++ /dev/null @@ -1,11 +0,0 @@ -mod arm; -mod lock_position; -mod look_at; -mod position; -mod rotation; -mod smooth; -mod yaw_pitch; - -pub use self::{ - arm::*, lock_position::*, look_at::*, position::*, rotation::*, smooth::*, yaw_pitch::*, -}; diff --git a/src/dolly/drivers/position.rs b/src/dolly/drivers/position.rs deleted file mode 100644 index eb73da6..0000000 --- a/src/dolly/drivers/position.rs +++ /dev/null @@ -1,41 +0,0 @@ -//use std::marker::PhantomData; - -//use glam::Vec3; -use bevy_math::Vec3; -use bevy_transform::prelude::Transform; - -use crate::dolly::{driver::RigDriver, rig::RigUpdateParams}; - -/* -use crate::{ - driver::RigDriver, handedness::Handedness, rig::RigUpdateParams, transform::Transform, -}; -*/ - -/// Directly sets the position of the camera -#[derive(Default, Debug)] -pub struct Position { - pub position: Vec3, -} - -impl Position { - /// - pub fn new(position: Vec3) -> Self { - Self { position } - } - - /// Add the specified vector to the position of this component - pub fn translate(&mut self, move_vec: Vec3) { - self.position += move_vec; - } -} - -impl RigDriver for Position { - fn update(&mut self, params: RigUpdateParams) -> Transform { - Transform { - translation: self.position, - rotation: params.parent.rotation, - scale: Vec3::ONE, - } - } -} diff --git a/src/dolly/drivers/rotation.rs b/src/dolly/drivers/rotation.rs deleted file mode 100644 index b00994c..0000000 --- a/src/dolly/drivers/rotation.rs +++ /dev/null @@ -1,35 +0,0 @@ -//use std::marker::PhantomData; - -//use glam::Quat; -use bevy_math::{Quat, Vec3}; -use bevy_transform::prelude::Transform; - -use crate::dolly::{driver::RigDriver, rig::RigUpdateParams}; - -/* -use crate::{ - driver::RigDriver, handedness::Handedness, rig::RigUpdateParams, transform::Transform, -}; -*/ - -/// Directly sets the rotation of the camera -#[derive(Default, Debug)] -pub struct Rotation { - pub rotation: Quat, -} - -impl Rotation { - pub fn new(rotation: Quat) -> Self { - Self { rotation } - } -} - -impl RigDriver for Rotation { - fn update(&mut self, params: RigUpdateParams) -> Transform { - Transform { - translation: params.parent.translation, - rotation: self.rotation, - scale: Vec3::ONE, - } - } -} diff --git a/src/dolly/drivers/smooth.rs b/src/dolly/drivers/smooth.rs deleted file mode 100644 index e786034..0000000 --- a/src/dolly/drivers/smooth.rs +++ /dev/null @@ -1,110 +0,0 @@ -//use std::marker::PhantomData; - -//use glam::{Quat, Vec3}; -use bevy_math::{Quat, Vec3}; -use bevy_transform::prelude::Transform; - -use crate::dolly::{ - driver::RigDriver, - //handedness::Handedness, - rig::RigUpdateParams, - //transform::Transform, - util::{ExpSmoothed, ExpSmoothingParams}, -}; - -/// Smooths the parent transformation. -#[derive(Debug)] -pub struct Smooth { - /// Exponential smoothing factor for the position - pub position_smoothness: f32, - - /// Exponential smoothing factor for the rotation - pub rotation_smoothness: f32, - - // The scale with which smoothing should be applied - output_offset_scale: f32, - - smoothed_position: ExpSmoothed, - smoothed_rotation: ExpSmoothed, -} - -impl Default for Smooth { - fn default() -> Self { - Self { - position_smoothness: 1.0, - rotation_smoothness: 1.0, - output_offset_scale: 1.0, - smoothed_position: Default::default(), - smoothed_rotation: Default::default(), - } - } -} - -impl Smooth { - /// Only smooth position - pub fn new_position(position_smoothness: f32) -> Self { - Self { - position_smoothness, - rotation_smoothness: 0.0, - ..Default::default() - } - } - - /// Only smooth rotation - pub fn new_rotation(rotation_smoothness: f32) -> Self { - Self { - rotation_smoothness, - position_smoothness: 0.0, - ..Default::default() - } - } - - /// Smooth both position and rotation - pub fn new_position_rotation(position_smoothness: f32, rotation_smoothness: f32) -> Self { - Self { - position_smoothness, - rotation_smoothness, - ..Default::default() - } - } - - /// Reverse the smoothing, causing the camera to look ahead of the parent transform - /// - /// This can be useful on top of [`Position`], and before another `Smooth` - /// in the chain to create a soft yet responsive follower camera. - /// - /// [`Position`]: struct.Position.html - /// [`Smooth`]: struct.Smooth.html - pub fn predictive(mut self, predictive: bool) -> Self { - self.output_offset_scale = if predictive { -1.0 } else { 1.0 }; - self - } -} - -impl RigDriver for Smooth { - fn update(&mut self, params: RigUpdateParams) -> Transform { - let translation = self.smoothed_position.exp_smooth_towards( - ¶ms.parent.translation, - ExpSmoothingParams { - smoothness: self.position_smoothness, - output_offset_scale: self.output_offset_scale, - delta_time_seconds: params.delta_time_seconds, - }, - ); - - let rotation = self.smoothed_rotation.exp_smooth_towards( - ¶ms.parent.rotation, - ExpSmoothingParams { - smoothness: self.rotation_smoothness, - output_offset_scale: self.output_offset_scale, - delta_time_seconds: params.delta_time_seconds, - }, - ); - - Transform { - translation, - rotation, - scale: Vec3::ONE, - } - } -} diff --git a/src/dolly/drivers/yaw_pitch.rs b/src/dolly/drivers/yaw_pitch.rs deleted file mode 100644 index 03b451b..0000000 --- a/src/dolly/drivers/yaw_pitch.rs +++ /dev/null @@ -1,103 +0,0 @@ -//use std::marker::PhantomData; - -//use glam::{EulerRot, Quat}; - -use bevy_math::{ - EulerRot, - //Vec3 - Quat, -}; -use bevy_transform::prelude::Transform; - -use crate::dolly::{driver::RigDriver, rig::RigUpdateParams}; - -/* -use crate::{ - driver::RigDriver, handedness::Handedness, rig::RigUpdateParams, transform::Transform, -}; -*/ - -/// Calculate camera rotation based on yaw and pitch angles. -/// -/// The angles follow the [`right-hand rule`] for curve orientation, and assume -/// an `OpenGL`-style coordinate system, meaning that for a camera to rotate right, -/// a negative value of yaw should be provided, and for it to rotate up, -/// a positive value of pitch. -/// -/// [`right-hand rule`]: https://en.wikipedia.org/wiki/Right-hand_rule#Curve_orientation_and_normal_vectors -#[derive(Debug)] -pub struct YawPitch { - /// [0..720) - /// - /// Note: Quaternions can encode 720 degrees of rotation, causing a slerp from 350 to 0 degrees - /// to happen counter-intuitively in the negative direction; the positive direction would go through 720, - /// thus being farther. By encoding rotation here in the 0..720 range, we reduce the risk of this happening. - pub yaw_degrees: f32, - - /// [-90..90] - pub pitch_degrees: f32, -} - -impl Default for YawPitch { - fn default() -> Self { - Self::new() - } -} - -impl YawPitch { - /// Creates camera looking forward along Z axis (negative or positive depends on system handedness) - pub fn new() -> Self { - Self { - yaw_degrees: 0.0, - pitch_degrees: 0.0, - } - } - - /// Initialize the yaw and pitch angles from a quaternion. - /// Any roll rotation will be ignored. - pub fn rotation_quat(mut self, rotation: Quat) -> Self { - self.set_rotation_quat(rotation); - self - } - - /// Set the yaw angle in degrees. - pub fn yaw_degrees(mut self, yaw_degrees: f32) -> Self { - self.yaw_degrees = yaw_degrees; - self - } - - /// Set the pitch angle in degrees. - pub fn pitch_degrees(mut self, pitch_degrees: f32) -> Self { - self.pitch_degrees = pitch_degrees; - self - } - - /// Additively rotate by the specified angles. - pub fn rotate_yaw_pitch(&mut self, yaw_degrees: f32, pitch_degrees: f32) { - self.yaw_degrees = (self.yaw_degrees + yaw_degrees) % 720_f32; - self.pitch_degrees = (self.pitch_degrees + pitch_degrees).clamp(-90.0, 90.0); - } - - /// Set the yaw and pitch angles from a quaternion. - /// Any roll rotation will be ignored. - pub fn set_rotation_quat(&mut self, rotation: Quat) { - let (yaw, pitch, _) = rotation.to_euler(EulerRot::YXZ); - self.yaw_degrees = yaw.to_degrees(); - self.pitch_degrees = pitch.to_degrees(); - } -} - -impl RigDriver for YawPitch { - fn update(&mut self, params: RigUpdateParams) -> Transform { - Transform { - translation: params.parent.translation, - rotation: Quat::from_euler( - EulerRot::YXZ, - self.yaw_degrees.to_radians(), - self.pitch_degrees.to_radians(), - 0.0, - ), - scale: Default::default(), - } - } -} diff --git a/src/dolly/handedness.rs b/src/dolly/handedness.rs deleted file mode 100644 index ed0298d..0000000 --- a/src/dolly/handedness.rs +++ /dev/null @@ -1,42 +0,0 @@ -use std::fmt::Debug; - -use bevy_math::{vec3, Vec3}; -//use glam::Vec3; - -pub trait Handedness: Clone + Copy + Debug + 'static { - const FORWARD_Z_SIGN: f32; - const FORWARD: Vec3 = vec3(0.0, 0.0, Self::FORWARD_Z_SIGN); - - fn right_from_up_and_forward(up: Vec3, forward: Vec3) -> Vec3; - fn up_from_right_and_forward(right: Vec3, forward: Vec3) -> Vec3; -} - -#[derive(Clone, Copy, Debug)] -pub struct LeftHanded; - -impl Handedness for LeftHanded { - const FORWARD_Z_SIGN: f32 = 1.0; - - fn right_from_up_and_forward(up: Vec3, forward: Vec3) -> Vec3 { - up.cross(forward) - } - - fn up_from_right_and_forward(right: Vec3, forward: Vec3) -> Vec3 { - forward.cross(right) - } -} - -#[derive(Clone, Copy, Debug)] -pub struct RightHanded; - -impl Handedness for RightHanded { - const FORWARD_Z_SIGN: f32 = -1.0; - - fn right_from_up_and_forward(up: Vec3, forward: Vec3) -> Vec3 { - forward.cross(up) - } - - fn up_from_right_and_forward(right: Vec3, forward: Vec3) -> Vec3 { - right.cross(forward) - } -} diff --git a/src/dolly/mod.rs b/src/dolly/mod.rs deleted file mode 100644 index e8b37e3..0000000 --- a/src/dolly/mod.rs +++ /dev/null @@ -1,6 +0,0 @@ -pub mod driver; -pub mod drivers; -pub mod handedness; -pub mod prelude; -pub mod rig; -pub mod util; diff --git a/src/dolly/prelude.rs b/src/dolly/prelude.rs deleted file mode 100644 index c94f316..0000000 --- a/src/dolly/prelude.rs +++ /dev/null @@ -1 +0,0 @@ -pub use crate::dolly::{drivers::*, handedness::*, rig::*}; diff --git a/src/dolly/rig.rs b/src/dolly/rig.rs deleted file mode 100644 index 2b79a8a..0000000 --- a/src/dolly/rig.rs +++ /dev/null @@ -1,117 +0,0 @@ -use bevy_transform::prelude::Transform; - -use crate::dolly::driver::{RigDriver, RigDriverTraits}; -use core::fmt::Debug; -//use std::marker::PhantomData; - -/// A chain of drivers, calculating displacements, and animating in succession. -#[derive(Debug)] -pub struct CameraRig { - /// - pub drivers: Vec>, - - /// - pub final_transform: Transform, -} - -// Prevents user calls to `RigDriver::update`. All updates must come from `CameraRig::update`. -struct RigUpdateToken; - -/// -pub struct RigUpdateParams<'a> { - /// - pub parent: &'a Transform, - /// - pub delta_time_seconds: f32, - - _token: RigUpdateToken, -} - -impl CameraRig { - /// Returns the first driver of the matching type. Panics if no such driver is present. - pub fn driver_mut(&mut self) -> &mut T { - self.try_driver_mut::().unwrap_or_else(|| { - panic!( - "No {} driver found in the CameraRig", - std::any::type_name::() - ) - }) - } - - /// Returns the Some with the first driver of the matching type, or `None` if no such driver is present. - pub fn try_driver_mut(&mut self) -> Option<&mut T> { - self.drivers - .iter_mut() - .find_map(|driver| driver.as_mut().as_any_mut().downcast_mut::()) - } - - /// Returns the first driver of the matching type. Panics if no such driver is present. - pub fn driver(&self) -> &T { - self.try_driver::().unwrap_or_else(|| { - panic!( - "No {} driver found in the CameraRig", - std::any::type_name::() - ) - }) - } - - /// Returns the Some with the first driver of the matching type, or `None` if no such driver is present. - pub fn try_driver(&self) -> Option<&T> { - self.drivers - .iter() - .find_map(|driver| driver.as_ref().as_any().downcast_ref::()) - } - - /// Runs all the drivers in sequence, animating the rig, and producing a final transform of the camera. - /// - /// Camera rigs are approximately framerate independent, so `update` can be called at any frequency. - pub fn update(&mut self, delta_time_seconds: f32) -> Transform { - let mut parent_transform = Transform::IDENTITY; - - for driver in self.drivers.iter_mut() { - let transform = driver.update(RigUpdateParams { - parent: &parent_transform, - delta_time_seconds, - _token: RigUpdateToken, - }); - - parent_transform = transform; - } - - self.final_transform = parent_transform; - self.final_transform - } - - /// Use this to make a new rig - pub fn builder() -> CameraRigBuilder { - CameraRigBuilder { - drivers: Default::default(), - } - } -} - -/// -pub struct CameraRigBuilder { - drivers: Vec>, -} - -impl CameraRigBuilder { - /// - pub fn with(mut self, driver: impl RigDriverTraits) -> Self { - self.drivers.push(Box::new(driver)); - self - } - - /// - pub fn build(self) -> CameraRig { - let mut rig = CameraRig { - drivers: self.drivers, - // Initialize with a dummy identity transform. Will be overridden in a moment. - final_transform: Transform::IDENTITY, - }; - - // Update once to find the final transform - rig.update(0.0); - rig - } -} diff --git a/src/dolly/transform.rs b/src/dolly/transform.rs deleted file mode 100644 index 1c9c973..0000000 --- a/src/dolly/transform.rs +++ /dev/null @@ -1,52 +0,0 @@ -use core::fmt::Debug; -//use glam::{Quat, Vec3}; -use bevy_math::{Quat, Vec3}; -use std::marker::PhantomData; - -use crate::handedness::Handedness; - -/// A thin wrapper over a `Vec3` and a `Quat` -#[derive(Clone, Copy, Debug)] -pub struct Transform { - pub position: Vec3, - pub rotation: Quat, - pub phantom: PhantomData, -} - -impl Transform { - /// - pub fn from_position_rotation(position: Vec3, rotation: Quat) -> Self { - Self { - position, - rotation, - phantom: PhantomData, - } - } - - /// - pub fn into_position_rotation(self) -> (Vec3, Quat) { - (self.position, self.rotation) - } - - /// +X - pub fn right(&self) -> Vec3 { - self.rotation * Vec3::X - } - - /// +Y - pub fn up(&self) -> Vec3 { - self.rotation * Vec3::Y - } - - /// +/-Z - pub fn forward(&self) -> Vec3 { - self.rotation * H::FORWARD - } - - /// - pub const IDENTITY: Transform = Transform { - position: Vec3::ZERO, - rotation: Quat::IDENTITY, - phantom: PhantomData, - }; -} diff --git a/src/dolly/util.rs b/src/dolly/util.rs deleted file mode 100644 index dd06d85..0000000 --- a/src/dolly/util.rs +++ /dev/null @@ -1,70 +0,0 @@ -use bevy_math::{Quat, Vec3}; - -pub(crate) trait Interpolate { - fn interpolate(self, other: Self, t: f32) -> Self; -} - -impl Interpolate for Vec3 { - fn interpolate(self, other: Self, t: f32) -> Self { - Vec3::lerp(self, other, t) - } -} - -impl Interpolate for Quat { - fn interpolate(self, other: Self, t: f32) -> Self { - // Technically should be a `slerp` for framerate independence, but the latter - // will rotate in the negative direction when interpolating a 180..360 degree rotation - // to the 0..180 range. See the comment about `yaw_degrees` in `YawPitch` for more details. - Quat::lerp(self.normalize(), other.normalize(), t).normalize() - } -} - -pub(crate) struct ExpSmoothingParams { - pub smoothness: f32, - pub output_offset_scale: f32, - pub delta_time_seconds: f32, -} - -#[derive(Default, Debug)] -pub(crate) struct ExpSmoothed(Option); - -impl ExpSmoothed { - pub(crate) fn exp_smooth_towards(&mut self, other: &T, params: ExpSmoothingParams) -> T { - // An ad-hoc multiplier to make default smoothness parameters - // produce good-looking results. - const SMOOTHNESS_MULT: f32 = 8.0; - - // Calculate the exponential blending based on frame time - let interp_t = 1.0 - - (-SMOOTHNESS_MULT * params.delta_time_seconds / params.smoothness.max(1e-5)).exp(); - - let prev = self.0.unwrap_or(*other); - let smooth = prev.interpolate(*other, interp_t); - - self.0 = Some(smooth); - - #[allow(clippy::float_cmp)] - if params.output_offset_scale != 1.0 { - Interpolate::interpolate(*other, smooth, params.output_offset_scale) - } else { - smooth - } - } -} - -/* -pub fn look_at(forward: Vec3) -> Quat { - forward - .try_normalize() - .and_then(|forward| { - let right = H::right_from_up_and_forward(Vec3::Y, forward).try_normalize()?; - let up = H::up_from_right_and_forward(right, forward); - Some(Quat::from_mat3(&Mat3::from_cols( - right, - up, - forward * H::FORWARD_Z_SIGN, - ))) - }) - .unwrap_or_default() -} -*/ diff --git a/src/lib.rs b/src/lib.rs index 25bc004..5a210c6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,4 +1,4 @@ -pub mod dolly; +pub use dolly; pub mod dolly_type; #[cfg(feature = "drivers")] From a41ab38b6bd77319ed627acbe05d963a7612b596 Mon Sep 17 00:00:00 2001 From: Mikkel Rasmussen Date: Sun, 3 Dec 2023 12:54:33 +0100 Subject: [PATCH 18/19] Updated toml --- Cargo.lock | 9 --------- Cargo.toml | 2 +- dolly | 1 - 3 files changed, 1 insertion(+), 11 deletions(-) delete mode 160000 dolly diff --git a/Cargo.lock b/Cargo.lock index d59eed6..fd3430a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -458,7 +458,6 @@ name = "bevy_dolly" version = "0.0.2" dependencies = [ "bevy", - "dolly", "leafwing-input-manager", ] @@ -1352,14 +1351,6 @@ dependencies = [ "libloading 0.8.1", ] -[[package]] -name = "dolly" -version = "0.4.2" -dependencies = [ - "bevy_math", - "bevy_transform", -] - [[package]] name = "downcast-rs" version = "1.2.0" diff --git a/Cargo.toml b/Cargo.toml index 9f128a1..533ffcc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -32,7 +32,7 @@ leafwing-input-manager = { version = "0.11.2", optional = true } [dependencies.bevy] version = "0.12" -features = ["bevy_render", "bevy_asset", "bevy_pbr"] +features = ["bevy_render", "bevy_asset", "bevy_pbr", "bevy_math", "bevy_transform"] default-features = false [dev-dependencies] diff --git a/dolly b/dolly deleted file mode 160000 index 2ceea75..0000000 --- a/dolly +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 2ceea759e20ddfeb5f7abd5f22ecebb9dde77038 From b67bce6d484d9c14317eac267fb072c017e7c730 Mon Sep 17 00:00:00 2001 From: Mikkel Rasmussen Date: Sun, 3 Dec 2023 12:59:22 +0100 Subject: [PATCH 19/19] Added bevy transform and math dependencies --- Cargo.lock | 2 ++ Cargo.toml | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index fd3430a..f9a8f8c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -458,6 +458,8 @@ name = "bevy_dolly" version = "0.0.2" dependencies = [ "bevy", + "bevy_math", + "bevy_transform", "leafwing-input-manager", ] diff --git a/Cargo.toml b/Cargo.toml index 533ffcc..d8b35dc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -28,11 +28,13 @@ helpers = ["dep:leafwing-input-manager"] [dependencies] #dolly = { path = "dolly", default-features = false } +bevy_math = "0.12" +bevy_transform = "0.12" leafwing-input-manager = { version = "0.11.2", optional = true } [dependencies.bevy] version = "0.12" -features = ["bevy_render", "bevy_asset", "bevy_pbr", "bevy_math", "bevy_transform"] +features = ["bevy_render", "bevy_asset", "bevy_pbr"] default-features = false [dev-dependencies]