WiP
This commit is contained in:
parent
348d7dce45
commit
ee31137795
6 changed files with 120 additions and 16 deletions
16
.gitignore
vendored
16
.gitignore
vendored
|
@ -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
|
||||
|
||||
|
|
10
Cargo.lock
generated
10
Cargo.lock
generated
|
@ -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"
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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(
|
||||
|
|
98
src/scene.rs
98
src/scene.rs
|
@ -1,4 +1,4 @@
|
|||
use bevy::prelude::*;
|
||||
use bevy::{prelude::*, math::bool};
|
||||
|
||||
pub struct BuildScenePlugin;
|
||||
|
||||
|
@ -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,
|
||||
|
||||
pub fn build_scene(mut commands: Commands) {
|
||||
commands.spawn((
|
||||
Person,
|
||||
Position { x: 10.0, y: 10.0 }
|
||||
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<Assets<Mesh>>,
|
||||
mut materials: ResMut<Assets<StandardMaterial>>,
|
||||
) {
|
||||
// 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()
|
||||
});
|
||||
|
||||
|
||||
// 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 } );
|
||||
|
@ -36,9 +118,7 @@ pub fn build_scene(mut commands: Commands) {
|
|||
|
||||
pub fn print_positions(query: Query<&Position>) {
|
||||
for _position in query.iter() {
|
||||
|
||||
_ = 33;
|
||||
// println!("position {:?} {:?}", position.x, position.y)
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue