diff options
| author | Sakarias Johansson <sakarias.johansson@goodbyekansas.com> | 2023-01-06 22:59:27 +0100 |
|---|---|---|
| committer | Sakarias Johansson <sakarias.johansson@goodbyekansas.com> | 2023-01-06 22:59:27 +0100 |
| commit | 928b4191bf5a0d27da6d680ccaade7f94860359e (patch) | |
| tree | b2c1e301c1c5c7b5d8cb9a92cc9d4c925e54a7b9 /racer-tracer/src/camera.rs | |
| parent | 372bc5b09c50cf2440e8f7762dd260cefd7bba7f (diff) | |
| download | racer-tracer-928b4191bf5a0d27da6d680ccaade7f94860359e.tar.gz racer-tracer-928b4191bf5a0d27da6d680ccaade7f94860359e.tar.xz racer-tracer-928b4191bf5a0d27da6d680ccaade7f94860359e.zip | |
☁ Add sky
Diffstat (limited to 'racer-tracer/src/camera.rs')
| -rw-r--r-- | racer-tracer/src/camera.rs | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/racer-tracer/src/camera.rs b/racer-tracer/src/camera.rs new file mode 100644 index 0000000..5f0abbb --- /dev/null +++ b/racer-tracer/src/camera.rs @@ -0,0 +1,34 @@ +use crate::image::Image; +use crate::vec3::Vec3; + +#[derive(Clone)] +pub struct Camera { + pub viewport_height: f64, + pub viewport_width: f64, + pub focal_length: f64, + pub origin: Vec3, + pub horizontal: Vec3, + pub vertical: Vec3, + pub lower_left_corner: Vec3, +} + +impl Camera { + pub fn new(image: &Image, viewport_height: f64, focal_length: f64) -> Camera { + let viewport_width = image.aspect_ratio * viewport_height; + let origin = Vec3::new(0.0, 0.0, 0.0); + let horizontal = Vec3::new(viewport_width, 0.0, 0.0); + let vertical = Vec3::new(0.0, viewport_height, 0.0); + Camera { + viewport_height, + viewport_width, + focal_length, + origin, + horizontal, + vertical, + lower_left_corner: origin + - horizontal / 2.0 + - vertical / 2.0 + - Vec3::new(0.0, 0.0, focal_length), + } + } +} |
