This commit is contained in:
Hartmut Seichter 2022-11-16 23:07:49 +01:00
parent c33335fc50
commit b4965a3b05
5 changed files with 727 additions and 546 deletions

1174
Cargo.lock generated

File diff suppressed because it is too large Load diff

View file

@ -6,5 +6,5 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies] [dependencies]
bevy = "0.8" # make sure this is the latest version bevy = "0.9.0"
# vrpn = "0.1.0" # not compatible with 2021 # vrpn = "0.1.0" # not compatible with 2021

View file

@ -1,4 +1,5 @@
use bevy::prelude::*; use bevy::{prelude::*, window::PresentMode};
use crate::scene::{*};
mod scene; mod scene;
mod offaxis; mod offaxis;
@ -6,25 +7,49 @@ mod offaxis;
fn main() { fn main() {
App::new() App::new()
.insert_resource(ClearColor(Color::rgb(0.0,0.1,0.9))) .insert_resource(ClearColor(Color::rgb(0.0,0.1,0.9)))
.insert_resource(WindowDescriptor{
title: "PixSpace".to_string(), // .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, width: 1280.0,
height: 800.0, height: 720.0,
..Default::default() present_mode: PresentMode::AutoVsync,
}) ..default()
},
..default()
}))
.add_plugins(DefaultPlugins) .add_plugins(DefaultPlugins)
.add_plugin(scene::BuildScenePlugin) .add_plugin(scene::BuildScenePlugin)
.add_startup_system(offaxis::camera_setup) // .add_startup_system(offaxis::camera_setup)
.add_system(bevy::window::close_on_esc) .add_system(bevy::window::close_on_esc)
.add_system(cycle_msaa)
// .add_system_to_stage( // .add_system_to_stage(
// CoreStage::PostUpdate, // CoreStage::PostUpdate,
// camera_system::<offaxis::OffAxisProjection>, // camera_system::<offaxis::OffAxisProjection>,
// ) // )
// .add_system(hello_world) // .add_system(hello_world)
// .add_startup_system(add_scene) .add_startup_system(build_scene)
// .add_system(print_positions) .add_system(print_positions)
.run(); .run();
} }
fn cycle_msaa(input: Res<Input<KeyCode>>, mut msaa: ResMut<Msaa>) {
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;
}
}
}

View file

@ -1,8 +1,8 @@
use bevy::prelude::*; use bevy::prelude::*;
// use bevy::render::primitives::Frustum; use bevy::render::primitives::Frustum;
use bevy::render::camera::{Camera, CameraProjection, DepthCalculation}; use bevy::render::camera::{Camera, CameraProjection};
// use bevy::render::view::VisibleEntities; use bevy::render::view::VisibleEntities;
#[derive(Component)] #[derive(Component)]
pub struct OffAxisProjection { pub struct OffAxisProjection {
@ -24,13 +24,13 @@ impl CameraProjection for OffAxisProjection {
self.aspect = width / height; self.aspect = width / height;
} }
fn depth_calculation(&self) -> DepthCalculation { // fn depth_calculation(&self) -> DepthCalculation {
// for 2D (camera doesn't rotate) // // for 2D (camera doesn't rotate)
DepthCalculation::ZDifference // DepthCalculation::ZDifference
// otherwise // // otherwise
//DepthCalculation::Distance // //DepthCalculation::Distance
} // }
fn far(&self) -> f32 { fn far(&self) -> f32 {
self.far self.far
@ -44,20 +44,26 @@ impl Default for OffAxisProjection {
} }
pub fn camera_setup(mut commands: Commands) { pub fn camera_setup(mut commands: Commands) {
print!("Setup {0}",line!());
// We need all the components that Bevy's built-in camera bundles would add // We need all the components that Bevy's built-in camera bundles would add
let projection = OffAxisProjection::default(); let projection = OffAxisProjection::default();
let camera = Camera { let camera = Camera {
// near: projection.near, // near: projection.near,
// far: projection.far, // far: projection.far,
..default() ..default()
}; };
/*
print!("Setup {0}",line!());
// position the camera like bevy would do by default for 2D: // position the camera like bevy would do by default for 2D:
let transform = Transform::from_xyz(0.0, 0.0, projection.far - 0.1); let transform = Transform::from_xyz(0.0, 0.0, projection.far - 0.1);
// frustum construction code copied from Bevy // frustum construction code copied from Bevy
let view_projection = let view_projection =
projection.get_projection_matrix() * transform.compute_matrix().inverse(); projection.get_projection_matrix() * transform.compute_matrix().inverse();
let frustum = Frustum::from_view_projection( let frustum = Frustum::from_view_projection(
&view_projection, &view_projection,
&transform.translation, &transform.translation,
@ -65,6 +71,8 @@ pub fn camera_setup(mut commands: Commands) {
projection.far, projection.far,
); );
print!("Setup {0}",line!());
commands.spawn_bundle(( commands.spawn_bundle((
camera, camera,
projection, projection,
@ -72,11 +80,12 @@ pub fn camera_setup(mut commands: Commands) {
VisibleEntities::default(), VisibleEntities::default(),
transform, transform,
GlobalTransform::default(), GlobalTransform::default(),
Camera2d, // Camera2d,
) )
); );
*/ print!("Setup {0}",line!());
} }
// fn main() { // fn main() {

View file

@ -4,21 +4,19 @@ pub struct BuildScenePlugin;
impl Plugin for BuildScenePlugin { impl Plugin for BuildScenePlugin {
fn build(&self, app: &mut App) { fn build(&self, app: &mut App) {
app app.add_startup_system(build_scene) // actual scene
.add_startup_system(build_scene) .add_system(print_positions); // debugging
.add_system(print_positions);
} }
} }
#[derive(Component)] #[derive(Component)]
struct Person; struct Person;
#[derive(Component)] #[derive(Component)]
struct Position { x: f32, y: f32 } pub struct Position { x: f32, y: f32 }
fn build_scene(mut commands: Commands) { pub fn build_scene(mut commands: Commands) {
commands.spawn() commands.spawn()
.insert(Person) .insert(Person)
.insert(Position { x: 10.0, y: 10.0 } ); .insert(Position { x: 10.0, y: 10.0 } );
@ -30,9 +28,10 @@ fn build_scene(mut commands: Commands) {
// }); // });
} }
fn print_positions(query : Query<&Position>) { pub fn print_positions(query : Query<&Position>) {
for position in query.iter() { for _position in query.iter() {
_ = 33;
// println!("position {:?} {:?}", position.x, position.y) // println!("position {:?} {:?}", position.x, position.y)
} }