diff options
Diffstat (limited to 'src/camera.cpp')
| -rw-r--r-- | src/camera.cpp | 27 |
1 files changed, 9 insertions, 18 deletions
diff --git a/src/camera.cpp b/src/camera.cpp index 908ba09..e9e5f60 100644 --- a/src/camera.cpp +++ b/src/camera.cpp @@ -10,27 +10,20 @@ camera::camera( float aspect_ratio, float aperture, float focus_dist - ) : position(position), lens_radius(aperture / 2.0), fov(v_fov), focus_distance(focus_dist), aspect_ratio(aspect_ratio) { + ) : position(position), lens_radius(aperture / 2.f), fov(v_fov), focus_distance(focus_dist) { forward = (target - position).normalize(); right = forward.cross(vec3{ 0.0, 1.0, 0.0 }).normalize(); up = right.cross(forward).normalize(); - auto h = tan(deg_to_rad(fov) / 2.0); - auto viewport_height = 2.0 * h; - auto viewport_width = viewport_height * aspect_ratio; - - horizontal = focus_dist * viewport_width * right; - vertical = focus_dist * viewport_height * up; - - first_pixel = position - horizontal / 2.0 - vertical / 2.0 + focus_distance * forward; + set_aspect_ratio(aspect_ratio); } -void camera::set_aspect_ratio(float aspect_ratio) { - aspect_ratio = aspect_ratio; +void camera::set_aspect_ratio(float ratio) { + aspect_ratio = ratio; - auto h = tan(deg_to_rad(fov) / 2.0); - auto viewport_height = 2.0 * h; + auto h = tan(deg_to_rad(fov) / 2.f); + auto viewport_height = 2.f * h; auto viewport_width = viewport_height * aspect_ratio; horizontal = focus_distance * viewport_width * right; @@ -39,7 +32,7 @@ void camera::set_aspect_ratio(float aspect_ratio) { first_pixel = position - horizontal / 2.0 - vertical / 2.0 + focus_distance * forward; } -void camera::move(vec3 v) { +void camera::move(const vec3& v) { position += v; first_pixel = position - horizontal / 2.0 - vertical / 2.0 + focus_distance * forward; } @@ -52,11 +45,9 @@ void camera::rotate_y(float theta) { right = forward.cross(vec3{ 0.0, 1.0, 0.0 }).normalize(); up = right.cross(forward).normalize(); - auto h = tan(deg_to_rad(fov) / 2.0); - auto viewport_height = 2.0 * h; - auto viewport_width = viewport_height * aspect_ratio; + auto h = tan(deg_to_rad(fov) / 2.f); + auto viewport_height = 2.f * h; - horizontal = focus_distance * viewport_width * right; vertical = focus_distance * viewport_height * up; first_pixel = position - horizontal / 2.0 - vertical / 2.0 + focus_distance * forward; } |
