This commit is contained in:
Hartmut Seichter 2022-12-14 22:55:26 +01:00
parent d98c0a87fa
commit 714be06192
4 changed files with 147 additions and 128 deletions

View file

@ -1,6 +1,8 @@
use bevy::{prelude::*, transform, math::Vec4Swizzles};
use bevy::{math::Vec4Swizzles, prelude::*, transform};
use crate::{screeninfo::ScreenInfo, offaxis::OffAxisProjection, projection::create_offaxis_matrices};
use crate::{
offaxis::OffAxisProjection, projection::create_offaxis_matrices, screeninfo::ScreenInfo,
};
#[derive(Component, Default)]
pub struct Viewer {
@ -28,38 +30,34 @@ impl Viewer {
}
}
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)| {
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,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_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);
let (view, projection) = create_offaxis_matrices(lower_left, lower_right, upper_left, eye, 1000.0f32);
offaxis.projection_matrix = projection;
offaxis.projection_matrix = projection;
*transform = Transform::from_matrix(view.inverse());
// *transform = Transform::from_translation(eye).looking_at(Vec3::ZERO, Vec3::Y);
info!("Viewer {:?}", viewer.position);
// *transform = Transform::from_translation(eye).looking_at(Vec3::ZERO, Vec3::Y);
});
}
pub fn simulate_viewer(mut query: Query<&mut Viewer>,time: Res<Time>) {
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();
@ -73,6 +71,23 @@ pub fn simulate_viewer(mut query: Query<&mut Viewer>,time: Res<Time>) {
z_distance + v.alpha.sin(),
);
info!("Viewer {:?}",v.position);
// info!("Viewer {:?}", v.position);
}
}
pub fn simulate_viewer_with_keyboard(
mut query: Query<&mut Viewer>,
input: Res<Input<KeyCode>>,
time: Res<Time>,
) {
for mut viewer in query.iter_mut() {
if input.pressed(KeyCode::W) {
viewer.position += Vec3::Z * time.delta_seconds();
} else if (input.pressed(KeyCode::S)) {
viewer.position -= Vec3::Z * time.delta_seconds();
}
}
}