summaryrefslogtreecommitdiff
path: root/racer-tracer/src/camera.rs
diff options
context:
space:
mode:
authorSakarias Johansson <sakarias.johansson@goodbyekansas.com>2023-01-08 17:51:44 +0100
committerSakarias Johansson <sakarias.johansson@goodbyekansas.com>2023-01-08 17:51:44 +0100
commit899f81eed6c221dce22333ad03704b12d7634a54 (patch)
treee9ea6b377bada412629341e666ae5d2eb929420a /racer-tracer/src/camera.rs
parent928b4191bf5a0d27da6d680ccaade7f94860359e (diff)
downloadracer-tracer-899f81eed6c221dce22333ad03704b12d7634a54.tar.gz
racer-tracer-899f81eed6c221dce22333ad03704b12d7634a54.tar.xz
racer-tracer-899f81eed6c221dce22333ad03704b12d7634a54.zip
🌍 Add Geometry
- 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).
Diffstat (limited to 'racer-tracer/src/camera.rs')
-rw-r--r--racer-tracer/src/camera.rs13
1 files changed, 10 insertions, 3 deletions
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,
+ )
+ }
}