[EDIT] code style guide finished

This commit is contained in:
Menno
2021-05-18 12:43:22 +02:00
parent 41e02b0c39
commit 438b219d0a
17 changed files with 83 additions and 86 deletions

View File

@@ -1,4 +1,4 @@
#include "Camera.h" #include "camera.h"
namespace entities namespace entities
{ {
@@ -7,26 +7,26 @@ namespace entities
rotation(rotation) rotation(rotation)
{} {}
void Camera::move(GLFWwindow* window) void Camera::Move(GLFWwindow* window)
{ {
if (glfwGetKey(window, GLFW_KEY_W) == GLFW_PRESS) if (glfwGetKey(window, GLFW_KEY_W) == GLFW_PRESS)
{ {
position.z -= speed; position.z -= SPEED;
} }
if (glfwGetKey(window, GLFW_KEY_S) == GLFW_PRESS) if (glfwGetKey(window, GLFW_KEY_S) == GLFW_PRESS)
{ {
position.z += speed; position.z += SPEED;
} }
if (glfwGetKey(window, GLFW_KEY_D) == GLFW_PRESS) if (glfwGetKey(window, GLFW_KEY_D) == GLFW_PRESS)
{ {
position.x += speed; position.x += SPEED;
} }
if (glfwGetKey(window, GLFW_KEY_A) == GLFW_PRESS) if (glfwGetKey(window, GLFW_KEY_A) == GLFW_PRESS)
{ {
position.x -= speed; position.x -= SPEED;
} }
} }
} }

View File

@@ -8,7 +8,7 @@ namespace entities
class Camera class Camera
{ {
private: private:
float speed = 0.02f; const float SPEED = 0.02f;
glm::vec3 position; glm::vec3 position;
glm::vec3 rotation; glm::vec3 rotation;
@@ -16,9 +16,9 @@ namespace entities
public: public:
Camera(const ::glm::vec3& position, const ::glm::vec3& rotation); 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 GetPosition() const{ return position; }
inline glm::vec3 getRotation() const{ return rotation; } inline glm::vec3 GetRotation() const{ return rotation; }
}; };
} }

View File

@@ -1,6 +1,4 @@
#include "Entity.h" #include "entity.h"
#include <iostream>
namespace entities 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.x += distance.x;
position.y += distance.y; position.y += distance.y;
position.z += distance.z; 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.x += rotation.x;
this->rotation.y += rotation.y; this->rotation.y += rotation.y;

View File

@@ -1,7 +1,7 @@
#pragma once #pragma once
#include <glm/gtc/matrix_transform.hpp> #include <glm/gtc/matrix_transform.hpp>
#include "../models/Model.h" #include "../models/model.h"
namespace entities namespace entities
{ {
@@ -16,16 +16,16 @@ namespace entities
public: public:
Entity(const models::TexturedModel& model, const glm::vec3& position, const glm::vec3& rotation, float scale); Entity(const models::TexturedModel& model, const glm::vec3& position, const glm::vec3& rotation, float scale);
void increasePosition(const glm::vec3& distance); void IncreasePosition(const glm::vec3& distance);
void increaseRotation(const glm::vec3& rotation); void IncreaseRotation(const glm::vec3& rotation);
inline models::TexturedModel getModel() const{return model;} inline models::TexturedModel GetModel() const{return model;}
inline void set_model(const ::models::TexturedModel& model) { this->model = model; } inline void SetModel(const ::models::TexturedModel& model) { this->model = model; }
inline glm::vec3 getPosition() const { return position; } inline glm::vec3 GetPosition() const { return position; }
inline void set_position(const ::glm::vec3& position) { this->position = position; } inline void SetPosition(const ::glm::vec3& position) { this->position = position; }
inline glm::vec3 getRotation() const { return rotation; } inline glm::vec3 GetRotation() const { return rotation; }
inline void set_rotation(const ::glm::vec3& rotation) { this->rotation = rotation; } inline void SetRotation(const ::glm::vec3& rotation) { this->rotation = rotation; }
inline float getScale() const { return scale; } inline float GetScale() const { return scale; }
inline void set_scale(const float scale) { this->scale = scale; } inline void SetScale(const float scale) { this->scale = scale; }
}; };
} }

View File

