Skip to content

Commit

Permalink
Update to Bevy 0.13 (#12)
Browse files Browse the repository at this point in the history
Co-authored-by: Hennadii Chernyshchyk <[email protected]>
  • Loading branch information
VirxEC and Shatur authored Feb 23, 2024
1 parent 7ba0537 commit 25233da
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 22 deletions.
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "bevy_spectator"
description = "A spectator camera plugin for Bevy"
version = "0.4.0"
version = "0.5.0"
edition = "2021"
authors = ["JonahPlusPlus <[email protected]>"]
license = "MIT OR Apache-2.0"
Expand All @@ -11,10 +11,10 @@ repository = "https://github.com/JonahPlusPlus/bevy_spectator"
exclude = ["/examples/"]

[dependencies]
bevy = { version = "0.12", default-features = false }
bevy = { version = "0.13", default-features = false }

[dev-dependencies]
bevy = { version = "0.12", default-features = false, features = [
bevy = { version = "0.13", default-features = false, features = [
"bevy_asset",
"bevy_core_pipeline",
"bevy_pbr",
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ fn setup(mut commands: Commands) {

| bevy | bevy_spectator |
|------|----------------|
| 0.13 | 0.5 |
| 0.12 | 0.4 |
| 0.11 | 0.3 |
| 0.10 | 0.2 |
Expand Down
2 changes: 2 additions & 0 deletions examples/2d_scene.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ use bevy_spectator::*;
fn main() {
App::new()
.insert_resource(SpectatorSettings {
base_speed: 100.0,
alt_speed: 350.0,
orthographic: true,
..default()
})
Expand Down
14 changes: 5 additions & 9 deletions examples/3d_scene.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,24 +23,20 @@ fn setup(
) {
// plane
commands.spawn(PbrBundle {
mesh: meshes.add(Mesh::from(shape::Plane {
size: 5.0,
subdivisions: 0,
})),
material: materials.add(Color::rgb(0.3, 0.5, 0.3).into()),
mesh: meshes.add(Plane3d::new(Vec3::Y).mesh().size(5.0, 5.0)),
material: materials.add(Color::rgb(0.3, 0.5, 0.3)),
..default()
});
// cube
commands.spawn(PbrBundle {
mesh: meshes.add(Mesh::from(shape::Cube { size: 1.0 })),
material: materials.add(Color::rgb(0.8, 0.7, 0.6).into()),
mesh: meshes.add(Cuboid::default()),
material: materials.add(Color::rgb(0.8, 0.7, 0.6)),
transform: Transform::from_xyz(0.0, 0.5, 0.0),
..default()
});
// light
commands.spawn(PointLightBundle {
point_light: PointLight {
intensity: 1500.0,
shadows_enabled: true,
..default()
},
Expand All @@ -50,7 +46,7 @@ fn setup(
// camera
commands.spawn((
Camera3dBundle {
transform: Transform::from_xyz(-1.0, 1.5, 1.0).looking_at(Vec3::ZERO, Vec3::Y),
transform: Transform::from_xyz(-3.0, 1.5, 3.0).looking_at(Vec3::ZERO, Vec3::Y),
..default()
},
Spectator,
Expand Down
41 changes: 31 additions & 10 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ fn spectator_init(
#[allow(clippy::too_many_arguments)]
fn spectator_update(
time: Res<Time>,
keys: Res<Input<KeyCode>>,
buttons: Res<Input<MouseButton>>,
keys: Res<ButtonInput<KeyCode>>,
buttons: Res<ButtonInput<MouseButton>>,
mut motion: EventReader<MouseMotion>,
mut settings: ResMut<SpectatorSettings>,
mut windows: Query<(&mut Window, Option<&PrimaryWindow>)>,
Expand Down Expand Up @@ -146,20 +146,41 @@ fn spectator_update(

// translation
{
let forward = if keys.pressed(KeyCode::W) { 1f32 } else { 0f32 };
let backward = if keys.pressed(KeyCode::S) { 1f32 } else { 0f32 };
let right = if keys.pressed(KeyCode::D) { 1f32 } else { 0f32 };
let left = if keys.pressed(KeyCode::A) { 1f32 } else { 0f32 };
let forward = if keys.pressed(KeyCode::KeyW) {
1f32
} else {
0f32
};

let backward = if keys.pressed(KeyCode::KeyS) {
1f32
} else {
0f32
};

let right = if keys.pressed(KeyCode::KeyD) {
1f32
} else {
0f32
};

let left = if keys.pressed(KeyCode::KeyA) {
1f32
} else {
0f32
};

let up_cond = if !settings.orthographic {
keys.pressed(KeyCode::Space)
} else {
keys.pressed(KeyCode::W)
keys.pressed(KeyCode::KeyW)
};
let up = if up_cond { 1f32 } else { 0f32 };

let down_cond = if !settings.orthographic {
keys.pressed(KeyCode::ControlLeft)
} else {
keys.pressed(KeyCode::S)
keys.pressed(KeyCode::KeyS)
};
let down = if down_cond { 1f32 } else { 0f32 };

Expand All @@ -177,11 +198,11 @@ fn spectator_update(
let delta_lateral = (right - left) * speed;
let delta_vertical = (up - down) * speed;

let mut forward = camera_transform.forward();
let mut forward = *camera_transform.forward();
forward.y = 0f32;
forward = forward.normalize_or_zero(); // fly fast even when look down/up

let mut right = camera_transform.right();
let mut right = *camera_transform.right();
right.y = 0f32; // more of a sanity check
let up = Vec3::Y;

Expand Down

0 comments on commit 25233da

Please sign in to comment.