switch to bevy 0.5 for egui-inspector compat; get spinny lights
This commit is contained in:
parent
fff3e98eca
commit
0a9659f364
5 changed files with 861 additions and 478 deletions
4
.rustfmt.toml
Normal file
4
.rustfmt.toml
Normal file
|
@ -0,0 +1,4 @@
|
|||
imports_granularity = "Crate"
|
||||
group_imports = "StdExternalCrate"
|
||||
wrap_comments = true
|
||||
edition = "2021"
|
1200
Cargo.lock
generated
1200
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
|
@ -6,4 +6,5 @@ edition = "2021"
|
|||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
bevy = { path = "../bevy" }
|
||||
bevy = "0.5"
|
||||
bevy-inspector-egui = "0.6.1"
|
||||
|
|
|
@ -1,8 +1,12 @@
|
|||
use bevy::app::{Events, ManualEventReader};
|
||||
use bevy::input::mouse::MouseMotion;
|
||||
use bevy::prelude::*;
|
||||
use bevy::{
|
||||
app::{Events, ManualEventReader},
|
||||
input::{mouse::MouseMotion, Input},
|
||||
prelude::*,
|
||||
};
|
||||
|
||||
// stolen with neither shame nor pity from git@github.com:sburris0/bevy_flycam.git, b90f6fc, which is copyright 2020 Spencer Burris
|
||||
// stolen with neither shame nor pity from
|
||||
// git@github.com:sburris0/bevy_flycam.git, b90f6fc, which is copyright 2020
|
||||
// Spencer Burris
|
||||
|
||||
/// Keeps track of mouse motion events, pitch, and yaw
|
||||
#[derive(Default)]
|
||||
|
@ -28,7 +32,7 @@ impl Default for MovementSettings {
|
|||
}
|
||||
|
||||
/// Used in queries when you want flycams and not other cameras
|
||||
#[derive(Debug, Component)]
|
||||
#[derive(Debug)]
|
||||
pub struct FlyCam;
|
||||
|
||||
/// Grabs/ungrabs mouse cursor
|
||||
|
@ -46,7 +50,7 @@ fn initial_grab_cursor(mut windows: ResMut<Windows>) {
|
|||
fn setup_player(mut commands: Commands) {
|
||||
commands
|
||||
.spawn_bundle(PerspectiveCameraBundle {
|
||||
transform: Transform::from_xyz(-2.0, 5.0, 5.0).looking_at(Vec3::ZERO, Vec3::Y),
|
||||
transform: Transform::from_xyz(0.0, 0.0, -1200.0).looking_at(Vec3::ZERO, Vec3::Y),
|
||||
..Default::default()
|
||||
})
|
||||
.insert(FlyCam);
|
||||
|
@ -101,7 +105,8 @@ fn player_look(
|
|||
for (_camera, mut transform) in query.iter_mut() {
|
||||
for ev in state.reader_motion.iter(&motion) {
|
||||
if window.cursor_locked() {
|
||||
// Using smallest of height or width ensures equal vertical and horizontal sensitivity
|
||||
// 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();
|
||||
|
@ -124,10 +129,11 @@ fn cursor_grab(keys: Res<Input<KeyCode>>, mut windows: ResMut<Windows>) {
|
|||
}
|
||||
}
|
||||
|
||||
/// Contains everything needed to add first-person fly camera behavior to your game
|
||||
/// Contains everything needed to add first-person fly camera behavior to your
|
||||
/// game
|
||||
pub struct PlayerPlugin;
|
||||
impl Plugin for PlayerPlugin {
|
||||
fn build(&self, app: &mut App) {
|
||||
fn build(&self, app: &mut bevy::prelude::AppBuilder) {
|
||||
app.init_resource::<InputState>()
|
||||
.init_resource::<MovementSettings>()
|
||||
.add_startup_system(setup_player.system())
|
||||
|
@ -141,7 +147,7 @@ impl Plugin for PlayerPlugin {
|
|||
/// Same as `PlayerPlugin` but does not spawn a camera
|
||||
pub struct NoCameraPlayerPlugin;
|
||||
impl Plugin for NoCameraPlayerPlugin {
|
||||
fn build(&self, app: &mut App) {
|
||||
fn build(&self, app: &mut bevy::prelude::AppBuilder) {
|
||||
app.init_resource::<InputState>()
|
||||
.init_resource::<MovementSettings>()
|
||||
.add_startup_system(initial_grab_cursor.system())
|
||||
|
|
106
src/main.rs
106
src/main.rs
|
@ -1,19 +1,23 @@
|
|||
use bevy::prelude::*;
|
||||
use cyber_rider::flycam::MovementSettings;
|
||||
use cyber_rider::flycam::PlayerPlugin;
|
||||
use bevy_inspector_egui::WorldInspectorPlugin;
|
||||
use cyber_rider::flycam::{MovementSettings, PlayerPlugin};
|
||||
|
||||
// stolen with neither shame nor pity from git@github.com:sburris0/bevy_flycam.git, b90f6fc, which is copyright 2020 Spencer Burris
|
||||
// stolen with neither shame nor pity from
|
||||
// git@github.com:sburris0/bevy_flycam.git, b90f6fc, which is copyright 2020
|
||||
// Spencer Burris
|
||||
|
||||
fn main() {
|
||||
App::new()
|
||||
App::build()
|
||||
.insert_resource(Msaa { samples: 4 })
|
||||
.add_plugins(DefaultPlugins)
|
||||
.add_plugin(PlayerPlugin)
|
||||
.add_plugin(WorldInspectorPlugin::new())
|
||||
.insert_resource(MovementSettings {
|
||||
sensitivity: 0.00015, // default: 0.00012
|
||||
speed: 12.0, // default: 12.0
|
||||
})
|
||||
.add_startup_system(setup.system())
|
||||
.add_system(animate_lights.system())
|
||||
.run();
|
||||
}
|
||||
|
||||
|
@ -23,22 +27,94 @@ fn setup(
|
|||
mut meshes: ResMut<Assets<Mesh>>,
|
||||
mut materials: ResMut<Assets<StandardMaterial>>,
|
||||
) {
|
||||
// plane
|
||||
let red_light = Light {
|
||||
intensity: 50_000.0,
|
||||
range: 1800.0,
|
||||
color: Color::RED,
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
let blue_light = Light {
|
||||
intensity: 50_000.0,
|
||||
range: 1800.0,
|
||||
color: Color::BLUE,
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
let purple_light = Light {
|
||||
intensity: 50_000.0,
|
||||
range: 1800.0,
|
||||
color: Color::PURPLE,
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
// world
|
||||
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()),
|
||||
mesh: meshes.add(Mesh::from(shape::Icosphere {
|
||||
radius: 300.0,
|
||||
subdivisions: 5,
|
||||
})),
|
||||
material: materials.add(StandardMaterial {
|
||||
base_color: Color::GRAY,
|
||||
metallic: 0.7,
|
||||
roughness: 0.2,
|
||||
..Default::default()
|
||||
}),
|
||||
|
||||
..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),
|
||||
// east light
|
||||
commands.spawn_bundle(LightBundle {
|
||||
transform: Transform::from_xyz(750.0, 0.0, 0.0),
|
||||
light: purple_light.clone(),
|
||||
..Default::default()
|
||||
});
|
||||
// light
|
||||
commands.spawn_bundle(PointLightBundle {
|
||||
transform: Transform::from_xyz(4.0, 8.0, 4.0),
|
||||
// west light
|
||||
commands.spawn_bundle(LightBundle {
|
||||
transform: Transform::from_xyz(-750.0, 0.0, 0.0),
|
||||
light: purple_light.clone(),
|
||||
..Default::default()
|
||||
});
|
||||
// north light
|
||||
commands.spawn_bundle(LightBundle {
|
||||
transform: Transform::from_xyz(0.0, 0.0, 750.0),
|
||||
light: purple_light.clone(),
|
||||
..Default::default()
|
||||
});
|
||||
// south light
|
||||
commands.spawn_bundle(LightBundle {
|
||||
transform: Transform::from_xyz(0.0, 0.0, -750.0),
|
||||
light: purple_light,
|
||||
..Default::default()
|
||||
});
|
||||
// up light
|
||||
commands.spawn_bundle(LightBundle {
|
||||
transform: Transform::from_xyz(0.0, 750.0, 0.0),
|
||||
light: red_light,
|
||||
..Default::default()
|
||||
});
|
||||
// down light
|
||||
commands.spawn_bundle(LightBundle {
|
||||
transform: Transform::from_xyz(0.0, 750.0, 0.0),
|
||||
light: blue_light,
|
||||
..Default::default()
|
||||
});
|
||||
}
|
||||
|
||||
fn animate_lights(mut query: Query<&mut Transform, With<Light>>) {
|
||||
for mut transform in query.iter_mut() {
|
||||
let translation = &transform.translation;
|
||||
let x = translation.x;
|
||||
let y = if translation.y.abs() < 0.1 {
|
||||
translation.y + 0.15
|
||||
} else {
|
||||
translation.y
|
||||
};
|
||||
|
||||
let theta = y.atan2(x) + 0.174533; // 10 degrees == 0.174533 radians
|
||||
let x_new = 750.0 * theta.cos();
|
||||
let y_new = 750.0 * theta.sin();
|
||||
|
||||
*transform = Transform::from_xyz(x_new, y_new, 0.0);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue