From 9fed028f9f935c59c334c9c39cdb20c17fe6fe31 Mon Sep 17 00:00:00 2001
From: Sebastian Gaida <gaida@ca-digit.com>
Date: Thu, 3 Jun 2021 12:48:03 +0200
Subject: [PATCH] [#42] add const to getter and remove redundant function

---
 modules/camera/include/vkcv/camera/Camera.hpp       | 13 ++-----------
 .../camera/include/vkcv/camera/TrackballCamera.hpp  |  6 +++---
 modules/camera/src/vkcv/camera/Camera.cpp           | 13 ++-----------
 modules/camera/src/vkcv/camera/TrackballCamera.cpp  |  6 +++---
 4 files changed, 10 insertions(+), 28 deletions(-)

diff --git a/modules/camera/include/vkcv/camera/Camera.hpp b/modules/camera/include/vkcv/camera/Camera.hpp
index f84cf2c2..999ad35c 100644
--- a/modules/camera/include/vkcv/camera/Camera.hpp
+++ b/modules/camera/include/vkcv/camera/Camera.hpp
@@ -64,16 +64,7 @@ namespace vkcv {
          * @brief Gets the view matrix of the camera
          * @return The view matrix of the camera
          */
-        const glm::mat4 getView() const;
-        
-        /**
-         * @brief Gets the view object containing the @p x, @p y, @p z axis in camera space, and the camera position @p pos in world space
-         * @param x The horizontal axis in camera space
-         * @param y The vertical axis in camera space
-         * @param z The depth axis in camera space
-         * @param pos The position of the camera in world space
-         */
-        void getView(glm::vec3 &x, glm::vec3 &y, glm::vec3 &z, glm::vec3 &pos);
+        const glm::mat4& getView();
 
         /**
          * @brief Updates the view matrix of the camera with respect to @p deltaTime
@@ -94,7 +85,7 @@ namespace vkcv {
          * @brief Gets the current projection of the camera
          * @return The current projection matrix
          */
-        const glm::mat4& getProjection() const;
+        const glm::mat4& getProjection();
 
         /**
          * @brief Sets the projection matrix of the camera to @p projection
diff --git a/modules/camera/include/vkcv/camera/TrackballCamera.hpp b/modules/camera/include/vkcv/camera/TrackballCamera.hpp
index a15eae3d..21f79f9d 100644
--- a/modules/camera/include/vkcv/camera/TrackballCamera.hpp
+++ b/modules/camera/include/vkcv/camera/TrackballCamera.hpp
@@ -26,19 +26,19 @@ namespace vkcv {
          * @brief Gets the radius of the trackball camera that specifies the distance of the trackball camera to the center point
          * @return The radius of the trackball camera
          */
-        float getRadius();
+        float getRadius() const;
 
         /**
          * @brief Sets the current radius of the trackball camera to @p radius
          * @param[in] radius The new radius of the trackball camera
          */
-        void setRadius(float radius);
+        void setRadius( const float radius);
 
         /**
          * @brief Gets the center point the trackball camera is looking at
          * @return The center point of the trackball camera
          */
-        glm::vec3& getCenter();
+        const glm::vec3& getCenter();
 
         /**
          * @brief Sets the current center point of the trackball camera to @p center
diff --git a/modules/camera/src/vkcv/camera/Camera.cpp b/modules/camera/src/vkcv/camera/Camera.cpp
index 908d681a..2f7ccf93 100644
--- a/modules/camera/src/vkcv/camera/Camera.cpp
+++ b/modules/camera/src/vkcv/camera/Camera.cpp
@@ -34,26 +34,17 @@ namespace vkcv {
         return m_view = glm::lookAt(m_position, m_position + getFront() , m_up);
     }
 
-    void Camera::getView(glm::vec3 &x, glm::vec3 &y, glm::vec3 &z, glm::vec3 &pos){
-        x = glm::vec3( glm::row(m_view, 0));
-        y = glm::vec3( glm::row(m_view, 1));
-        z = glm::vec3( glm::row(m_view, 2));
-        pos = glm::vec3( glm::column(m_view, 3));
-        glm::mat3 mat_inv = glm::inverse( glm::mat3(m_view));
-        pos = -mat_inv * pos;
-    }
-
     void Camera::getNearFar( float &near, float &far) const {
         near = m_near;
         far = m_far;
     }
 
 
-    const glm::mat4 Camera::getView() const {
+    const glm::mat4& Camera::getView() {
         return m_view;
     }
 
-    const glm::mat4& Camera::getProjection() const {
+    const glm::mat4& Camera::getProjection() {
         return m_projection;
     }
 
diff --git a/modules/camera/src/vkcv/camera/TrackballCamera.cpp b/modules/camera/src/vkcv/camera/TrackballCamera.cpp
index c7a95307..e5ee35f5 100644
--- a/modules/camera/src/vkcv/camera/TrackballCamera.cpp
+++ b/modules/camera/src/vkcv/camera/TrackballCamera.cpp
@@ -14,18 +14,18 @@ namespace vkcv {
 
     TrackballCamera::~TrackballCamera() = default;
 
-    float TrackballCamera::getRadius() {
+    float TrackballCamera::getRadius() const{
         return m_radius;
     }
 
-    void TrackballCamera::setRadius(float radius) {
+    void TrackballCamera::setRadius( const float radius) {
         if (m_radius < 0.1f) {
             m_radius = 0.1f;
         }
         m_radius = radius;
     }
 
-    glm::vec3& TrackballCamera::getCenter() {
+    const glm::vec3& TrackballCamera::getCenter() {
         return m_center;
     }
 
-- 
GitLab