summaryrefslogtreecommitdiff
path: root/racer-tracer/src/camera.rs
diff options
context:
space:
mode:
Diffstat (limited to 'racer-tracer/src/camera.rs')
-rw-r--r--racer-tracer/src/camera.rs34
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),
+ }
+ }
+}