diff options
author | Julian T <julian@jtle.dk> | 2021-02-03 14:23:14 +0100 |
---|---|---|
committer | Julian T <julian@jtle.dk> | 2021-02-03 14:23:14 +0100 |
commit | f02aabd4db7232f927622b87ea885491e6651b44 (patch) | |
tree | 0a219e2f5b65edd7cead6ff751058a2ec7431ab1 /src/camera/camera.rs | |
parent | 2b4adacea3c76b8b33dc5f50d296dd4a61107c16 (diff) |
Work on camera implementation using Transformationscamera-using-transform
Not sure if this is really neccesary, will take that later, now it is
saved on this commit.
The reason it ditched it is that it requires the ability to inverse
matrixes, which is really complicated
Diffstat (limited to 'src/camera/camera.rs')
-rw-r--r-- | src/camera/camera.rs | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/src/camera/camera.rs b/src/camera/camera.rs new file mode 100644 index 0000000..102e57b --- /dev/null +++ b/src/camera/camera.rs @@ -0,0 +1,40 @@ +//! Implements ray generation +//! +//! Rays are generated by transforming between different spaces summed below. +//! +//! - *World space*: Where objects are located in the scene, this will be 3d coordinates +//! - *Camera space*: Originated at the origin of the camera, with z mapped to the viewing +//! direction +//! +//! Camera space will be represented in different ways: +//! - *Screen space*: Everything in the screen space is projected onto the film, when z=0 this will +//! correspond +//! - *Normalized Device Coordinates(NDC) space*: Is defined as (0, 0, 0) as the upper-left corner of +//! the film, and (1, 1, 0) to be the bottom right corner. +//! - *Raster space*: Same as NDC space but, (1, 1, 0) is mapped to (width, height, 0) +//! +//! More in depth description is in pbr-book chapter 6 +use crate::Float; +use crate::core::{Transform, Ray, Vector2i, Bound2f}; + +/// General implementation for all projective based cameras +struct ProjectiveCamera { + cam2wor: Transform, + cam2scr: Transform, +} + +impl ProjectiveCamera { + fn new(cam2wor: Transform, cam2scr: Transform, resolution: &Vector2i, screenwindow: &Bound2f) -> Self { + let screensize = screenwindow.diagonal(); + // Calculate the conversion from screen space to raster space + let scr2ras = Transform::new_scale(resolution.x as Float, resolution.y as Float, 1.0) * + Transform::new_scale(1.0 / (screensize.x), 1.0 / (screensize.y), 1.0) * + Transform::new_translate(-screenwindow.min.x, -screenwindow.min.y, 0.0); + let ras2scr = + + Self { + cam2wor, + cam2scr, + } + } +} |