From 289de08efbf985929b7953eaa7f0627bb2821fcc Mon Sep 17 00:00:00 2001 From: Michael Zhang Date: Tue, 31 Jan 2023 01:48:57 -0600 Subject: [PATCH] 2023-01-30 progress --- assignment-1/src/main.rs | 24 ++++++++++++++++++++---- assignment-1/src/vec3.rs | 11 +++++++++++ 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/assignment-1/src/main.rs b/assignment-1/src/main.rs index dc1df78..4d01571 100644 --- a/assignment-1/src/main.rs +++ b/assignment-1/src/main.rs @@ -1,13 +1,15 @@ mod input_file; mod ray; mod scene_data; -mod view; mod vec3; +mod view; use std::path::PathBuf; use anyhow::Result; use clap::Parser; +use vec3::Vec3; +use view::Rect; use crate::input_file::parse_input_file; @@ -32,10 +34,24 @@ fn main() -> Result<()> { let scene = parse_input_file(&opt.input_path)?; - // Loop through every single pixel of the output file - for (px, py) in (0..scene.image_width).zip(0..scene.image_height) { + // Compute viewing directions + let u = Vec3::cross(scene.view_dir, scene.up_dir).unit(); + let v = Vec3::cross(u, scene.view_dir).unit(); - } + // Compute viewing window corners + // TODO: See slide 101 + // Also need to reverse calculation for d based on hfov + let n = scene.view_dir.unit(); + let d = 1.0; + let view_window = Rect { + upper_left: scene.eye_pos + n * d, // + ... + upper_right: scene.eye_pos + n * d, + lower_left: scene.eye_pos + n * d, + lower_right: scene.eye_pos + n * d, + }; + + // Loop through every single pixel of the output file + for (px, py) in (0..scene.image_width).zip(0..scene.image_height) {} Ok(()) } diff --git a/assignment-1/src/vec3.rs b/assignment-1/src/vec3.rs index 77495da..4c7aee9 100644 --- a/assignment-1/src/vec3.rs +++ b/assignment-1/src/vec3.rs @@ -16,6 +16,7 @@ impl Vec3 { } impl Vec3 { + /// Cross product on floats pub fn cross(u: Self, v: Self) -> Self { Vec3::new( u.y * v.z - u.z * v.y, @@ -23,6 +24,16 @@ impl Vec3 { u.x * v.y - u.y * v.x, ) } + + pub fn norm(&self) -> T { + (self.x.powi(2) + self.y.powi(2) + self.z.powi(2)).sqrt() + } + + /// Normalize + pub fn unit(&self) -> Self { + let norm = self.norm(); + Vec3::new(self.x / norm, self.y / norm, self.z / norm) + } } /// Vector addition