diff --git a/.gitignore b/.gitignore index 8a2aacd..5b3a97c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,17 @@ -# Rust -/target +# Generated by Cargo +# will have compiled files and executables +debug/ +target/ + +# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries +# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html +Cargo.lock + +# These are backup files generated by rustfmt +**/*.rs.bk + +# MSVC Windows builds of rustc generate these, which store debugging information +*.pdb # Visual Studio Code diff --git a/Cargo.lock b/Cargo.lock index 71b9a09..900209c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -188,6 +188,7 @@ version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3654d60973fcde065efcfe0c9066c81a76987d28c45233998b2ccdc581dcd914" dependencies = [ + "bevy_dylib", "bevy_internal", ] @@ -328,6 +329,15 @@ dependencies = [ "bevy_utils", ] +[[package]] +name = "bevy_dylib" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0d52cc91729fc26ea7038ad49ed773e0577688e328b6f7466be3d5070b45cea9" +dependencies = [ + "bevy_internal", +] + [[package]] name = "bevy_ecs" version = "0.9.0" diff --git a/Cargo.toml b/Cargo.toml index 8f4d855..9eed193 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,5 +6,6 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -bevy = "0.9.0" +# bevy = "0.9.0" +bevy = { version = "0.9.0", features = ["dynamic"] } # vrpn = "0.1.0" # not compatible with 2021 diff --git a/README.md b/README.md index 05f25c1..00857a8 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,7 @@ Ideas are derived from a software written several years ago called VisionSpace. # TODO +* [ ] build a system that updates a cameras frustum (w/ offaxis) * [ ] multiple cameras * [ ] custom projection matrices (https://bevy-cheatbook.github.io/cookbook/custom-projection.html) * [ ] render to texture diff --git a/src/main.rs b/src/main.rs index 4b56deb..d319cc5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -26,7 +26,7 @@ fn main() { })) // .add_plugins(DefaultPlugins) .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(cycle_msaa) // .add_system_to_stage( diff --git a/src/scene.rs b/src/scene.rs index 1da4c85..57cc6af 100644 --- a/src/scene.rs +++ b/src/scene.rs @@ -1,11 +1,11 @@ -use bevy::prelude::*; +use bevy::{prelude::*, math::bool}; pub struct BuildScenePlugin; impl Plugin for BuildScenePlugin { fn build(&self, app: &mut App) { app.add_startup_system(build_scene) // actual scene - .add_system(print_positions); // debugging + .add_system(print_positions); // debugging } } @@ -13,16 +13,98 @@ impl Plugin for BuildScenePlugin { struct Person; #[derive(Component)] -pub struct Position { x: f32, y: f32 } +pub struct Position { + x: f32, + y: f32, +} + +#[derive(Component)] +pub struct ProjectionScreen { + bottom_left: Vec3, + bottom_right: Vec3, + top_left: Vec3, + top_right: Vec3, + + dir_right: Vec3, + dir_up: Vec3, + dir_normal: Vec3, + + matrix: Mat4 + +} + +fn compute_offaxis_frustum ( + projectionScreen: ProjectionScreen, + eyePos: Vec3, + mut camera: Camera3dBundle, + clampNearPlane: bool, +) +{ + let pa = projectionScreen.bottom_left; + let pb = projectionScreen.bottom_right; + let pc = projectionScreen.top_left; + let pd = projectionScreen.top_right; + + let vu = projectionScreen.dir_up; + let vr = projectionScreen.dir_right; + let vn = projectionScreen.dir_normal; + + let m = projectionScreen.matrix; + + let va = pa - eyePos; + let vb = pb - eyePos; + let vc = pc - eyePos; + let vd = pd - eyePos; + + let viewDir = eyePos + va + vb + vc + vd; + + let d = -va.dot(vn); + + if (clampNearPlane) { + // camera.frustum.planes[4]. // should be near + } +} + +pub fn build_scene( + mut commands: Commands, + mut meshes: ResMut>, + mut materials: ResMut>, +) { + // plane + commands.spawn(PbrBundle { + mesh: meshes.add(Mesh::from(shape::Plane { size: 5.0 })), + material: materials.add(Color::rgb(0.3, 0.5, 0.3).into()), + ..default() + }); + // cube + commands.spawn(PbrBundle { + mesh: meshes.add(Mesh::from(shape::Cube { size: 1.0 })), + material: materials.add(Color::rgb(0.8, 0.7, 0.6).into()), + transform: Transform::from_xyz(0.0, 0.5, 0.0), + ..default() + }); + // light + commands.spawn(PointLightBundle { + point_light: PointLight { + intensity: 1500.0, + shadows_enabled: true, + ..default() + }, + transform: Transform::from_xyz(4.0, 8.0, 4.0), + ..default() + }); -pub fn build_scene(mut commands: Commands) { - commands.spawn(( - Person, - Position { x: 10.0, y: 10.0 } + // camera - ) - ); + let mut cam = Camera3dBundle { + transform: Transform::from_xyz(-2.0, 2.5, 5.0).looking_at(Vec3::ZERO, Vec3::Y), + ..default() + }; + + commands.spawn(cam); + + commands.spawn((Person, Position { x: 10.0, y: 10.0 })); // commands.spawn() // .insert(Person) // .insert(Position { x: 10.0, y: 10.0 } ); @@ -34,11 +116,9 @@ pub fn build_scene(mut commands: Commands) { // }); } -pub fn print_positions(query : Query<&Position>) { +pub fn print_positions(query: Query<&Position>) { for _position in query.iter() { - _ = 33; // println!("position {:?} {:?}", position.x, position.y) - } }