2023-01-30 progress
This commit is contained in:
parent
b6c6ac9e35
commit
289de08efb
2 changed files with 31 additions and 4 deletions
|
@ -1,13 +1,15 @@
|
||||||
mod input_file;
|
mod input_file;
|
||||||
mod ray;
|
mod ray;
|
||||||
mod scene_data;
|
mod scene_data;
|
||||||
mod view;
|
|
||||||
mod vec3;
|
mod vec3;
|
||||||
|
mod view;
|
||||||
|
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
|
use vec3::Vec3;
|
||||||
|
use view::Rect;
|
||||||
|
|
||||||
use crate::input_file::parse_input_file;
|
use crate::input_file::parse_input_file;
|
||||||
|
|
||||||
|
@ -32,10 +34,24 @@ fn main() -> Result<()> {
|
||||||
|
|
||||||
let scene = parse_input_file(&opt.input_path)?;
|
let scene = parse_input_file(&opt.input_path)?;
|
||||||
|
|
||||||
// Loop through every single pixel of the output file
|
// Compute viewing directions
|
||||||
for (px, py) in (0..scene.image_width).zip(0..scene.image_height) {
|
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(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,6 +16,7 @@ impl<T> Vec3<T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: Float> Vec3<T> {
|
impl<T: Float> Vec3<T> {
|
||||||
|
/// Cross product on floats
|
||||||
pub fn cross(u: Self, v: Self) -> Self {
|
pub fn cross(u: Self, v: Self) -> Self {
|
||||||
Vec3::new(
|
Vec3::new(
|
||||||
u.y * v.z - u.z * v.y,
|
u.y * v.z - u.z * v.y,
|
||||||
|
@ -23,6 +24,16 @@ impl<T: Float> Vec3<T> {
|
||||||
u.x * v.y - u.y * v.x,
|
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
|
/// Vector addition
|
||||||
|
|
Loading…
Reference in a new issue