migrate to bevy 0.10.1
This commit is contained in:
parent
ed66390929
commit
105faee1b6
7 changed files with 1050 additions and 864 deletions
1738
Cargo.lock
generated
1738
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
|
@ -9,7 +9,8 @@ readme = "README.md"
|
|||
|
||||
[dependencies]
|
||||
# bevy = "0.9.0"
|
||||
bevy = { version = "0.9.1", features = ["dynamic"] }
|
||||
# bevy = { version = "0.10.1", features = ["dynamic"] }
|
||||
bevy = { version = "0.10.1" }
|
||||
rand = "0.8.4"
|
||||
# vrpn = "0.1.0" # not compatible with 2021
|
||||
vrpn = { git = "https://github.com/seichter/vrpn-rs" }
|
||||
|
|
|
@ -3,20 +3,22 @@ use bevy::prelude::*;
|
|||
|
||||
// this seems to crash
|
||||
|
||||
pub fn toggle_fullscreeen(
|
||||
input: Res<Input<KeyCode>>,
|
||||
mut windows: ResMut<Windows>,
|
||||
) {
|
||||
let window = windows
|
||||
.get_primary_mut()
|
||||
.unwrap();
|
||||
// pub fn toggle_fullscreeen(
|
||||
// input: Res<Input<KeyCode>>,
|
||||
// mut windows: ResMut<Windows>,
|
||||
// ) {
|
||||
// let window = windows
|
||||
// .get_primary_mut()
|
||||
// .unwrap();
|
||||
|
||||
if input.pressed(KeyCode::F) /*&& input.just_pressed(KeyCode::Return) */ {
|
||||
if window.mode() == WindowMode::Windowed {
|
||||
window.set_mode(WindowMode::BorderlessFullscreen);
|
||||
} else {
|
||||
window.set_mode(WindowMode::Windowed);
|
||||
}
|
||||
}
|
||||
}
|
||||
// if input.pressed(KeyCode::F) /*&& input.just_pressed(KeyCode::Return) */ {
|
||||
// /*
|
||||
// if window.mode() == WindowMode::Windowed {
|
||||
// window.set_mode(WindowMode::BorderlessFullscreen);
|
||||
// } else {
|
||||
// window.set_mode(WindowMode::Windowed);
|
||||
// }
|
||||
// */
|
||||
// }
|
||||
// }
|
||||
|
||||
|
|
35
src/main.rs
35
src/main.rs
|
@ -12,8 +12,10 @@ use crate::tracker::*;
|
|||
use crate::console::*;
|
||||
|
||||
|
||||
use bevy::render::primitives::Frustum;
|
||||
use bevy::transform::commands;
|
||||
use bevy::{prelude::*, window::PresentMode, render::camera::CameraProjectionPlugin};
|
||||
use offaxis::{offaxis_camera_setup, OffAxisProjection};
|
||||
use offaxis::{offaxis_camera_setup, setup_offaxis_010, OffAxisProjection};
|
||||
|
||||
mod offaxis;
|
||||
mod scene;
|
||||
|
@ -24,20 +26,22 @@ mod projection;
|
|||
mod tracker;
|
||||
mod console;
|
||||
|
||||
|
||||
fn main() {
|
||||
App::new()
|
||||
.add_plugins(DefaultPlugins)
|
||||
.insert_resource(ClearColor(Color::rgb(0.5, 0.5, 0.5)))
|
||||
.add_plugins(DefaultPlugins.set(WindowPlugin {
|
||||
window: WindowDescriptor {
|
||||
title: "PixSpace".to_string(),
|
||||
width: 1280.0,
|
||||
height: 720.0,
|
||||
present_mode: PresentMode::AutoVsync,
|
||||
// mode: WindowMode::BorderlessFullscreen,
|
||||
..default()
|
||||
},
|
||||
..default()
|
||||
}))
|
||||
// .add_plugins(DefaultPlugins.set(WindowPlugin {
|
||||
// window: WindowDescriptor {
|
||||
// title: "PixSpace".to_string(),
|
||||
// width: 1280.0,
|
||||
// height: 720.0,
|
||||
// present_mode: PresentMode::AutoVsync,
|
||||
// // mode: WindowMode::BorderlessFullscreen,
|
||||
// ..default()
|
||||
// },
|
||||
// ..default()
|
||||
// }))
|
||||
// use hot reloading
|
||||
// .add_plugins(DefaultPlugins.set(AssetPlugin {
|
||||
// watch_for_changes: true,
|
||||
|
@ -45,11 +49,12 @@ fn main() {
|
|||
// }))
|
||||
// .add_plugin(scene::BuildScenePlugin)
|
||||
.add_system(bevy::window::close_on_esc)
|
||||
.add_system(cycle_msaa)
|
||||
// .add_system(cycle_msaa)
|
||||
.add_startup_system(build_scene)
|
||||
// .add_system(modify_projection)
|
||||
|
||||
.add_startup_system(offaxis_camera_setup)
|
||||
// .add_startup_system(offaxis_camera_setup)
|
||||
.add_startup_system(setup_offaxis_010)
|
||||
// .add_startup_system(setup_tracker)
|
||||
// .add_system(update_tracker)
|
||||
// .add_startup_system(setup_threaded_tracker)
|
||||
|
@ -60,7 +65,7 @@ fn main() {
|
|||
// .add_system(simulate_viewer_with_circle)
|
||||
.add_system(simulate_viewer_with_keyboard)
|
||||
.add_system(apply_viewer_to_projections)
|
||||
.add_system(toggle_fullscreeen)
|
||||
// .add_system(cargo butoggle_fullscreeen)
|
||||
.run();
|
||||
}
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
use bevy::prelude::*;
|
||||
|
||||
use bevy::render::camera::{Camera, CameraProjection};
|
||||
use bevy::render::view::visibility::*;
|
||||
use bevy::render::view::{visibility::*, self};
|
||||
use bevy::render::primitives::Frustum;
|
||||
use bevy::render::view::VisibleEntities;
|
||||
use bevy::math::Mat4;
|
||||
|
@ -54,6 +54,25 @@ impl Default for OffAxisProjection {
|
|||
}
|
||||
|
||||
|
||||
pub fn setup_offaxis_010(
|
||||
mut commands: Commands
|
||||
) {
|
||||
|
||||
let projection = OffAxisProjection::default();
|
||||
|
||||
// let transform = Transform::from_xyz(0.0, 0.0, 0.0);
|
||||
|
||||
let view_projection = projection.get_projection_matrix();
|
||||
|
||||
commands.spawn(Camera3dBundle{
|
||||
transform: Transform::from_xyz(-2.0, 2.5, 5.0).looking_at(Vec3::ZERO, Vec3::Y),
|
||||
frustum: Frustum::from_view_projection(&view_projection),
|
||||
..default()
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
pub fn offaxis_camera_setup(mut commands: Commands) {
|
||||
|
||||
let projection = OffAxisProjection::default();
|
||||
|
@ -66,12 +85,14 @@ pub fn offaxis_camera_setup(mut commands: Commands) {
|
|||
// frustum construction code copied from Bevy
|
||||
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,
|
||||
);
|
||||
// let frustum = Frustum::from_view_projection(
|
||||
// &view_projection,
|
||||
// &transform.translation,
|
||||
// &transform.back(),
|
||||
// projection.far,
|
||||
// );
|
||||
|
||||
let frustum = Frustum::from_view_projection(&view_projection);
|
||||
|
||||
commands.spawn((
|
||||
bevy::render::camera::CameraRenderGraph::new(bevy::core_pipeline::core_3d::graph::NAME),
|
||||
|
|
|
@ -10,7 +10,7 @@ pub fn build_scene(
|
|||
) {
|
||||
// plane
|
||||
commands.spawn(PbrBundle {
|
||||
mesh: meshes.add(Mesh::from(shape::Plane { size: 2.5 })),
|
||||
mesh: meshes.add(shape::Plane::from_size(5.0).into()),
|
||||
material: materials.add(Color::rgb(0.3, 0.5, 0.3).into()),
|
||||
transform: Transform::from_xyz(0.0, -0.5, 0.0),
|
||||
..default()
|
||||
|
|
69
src/utils.rs
69
src/utils.rs
|
@ -7,43 +7,46 @@ use crate::viewer::Viewer;
|
|||
|
||||
use bevy::{prelude::*, window::PresentMode, render::camera::CameraProjectionPlugin};
|
||||
|
||||
pub 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
// pub fn cycle_msaa(input: Res<Input<KeyCode>>, mut msaa: ResMut<Msaa>) {
|
||||
// if input.just_pressed(KeyCode::M) {
|
||||
|
||||
// pub fn update_offaxis(mut query : Query<(
|
||||
// &mut OffAxisProjection,
|
||||
// &mut Transform,
|
||||
// &ScreenInfo,
|
||||
// &Viewer
|
||||
// )>
|
||||
// ) {
|
||||
// for (mut projection,mut transform,screen_info,viewer) in query.iter_mut() {
|
||||
// // msaa
|
||||
|
||||
// // we fake access to far for updating the matrix
|
||||
// (*projection).far *= 1.0;
|
||||
|
||||
// info!("Projection {:?}",*projection);
|
||||
|
||||
// info!("Screen Info {:?}",screen_info.name);
|
||||
|
||||
// info!("Viewer {:?}",viewer.position);
|
||||
|
||||
// *transform = Transform::from_translation(viewer.position).with_rotation(transform.rotation);
|
||||
|
||||
|
||||
|
||||
// }
|
||||
// // if msaa.samples == 4 {
|
||||
// // info!("Not using MSAA");
|
||||
// // msaa.samples = 1;
|
||||
// // } else {
|
||||
// // info!("Using 4x MSAA");
|
||||
// // msaa.samples = 4;
|
||||
// // }
|
||||
// // }
|
||||
// }
|
||||
|
||||
// // pub fn update_offaxis(mut query : Query<(
|
||||
// // &mut OffAxisProjection,
|
||||
// // &mut Transform,
|
||||
// // &ScreenInfo,
|
||||
// // &Viewer
|
||||
// // )>
|
||||
// // ) {
|
||||
// // for (mut projection,mut transform,screen_info,viewer) in query.iter_mut() {
|
||||
|
||||
// // // we fake access to far for updating the matrix
|
||||
// // (*projection).far *= 1.0;
|
||||
|
||||
// // info!("Projection {:?}",*projection);
|
||||
|
||||
// // info!("Screen Info {:?}",screen_info.name);
|
||||
|
||||
// // info!("Viewer {:?}",viewer.position);
|
||||
|
||||
// // *transform = Transform::from_translation(viewer.position).with_rotation(transform.rotation);
|
||||
|
||||
|
||||
|
||||
// // }
|
||||
// // }
|
||||
|
||||
|
||||
fn intersection_point(
|
||||
center_point: Vec3,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue