diff options
| author | ladevieq <ladevie.quentin@gmail.com> | 2021-05-23 13:32:02 +0200 |
|---|---|---|
| committer | ladevieq <ladevie.quentin@gmail.com> | 2021-05-23 13:32:02 +0200 |
| commit | 2c07c0b7df2b13cd5deea8233e1c4eb61a85a766 (patch) | |
| tree | 2133f08ab5ec84ee8013b43fd288120e1eaf85b7 /src/camera.cpp | |
| parent | b715df2c21dbb8656fc01d5a64605ac18cb5c6e4 (diff) | |
Naive BVH working + camera simple camera rotation
Diffstat (limited to 'src/camera.cpp')
| -rw-r--r-- | src/camera.cpp | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/src/camera.cpp b/src/camera.cpp index ff09e20..917cb4e 100644 --- a/src/camera.cpp +++ b/src/camera.cpp @@ -10,7 +10,7 @@ camera::camera( float aspect_ratio, float aperture, float focus_dist - ) : position(position), lens_radius(aperture / 2.0), fov(v_fov), focus_distance(focus_dist) { + ) : position(position), lens_radius(aperture / 2.0), fov(v_fov), focus_distance(focus_dist), aspect_ratio(aspect_ratio) { forward = (target - position).unit(); right = forward.cross(vec3{ 0.0, 1.0, 0.0 }).unit(); @@ -27,6 +27,8 @@ camera::camera( } void camera::set_aspect_ratio(float aspect_ratio) { + aspect_ratio = aspect_ratio; + auto h = tan(deg_to_rad(fov) / 2.0); auto viewport_height = 2.0 * h; auto viewport_width = viewport_height * aspect_ratio; @@ -41,3 +43,19 @@ void camera::move(vec3 v) { position += v; first_pixel = position - horizontal / 2.0 - vertical / 2.0 + focus_distance * forward; } + +void camera::rotate_y(float theta) { + forward.x = forward.x * cos(theta) - forward.z * sin(theta); + forward.z = forward.x * sin(theta) + forward.z * cos(theta); + + right = forward.cross(vec3{ 0.0, 1.0, 0.0 }).unit(); + up = right.cross(forward).unit(); + + auto h = tan(deg_to_rad(fov) / 2.0); + auto viewport_height = 2.0 * h; + auto viewport_width = viewport_height * aspect_ratio; + + horizontal = focus_distance * viewport_width * right; + vertical = focus_distance * viewport_height * up; + first_pixel = position - horizontal / 2.0 - vertical / 2.0 + focus_distance * forward; +} |
