]> git.localhorst.tv Git - blank.git/blobdiff - src/camera.cpp
remove unused (explicit) destructors
[blank.git] / src / camera.cpp
index 8a3a8a1bfe3b7559b8d4c1cd42ee8c4adaa85933..c5283bd7f77bf86729b688342265dc4919bab47f 100644 (file)
@@ -13,14 +13,11 @@ Camera::Camera()
 , near_clip(0.1f)
 , far_clip(100.0f)
 , projection(glm::perspective(fov, aspect, near_clip, far_clip))
+, view(glm::inverse(Transform()))
 , vp(projection) {
 
 }
 
-Camera::~Camera() {
-
-}
-
 
 void Camera::Viewport(int width, int height) {
        Viewport(0, 0, width, height);
@@ -51,10 +48,20 @@ void Camera::Clip(float near, float far) {
        UpdateProjection();
 }
 
+Ray Camera::Aim() const {
+       const glm::mat4 inv_vp(glm::inverse(vp));
+       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);
-       vp = projection * glm::inverse(Transform());
+       view = glm::inverse(Transform());
+       vp = projection * view;
 }
 
 void Camera::UpdateProjection() {