@@ -5,12 +5,12 @@
#include "stb_image.h" #include "stb_image.h"
#include <ostream> #include <ostream>
#include "models/Model.h" #include "models/model.h"
#include "renderEngine/loader.h" #include "renderEngine/loader.h"
#include "renderEngine/obj_loader.h" #include "renderEngine/obj_loader.h"
#include "renderEngine/Renderer.h" #include "renderEngine/renderer.h"
#include "shaders/static_shader.h" #include "shaders/static_shader.h"
#include "toolbox/math.h" #include "toolbox/toolbox.h"
#pragma comment(lib, "glfw3.lib") #pragma comment(lib, "glfw3.lib")
#pragma comment(lib, "glew32s.lib") #pragma comment(lib, "glew32s.lib")
@@ -60,8 +60,8 @@ int main(void)
{ {
// Update // Update
const double delta = UpdateDelta(); const double delta = UpdateDelta();
entity.increaseRotation(glm::vec3(0, 1, 0)); entity.IncreaseRotation(glm::vec3(0, 1, 0));
camera.move(window); camera.Move(window);
// Render // Render
render_engine::renderer::Prepare(); render_engine::renderer::Prepare();

View File

@@ -5,24 +5,24 @@
namespace models 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). This structure represents a Bare bones Model (A mesh without a texture).
The vaoID, points to an ID stored by openGL and the The vao_id, points to an ID stored by openGL and the
vertexCount is how many triangles in the mesh there are. vertex_count is how many triangles in the mesh there are.
*/ */
struct RawModel struct RawModel
{ {
GLuint vaoID; GLuint vao_id;
int vertexCount; 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 struct ModelTexture
{ {
GLuint textureID; GLuint texture_id;
}; };
/* /*
@@ -32,7 +32,7 @@ namespace models
*/ */
struct TexturedModel struct TexturedModel
{ {
RawModel rawModel; RawModel raw_model;
ModelTexture texture; ModelTexture texture;
}; };
} }

View File

@@ -6,9 +6,9 @@ namespace render_engine
{ {
namespace loader namespace loader
{ {
static GLuint create_vao(); static GLuint CreateVao();
static void store_data_in_attribute_list(int attribute_number, int coordinate_size, std::vector<float>& data); static void StoreDataInAttributeList(int attribute_number, int coordinate_size, std::vector<float>& data);
static void bind_indices_buffer(std::vector<unsigned int>& indices); static void BindIndicesBuffer(std::vector<unsigned int>& indices);
static std::vector<GLuint> vaos; static std::vector<GLuint> vaos;
static std::vector<GLuint> vbos; static std::vector<GLuint> vbos;
@@ -19,10 +19,10 @@ namespace render_engine
*/ */
struct models::RawModel LoadToVAO(std::vector<float>& positions, std::vector<float>& texture_coords, std::vector<unsigned int>& indices) struct models::RawModel LoadToVAO(std::vector<float>& positions, std::vector<float>& texture_coords, std::vector<unsigned int>& indices)
{ {
GLuint vao_id = create_vao(); GLuint vao_id = CreateVao();
bind_indices_buffer(indices); BindIndicesBuffer(indices);
store_data_in_attribute_list(0, 3, positions); StoreDataInAttributeList(0, 3, positions);
store_data_in_attribute_list(1, 2, texture_coords); StoreDataInAttributeList(1, 2, texture_coords);
glBindVertexArray(0); glBindVertexArray(0);
return { vao_id, static_cast<int>(indices.size()) }; return { vao_id, static_cast<int>(indices.size()) };
} }
@@ -61,7 +61,7 @@ namespace render_engine
/* /*
This function will create a new VAO for a new mesh. This function will create a new VAO for a new mesh.
*/ */
static GLuint create_vao() static GLuint CreateVao()
{ {
GLuint vao_id; GLuint vao_id;
glGenVertexArrays(1, &vao_id); glGenVertexArrays(1, &vao_id);
@@ -73,7 +73,7 @@ namespace render_engine
/* /*
This function can store data (vbo) in a vao. This function can store data (vbo) in a vao.
*/ */
static void store_data_in_attribute_list(int attribute_number, int coordinate_size, std::vector<float>& data) static void StoreDataInAttributeList(int attribute_number, int coordinate_size, std::vector<float>& data)
{ {
GLuint vbo_id; GLuint vbo_id;
glGenBuffers(1, &vbo_id); glGenBuffers(1, &vbo_id);
@@ -105,7 +105,7 @@ namespace render_engine
3,1,2 3,1,2
}; };
*/ */
static void bind_indices_buffer(std::vector<unsigned int>& indices) static void BindIndicesBuffer(std::vector<unsigned int>& indices)
{ {
GLuint vbo_id; GLuint vbo_id;
glGenBuffers(1, &vbo_id); glGenBuffers(1, &vbo_id);

View File

@@ -2,7 +2,7 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include "../models/Model.h" #include "../models/model.h"
namespace render_engine namespace render_engine
{ {

View File

@@ -1,9 +1,8 @@
#include <GL/glew.h> #include <GL/glew.h>
#include <glm/gtc/matrix_transform.hpp> #include <glm/gtc/matrix_transform.hpp>
#include <iostream> #include "../models/model.h"
#include "../models/Model.h"
#include "renderer.h" #include "renderer.h"
#include "../toolbox/math.h" #include "../toolbox/toolbox.h"
namespace render_engine namespace render_engine
{ {
@@ -41,24 +40,24 @@ namespace render_engine
*/ */
void Render(entities::Entity& entity, shaders::StaticShader& shader) void Render(entities::Entity& entity, shaders::StaticShader& shader)
{ {
const models::TexturedModel model = entity.getModel(); const models::TexturedModel model = entity.GetModel();
const models::RawModel rawModel = model.rawModel; const models::RawModel rawModel = model.raw_model;
// Enable the model // Enable the model
glBindVertexArray(rawModel.vaoID); glBindVertexArray(rawModel.vao_id);
// Enable the inputs for the vertexShader // Enable the inputs for the vertexShader
glEnableVertexAttribArray(0); glEnableVertexAttribArray(0);
glEnableVertexAttribArray(1); glEnableVertexAttribArray(1);
// Load the transformation of the model into the shader // 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); shader.LoadModelMatrix(modelMatrix);
// Draw the model // Draw the model
glActiveTexture(GL_TEXTURE0); glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, model.texture.textureID); glBindTexture(GL_TEXTURE_2D, model.texture.texture_id);
glDrawElements(GL_TRIANGLES, rawModel.vertexCount, GL_UNSIGNED_INT, 0); glDrawElements(GL_TRIANGLES, rawModel.vertex_count, GL_UNSIGNED_INT, 0);
glDisableVertexAttribArray(0); glDisableVertexAttribArray(0);
glDisableVertexAttribArray(1); glDisableVertexAttribArray(1);

View File

@@ -1,6 +1,6 @@
#pragma once #pragma once
#include "../entities/Entity.h" #include "../entities/entity.h"
#include "../shaders/static_shader.h" #include "../shaders/static_shader.h"
namespace render_engine namespace render_engine

View File

@@ -1,6 +1,6 @@
#pragma once #pragma once
#include <string> #include <string>
#include "../models/Model.h" #include "../models/model.h"
models::RawModel LoadObjModel(std::string file_name); models::RawModel LoadObjModel(std::string file_name);

View File

@@ -1,5 +1,5 @@
#include "static_shader.h" #include "static_shader.h"
#include "../toolbox/math.h" #include "../toolbox/toolbox.h"
namespace shaders namespace shaders
{ {

View File

@@ -2,7 +2,7 @@
#include <glm/gtc/matrix_transform.hpp> #include <glm/gtc/matrix_transform.hpp>
#include "shader_program.h" #include "shader_program.h"
#include "../entities/Camera.h" #include "../entities/camera.h"
/* /*
This class does represents the shaders for the models. This class does represents the shaders for the models.

View File

@@ -1,4 +1,4 @@
#include "math.h" #include "toolbox.h"
namespace toolbox namespace toolbox
{ {
@@ -16,10 +16,10 @@ namespace toolbox
glm::mat4 CreateViewMatrix(entities::Camera& camera) glm::mat4 CreateViewMatrix(entities::Camera& camera)
{ {
glm::mat4 matrix(1.0f); 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().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().y), glm::vec3(0, 1, 0));
matrix = glm::rotate(matrix, glm::radians(camera.getRotation().z), glm::vec3(0, 0, 1)); 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); const glm::vec3 negative_cam_pos = glm::vec3(-camera.GetPosition().x, -camera.GetPosition().y, -camera.GetPosition().z);
matrix = glm::translate(matrix, negative_cam_pos); matrix = glm::translate(matrix, negative_cam_pos);
return matrix; return matrix;
} }

View File

@@ -1,6 +1,6 @@
#pragma once #pragma once
#include "../entities/Camera.h" #include "../entities/camera.h"
#include <glm/gtc/matrix_transform.hpp> #include <glm/gtc/matrix_transform.hpp>
namespace toolbox namespace toolbox

View File

@@ -19,27 +19,27 @@
</ProjectConfiguration> </ProjectConfiguration>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClCompile Include="src\entities\Camera.cpp" /> <ClCompile Include="src\entities\camera.cpp" />
<ClCompile Include="src\entities\Entity.cpp" /> <ClCompile Include="src\entities\entity.cpp" />
<ClCompile Include="src\main.cpp" /> <ClCompile Include="src\main.cpp" />
<ClCompile Include="src\renderEngine\Loader.cpp" /> <ClCompile Include="src\renderEngine\loader.cpp" />
<ClCompile Include="src\renderEngine\obj_loader.cpp" /> <ClCompile Include="src\renderEngine\obj_loader.cpp" />
<ClCompile Include="src\renderEngine\Renderer.cpp" /> <ClCompile Include="src\renderEngine\renderer.cpp" />
<ClCompile Include="src\shaders\shader_program.cpp" /> <ClCompile Include="src\shaders\shader_program.cpp" />
<ClCompile Include="src\shaders\static_shader.cpp" /> <ClCompile Include="src\shaders\static_shader.cpp" />
<ClCompile Include="src\toolbox\math.cpp" /> <ClCompile Include="src\toolbox\toolbox.cpp" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="src\entities\Camera.h" /> <ClInclude Include="src\entities\camera.h" />
<ClInclude Include="src\entities\Entity.h" /> <ClInclude Include="src\entities\entity.h" />
<ClInclude Include="src\models\Model.h" /> <ClInclude Include="src\models\model.h" />
<ClInclude Include="src\renderEngine\Loader.h" /> <ClInclude Include="src\renderEngine\loader.h" />
<ClInclude Include="src\renderEngine\obj_loader.h" /> <ClInclude Include="src\renderEngine\obj_loader.h" />
<ClInclude Include="src\renderEngine\Renderer.h" /> <ClInclude Include="src\renderEngine\renderer.h" />
<ClInclude Include="src\shaders\shader_program.h" /> <ClInclude Include="src\shaders\shader_program.h" />
<ClInclude Include="src\shaders\static_shader.h" /> <ClInclude Include="src\shaders\static_shader.h" />
<ClInclude Include="src\stb_image.h" /> <ClInclude Include="src\stb_image.h" />
<ClInclude Include="src\toolbox\math.h" /> <ClInclude Include="src\toolbox\toolbox.h" />
</ItemGroup> </ItemGroup>
<PropertyGroup Label="Globals"> <PropertyGroup Label="Globals">
<VCProjectVersion>16.0</VCProjectVersion> <VCProjectVersion>16.0</VCProjectVersion>

View File

@@ -30,9 +30,6 @@
<ClCompile Include="src\main.cpp"> <ClCompile Include="src\main.cpp">
<Filter>Source Files</Filter> <Filter>Source Files</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="src\toolbox\math.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="src\shaders\shader_program.cpp"> <ClCompile Include="src\shaders\shader_program.cpp">
<Filter>Source Files</Filter> <Filter>Source Files</Filter>
</ClCompile> </ClCompile>
@@ -42,6 +39,9 @@
<ClCompile Include="src\renderEngine\obj_loader.cpp"> <ClCompile Include="src\renderEngine\obj_loader.cpp">
<Filter>Source Files</Filter> <Filter>Source Files</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="src\toolbox\toolbox.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="src\entities\Camera.h"> <ClInclude Include="src\entities\Camera.h">
@@ -62,9 +62,6 @@
<ClInclude Include="src\stb_image.h"> <ClInclude Include="src\stb_image.h">
<Filter>Header Files</Filter> <Filter>Header Files</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="src\toolbox\math.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="src\shaders\shader_program.h"> <ClInclude Include="src\shaders\shader_program.h">
<Filter>Header Files</Filter> <Filter>Header Files</Filter>
</ClInclude> </ClInclude>
@@ -74,5 +71,8 @@
<ClInclude Include="src\renderEngine\obj_loader.h"> <ClInclude Include="src\renderEngine\obj_loader.h">
<Filter>Header Files</Filter> <Filter>Header Files</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="src\toolbox\toolbox.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup> </ItemGroup>
</Project> </Project>