Now using Camera to generate rays in test scene.
This commit is contained in:
parent
7c5c2e4308
commit
d25f8308a2
28
src/main.rs
28
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));
|
||||
|
|
|
@ -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`.
|
||||
|
|
Loading…
Reference in New Issue
Block a user