From d25f8308a2404fb88ff7fcb8ad89b9ccef96de3f Mon Sep 17 00:00:00 2001 From: Nathan Vegdahl Date: Sat, 2 Jan 2016 21:23:17 -0800 Subject: [PATCH] Now using Camera to generate rays in test scene. --- src/main.rs | 28 ++++++++++++++++------------ src/math/matrix.rs | 11 ++++++++++- 2 files changed, 26 insertions(+), 13 deletions(-) diff --git a/src/main.rs b/src/main.rs index a64d228..b52d641 100644 --- a/src/main.rs +++ b/src/main.rs @@ -20,9 +20,10 @@ use std::path::Path; use docopt::Docopt; use image::Image; -use math::{Point, Vector, fast_logit}; +use math::{Point, Matrix4x4, fast_logit}; use ray::Ray; use bbox::BBox; +use camera::Camera; // ---------------------------------------------------------------- @@ -119,6 +120,11 @@ fn main() { }); println!("Scene built."); + let cam = Camera::new(vec![Matrix4x4::from_location(Point::new(256.0, 256.0, -1024.0))], + vec![0.785], + vec![20.0], + vec![1026.0]); + let mut rays = Vec::new(); let mut isects = Vec::new(); @@ -132,17 +138,15 @@ fn main() { rays.clear(); isects.clear(); for si in 0..samples_per_pixel { - let mut ray = Ray::new(Point::new(0.5 + x as f32 + - fast_logit(halton::sample(0, - offset + si as u32), - 1.5), - 0.5 + y as f32 + - fast_logit(halton::sample(3, - offset + si as u32), - 1.5), - 0.0), - Vector::new(0.0, 0.0, 1.0), - 0.0); + let mut ray = { + let filter_x = fast_logit(halton::sample(3, offset + si as u32), 1.5); + let filter_y = fast_logit(halton::sample(4, offset + si as u32), 1.5); + cam.generate_ray((x as f32 + filter_x) / 512.0 - 0.5, + (y as f32 + filter_y) / 512.0 - 0.5, + halton::sample(0, offset + si as u32), + halton::sample(1, offset + si as u32), + halton::sample(2, offset + si as u32)) + }; ray.id = si as u32; rays.push(ray); isects.push((false, 0.0, 0.0)); diff --git a/src/math/matrix.rs b/src/math/matrix.rs index f3a85dd..58ea061 100644 --- a/src/math/matrix.rs +++ b/src/math/matrix.rs @@ -6,7 +6,7 @@ use std::ops::{Index, IndexMut, Mul}; use float4::Float4; use lerp::Lerp; - +use super::Point; /// A 4x4 matrix, used for transforms @@ -57,6 +57,15 @@ impl Matrix4x4 { } } + pub fn from_location(loc: Point) -> Matrix4x4 { + Matrix4x4 { + values: [Float4::new(1.0, 0.0, 0.0, loc[0]), + Float4::new(0.0, 1.0, 0.0, loc[1]), + Float4::new(0.0, 0.0, 1.0, loc[2]), + Float4::new(0.0, 0.0, 0.0, 1.0)], + } + } + /// Returns whether the matrices are approximately equal to each other. /// Each corresponding element in the matrices cannot have a relative error /// exceeding `epsilon`.