From 9568b54b870075cac4b1e24950243bad785fea0d Mon Sep 17 00:00:00 2001 From: Teo-CD Date: Sun, 3 Nov 2019 15:31:45 +0100 Subject: [PATCH 1/4] 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; From 5f1cd422ff1179dea2e1c188e3b17e644230e474 Mon Sep 17 00:00:00 2001 From: Teo-CD Date: Sun, 3 Nov 2019 15:32:47 +0100 Subject: [PATCH 2/4] Moved resources to the example directory --- {resources => example/resources}/RAPTOR.off | 0 {resources => example/resources}/RAPTOR.tga | Bin {resources => example/resources}/arbre.tga | Bin {resources => example/resources}/arbre_masque.tga | Bin 4 files changed, 0 insertions(+), 0 deletions(-) rename {resources => example/resources}/RAPTOR.off (100%) rename {resources => example/resources}/RAPTOR.tga (100%) rename {resources => example/resources}/arbre.tga (100%) rename {resources => example/resources}/arbre_masque.tga (100%) diff --git a/resources/RAPTOR.off b/example/resources/RAPTOR.off similarity index 100% rename from resources/RAPTOR.off rename to example/resources/RAPTOR.off diff --git a/resources/RAPTOR.tga b/example/resources/RAPTOR.tga similarity index 100% rename from resources/RAPTOR.tga rename to example/resources/RAPTOR.tga diff --git a/resources/arbre.tga b/example/resources/arbre.tga similarity index 100% rename from resources/arbre.tga rename to example/resources/arbre.tga diff --git a/resources/arbre_masque.tga b/example/resources/arbre_masque.tga similarity index 100% rename from resources/arbre_masque.tga rename to example/resources/arbre_masque.tga From d0b533608a4e293580b8b8fe235cf4dab7571fa2 Mon Sep 17 00:00:00 2001 From: Teo-CD Date: Sun, 3 Nov 2019 15:49:55 +0100 Subject: [PATCH 3/4] Fixed colors of RGBA TGA not being inverted --- src/DataHandling/Texture.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/DataHandling/Texture.cpp b/src/DataHandling/Texture.cpp index 003d030..23bf41e 100644 --- a/src/DataHandling/Texture.cpp +++ b/src/DataHandling/Texture.cpp @@ -117,6 +117,7 @@ bool Texture::load_rgba_tga(const std::string& rgb_filename, const std::string& // Now we have an RGBA image, update color_bits color_bits = 32; + invert_channels(0,2); return true; } From 37e525d6ee02e7a96e802c2f6e1bd0a55bf1d82c Mon Sep 17 00:00:00 2001 From: Teo-CD Date: Sun, 3 Nov 2019 15:50:37 +0100 Subject: [PATCH 4/4] Moved OpenGL texture generation to the Texture class --- example/main.cpp | 8 -------- src/DataHandling/Texture.cpp | 16 ++++++++++++++++ src/DataHandling/Texture.h | 3 +++ 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/example/main.cpp b/example/main.cpp index 0258053..a589260 100644 --- a/example/main.cpp +++ b/example/main.cpp @@ -103,17 +103,9 @@ int main(int argc, char** argv) // Load and generate tree texture tree_texture.load_rgba_tga("resources/arbre.tga","resources/arbre_masque.tga"); - glGenTextures(1,tree_texture.opengl_id); - // TODO : Put in the Texture class - glBindTexture(GL_TEXTURE_2D,tree_texture.opengl_id[0]); - gluBuild2DMipmaps(GL_TEXTURE_2D,GL_RGBA8,tree_texture.width,tree_texture.height,GL_RGBA,GL_UNSIGNED_BYTE,tree_texture.image_data); // Load and generate raptor texture raptor_texture.load_rgb_tga("resources/RAPTOR.tga"); - glGenTextures(1, raptor_texture.opengl_id); - // TODO : Put in the Texture class - glBindTexture(GL_TEXTURE_2D, raptor_texture.opengl_id[0]); - gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGB8, raptor_texture.width, raptor_texture.height, GL_RGB, GL_UNSIGNED_BYTE, raptor_texture.image_data); // Load raptor model raptor.load_ascii_off_file("resources/RAPTOR.off"); diff --git a/src/DataHandling/Texture.cpp b/src/DataHandling/Texture.cpp index 23bf41e..4f64c7b 100644 --- a/src/DataHandling/Texture.cpp +++ b/src/DataHandling/Texture.cpp @@ -73,6 +73,7 @@ bool Texture::load_rgb_tga(const std::string& rgb_filename) { bool return_value = load_tga(rgb_filename,image_data); invert_channels(0,2); + generate_texture(); return return_value; } @@ -118,9 +119,24 @@ bool Texture::load_rgba_tga(const std::string& rgb_filename, const std::string& color_bits = 32; invert_channels(0,2); + generate_texture(); return true; } +void Texture::generate_texture() +{ + glGenTextures(1,opengl_id); + glBindTexture(GL_TEXTURE_2D,opengl_id[0]); + if (color_bits == 24) + { + gluBuild2DMipmaps(GL_TEXTURE_2D,GL_RGB8,width,height,GL_RGB,GL_UNSIGNED_BYTE,image_data); + } + else if (color_bits == 32) + { + gluBuild2DMipmaps(GL_TEXTURE_2D,GL_RGBA8,width,height,GL_RGBA,GL_UNSIGNED_BYTE,image_data); + } +} + void Texture::invert_channels(uint8_t first_channel, uint8_t second_channel) { uint8_t increment = color_bits/8; diff --git a/src/DataHandling/Texture.h b/src/DataHandling/Texture.h index d0c791e..0eed6d6 100644 --- a/src/DataHandling/Texture.h +++ b/src/DataHandling/Texture.h @@ -33,6 +33,9 @@ private: /// Load and RGB TGA image file to an array bool load_tga(const std::string& filename, uint8_t*& data_array); + /// Initialize the texture for OpenGL + void generate_texture(); + void invert_channels(uint8_t first_channel,uint8_t second_channel); };