[EDIT] code style guide finished
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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; }
|
||||
};
|
||||
}
|
||||
@@ -1,6 +1,4 @@
|
||||
#include "Entity.h"
|
||||
|
||||
#include <iostream>
|
||||
#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;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <glm/gtc/matrix_transform.hpp>
|
||||
#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; }
|
||||
};
|
||||
}
|
||||
10
src/main.cpp
10
src/main.cpp
@@ -5,12 +5,12 @@
|
||||
#include "stb_image.h"
|
||||
#include <ostream>
|
||||
|
||||
#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();
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
}
|
||||
@@ -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<float>& data);
|
||||
static void bind_indices_buffer(std::vector<unsigned int>& indices);
|
||||
static GLuint CreateVao();
|
||||
static void StoreDataInAttributeList(int attribute_number, int coordinate_size, std::vector<float>& data);
|
||||
static void BindIndicesBuffer(std::vector<unsigned int>& indices);
|
||||
|
||||
static std::vector<GLuint> vaos;
|
||||
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)
|
||||
{
|
||||
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<int>(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<float>& data)
|
||||
static void StoreDataInAttributeList(int attribute_number, int coordinate_size, std::vector<float>& 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<unsigned int>& indices)
|
||||
static void BindIndicesBuffer(std::vector<unsigned int>& indices)
|
||||
{
|
||||
GLuint vbo_id;
|
||||
glGenBuffers(1, &vbo_id);
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "../models/Model.h"
|
||||
#include "../models/model.h"
|
||||
|
||||
namespace render_engine
|
||||
{
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
#include <GL/glew.h>
|
||||
#include <glm/gtc/matrix_transform.hpp>
|
||||
#include <iostream>
|
||||
#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);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "../entities/Entity.h"
|
||||
#include "../entities/entity.h"
|
||||
#include "../shaders/static_shader.h"
|
||||
|
||||
namespace render_engine
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include "../models/Model.h"
|
||||
#include "../models/model.h"
|
||||
|
||||
models::RawModel LoadObjModel(std::string file_name);
|
||||
@@ -1,5 +1,5 @@
|
||||
#include "static_shader.h"
|
||||
#include "../toolbox/math.h"
|
||||
#include "../toolbox/toolbox.h"
|
||||
|
||||
namespace shaders
|
||||
{
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
#include <glm/gtc/matrix_transform.hpp>
|
||||
#include "shader_program.h"
|
||||
#include "../entities/Camera.h"
|
||||
#include "../entities/camera.h"
|
||||
|
||||
/*
|
||||
This class does represents the shaders for the models.
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "../entities/Camera.h"
|
||||
#include "../entities/camera.h"
|
||||
#include <glm/gtc/matrix_transform.hpp>
|
||||
|
||||
namespace toolbox
|
||||
Reference in New Issue
Block a user