Skip to content

Commit

Permalink
Merge pull request #16 from BlackPhlox/0.7
Browse files Browse the repository at this point in the history
  • Loading branch information
BlackPhlox authored Apr 15, 2022
2 parents ce739bb + 1df1d5e commit 075904b
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 28 deletions.
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "bevy_flycam"
version = "0.6.0"
version = "0.7.0"
authors = ["Spencer Burris <[email protected]>"]
edition = "2021"
license = "ISC"
Expand All @@ -14,7 +14,7 @@ resolver = "2"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
bevy = {version = "0.6", default-features = false, features = ["bevy_render"]}
bevy = {version = "0.7", default-features = false, features = ["bevy_render"]}

[dev-dependencies]
bevy = {version = "0.6", default-features = false, features = ["x11", "wayland", "bevy_pbr", "bevy_core_pipeline"]}
bevy = {version = "0.7", default-features = false, features = ["x11", "wayland", "bevy_pbr", "bevy_core_pipeline"]}
14 changes: 11 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
![docs.rs](https://img.shields.io/docsrs/bevy_flycam)


A basic first-person fly camera for Bevy 0.6
A basic first-person fly camera for Bevy 0.7

## Controls
* WASD to move horizontally
Expand All @@ -25,15 +25,15 @@ There are a few notable differences from [bevy_fly_camera](https://github.com/mc
1. Add to `Cargo.toml` or copy `lib.rs` to your own file
```toml
[dependencies]
bevy = "0.6"
bevy = "0.7"
bevy_flycam = "*"
```

or

```toml
[dependencies]
bevy = "0.6"
bevy = "0.7"
bevy_flycam = { git = "https://github.com/sburris0/bevy_flycam" }
```

Expand Down Expand Up @@ -74,5 +74,13 @@ fn main() {
}
```

# Support
[![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)

bevy_flycam's crate version follows bevy's X version as shown:
|bevy|bevy_flycam|
|---|---|
|0.X.Y|0.X|

## Contributing
PRs are very welcome.
3 changes: 0 additions & 3 deletions examples/basic.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
// Remove the line below if you are copying this to your own project
extern crate bevy_flycam;

use bevy::prelude::*;
use bevy_flycam::MovementSettings;
use bevy_flycam::PlayerPlugin;
Expand Down
7 changes: 2 additions & 5 deletions examples/scroll.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
// Remove the line below if you are copying this to your own project
extern crate bevy_flycam;

use bevy::{
input::mouse::MouseWheel, prelude::*, render::camera::Camera, render::camera::CameraProjection,
render::camera::PerspectiveProjection, window::Windows,
Expand Down Expand Up @@ -71,7 +68,7 @@ fn setup(
info!("Changing the selected value by scrolling the mousewheel");
}

// Listens for Z key being pressed and toggles between the two scroll-type states
/// Listens for Z key being pressed and toggles between the two scroll-type states [`ScrollType`]
#[allow(unused_must_use)]
fn switch_scroll_type(
mut scroll_type: ResMut<State<ScrollType>>,
Expand All @@ -88,7 +85,7 @@ fn switch_scroll_type(
}
}

// Depending on the state, the mouse-scroll changes either the movement speed or the field-of-view of the camera
/// Depending on the state, the mouse-scroll changes either the movement speed or the field-of-view of the camera
fn scroll(
mut settings: ResMut<MovementSettings>,
scroll_type: Res<State<ScrollType>>,
Expand Down
29 changes: 15 additions & 14 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use bevy::app::{Events, ManualEventReader};
use bevy::ecs::event::{Events, ManualEventReader};
use bevy::input::mouse::MouseMotion;
use bevy::prelude::*;

Expand All @@ -25,7 +25,7 @@ impl Default for MovementSettings {
}
}

/// Used in queries when you want flycams and not other cameras
/// A marker component used in queries when you want flycams and not other cameras
#[derive(Component)]
pub struct FlyCam;

Expand Down Expand Up @@ -56,10 +56,10 @@ fn player_move(
time: Res<Time>,
windows: Res<Windows>,
settings: Res<MovementSettings>,
mut query: Query<(&FlyCam, &mut Transform)>,
mut query: Query<&mut Transform, With<FlyCam>>,
) {
let window = windows.get_primary().unwrap();
for (_camera, mut transform) in query.iter_mut() {
for mut transform in query.iter_mut() {
let mut velocity = Vec3::ZERO;
let local_z = transform.local_z();
let forward = -Vec3::new(local_z.x, 0., local_z.z);
Expand Down Expand Up @@ -91,24 +91,25 @@ fn player_look(
windows: Res<Windows>,
mut state: ResMut<InputState>,
motion: Res<Events<MouseMotion>>,
mut query: Query<(&FlyCam, &mut Transform)>,
mut query: Query<&mut Transform, With<FlyCam>>,
) {
let window = windows.get_primary().unwrap();
for (_camera, mut transform) in query.iter_mut() {
for ev in state.reader_motion.iter(&motion) {
let mut delta_state = state.as_mut();
for mut transform in query.iter_mut() {
for ev in delta_state.reader_motion.iter(&motion) {
if window.cursor_locked() {
// Using smallest of height or width ensures equal vertical and horizontal sensitivity
let window_scale = window.height().min(window.width());

state.pitch -= (settings.sensitivity * ev.delta.y * window_scale).to_radians();
state.yaw -= (settings.sensitivity * ev.delta.x * window_scale).to_radians();
delta_state.pitch -=
(settings.sensitivity * ev.delta.y * window_scale).to_radians();
delta_state.yaw -= (settings.sensitivity * ev.delta.x * window_scale).to_radians();
}

state.pitch = state.pitch.clamp(-1.54, 1.54);
delta_state.pitch = delta_state.pitch.clamp(-1.54, 1.54);

// Order is important to prevent unintended roll
transform.rotation = Quat::from_axis_angle(Vec3::Y, state.yaw)
* Quat::from_axis_angle(Vec3::X, state.pitch);
transform.rotation = Quat::from_axis_angle(Vec3::Y, delta_state.yaw)
* Quat::from_axis_angle(Vec3::X, delta_state.pitch);
}
}
}
Expand All @@ -134,7 +135,7 @@ impl Plugin for PlayerPlugin {
}
}

/// Same as `PlayerPlugin` but does not spawn a camera
/// Same as [`PlayerPlugin`] but does not spawn a camera
pub struct NoCameraPlayerPlugin;
impl Plugin for NoCameraPlayerPlugin {
fn build(&self, app: &mut App) {
Expand Down

0 comments on commit 075904b

Please sign in to comment.