From 9568b54b870075cac4b1e24950243bad785fea0d Mon Sep 17 00:00:00 2001 From: Teo-CD Date: Sun, 3 Nov 2019 15:31:45 +0100 Subject: [PATCH] Added getters for camera properties Added world translation for camera Renamed previous translation to local_translate --- example/main.cpp | 12 ++++++------ src/Camera.cpp | 21 ++++++++++++++++++++- src/Camera.h | 9 ++++++++- 3 files changed, 34 insertions(+), 8 deletions(-) diff --git a/example/main.cpp b/example/main.cpp index fd68134..0258053 100644 --- a/example/main.cpp +++ b/example/main.cpp @@ -36,30 +36,30 @@ void manage_inputs() if (InputStatus::is_special_key_pressed(GLUT_KEY_RIGHT)) { timer_ticks += 5; - OGLE::camera.translate({0,0,0.1}); + OGLE::camera.local_translate({0, 0, 0.1}); } if (InputStatus::is_special_key_pressed(GLUT_KEY_LEFT)) { timer_ticks -= 5; - OGLE::camera.translate({0,0,-0.1}); + OGLE::camera.local_translate({0, 0, -0.1}); } if (InputStatus::is_key_pressed(' ')) { - OGLE::camera.translate({0,0.1,0}); + OGLE::camera.local_translate({0, 0.1, 0}); } if (InputStatus::is_special_key_pressed(GLUT_KEY_PAGE_DOWN)) { - OGLE::camera.translate({0,-0.1,0}); + OGLE::camera.local_translate({0, -0.1, 0}); } if (InputStatus::is_special_key_pressed(GLUT_KEY_UP)) { - OGLE::camera.translate({0.1,0,0}); + OGLE::camera.local_translate({0.1, 0, 0}); } if (InputStatus::is_special_key_pressed(GLUT_KEY_DOWN)) { - OGLE::camera.translate({-0.1,0,0}); + OGLE::camera.local_translate({-0.1, 0, 0}); } // Get mouse delta since last frame diff --git a/src/Camera.cpp b/src/Camera.cpp index f1d66b9..ea51a3a 100644 --- a/src/Camera.cpp +++ b/src/Camera.cpp @@ -17,7 +17,11 @@ Camera::Camera(const Vec3d& eye_pos, const Vec3d& look_direction, const Vec3d& u compute_base_change(); } -void Camera::translate(const Vec3d& translation) +void Camera::translate(const Vec3d &translation) { + eye = eye + translation; +} + +void Camera::local_translate(const Vec3d& translation) { eye = eye + translation * rotation_quaternion; } @@ -55,6 +59,21 @@ void Camera::set_position(const Vec3d& eye_pos) gaze = eye_pos; } +const Vec3d& Camera::get_eyepos() const +{ + return eye; +} + +const Vec3d& Camera::get_gaze() const +{ + return gaze; +} + +const Vec3d& Camera::get_gazeup() const +{ + return gaze_up; +} + void Camera::compute_base_change() { // Third vector of the base, should already be normalized diff --git a/src/Camera.h b/src/Camera.h index b6f1c38..d05cdc1 100644 --- a/src/Camera.h +++ b/src/Camera.h @@ -15,9 +15,12 @@ class Camera { public: Camera(const Vec3d& eye_pos,const Vec3d& look_direction,const Vec3d& up_vector); + /// Translates the camera according to the world axises. + /// \param translation Translation in the world coordinates system. + void translate(const Vec3d& translation); /// Translates the camera relative to its current position and look direction. /// \param translation Translation where x is pointing in the direction of vision. - void translate(const Vec3d& translation); + void local_translate(const Vec3d& translation); /// Rotates the gaze around its local x and z but around global y, relatively to the current orientation. /// This is to provide a coherent movement in regards to mouse movement. /// \param rotation Angles are radians to rotate about each axis. @@ -27,6 +30,10 @@ public: void look(); void set_position(const Vec3d& eye_pos); + + const Vec3d& get_eyepos() const; + const Vec3d& get_gaze() const; + const Vec3d& get_gazeup() const; private: Vec3d eye; Vec3d gaze;