diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/camera.cpp | 20 | ||||
| -rw-r--r-- | src/main.cpp | 10 |
2 files changed, 29 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; +} diff --git a/src/main.cpp b/src/main.cpp index 19b7b54..f8699af 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -126,6 +126,16 @@ int main() { move_vec = -((input_data*) renderer.compute_shader_buffer.alloc_info.pMappedData)->cam.right.unit() * move_speed; break; } + case KEYS::E: { + ((input_data*) renderer.compute_shader_buffer.alloc_info.pMappedData)->cam.rotate_y(0.001f * delta_time); + reset_accumulation = true; + break; + } + case KEYS::Q: { + ((input_data*) renderer.compute_shader_buffer.alloc_info.pMappedData)->cam.rotate_y(-0.001f * delta_time); + reset_accumulation = true; + break; + } case KEYS::SPACE: { move_vec = ((input_data*) renderer.compute_shader_buffer.alloc_info.pMappedData)->cam.up.unit() * move_speed; break; |
