From 675d9f837d1753d40f7f259c9b3f93d1629ad4b5 Mon Sep 17 00:00:00 2001 From: numzero Date: Sun, 21 Apr 2024 20:17:58 +0300 Subject: [PATCH] Extract yaw-pitch-roll processing into a function --- src/main.rs | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/src/main.rs b/src/main.rs index 2ed15ce..eb0ab86 100644 --- a/src/main.rs +++ b/src/main.rs @@ -38,6 +38,23 @@ impl Image { } } +fn ypr_to_mat(ypr: Vec3) -> Mat3 { + let Vec3 { x: yaw, y: pitch, z: roll } = ypr; + let m_roll = mat3( + roll.cos(), roll.sin(), 0.0, + -roll.sin(), roll.cos(), 0.0, + 0.0, 0.0, 1.0); + let m_yaw = mat3( + yaw.cos(), 0.0, yaw.sin(), + 0.0, 1.0, 0.0, + -yaw.sin(), 0.0, yaw.cos()); + let m_pitch = mat3( + 1.0, 0.0, 0.0, + 0.0, pitch.cos(), -pitch.sin(), + 0.0, pitch.sin(), pitch.cos()); + m_roll * m_pitch * m_yaw +} + fn main() -> io::Result<()> { let args: Vec = env::args().collect(); let mesh = { @@ -50,22 +67,7 @@ fn main() -> io::Result<()> { h: H, data: vec![0; (3 * W * H) as usize], }; - let yaw = PI / 4.0; - let pitch = PI / 6.0; - let roll = 0.0f32; - let m_roll = mat3( - roll.cos(), roll.sin(), 0.0, - -roll.sin(), roll.cos(), 0.0, - 0.0, 0.0, 1.0); - let m_yaw = mat3( - -yaw.cos(), 0.0, yaw.sin(), - 0.0, 1.0, 0.0, - -yaw.sin(), 0.0, -yaw.cos()); - let m_pitch = mat3( - 1.0, 0.0, 0.0, - 0.0, pitch.cos(), pitch.sin(), - 0.0, -pitch.sin(), pitch.cos()); - let m_view = m_roll * m_pitch * m_yaw; + let m_view = ypr_to_mat(vec3(135.0 * PI / 180.0, -30.0 * PI / 180.0, 0.0f32)); let m_camera = transpose(&m_view); let img_size = vec2(W as f32, H as f32); for y in 0..H {