From 438b219d0ae181fb185e1d2ed84bee743360e9bc Mon Sep 17 00:00:00 2001 From: Menno Date: Tue, 18 May 2021 12:43:22 +0200 Subject: [PATCH] [EDIT] code style guide finished --- src/entities/Camera.cpp | 12 ++++++------ src/entities/Camera.h | 8 ++++---- src/entities/Entity.cpp | 8 +++----- src/entities/Entity.h | 22 +++++++++++----------- src/main.cpp | 10 +++++----- src/models/Model.h | 16 ++++++++-------- src/renderEngine/Loader.cpp | 20 ++++++++++---------- src/renderEngine/Loader.h | 2 +- src/renderEngine/Renderer.cpp | 17 ++++++++--------- src/renderEngine/Renderer.h | 2 +- src/renderEngine/obj_loader.h | 2 +- src/shaders/static_shader.cpp | 2 +- src/shaders/static_shader.h | 2 +- src/toolbox/{math.cpp => toolbox.cpp} | 10 +++++----- src/toolbox/{math.h => toolbox.h} | 2 +- wk2_fps.vcxproj | 22 +++++++++++----------- wk2_fps.vcxproj.filters | 12 ++++++------ 17 files changed, 83 insertions(+), 86 deletions(-) rename src/toolbox/{math.cpp => toolbox.cpp} (68%) rename src/toolbox/{math.h => toolbox.h} (89%) diff --git a/src/entities/Camera.cpp b/src/entities/Camera.cpp index 03f4330..eb4ecb4 100644 --- a/src/entities/Camera.cpp +++ b/src/entities/Camera.cpp @@ -1,4 +1,4 @@ -#include "Camera.h" +#include "camera.h" namespace entities { @@ -7,26 +7,26 @@ namespace entities rotation(rotation) {} - void Camera::move(GLFWwindow* window) + void Camera::Move(GLFWwindow* window) { if (glfwGetKey(window, GLFW_KEY_W) == GLFW_PRESS) { - position.z -= speed; + position.z -= SPEED; } if (glfwGetKey(window, GLFW_KEY_S) == GLFW_PRESS) { - position.z += speed; + position.z += SPEED; } if (glfwGetKey(window, GLFW_KEY_D) == GLFW_PRESS) { - position.x += speed; + position.x += SPEED; } if (glfwGetKey(window, GLFW_KEY_A) == GLFW_PRESS) { - position.x -= speed; + position.x -= SPEED; } } } diff --git a/src/entities/Camera.h b/src/entities/Camera.h index cd4054e..b85f0f0 100644 --- a/src/entities/Camera.h +++ b/src/entities/Camera.h @@ -8,7 +8,7 @@ namespace entities class Camera { private: - float speed = 0.02f; + const float SPEED = 0.02f; glm::vec3 position; glm::vec3 rotation; @@ -16,9 +16,9 @@ namespace entities public: Camera(const ::glm::vec3& position, const ::glm::vec3& rotation); - void move(GLFWwindow* window); + void Move(GLFWwindow* window); - inline glm::vec3 getPosition() const{ return position; } - inline glm::vec3 getRotation() const{ return rotation; } + inline glm::vec3 GetPosition() const{ return position; } + inline glm::vec3 GetRotation() const{ return rotation; } }; } \ No newline at end of file diff --git a/src/entities/Entity.cpp b/src/entities/Entity.cpp index 4aa7ca2..f74432d 100644 --- a/src/entities/Entity.cpp +++ b/src/entities/Entity.cpp @@ -1,6 +1,4 @@ -#include "Entity.h" - -#include +#include "entity.h" namespace entities { @@ -12,14 +10,14 @@ namespace entities { } - void Entity::increasePosition(const glm::vec3& distance) + void Entity::IncreasePosition(const glm::vec3& distance) { position.x += distance.x; position.y += distance.y; position.z += distance.z; } - void Entity::increaseRotation(const glm::vec3& rotation) + void Entity::IncreaseRotation(const glm::vec3& rotation) { this->rotation.x += rotation.x; this->rotation.y += rotation.y; diff --git a/src/entities/Entity.h b/src/entities/Entity.h index 07bf3c3..8355488 100644 --- a/src/entities/Entity.h +++ b/src/entities/Entity.h @@ -1,7 +1,7 @@ #pragma once #include -#include "../models/Model.h" +#include "../models/model.h" namespace entities { @@ -16,16 +16,16 @@ namespace entities public: Entity(const models::TexturedModel& model, const glm::vec3& position, const glm::vec3& rotation, float scale); - void increasePosition(const glm::vec3& distance); - void increaseRotation(const glm::vec3& rotation); + void IncreasePosition(const glm::vec3& distance); + void IncreaseRotation(const glm::vec3& rotation); - inline models::TexturedModel getModel() const{return model;} - inline void set_model(const ::models::TexturedModel& model) { this->model = model; } - inline glm::vec3 getPosition() const { return position; } - inline void set_position(const ::glm::vec3& position) { this->position = position; } - inline glm::vec3 getRotation() const { return rotation; } - inline void set_rotation(const ::glm::vec3& rotation) { this->rotation = rotation; } - inline float getScale() const { return scale; } - inline void set_scale(const float scale) { this->scale = scale; } + inline models::TexturedModel GetModel() const{return model;} + inline void SetModel(const ::models::TexturedModel& model) { this->model = model; } + inline glm::vec3 GetPosition() const { return position; } + inline void SetPosition(const ::glm::vec3& position) { this->position = position; } + inline glm::vec3 GetRotation() const { return rotation; } + inline void SetRotation(const ::glm::vec3& rotation) { this->rotation = rotation; } + inline float GetScale() const { return scale; } + inline void SetScale(const float scale) { this->scale = scale; } }; } \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index f0bf363..316baec 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -5,12 +5,12 @@ #include "stb_image.h" #include -#include "models/Model.h" +#include "models/model.h" #include "renderEngine/loader.h" #include "renderEngine/obj_loader.h" -#include "renderEngine/Renderer.h" +#include "renderEngine/renderer.h" #include "shaders/static_shader.h" -#include "toolbox/math.h" +#include "toolbox/toolbox.h" #pragma comment(lib, "glfw3.lib") #pragma comment(lib, "glew32s.lib") @@ -60,8 +60,8 @@ int main(void) { // Update const double delta = UpdateDelta(); - entity.increaseRotation(glm::vec3(0, 1, 0)); - camera.move(window); + entity.IncreaseRotation(glm::vec3(0, 1, 0)); + camera.Move(window); // Render render_engine::renderer::Prepare(); diff --git a/src/models/Model.h b/src/models/Model.h index 5fd7f6e..5bc8bf3 100644 --- a/src/models/Model.h +++ b/src/models/Model.h @@ -5,24 +5,24 @@ namespace models { /* - Structure for storing a vboID and vertexCount. + Structure for storing a vboID and vertex_count. This structure represents a Bare bones Model (A mesh without a texture). - The vaoID, points to an ID stored by openGL and the - vertexCount is how many triangles in the mesh there are. + The vao_id, points to an ID stored by openGL and the + vertex_count is how many triangles in the mesh there are. */ struct RawModel { - GLuint vaoID; - int vertexCount; + GLuint vao_id; + int vertex_count; }; /* - Structure for storing a texture (textureID) to apply to a RawModel. + Structure for storing a texture (texture_id) to apply to a RawModel. */ struct ModelTexture { - GLuint textureID; + GLuint texture_id; }; /* @@ -32,7 +32,7 @@ namespace models */ struct TexturedModel { - RawModel rawModel; + RawModel raw_model; ModelTexture texture; }; } \ No newline at end of file diff --git a/src/renderEngine/Loader.cpp b/src/renderEngine/Loader.cpp index 669ed27..9b66503 100644 --- a/src/renderEngine/Loader.cpp +++ b/src/renderEngine/Loader.cpp @@ -6,9 +6,9 @@ namespace render_engine { namespace loader { - static GLuint create_vao(); - static void store_data_in_attribute_list(int attribute_number, int coordinate_size, std::vector& data); - static void bind_indices_buffer(std::vector& indices); + static GLuint CreateVao(); + static void StoreDataInAttributeList(int attribute_number, int coordinate_size, std::vector& data); + static void BindIndicesBuffer(std::vector& indices); static std::vector vaos; static std::vector vbos; @@ -19,10 +19,10 @@ namespace render_engine */ struct models::RawModel LoadToVAO(std::vector& positions, std::vector& texture_coords, std::vector& indices) { - GLuint vao_id = create_vao(); - bind_indices_buffer(indices); - store_data_in_attribute_list(0, 3, positions); - store_data_in_attribute_list(1, 2, texture_coords); + GLuint vao_id = CreateVao(); + BindIndicesBuffer(indices); + StoreDataInAttributeList(0, 3, positions); + StoreDataInAttributeList(1, 2, texture_coords); glBindVertexArray(0); return { vao_id, static_cast(indices.size()) }; } @@ -61,7 +61,7 @@ namespace render_engine /* This function will create a new VAO for a new mesh. */ - static GLuint create_vao() + static GLuint CreateVao() { GLuint vao_id; glGenVertexArrays(1, &vao_id); @@ -73,7 +73,7 @@ namespace render_engine /* This function can store data (vbo) in a vao. */ - static void store_data_in_attribute_list(int attribute_number, int coordinate_size, std::vector& data) + static void StoreDataInAttributeList(int attribute_number, int coordinate_size, std::vector& data) { GLuint vbo_id; glGenBuffers(1, &vbo_id); @@ -105,7 +105,7 @@ namespace render_engine 3,1,2 }; */ - static void bind_indices_buffer(std::vector& indices) + static void BindIndicesBuffer(std::vector& indices) { GLuint vbo_id; glGenBuffers(1, &vbo_id); diff --git a/src/renderEngine/Loader.h b/src/renderEngine/Loader.h index 121c2b9..e1baf76 100644 --- a/src/renderEngine/Loader.h +++ b/src/renderEngine/Loader.h @@ -2,7 +2,7 @@ #include #include -#include "../models/Model.h" +#include "../models/model.h" namespace render_engine { diff --git a/src/renderEngine/Renderer.cpp b/src/renderEngine/Renderer.cpp index ed99dc8..b1d2564 100644 --- a/src/renderEngine/Renderer.cpp +++ b/src/renderEngine/Renderer.cpp @@ -1,9 +1,8 @@ #include #include -#include -#include "../models/Model.h" +#include "../models/model.h" #include "renderer.h" -#include "../toolbox/math.h" +#include "../toolbox/toolbox.h" namespace render_engine { @@ -41,24 +40,24 @@ namespace render_engine */ void Render(entities::Entity& entity, shaders::StaticShader& shader) { - const models::TexturedModel model = entity.getModel(); - const models::RawModel rawModel = model.rawModel; + const models::TexturedModel model = entity.GetModel(); + const models::RawModel rawModel = model.raw_model; // Enable the model - glBindVertexArray(rawModel.vaoID); + glBindVertexArray(rawModel.vao_id); // Enable the inputs for the vertexShader glEnableVertexAttribArray(0); glEnableVertexAttribArray(1); // Load the transformation of the model into the shader - const glm::mat4 modelMatrix = toolbox::CreateModelMatrix(entity.getPosition(), entity.getRotation(), entity.getScale()); + const glm::mat4 modelMatrix = toolbox::CreateModelMatrix(entity.GetPosition(), entity.GetRotation(), entity.GetScale()); shader.LoadModelMatrix(modelMatrix); // Draw the model glActiveTexture(GL_TEXTURE0); - glBindTexture(GL_TEXTURE_2D, model.texture.textureID); - glDrawElements(GL_TRIANGLES, rawModel.vertexCount, GL_UNSIGNED_INT, 0); + glBindTexture(GL_TEXTURE_2D, model.texture.texture_id); + glDrawElements(GL_TRIANGLES, rawModel.vertex_count, GL_UNSIGNED_INT, 0); glDisableVertexAttribArray(0); glDisableVertexAttribArray(1); diff --git a/src/renderEngine/Renderer.h b/src/renderEngine/Renderer.h index 06c10dc..17358fb 100644 --- a/src/renderEngine/Renderer.h +++ b/src/renderEngine/Renderer.h @@ -1,6 +1,6 @@ #pragma once -#include "../entities/Entity.h" +#include "../entities/entity.h" #include "../shaders/static_shader.h" namespace render_engine diff --git a/src/renderEngine/obj_loader.h b/src/renderEngine/obj_loader.h index 9bde11f..c349f75 100644 --- a/src/renderEngine/obj_loader.h +++ b/src/renderEngine/obj_loader.h @@ -1,6 +1,6 @@ #pragma once #include -#include "../models/Model.h" +#include "../models/model.h" models::RawModel LoadObjModel(std::string file_name); \ No newline at end of file diff --git a/src/shaders/static_shader.cpp b/src/shaders/static_shader.cpp index 8a85d38..b256b09 100644 --- a/src/shaders/static_shader.cpp +++ b/src/shaders/static_shader.cpp @@ -1,5 +1,5 @@ #include "static_shader.h" -#include "../toolbox/math.h" +#include "../toolbox/toolbox.h" namespace shaders { diff --git a/src/shaders/static_shader.h b/src/shaders/static_shader.h index 4abeba5..8d24f4f 100644 --- a/src/shaders/static_shader.h +++ b/src/shaders/static_shader.h @@ -2,7 +2,7 @@ #include #include "shader_program.h" -#include "../entities/Camera.h" +#include "../entities/camera.h" /* This class does represents the shaders for the models. diff --git a/src/toolbox/math.cpp b/src/toolbox/toolbox.cpp similarity index 68% rename from src/toolbox/math.cpp rename to src/toolbox/toolbox.cpp index cfe2ea2..e95d716 100644 --- a/src/toolbox/math.cpp +++ b/src/toolbox/toolbox.cpp @@ -1,4 +1,4 @@ -#include "math.h" +#include "toolbox.h" namespace toolbox { @@ -16,10 +16,10 @@ namespace toolbox glm::mat4 CreateViewMatrix(entities::Camera& camera) { glm::mat4 matrix(1.0f); - matrix = glm::rotate(matrix, glm::radians(camera.getRotation().x), glm::vec3(1, 0, 0)); - matrix = glm::rotate(matrix, glm::radians(camera.getRotation().y), glm::vec3(0, 1, 0)); - matrix = glm::rotate(matrix, glm::radians(camera.getRotation().z), glm::vec3(0, 0, 1)); - const glm::vec3 negative_cam_pos = glm::vec3(-camera.getPosition().x, -camera.getPosition().y, -camera.getPosition().z); + matrix = glm::rotate(matrix, glm::radians(camera.GetRotation().x), glm::vec3(1, 0, 0)); + matrix = glm::rotate(matrix, glm::radians(camera.GetRotation().y), glm::vec3(0, 1, 0)); + matrix = glm::rotate(matrix, glm::radians(camera.GetRotation().z), glm::vec3(0, 0, 1)); + const glm::vec3 negative_cam_pos = glm::vec3(-camera.GetPosition().x, -camera.GetPosition().y, -camera.GetPosition().z); matrix = glm::translate(matrix, negative_cam_pos); return matrix; } diff --git a/src/toolbox/math.h b/src/toolbox/toolbox.h similarity index 89% rename from src/toolbox/math.h rename to src/toolbox/toolbox.h index e38f164..5e006eb 100644 --- a/src/toolbox/math.h +++ b/src/toolbox/toolbox.h @@ -1,6 +1,6 @@ #pragma once -#include "../entities/Camera.h" +#include "../entities/camera.h" #include namespace toolbox diff --git a/wk2_fps.vcxproj b/wk2_fps.vcxproj index 4cd433f..44ab9be 100644 --- a/wk2_fps.vcxproj +++ b/wk2_fps.vcxproj @@ -19,27 +19,27 @@ - - + + - + - + - + - - - - + + + + - + - + 16.0 diff --git a/wk2_fps.vcxproj.filters b/wk2_fps.vcxproj.filters index 87924e7..d3370e0 100644 --- a/wk2_fps.vcxproj.filters +++ b/wk2_fps.vcxproj.filters @@ -30,9 +30,6 @@ Source Files - - Source Files - Source Files @@ -42,6 +39,9 @@ Source Files + + Source Files + @@ -62,9 +62,6 @@ Header Files - - Header Files - Header Files @@ -74,5 +71,8 @@ Header Files + + Header Files + \ No newline at end of file