minor update
This commit is contained in:
parent
4a8c9a298a
commit
3b18d1e032
7 changed files with 154 additions and 133 deletions
18
LICENSE.md
Normal file
18
LICENSE.md
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
Copyright 2022 Hartmut Seichter
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
a copy of this software and associated documentation files (the "Software"), to
|
||||||
|
deal in the Software without restriction, including without limitation the
|
||||||
|
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||||
|
sell copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included
|
||||||
|
in all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||||
|
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||||
|
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
54
src/main.rs
54
src/main.rs
|
@ -1,21 +1,24 @@
|
||||||
|
/**
|
||||||
|
* PixSpace is a Virtual Reality Toolkit to run projective VR setups
|
||||||
|
*
|
||||||
|
* © Copyright 2022 Hartmut Seichter
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
use crate::scene::*;
|
use crate::scene::*;
|
||||||
|
use crate::utils::*;
|
||||||
|
|
||||||
use bevy::{prelude::*, window::PresentMode, render::camera::CameraProjectionPlugin};
|
use bevy::{prelude::*, window::PresentMode, render::camera::CameraProjectionPlugin};
|
||||||
use offaxis::{offaxis_camera_setup, OffAxisProjection};
|
use offaxis::{offaxis_camera_setup, OffAxisProjection};
|
||||||
|
|
||||||
mod offaxis;
|
mod offaxis;
|
||||||
mod scene;
|
mod scene;
|
||||||
mod screeninfo;
|
mod screeninfo;
|
||||||
|
mod utils;
|
||||||
|
|
||||||
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(),
|
|
||||||
// width: 1280.0,
|
|
||||||
// height: 800.0,
|
|
||||||
// present_mode: PresentMode::AutoVsync,
|
|
||||||
// ..Default::default()
|
|
||||||
// })
|
|
||||||
.add_plugins(DefaultPlugins.set(WindowPlugin {
|
.add_plugins(DefaultPlugins.set(WindowPlugin {
|
||||||
window: WindowDescriptor {
|
window: WindowDescriptor {
|
||||||
title: "PixSpace".to_string(),
|
title: "PixSpace".to_string(),
|
||||||
|
@ -26,47 +29,16 @@ fn main() {
|
||||||
},
|
},
|
||||||
..default()
|
..default()
|
||||||
}))
|
}))
|
||||||
// .add_plugins(DefaultPlugins)
|
// .add_plugin(scene::BuildScenePlugin)
|
||||||
.add_plugin(scene::BuildScenePlugin)
|
|
||||||
// .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(cycle_msaa)
|
||||||
// .add_system_to_stage(
|
|
||||||
// CoreStage::PostUpdate,
|
|
||||||
// camera_system::<offaxis::OffAxisProjection>,
|
|
||||||
// )
|
|
||||||
// .add_system(hello_world)
|
|
||||||
.add_startup_system(build_scene)
|
.add_startup_system(build_scene)
|
||||||
.add_system(modify_projection)
|
// .add_system(modify_projection)
|
||||||
|
|
||||||
.add_startup_system(offaxis_camera_setup)
|
.add_startup_system(offaxis_camera_setup)
|
||||||
// .add_system(print_positions)
|
|
||||||
// .add_system(modify_frustum)
|
|
||||||
|
|
||||||
.add_plugin(CameraProjectionPlugin::<OffAxisProjection>::default())
|
.add_plugin(CameraProjectionPlugin::<OffAxisProjection>::default())
|
||||||
|
|
||||||
.add_system(update_offaxis)
|
.add_system(update_offaxis)
|
||||||
.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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn update_offaxis(mut query : Query<&mut OffAxisProjection>)
|
|
||||||
{
|
|
||||||
for mut q in query.iter_mut() {
|
|
||||||
|
|
||||||
// we fake access to far for updating the matrix
|
|
||||||
(*q).far *= 1.0;
|
|
||||||
|
|
||||||
println!("Update {:?}",q);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -4,9 +4,7 @@ use bevy::render::camera::{Camera, CameraProjection};
|
||||||
use bevy::render::primitives::Frustum;
|
use bevy::render::primitives::Frustum;
|
||||||
use bevy::render::view::VisibleEntities;
|
use bevy::render::view::VisibleEntities;
|
||||||
|
|
||||||
|
use crate::screeninfo::ScreenInfo;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#[derive(Component, Debug, Clone, Reflect)]
|
#[derive(Component, Debug, Clone, Reflect)]
|
||||||
#[reflect(Component, Default)]
|
#[reflect(Component, Default)]
|
||||||
|
@ -18,7 +16,9 @@ pub struct OffAxisProjection {
|
||||||
|
|
||||||
impl CameraProjection for OffAxisProjection {
|
impl CameraProjection for OffAxisProjection {
|
||||||
fn get_projection_matrix(&self) -> Mat4 {
|
fn get_projection_matrix(&self) -> Mat4 {
|
||||||
|
|
||||||
println!("Here we go! {:?}",self);
|
println!("Here we go! {:?}",self);
|
||||||
|
|
||||||
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)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,14 +27,6 @@ impl CameraProjection for OffAxisProjection {
|
||||||
self.aspect = width / height;
|
self.aspect = width / height;
|
||||||
}
|
}
|
||||||
|
|
||||||
// fn depth_calculation(&self) -> DepthCalculation {
|
|
||||||
// // for 2D (camera doesn't rotate)
|
|
||||||
// DepthCalculation::ZDifference
|
|
||||||
|
|
||||||
// // otherwise
|
|
||||||
// //DepthCalculation::Distance
|
|
||||||
// }
|
|
||||||
|
|
||||||
fn far(&self) -> f32 {
|
fn far(&self) -> f32 {
|
||||||
self.far
|
self.far
|
||||||
}
|
}
|
||||||
|
@ -51,16 +43,9 @@ impl Default for OffAxisProjection {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn offaxis_camera_setup(mut commands: Commands) {
|
pub fn offaxis_camera_setup(mut commands: Commands) {
|
||||||
print!("Setup {0}", line!());
|
|
||||||
|
|
||||||
// We need all the components that Bevy's built-in camera bundles would add
|
|
||||||
|
|
||||||
let projection = OffAxisProjection::default();
|
let projection = OffAxisProjection::default();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
println!("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);
|
||||||
|
|
||||||
|
@ -73,9 +58,7 @@ pub fn offaxis_camera_setup(mut commands: Commands) {
|
||||||
&transform.back(),
|
&transform.back(),
|
||||||
projection.far,
|
projection.far,
|
||||||
);
|
);
|
||||||
|
|
||||||
print!("Setup {0}\n", line!());
|
|
||||||
|
|
||||||
commands.spawn((
|
commands.spawn((
|
||||||
bevy::render::camera::CameraRenderGraph::new(bevy::core_pipeline::core_3d::graph::NAME),
|
bevy::render::camera::CameraRenderGraph::new(bevy::core_pipeline::core_3d::graph::NAME),
|
||||||
projection,
|
projection,
|
||||||
|
@ -84,24 +67,7 @@ pub fn offaxis_camera_setup(mut commands: Commands) {
|
||||||
GlobalTransform::default(),
|
GlobalTransform::default(),
|
||||||
VisibleEntities::default(),
|
VisibleEntities::default(),
|
||||||
Camera::default(),
|
Camera::default(),
|
||||||
Camera3d::default()
|
Camera3d::default(),
|
||||||
|
ScreenInfo::default()
|
||||||
));
|
));
|
||||||
|
|
||||||
println!("Setup {0}\t{1}\n", line!(), file!());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// fn main() {
|
|
||||||
// // need to add a bevy-internal camera system to update
|
|
||||||
// // the projection on window resizing
|
|
||||||
|
|
||||||
// use bevy::render::camera::camera_system;
|
|
||||||
|
|
||||||
// App::new()
|
|
||||||
// .add_plugins(DefaultPlugins)
|
|
||||||
// .add_startup_system(setup)
|
|
||||||
// .add_system_to_stage(
|
|
||||||
// CoreStage::PostUpdate,
|
|
||||||
// camera_system::<SimpleOrthoProjection>,
|
|
||||||
// )
|
|
||||||
// .run();
|
|
||||||
// }
|
|
||||||
|
|
79
src/scene.rs
79
src/scene.rs
|
@ -3,23 +3,14 @@ use rand::prelude::*;
|
||||||
use bevy::render::primitives::Plane;
|
use bevy::render::primitives::Plane;
|
||||||
|
|
||||||
|
|
||||||
pub struct BuildScenePlugin;
|
// pub struct BuildScenePlugin;
|
||||||
|
|
||||||
impl Plugin for BuildScenePlugin {
|
// impl Plugin for BuildScenePlugin {
|
||||||
fn build(&self, app: &mut App) {
|
// fn build(&self, app: &mut App) {
|
||||||
app.add_startup_system(build_scene) // actual scene
|
// app.add_startup_system(build_scene) // actual scene
|
||||||
.add_system(print_positions); // debugging
|
// .add_system(print_positions); // debugging
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
#[derive(Component)]
|
|
||||||
struct Person;
|
|
||||||
|
|
||||||
#[derive(Component)]
|
|
||||||
pub struct Position {
|
|
||||||
x: f32,
|
|
||||||
y: f32,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Component)]
|
#[derive(Component)]
|
||||||
pub struct ProjectionScreen {
|
pub struct ProjectionScreen {
|
||||||
|
@ -136,50 +127,50 @@ pub fn build_scene(
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
pub fn modify_frustum(mut query: Query<&Frustum>)
|
// pub fn modify_frustum(mut query: Query<&Frustum>)
|
||||||
{
|
// {
|
||||||
let mut rng = rand::thread_rng();
|
// let mut rng = rand::thread_rng();
|
||||||
|
|
||||||
for mut q in query.iter() {
|
// for mut q in query.iter() {
|
||||||
|
|
||||||
for mut p in q.planes {
|
// for mut p in q.planes {
|
||||||
|
|
||||||
println!("{:?}",p);
|
// println!("{:?}",p);
|
||||||
|
|
||||||
let mut n = p.normal_d();
|
// let mut n = p.normal_d();
|
||||||
|
|
||||||
n.w += rng.gen::<f32>();
|
// n.w += rng.gen::<f32>();
|
||||||
|
|
||||||
p = Plane::new(n);
|
// p = Plane::new(n);
|
||||||
|
|
||||||
println!("{:?}",p);
|
// println!("{:?}",p);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// p.normal_d() += rng.gen();
|
// // p.normal_d() += rng.gen();
|
||||||
}
|
// }
|
||||||
|
|
||||||
// println!("{:?}",q.frustum.planes.len());
|
// // println!("{:?}",q.frustum.planes.len());
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
|
|
||||||
pub fn modify_projection(mut query: Query<&Projection>)
|
// pub fn modify_projection(mut query: Query<&Projection>)
|
||||||
{
|
// {
|
||||||
let mut rng = rand::thread_rng();
|
// let mut rng = rand::thread_rng();
|
||||||
|
|
||||||
for mut q in query.iter() {
|
// for mut q in query.iter() {
|
||||||
|
|
||||||
print!("{:?}",q);
|
// print!("{:?}",q);
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
pub fn print_positions(query: Query<&Position>) {
|
// pub fn print_positions(query: Query<&Position>) {
|
||||||
for _position in query.iter() {
|
// for _position in query.iter() {
|
||||||
_ = 33;
|
// _ = 33;
|
||||||
// println!("position {:?} {:?}", position.x, position.y)
|
// // println!("position {:?} {:?}", position.x, position.y)
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
// Problem with off-axis
|
// Problem with off-axis
|
||||||
// projection 2401, 240
|
// projection 2401, 240
|
|
@ -2,20 +2,23 @@
|
||||||
use bevy::{prelude::*, math::bool, render::primitives::Frustum};
|
use bevy::{prelude::*, math::bool, render::primitives::Frustum};
|
||||||
use rand::prelude::*;
|
use rand::prelude::*;
|
||||||
use bevy::render::primitives::Plane;
|
use bevy::render::primitives::Plane;
|
||||||
|
|
||||||
enum EyePos {
|
enum EyePos {
|
||||||
Left,
|
Left,
|
||||||
Right
|
Right
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#[derive(Default,Component)]
|
||||||
pub struct ScreenInfo {
|
pub struct ScreenInfo {
|
||||||
name : String, // main
|
pub name : String, // main (to identify the screen)
|
||||||
width : f32, // 3.08
|
width : f32, // 3.08 (full width in m)
|
||||||
height : f32, // 2.33
|
height : f32, // 2.33 (full height in m)
|
||||||
|
|
||||||
center : Vec3, // 0.0 -1.15 -3.08
|
center : Vec3, // 0.0 -1.15 -3.08 (mid point of screen in global coordinated - tracking!)
|
||||||
normal : Vec3, // 0.0 0.0 1.0
|
normal : Vec3, // 0.0 0.0 1.0 (orientation of front side)
|
||||||
up: Vec3, // 0.0 1.0 0.0 (vertical)
|
up: Vec3, // 0.0 1.0 0.0 (vertical axis)
|
||||||
horizontal: Vec3,
|
horizontal: Vec3, // right vector computed as orthonormal
|
||||||
|
|
||||||
top : Vec3,
|
top : Vec3,
|
||||||
bottom : Vec3,
|
bottom : Vec3,
|
||||||
|
@ -25,6 +28,22 @@ pub struct ScreenInfo {
|
||||||
|
|
||||||
impl ScreenInfo {
|
impl ScreenInfo {
|
||||||
|
|
||||||
|
fn default() -> Self {
|
||||||
|
Self {
|
||||||
|
name: String::from("main"),
|
||||||
|
width: 3.08,
|
||||||
|
height: 2.33,
|
||||||
|
center: Vec3 { x: 0.0, y: -1.15, z: -3.08 },
|
||||||
|
normal: Vec3::Z,
|
||||||
|
up: Vec3::Y,
|
||||||
|
horizontal: Vec3::ZERO,
|
||||||
|
top: Vec3::ZERO,
|
||||||
|
bottom: Vec3::ZERO,
|
||||||
|
left: Vec3::ZERO,
|
||||||
|
right: Vec3::ZERO,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
fn update(&mut self) {
|
fn update(&mut self) {
|
||||||
|
|
||||||
|
@ -49,6 +68,7 @@ impl ScreenInfo {
|
||||||
|
|
||||||
let intersection_point = p1 + ((p2 - p1) * u);
|
let intersection_point = p1 + ((p2 - p1) * u);
|
||||||
|
|
||||||
|
// returns a tuple if the intersection point is in front and the actual point
|
||||||
(u >= 0.0 && u <= 1.0,intersection_point)
|
(u >= 0.0 && u <= 1.0,intersection_point)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -60,6 +80,5 @@ impl ScreenInfo {
|
||||||
|
|
||||||
self.intersection(p1, p2)
|
self.intersection(p1, p2)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
33
src/utils.rs
Normal file
33
src/utils.rs
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
use crate::scene::*;
|
||||||
|
use crate::offaxis::*;
|
||||||
|
use crate::screeninfo;
|
||||||
|
use crate::screeninfo::ScreenInfo;
|
||||||
|
|
||||||
|
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 update_offaxis(mut query : Query<(
|
||||||
|
&mut OffAxisProjection,
|
||||||
|
&ScreenInfo
|
||||||
|
)>
|
||||||
|
) {
|
||||||
|
for (mut q,si) in query.iter_mut() {
|
||||||
|
|
||||||
|
// we fake access to far for updating the matrix
|
||||||
|
(*q).far *= 1.0;
|
||||||
|
|
||||||
|
println!("Update {:?}",q);
|
||||||
|
println!("Screeninfo {0}",si.name.len());
|
||||||
|
}
|
||||||
|
}
|
22
src/viewer.rs
Normal file
22
src/viewer.rs
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
use bevy::{prelude::*, window::PresentMode, render::camera::CameraProjectionPlugin};
|
||||||
|
use offaxis::{offaxis_camera_setup, OffAxisProjection};
|
||||||
|
|
||||||
|
|
||||||
|
#[derive(Component)]
|
||||||
|
struct Viewer;
|
||||||
|
|
||||||
|
#[derive(Component)]
|
||||||
|
pub struct Viewer {
|
||||||
|
position: Vec3,
|
||||||
|
orientation: Quat,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
impl Viewer {
|
||||||
|
|
||||||
|
fn default() -> Self {
|
||||||
|
Self {
|
||||||
|
position: Vec3::ZERO,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue