From 451e94b5fd81589474f882f118a2a6d8852624ea Mon Sep 17 00:00:00 2001 From: ScorpionX90 Date: Thu, 18 Sep 2025 20:06:04 +0200 Subject: [PATCH] backfaces --- gloom-rs/report/exercise2.md | 2 ++ gloom-rs/src/main.rs | 22 +++++++++++----------- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/gloom-rs/report/exercise2.md b/gloom-rs/report/exercise2.md index 22431d4..bceb1ce 100644 --- a/gloom-rs/report/exercise2.md +++ b/gloom-rs/report/exercise2.md @@ -89,6 +89,8 @@ together, it is impossible to observe rotational transformations from only changing one value at a time, starting from the identity matrix. +## Bonus task a) is implemented in code + ## Bonus task b) Applying some perspective to our scene, we see that the smooth interolation qualifier yields a color interpolation which is corrected in terms of perspective. In the below image you can clearly see how the colors are shifted between the smooth and noperspective interpolation models: diff --git a/gloom-rs/src/main.rs b/gloom-rs/src/main.rs index ea6dc13..dc27be3 100644 --- a/gloom-rs/src/main.rs +++ b/gloom-rs/src/main.rs @@ -199,8 +199,11 @@ fn main() { let indices = vec![ 0,1,2, + 0,2,1, 3,4,5, - 6,7,8 + 3,5,4, + 6,7,8, + 6,8,7 ]; let colors = vec![ @@ -292,21 +295,18 @@ fn main() { VirtualKeyCode::Up => { tilt_transform = glm::rotation(-angle_speed, - &glm::vec3(0.0, 1.0, 0.0).cross(&cam_direction)); + &glm::vec3(1.0, 0.0, 0.0)); } VirtualKeyCode::Down => { tilt_transform = glm::rotation(angle_speed, - &glm::vec3(0.0, 1.0, 0.0).cross(&cam_direction)); + &glm::vec3(1.0, 0.0, 0.0)); } VirtualKeyCode::Left => { yaw_transform = glm::rotation(-angle_speed, &glm::vec3(0.0, 1.0, 0.0)); - cam_direction = glm::rotate_vec3( - &cam_direction, -angle_speed, &glm::vec3(0.0, 1.0, 0.0)); + } VirtualKeyCode::Right => { yaw_transform = glm::rotation(angle_speed, &glm::vec3(0.0, 1.0, 0.0)); - cam_direction = glm::rotate_vec3( - &cam_direction, angle_speed, &glm::vec3(0.0, 1.0, 0.0)); } // default handler: @@ -325,10 +325,10 @@ fn main() { // == // Please compute camera transforms here (exercise 2 & 3) motion_transform = glm::identity(); - motion_transform *= glm::translate(&motion_transform, &camera_motion); - motion_transform *= yaw_transform; - motion_transform *= tilt_transform; - transformation = motion_transform * transformation; + motion_transform *= tilt_transform; // local tilt + motion_transform *= glm::translate(&glm::identity(), &camera_motion); // move in world space + transformation = yaw_transform * motion_transform * transformation; + // Reset frame transforms camera_motion = glm::vec3(0.0, 0.0, 0.0);