Make the planet wireframe.
This commit is contained in:
parent
768bdf67ad
commit
20f68b2bec
8 changed files with 96 additions and 24 deletions
27
Cargo.lock
generated
27
Cargo.lock
generated
|
@ -390,6 +390,17 @@ dependencies = [
|
|||
"glam",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "bevy_mod_debugdump"
|
||||
version = "0.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5951114fabf7153eaa8050b3072f41ea2867202beadd42f1be13c94d918b3025"
|
||||
dependencies = [
|
||||
"bevy",
|
||||
"itertools",
|
||||
"pretty-type-name",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "bevy_pbr"
|
||||
version = "0.6.0"
|
||||
|
@ -980,6 +991,7 @@ name = "cyber_rider"
|
|||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"bevy",
|
||||
"bevy_mod_debugdump",
|
||||
"heron",
|
||||
]
|
||||
|
||||
|
@ -1506,6 +1518,15 @@ dependencies = [
|
|||
"mach",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "itertools"
|
||||
version = "0.10.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a9a9d19fa1e79b6215ff29b9d6880b706147f16e9b1dbb1e4e5947b5b02bc5e3"
|
||||
dependencies = [
|
||||
"either",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "itoa"
|
||||
version = "1.0.1"
|
||||
|
@ -2059,6 +2080,12 @@ version = "0.2.16"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "eb9f9e6e233e5c4a35559a617bf40a4ec447db2e84c20b55a6f83167b7e57872"
|
||||
|
||||
[[package]]
|
||||
name = "pretty-type-name"
|
||||
version = "1.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a8815d101cfb4cb491154896bdab292a395a7ac9ab185a9941a2f5be0135900d"
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro-crate"
|
||||
version = "1.1.0"
|
||||
|
|
11
Cargo.toml
11
Cargo.toml
|
@ -3,6 +3,9 @@ name = "cyber_rider"
|
|||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
bevy_mod_debugdump = "0.3.0"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies.bevy]
|
||||
|
@ -28,10 +31,10 @@ heron = { path = "../heron/" }
|
|||
[patch."https://github.com/bevyengine/bevy"]
|
||||
bevy = { path = "../bevy/" }
|
||||
|
||||
# Enable optimizations for dependencies (incl. Bevy), but not for our code:
|
||||
[profile.dev.package."*"]
|
||||
opt-level = 3
|
||||
|
||||
# Maybe also enable only a small amount of optimization for our code:
|
||||
[profile.dev]
|
||||
opt-level = 1
|
||||
|
||||
# Enable optimizations for dependencies (incl. Bevy), but not for our code:
|
||||
[profile.dev.package."*"]
|
||||
opt-level = 3
|
||||
|
|
|
@ -24,8 +24,8 @@ fn follow_cyberbike(
|
|||
let bike_xform = bike_query.single();
|
||||
let up = bike_xform.translation.normalize();
|
||||
|
||||
let look_at = bike_xform.translation + (bike_xform.forward() * CAM_DIST);
|
||||
let cam_pos = bike_xform.translation + (bike_xform.back() * CAM_DIST * 1.5) + (up * CAM_DIST);
|
||||
let look_at = bike_xform.translation + (bike_xform.forward() * 200.0);
|
||||
let cam_pos = bike_xform.translation + (bike_xform.back() * 2.7) + (up * 2.4);
|
||||
|
||||
let mut cam_xform = cam_query.single_mut();
|
||||
cam_xform.translation = cam_pos;
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
use bevy::prelude::*;
|
||||
use heron::prelude::{CollisionShape, RigidBody};
|
||||
|
||||
use crate::Label;
|
||||
|
||||
pub const PLANET_RADIUS: f32 = 350.0;
|
||||
pub(crate) const SPAWN_ALTITUDE: f32 = PLANET_RADIUS + 100.0;
|
||||
|
||||
|
@ -63,7 +65,7 @@ fn spawn_cyberbike(mut commands: Commands, asset_server: Res<AssetServer>) {
|
|||
pub struct CyberGeomPlugin;
|
||||
impl Plugin for CyberGeomPlugin {
|
||||
fn build(&self, app: &mut App) {
|
||||
app.add_startup_system(spawn_giant_sphere)
|
||||
.add_startup_system(spawn_cyberbike);
|
||||
app.add_startup_system(spawn_giant_sphere.label(Label::Geometry))
|
||||
.add_startup_system(spawn_cyberbike.label(Label::Geometry));
|
||||
}
|
||||
}
|
||||
|
|
30
src/glamor.rs
Normal file
30
src/glamor.rs
Normal file
|
@ -0,0 +1,30 @@
|
|||
use bevy::{
|
||||
pbr::wireframe::{Wireframe, WireframeConfig, WireframePlugin},
|
||||
prelude::*,
|
||||
render::{options::WgpuOptions, render_resource::WgpuFeatures},
|
||||
};
|
||||
|
||||
use crate::geometry::CyberSphere;
|
||||
|
||||
fn wireframe(
|
||||
mut commands: Commands,
|
||||
mut wireframe_config: ResMut<WireframeConfig>,
|
||||
query: Query<Entity, With<CyberSphere>>,
|
||||
) {
|
||||
let ent = query.single();
|
||||
wireframe_config.global = false;
|
||||
commands.entity(ent).insert(Wireframe);
|
||||
}
|
||||
|
||||
// public plugin
|
||||
pub struct CyberGlamorPlugin;
|
||||
impl Plugin for CyberGlamorPlugin {
|
||||
fn build(&self, app: &mut App) {
|
||||
app.insert_resource(WgpuOptions {
|
||||
features: WgpuFeatures::POLYGON_MODE_LINE,
|
||||
..Default::default()
|
||||
})
|
||||
.add_startup_system_to_stage(StartupStage::PostStartup, wireframe)
|
||||
.add_plugin(WireframePlugin);
|
||||
}
|
||||
}
|
16
src/lib.rs
16
src/lib.rs
|
@ -1,12 +1,24 @@
|
|||
use bevy::prelude::{ResMut, Windows};
|
||||
use bevy::{
|
||||
ecs::schedule::StageLabel,
|
||||
prelude::{ResMut, SystemLabel, Windows},
|
||||
};
|
||||
|
||||
pub mod action;
|
||||
pub mod camera;
|
||||
pub mod geometry;
|
||||
pub mod glamor;
|
||||
pub mod input;
|
||||
pub mod lights;
|
||||
pub mod action;
|
||||
pub mod ui;
|
||||
|
||||
#[derive(Clone, Debug, Hash, PartialEq, Eq, SystemLabel, StageLabel)]
|
||||
pub enum Label {
|
||||
Geometry,
|
||||
Glamor,
|
||||
Input,
|
||||
Action,
|
||||
}
|
||||
|
||||
pub fn disable_mouse_trap(mut windows: ResMut<Windows>) {
|
||||
let window = windows.get_primary_mut().unwrap();
|
||||
window.set_cursor_lock_mode(false);
|
||||
|
|
13
src/main.rs
13
src/main.rs
|
@ -4,6 +4,7 @@ use cyber_rider::{
|
|||
camera::CyberCamPlugin,
|
||||
disable_mouse_trap,
|
||||
geometry::CyberGeomPlugin,
|
||||
glamor::CyberGlamorPlugin,
|
||||
input::CyberInputPlugin,
|
||||
lights::CyberSpaceLightsPlugin,
|
||||
ui::CyberUIPlugin,
|
||||
|
@ -17,10 +18,11 @@ const MOVEMENT_SETTINGS: MovementSettings = MovementSettings {
|
|||
};
|
||||
|
||||
fn main() {
|
||||
App::new()
|
||||
.insert_resource(Msaa { samples: 4 })
|
||||
let mut app = App::new();
|
||||
app.insert_resource(Msaa { samples: 4 })
|
||||
.add_plugins(DefaultPlugins)
|
||||
.add_plugin(CyberGeomPlugin)
|
||||
.add_plugin(CyberGlamorPlugin)
|
||||
.add_plugin(CyberInputPlugin)
|
||||
.add_plugin(CyberPhysicsPlugin)
|
||||
.insert_resource(MOVEMENT_SETTINGS)
|
||||
|
@ -28,6 +30,9 @@ fn main() {
|
|||
.add_plugin(CyberSpaceLightsPlugin)
|
||||
.add_plugin(CyberUIPlugin)
|
||||
.add_startup_system(disable_mouse_trap)
|
||||
.add_system(bevy::input::system::exit_on_esc_system)
|
||||
.run();
|
||||
.add_system(bevy::input::system::exit_on_esc_system);
|
||||
|
||||
//bevy_mod_debugdump::print_schedule(&mut app);
|
||||
|
||||
app.run();
|
||||
}
|
||||
|
|
13
src/ui.rs
13
src/ui.rs
|
@ -1,6 +1,6 @@
|
|||
use bevy::prelude::*;
|
||||
|
||||
use crate::{action::CyberBikeState, geometry::PLANET_RADIUS};
|
||||
use crate::action::CyberBikeState;
|
||||
|
||||
#[derive(Component)]
|
||||
struct UpText;
|
||||
|
@ -32,17 +32,10 @@ fn setup_ui(mut commands: Commands, asset_server: Res<AssetServer>) {
|
|||
.insert(UpText);
|
||||
}
|
||||
|
||||
fn update_ui(
|
||||
state_query: Query<(&CyberBikeState, &Transform)>,
|
||||
mut text_query: Query<&mut Text, With<UpText>>,
|
||||
) {
|
||||
fn update_ui(state_query: Query<&CyberBikeState>, mut text_query: Query<&mut Text, With<UpText>>) {
|
||||
let mut text = text_query.single_mut();
|
||||
let state = state_query.single();
|
||||
text.sections[0].value = format!(
|
||||
"spd: {:.2}\nalt: {:.2}",
|
||||
state.0.velocity.length(),
|
||||
state.1.translation.length() - PLANET_RADIUS
|
||||
);
|
||||
text.sections[0].value = format!("spd: {:.2}", state.velocity.length(),);
|
||||
}
|
||||
|
||||
pub struct CyberUIPlugin;
|
||||
|
|
Loading…
Reference in a new issue