Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
BlackPhlox authored Apr 3, 2023
2 parents 702b2e4 + 650b7ef commit aaa88d6
Show file tree
Hide file tree
Showing 7 changed files with 193 additions and 46 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,6 @@ Cargo.lock

# These are backup files generated by rustfmt
**/*.rs.bk

# IDE
.idea/
7 changes: 3 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "bevy_flycam"
version = "0.9.0"
version = "0.10.0"
authors = ["Spencer Burris <[email protected]>"]
edition = "2021"
license = "ISC"
Expand All @@ -10,11 +10,10 @@ repository = "https://github.com/sburris0/bevy_flycam/"
readme = "README.md"
keywords = ["gamedev", "bevy", "3d", "camera"]
categories = ["game-engines", "game-development"]
resolver = "2"

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

[dev-dependencies]
bevy = {version = "0.9", default-features = false, features = ["x11", "wayland", "bevy_pbr", "bevy_core_pipeline", "bevy_asset"]}
bevy = { version = "0.10.0", default-features = false, features = ["x11", "wayland", "bevy_pbr", "bevy_core_pipeline", "bevy_asset"] }
12 changes: 6 additions & 6 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.9
A basic first-person fly camera for Bevy 0.10

## 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.9"
bevy = "0.10"
bevy_flycam = "*"
```

or

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

Expand Down Expand Up @@ -78,9 +78,9 @@ fn main() {
[![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|
| bevy | bevy_flycam |
| :-- | :-- |
| `0.10.0` | `0.10` |

## Contributing
PRs are very welcome.
9 changes: 6 additions & 3 deletions examples/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ use bevy_flycam::PlayerPlugin;

fn main() {
App::new()
.insert_resource(Msaa { samples: 4 })
.insert_resource(Msaa::Sample4)
.add_plugins(DefaultPlugins)
.add_plugin(PlayerPlugin)
.insert_resource(MovementSettings {
sensitivity: 0.00015, // default: 0.00012
speed: 12.0, // default: 12.0
})
.add_startup_system(setup)
.add_system(setup.on_startup())
.run();
}

Expand All @@ -26,7 +26,10 @@ fn setup(
) {
// plane
commands.spawn(PbrBundle {
mesh: meshes.add(Mesh::from(shape::Plane { size: 5.0 })),
mesh: meshes.add(Mesh::from(shape::Plane {
size: 5.0,
subdivisions: 0,
})),
material: materials.add(Color::rgb(0.3, 0.5, 0.3).into()),
..Default::default()
});
Expand Down
57 changes: 57 additions & 0 deletions examples/key_bindings.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// Remove the line below if you are copying this to your own project
extern crate bevy_flycam;

use bevy::prelude::*;
use bevy_flycam::PlayerPlugin;
use bevy_flycam::{KeyBindings, MovementSettings};

//From bevy examples:
//https://github.com/bevyengine/bevy/blob/latest/examples/3d/3d_scene.rs

fn main() {
App::build()
.insert_resource(Msaa { samples: 4 })
.add_plugins(DefaultPlugins)
.add_plugin(PlayerPlugin)
.insert_resource(MovementSettings {
sensitivity: 0.00015, // default: 0.00012
speed: 12.0, // default: 12.0
})
.insert_resource(KeyBindings {
move_forward: KeyCode::A,
move_backward: KeyCode::Z,
move_left: KeyCode::Q,
move_right: KeyCode::W,
move_ascend: KeyCode::C,
move_descend: KeyCode::V,
toggle_grab_cursor: KeyCode::F,
})
.add_startup_system(setup.system())
.run();
}

/// set up a simple 3D scene
fn setup(
mut commands: Commands,
mut meshes: ResMut<Assets<Mesh>>,
mut materials: ResMut<Assets<StandardMaterial>>,
) {
// plane
commands.spawn_bundle(PbrBundle {
mesh: meshes.add(Mesh::from(shape::Plane { size: 5.0 })),
material: materials.add(Color::rgb(0.3, 0.5, 0.3).into()),
..Default::default()
});
// cube
commands.spawn_bundle(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::default()
});
// light
commands.spawn_bundle(LightBundle {
transform: Transform::from_xyz(4.0, 8.0, 4.0),
..Default::default()
});
}
24 changes: 14 additions & 10 deletions examples/scroll.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,25 @@ use bevy_flycam::{FlyCam, MovementSettings, NoCameraPlayerPlugin};
// From bevy examples:
// https://github.com/bevyengine/bevy/blob/latest/examples/3d/3d_scene.rs

#[derive(Clone, Eq, PartialEq, Debug, Hash)]
#[derive(States, Default, Clone, Eq, PartialEq, Debug, Hash)]
enum ScrollType {
#[default]
MovementSpeed,
Zoom,
}

fn main() {
App::new()
.insert_resource(Msaa { samples: 4 })
.insert_resource(Msaa::Sample4)
.add_plugins(DefaultPlugins)
//NoCameraPlayerPlugin as we provide the camera
.add_plugin(NoCameraPlayerPlugin)
.insert_resource(MovementSettings {
..Default::default()
})
// Setting initial state
.add_state(ScrollType::MovementSpeed)
.add_startup_system(setup)
.add_state::<ScrollType>()
.add_system(setup.on_startup())
.add_system(switch_scroll_type)
.add_system(scroll)
.run();
Expand All @@ -35,7 +36,10 @@ fn setup(
) {
// plane
commands.spawn(PbrBundle {
mesh: meshes.add(Mesh::from(shape::Plane { size: 5.0 })),
mesh: meshes.add(Mesh::from(shape::Plane {
size: 5.0,
subdivisions: 0,
})),
material: materials.add(Color::rgb(0.3, 0.5, 0.3).into()),
..Default::default()
});
Expand Down Expand Up @@ -66,19 +70,19 @@ fn setup(
}

/// 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>>,
scroll_type: Res<State<ScrollType>>,
mut next_scroll_type: ResMut<NextState<ScrollType>>,
keyboard_input: Res<Input<KeyCode>>,
) {
if keyboard_input.just_pressed(KeyCode::Z) {
let result = match scroll_type.current() {
let result = match scroll_type.0 {
ScrollType::MovementSpeed => ScrollType::Zoom,
ScrollType::Zoom => ScrollType::MovementSpeed,
};

println!("{:?}", result);
scroll_type.set(result);
next_scroll_type.set(result);
}
}

Expand All @@ -90,7 +94,7 @@ fn scroll(
mut query: Query<(&FlyCam, &mut Projection)>,
) {
for event in mouse_wheel_events.iter() {
if *scroll_type.current() == ScrollType::MovementSpeed {
if scroll_type.0 == ScrollType::MovementSpeed {
settings.speed = (settings.speed + event.y * 0.1).abs();
println!("Speed: {:?}", settings.speed);
} else {
Expand Down
Loading

0 comments on commit aaa88d6

Please sign in to comment.