X-Git-Url: https://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fcamera.cpp;h=f4e3171b01fb2697062cbb1bea6180f00a9ec109;hb=e53a0e2e711a7d8bd9b0ddacd1360aa14370643f;hp=4bbb0f12f0fadb6955bf230d99a88fa116d65355;hpb=41e0223ec090142bf03066f4f5fc1f5005095072;p=blank.git diff --git a/src/camera.cpp b/src/camera.cpp index 4bbb0f1..f4e3171 100644 --- a/src/camera.cpp +++ b/src/camera.cpp @@ -1,68 +1,54 @@ #include "camera.hpp" +#include "geometry.hpp" + #include #include namespace blank { -Camera::Camera() -: FPSController() -, fov(45.0f) +Camera::Camera() noexcept +: fov(PI_0p25) , aspect(1.0f) , near_clip(0.1f) -, far_clip(100.0f) -, projection(glm::perspective(fov, aspect, near_clip, far_clip)) -, view(glm::inverse(Transform())) { +, far_clip(256.0f) +, projection(glm::perspective(fov, aspect, near_clip, far_clip)) { } -void Camera::Viewport(int width, int height) { +void Camera::Viewport(int width, int height) noexcept { Viewport(0, 0, width, height); } -void Camera::Viewport(int x, int y, int width, int height) { +void Camera::Viewport(int x, int y, int width, int height) noexcept { glViewport(x, y, width, height); Aspect(width, height); } -void Camera::FOV(float f) { +void Camera::FOV(float f) noexcept { fov = f; UpdateProjection(); } -void Camera::Aspect(float r) { +void Camera::Aspect(float r) noexcept { aspect = r; UpdateProjection(); } -void Camera::Aspect(float w, float h) { +void Camera::Aspect(float w, float h) noexcept { Aspect(w / h); } -void Camera::Clip(float near, float far) { +void Camera::Clip(float near, float far) noexcept { near_clip = near; far_clip = far; UpdateProjection(); } -Ray Camera::Aim() const { - const glm::mat4 inv_vp(glm::inverse(projection * view)); - glm::vec4 from = inv_vp * glm::vec4(0.0f, 0.0f, -1.0f, 1.0f); - from /= from.w; - glm::vec4 to = inv_vp * glm::vec4(0.0f, 0.0f, 1.0f, 1.0f); - to /= to.w; - return Ray{ glm::vec3(from), glm::normalize(glm::vec3(to - from)) }; -} - - -void Camera::Update(int dt) { - FPSController::Update(dt); - view = glm::inverse(Transform()); -} -void Camera::UpdateProjection() { +void Camera::UpdateProjection() noexcept { projection = glm::perspective(fov, aspect, near_clip, far_clip); }