update to utilize a proper off-axis projection including a demo scene to prototype all systems
This commit is contained in:
parent
040bc8d88a
commit
9c778afa2b
7 changed files with 130 additions and 81 deletions
|
@ -1,7 +1,6 @@
|
|||
use bevy::{prelude::*, render::camera::CameraProjectionPlugin, window::PresentMode};
|
||||
use bevy::{prelude::*, transform, math::Vec4Swizzles};
|
||||
|
||||
use crate::screeninfo::ScreenInfo;
|
||||
// use offaxis::{offaxis_camera_setup, OffAxisProjection};
|
||||
use crate::{screeninfo::ScreenInfo, offaxis::OffAxisProjection, projection::create_offaxis_matrices};
|
||||
|
||||
#[derive(Component, Default)]
|
||||
pub struct Viewer {
|
||||
|
@ -29,27 +28,48 @@ impl Viewer {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn simulate_viewer(mut query: Query<&mut Viewer>) {
|
||||
for mut v in query.iter_mut() {
|
||||
//v.position += Vec3::Y * 0.005;
|
||||
v.alpha += 0.01;
|
||||
let radius = 1.5;
|
||||
|
||||
let z_distance = 8.0_f32;
|
||||
pub fn apply_viewer_to_projections(mut query: Query<(&Viewer,&ScreenInfo,&mut OffAxisProjection,&mut Transform)>)
|
||||
{
|
||||
query.for_each_mut(|(viewer,screen_info,mut offaxis, mut transform)| {
|
||||
|
||||
let eye = viewer.position;
|
||||
|
||||
|
||||
let (lower_left,lower_right,upper_left,_) = screen_info.corner_points();
|
||||
|
||||
// let lower_left = Vec3::new(screen_info.center.x - screen_info.width / 2.0,screen_info.center.y - screen_info.height / 2.0,screen_info.center.z);
|
||||
// let upper_left = Vec3::new(screen_info.center.x - screen_info.width / 2.0,screen_info.center.y + screen_info.height / 2.0,screen_info.center.z);
|
||||
|
||||
// let lower_right = Vec3::new(screen_info.center.x + screen_info.width / 2.0,screen_info.center.y - screen_info.height / 2.0,screen_info.center.z);
|
||||
|
||||
|
||||
let (view, projection) = create_offaxis_matrices(lower_left, lower_right, upper_left, eye, 1000.0f32);
|
||||
|
||||
offaxis.projection_matrix = projection;
|
||||
|
||||
*transform = Transform::from_matrix(view.inverse());
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
pub fn simulate_viewer(mut query: Query<&mut Viewer>,time: Res<Time>) {
|
||||
for mut v in query.iter_mut() {
|
||||
|
||||
//v.position += Vec3::Y * 0.005;
|
||||
v.alpha += 1.5 * time.delta_seconds();
|
||||
|
||||
let radius = 1.0;
|
||||
|
||||
let z_distance = 2.0_f32;
|
||||
|
||||
v.position = Vec3::new(
|
||||
v.alpha.sin() * radius,
|
||||
v.alpha.cos() * radius + 1.0_f32,
|
||||
v.alpha.cos() * radius,
|
||||
z_distance,
|
||||
);
|
||||
|
||||
let vm = Mat4::look_at_rh(v.position, Vec3::ZERO, Vec3::Y);
|
||||
|
||||
println!("{:?}", vm);
|
||||
|
||||
// view matrices should be orientation only
|
||||
let dir = Quat::from_mat4(&vm);
|
||||
|
||||
v.orientation = dir;
|
||||
info!("Viewer {:?}",v.position);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue