From 348d7dce45e2160de0ca844296f108369743ec4a Mon Sep 17 00:00:00 2001 From: Hartmut Seichter Date: Thu, 17 Nov 2022 20:10:49 +0100 Subject: [PATCH] added more features back --- src/main.rs | 87 ++++++++++++++++++++++++-------------------------- src/offaxis.rs | 48 +++++++++++++--------------- 2 files changed, 65 insertions(+), 70 deletions(-) diff --git a/src/main.rs b/src/main.rs index 2b0c631..4b56deb 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,55 +1,52 @@ +use crate::scene::*; use bevy::{prelude::*, window::PresentMode}; -use crate::scene::{*}; -mod scene; mod offaxis; +mod scene; fn main() { App::new() - .insert_resource(ClearColor(Color::rgb(0.0,0.1,0.9))) - - // .insert_resource(WindowDescriptor{ - // title: "PixSpace".to_string(), - // width: 1280.0, - // height: 800.0, - // present_mode: PresentMode::AutoVsync, - // ..Default::default() - // }) - - .add_plugins(DefaultPlugins.set(WindowPlugin { - window: WindowDescriptor { - width: 1280.0, - height: 720.0, - present_mode: PresentMode::AutoVsync, - ..default() - }, - ..default() - })) - .add_plugins(DefaultPlugins) - .add_plugin(scene::BuildScenePlugin) - // .add_startup_system(offaxis::camera_setup) - .add_system(bevy::window::close_on_esc) - .add_system(cycle_msaa) + .insert_resource(ClearColor(Color::rgb(0.0, 0.1, 0.9))) + // .insert_resource(WindowDescriptor{ + // title: "PixSpace".to_string(), + // width: 1280.0, + // height: 800.0, + // present_mode: PresentMode::AutoVsync, + // ..Default::default() + // }) + .add_plugins(DefaultPlugins.set(WindowPlugin { + window: WindowDescriptor { + title: "PixSpace".to_string(), + width: 1280.0, + height: 720.0, + present_mode: PresentMode::AutoVsync, + ..default() + }, + ..default() + })) + // .add_plugins(DefaultPlugins) + .add_plugin(scene::BuildScenePlugin) + .add_startup_system(offaxis::camera_setup) + .add_system(bevy::window::close_on_esc) + .add_system(cycle_msaa) // .add_system_to_stage( - // CoreStage::PostUpdate, - // camera_system::, + // CoreStage::PostUpdate, + // camera_system::, // ) - // .add_system(hello_world) - .add_startup_system(build_scene) - .add_system(print_positions) - .run(); - } + // .add_system(hello_world) + .add_startup_system(build_scene) + .add_system(print_positions) + .run(); +} - - - fn cycle_msaa(input: Res>, mut msaa: ResMut) { - if input.just_pressed(KeyCode::M) { - if msaa.samples == 4 { - info!("Not using MSAA"); - msaa.samples = 1; - } else { - info!("Using 4x MSAA"); - msaa.samples = 4; - } +fn cycle_msaa(input: Res>, mut msaa: ResMut) { + if input.just_pressed(KeyCode::M) { + if msaa.samples == 4 { + info!("Not using MSAA"); + msaa.samples = 1; + } else { + info!("Using 4x MSAA"); + msaa.samples = 4; } - } \ No newline at end of file + } +} diff --git a/src/offaxis.rs b/src/offaxis.rs index 62295ac..2ed816f 100644 --- a/src/offaxis.rs +++ b/src/offaxis.rs @@ -1,7 +1,7 @@ use bevy::prelude::*; -use bevy::render::primitives::Frustum; use bevy::render::camera::{Camera, CameraProjection}; +use bevy::render::primitives::Frustum; use bevy::render::view::VisibleEntities; #[derive(Component)] @@ -14,9 +14,7 @@ pub struct OffAxisProjection { impl CameraProjection for OffAxisProjection { fn get_projection_matrix(&self) -> Mat4 { println!("Here we go!"); - Mat4::orthographic_rh( - -self.aspect, self.aspect, -1.0, 1.0, self.near, self.far - ) + Mat4::orthographic_rh(-self.aspect, self.aspect, -1.0, 1.0, self.near, self.far) } // what to do on window resize @@ -39,12 +37,16 @@ impl CameraProjection for OffAxisProjection { impl Default for OffAxisProjection { fn default() -> Self { - Self { near: 0.0, far: 1000.0, aspect: 1.0 } + Self { + near: 0.0, + far: 1000.0, + aspect: 1.0, + } } } pub fn camera_setup(mut commands: Commands) { - print!("Setup {0}",line!()); + print!("Setup {0}", line!()); // We need all the components that Bevy's built-in camera bundles would add @@ -56,36 +58,32 @@ pub fn camera_setup(mut commands: Commands) { ..default() }; - print!("Setup {0}",line!()); + print!("Setup {0}", line!()); // position the camera like bevy would do by default for 2D: let transform = Transform::from_xyz(0.0, 0.0, projection.far - 0.1); // frustum construction code copied from Bevy - let view_projection = - projection.get_projection_matrix() * transform.compute_matrix().inverse(); - - let frustum = Frustum::from_view_projection( + let view_projection = projection.get_projection_matrix() * transform.compute_matrix().inverse(); + + let frustum = Frustum::from_view_projection( &view_projection, &transform.translation, &transform.back(), projection.far, - ); + ); - print!("Setup {0}",line!()); - - // commands.spawn_bundle(( - // camera, - // projection, - // frustum, - // VisibleEntities::default(), - // transform, - // GlobalTransform::default(), - // // Camera2d, - // ) - // ); + print!("Setup {0}\n", line!()); - print!("Setup {0}",line!()); + commands.spawn(( + camera, + projection, + frustum, + VisibleEntities::default(), + transform, + GlobalTransform::default(), + )); + print!("Setup {0}\t{1}\n", line!(), file!()); } // fn main() {