WiP
This commit is contained in:
parent
348d7dce45
commit
ee31137795
6 changed files with 120 additions and 16 deletions
104
src/scene.rs
104
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<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()
|
||||
});
|
||||
|
||||
|
||||
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)
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue