diff --git a/src/bin/wireframe/main.rs b/src/bin/wireframe/main.rs index afa4525..60f9a28 100644 --- a/src/bin/wireframe/main.rs +++ b/src/bin/wireframe/main.rs @@ -25,6 +25,7 @@ fn prepare_scene(device: &wgpu::Device) -> Vec { .collect() } +#[cfg(any())] mod camctl { use glam::{vec3, Mat4, Quat, Vec3}; @@ -58,6 +59,39 @@ mod camctl { } } +mod camctl { + use glam::{vec3, Mat4, Quat, Vec3}; + + pub struct CameraLocation { + pos: Vec3, + rot: Vec3, + } + + fn rot_quat(rot: Vec3) -> Quat { + Quat::from_euler(glam::EulerRot::XYZ, rot.z, rot.y, rot.x) + } + + impl CameraLocation { + pub fn new() -> CameraLocation { + let rot = vec3(std::f32::consts::FRAC_PI_4, 0., 0.); + let pos = rot_quat(rot) * vec3(-200., 0., 50.); + CameraLocation { pos, rot } + } + + pub fn view_mtx(&self) -> Mat4 { + Mat4::from_quat(rot_quat(-self.rot)) * Mat4::from_translation(-self.pos) + } + + pub fn move_rel(&mut self, offset: Vec3) { + self.pos += rot_quat(vec3(self.rot.x, 0., 0.)) * offset; + } + + pub fn rotate_rel_ypr(&mut self, ypr: Vec3) { + self.rot += ypr; + } + } +} + mod keyctl { use std::{collections::HashSet, iter::Sum}; use winit::{event::ElementState, keyboard::PhysicalKey}; @@ -101,6 +135,8 @@ static KEYS_MOVE: &'static [(PhysicalKey, Vec3)] = &[ (PhysicalKey::Code(KeyCode::KeyD), vec3(0., -1., 0.)), (PhysicalKey::Code(KeyCode::KeyE), vec3(0., 0., 1.)), (PhysicalKey::Code(KeyCode::KeyQ), vec3(0., 0., -1.)), + (PhysicalKey::Code(KeyCode::Space), vec3(0., 0., 1.)), + (PhysicalKey::Code(KeyCode::ShiftLeft), vec3(0., 0., -1.)), ]; static KEYS_ROTATE: &'static [(PhysicalKey, Vec3)] = &[