2022-12-11 12:41:34 +01:00
|
|
|
use bevy::{prelude::*, render::camera::CameraProjectionPlugin, window::PresentMode};
|
2022-12-09 21:30:47 +01:00
|
|
|
|
|
|
|
use crate::screeninfo::ScreenInfo;
|
2022-12-06 21:12:15 +01:00
|
|
|
// use offaxis::{offaxis_camera_setup, OffAxisProjection};
|
2022-12-06 15:44:16 +01:00
|
|
|
|
2022-12-11 12:41:34 +01:00
|
|
|
#[derive(Component, Default)]
|
2022-12-06 15:44:16 +01:00
|
|
|
pub struct Viewer {
|
2022-12-06 21:12:15 +01:00
|
|
|
pub position: Vec3,
|
|
|
|
pub orientation: Quat,
|
2022-12-06 15:44:16 +01:00
|
|
|
|
2022-12-06 21:12:15 +01:00
|
|
|
pub alpha: f32,
|
|
|
|
}
|
2022-12-06 15:44:16 +01:00
|
|
|
|
|
|
|
impl Viewer {
|
2022-12-11 12:41:34 +01:00
|
|
|
pub fn new(position: Vec3) -> Self {
|
2022-12-06 21:12:15 +01:00
|
|
|
Self {
|
|
|
|
position,
|
|
|
|
orientation: Quat::IDENTITY,
|
|
|
|
alpha: 0.0,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn default() -> Self {
|
2022-12-06 15:44:16 +01:00
|
|
|
Self {
|
|
|
|
position: Vec3::ZERO,
|
2022-12-06 21:12:15 +01:00
|
|
|
orientation: Quat::IDENTITY,
|
2022-12-11 12:41:34 +01:00
|
|
|
alpha: 0.0,
|
2022-12-06 15:44:16 +01:00
|
|
|
}
|
|
|
|
}
|
2022-12-06 21:12:15 +01:00
|
|
|
}
|
|
|
|
|
2022-12-11 12:41:34 +01:00
|
|
|
pub fn simulate_viewer(mut query: Query<&mut Viewer>, screen_info: Query<&ScreenInfo>) {
|
|
|
|
for mut v in query.iter_mut() {
|
2022-12-06 21:12:15 +01:00
|
|
|
//v.position += Vec3::Y * 0.005;
|
|
|
|
v.alpha += 0.01;
|
2022-12-07 20:41:17 +01:00
|
|
|
let radius = 1.5;
|
2022-12-09 21:30:47 +01:00
|
|
|
|
|
|
|
let z_distance = 8.0_f32;
|
|
|
|
|
2022-12-11 12:41:34 +01:00
|
|
|
v.position = Vec3::new(
|
|
|
|
v.alpha.sin() * radius,
|
|
|
|
v.alpha.cos() * radius + 1.0_f32,
|
|
|
|
z_distance,
|
|
|
|
);
|
2022-12-07 20:41:17 +01:00
|
|
|
|
|
|
|
let vm = Mat4::look_at_rh(v.position, Vec3::ZERO, Vec3::Y);
|
|
|
|
|
2022-12-11 12:41:34 +01:00
|
|
|
println!("{:?}", vm);
|
2022-12-07 20:41:17 +01:00
|
|
|
|
|
|
|
// view matrices should be orientation only
|
|
|
|
let dir = Quat::from_mat4(&vm);
|
|
|
|
|
|
|
|
v.orientation = dir;
|
2022-12-06 21:12:15 +01:00
|
|
|
}
|
2022-12-11 12:41:34 +01:00
|
|
|
}
|