From 899f81eed6c221dce22333ad03704b12d7634a54 Mon Sep 17 00:00:00 2001 From: Sakarias Johansson Date: Sun, 8 Jan 2023 17:51:44 +0100 Subject: =?UTF-8?q?=F0=9F=8C=8D=20Add=20Geometry?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Created a trait for all geometry that has to implement a hit function. Depending on if the ray hits or not it returns an option with the color. - Add support for multiple samples per pixel Current issues: - Using cooperative multitasking which isn't that helpful in this situation since it's like running without async but without overhead. Should switch to rayon. - All data gets copied once per job. Will decide later what to do (copy or put locks and share data between jobs). --- racer-tracer/src/camera.rs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'racer-tracer/src/camera.rs') diff --git a/racer-tracer/src/camera.rs b/racer-tracer/src/camera.rs index 5f0abbb..2c7be12 100644 --- a/racer-tracer/src/camera.rs +++ b/racer-tracer/src/camera.rs @@ -1,4 +1,5 @@ use crate::image::Image; +use crate::ray::Ray; use crate::vec3::Vec3; #[derive(Clone)] @@ -9,7 +10,7 @@ pub struct Camera { pub origin: Vec3, pub horizontal: Vec3, pub vertical: Vec3, - pub lower_left_corner: Vec3, + pub upper_left_corner: Vec3, } impl Camera { @@ -25,10 +26,16 @@ impl Camera { origin, horizontal, vertical, - lower_left_corner: origin + upper_left_corner: origin + vertical / 2.0 - horizontal / 2.0 - - vertical / 2.0 - Vec3::new(0.0, 0.0, focal_length), } } + + pub fn get_ray(&self, u: f64, v: f64) -> Ray { + Ray::new( + self.origin, + self.upper_left_corner + u * self.horizontal - v * self.vertical - self.origin, + ) + } } -- cgit v1.2.3