Merge branch 'master' of github.com:sippeangelo/Escape-the-Dawn
Conflicts: Escape-the-Dawn/Escape-the-Dawn.vcxproj.filters
This commit is contained in:
@@ -0,0 +1,74 @@
|
|||||||
|
#include "Camera.h"
|
||||||
|
|
||||||
|
Camera::Camera(float yFOV, float aspectRatio, float nearClip, float farClip)
|
||||||
|
{
|
||||||
|
m_FOV = yFOV;
|
||||||
|
m_AspectRatio = aspectRatio;
|
||||||
|
m_NearClip = nearClip;
|
||||||
|
m_FarClip = farClip;
|
||||||
|
|
||||||
|
m_Position = glm::vec3(0.0);
|
||||||
|
m_Pitch = 0.f;
|
||||||
|
m_Yaw = 0.f;
|
||||||
|
|
||||||
|
UpdateProjectionMatrix();
|
||||||
|
UpdateViewMatrix();
|
||||||
|
}
|
||||||
|
|
||||||
|
glm::vec3 Camera::Forward()
|
||||||
|
{
|
||||||
|
return glm::rotate(glm::vec3(0.f, 0.f, -1.f), -m_Yaw, glm::vec3(0.f, 1.f, 0.f));
|
||||||
|
}
|
||||||
|
|
||||||
|
glm::vec3 Camera::Right()
|
||||||
|
{
|
||||||
|
return glm::rotate(glm::vec3(1.f, 0.f, 0.f), -m_Yaw, glm::vec3(0.f, 1.f, 0.f));
|
||||||
|
}
|
||||||
|
|
||||||
|
glm::mat4 Camera::Orientation()
|
||||||
|
{
|
||||||
|
glm::mat4 orientation(1.f);
|
||||||
|
orientation = glm::rotate(orientation, m_Pitch, glm::vec3(1.f, 0.f, 0.f));
|
||||||
|
orientation = glm::rotate(orientation, m_Yaw, glm::vec3(0.f, 1.f, 0.f));
|
||||||
|
return orientation;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Camera::AspectRatio(float val)
|
||||||
|
{
|
||||||
|
m_AspectRatio = val;
|
||||||
|
UpdateProjectionMatrix();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Camera::Position(glm::vec3 val)
|
||||||
|
{
|
||||||
|
m_Position = val;
|
||||||
|
UpdateViewMatrix();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Camera::Pitch(float val)
|
||||||
|
{
|
||||||
|
m_Pitch = val;
|
||||||
|
UpdateViewMatrix();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Camera::Yaw(float val)
|
||||||
|
{
|
||||||
|
m_Yaw = val;
|
||||||
|
UpdateViewMatrix();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Camera::UpdateProjectionMatrix()
|
||||||
|
{
|
||||||
|
m_ProjectionMatrix = glm::perspective(
|
||||||
|
m_FOV,
|
||||||
|
m_AspectRatio,
|
||||||
|
m_NearClip,
|
||||||
|
m_FarClip
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Camera::UpdateViewMatrix()
|
||||||
|
{
|
||||||
|
m_ViewMatrix = glm::translate(Orientation(), -m_Position);
|
||||||
|
}
|
||||||
@@ -0,0 +1,53 @@
|
|||||||
|
#ifndef Camera_h__
|
||||||
|
#define Camera_h__
|
||||||
|
|
||||||
|
#define GLM_FORCE_RADIANS
|
||||||
|
#include <glm/glm.hpp>
|
||||||
|
#include <glm/gtc/constants.hpp>
|
||||||
|
#include <glm/gtc/matrix_transform.hpp>
|
||||||
|
#include <glm/gtx/rotate_vector.hpp>
|
||||||
|
|
||||||
|
class Camera
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
Camera(float yFOV, float aspectRatio, float nearClip, float farClip);
|
||||||
|
|
||||||
|
glm::vec3 Forward();
|
||||||
|
glm::vec3 Right();
|
||||||
|
glm::mat4 Orientation();
|
||||||
|
|
||||||
|
float AspectRatio() const { return m_AspectRatio; }
|
||||||
|
void AspectRatio(float val);
|
||||||
|
|
||||||
|
glm::vec3 Position() const { return m_Position; }
|
||||||
|
void Position(glm::vec3 val);
|
||||||
|
|
||||||
|
float Pitch() const { return m_Pitch; }
|
||||||
|
void Pitch(float val);
|
||||||
|
float Yaw() const { return m_Yaw; }
|
||||||
|
void Yaw(float val);
|
||||||
|
|
||||||
|
glm::mat4 ProjectionMatrix() const { return m_ProjectionMatrix; }
|
||||||
|
void ProjectionMatrix(glm::mat4 val) { m_ProjectionMatrix = val; }
|
||||||
|
|
||||||
|
glm::mat4 ViewMatrix() const { return m_ViewMatrix; }
|
||||||
|
void ViewMatrix(glm::mat4 val) { m_ViewMatrix = val; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
void UpdateProjectionMatrix();
|
||||||
|
void UpdateViewMatrix();
|
||||||
|
|
||||||
|
float m_FOV;
|
||||||
|
float m_AspectRatio;
|
||||||
|
float m_NearClip;
|
||||||
|
float m_FarClip;
|
||||||
|
|
||||||
|
glm::vec3 m_Position;
|
||||||
|
float m_Pitch;
|
||||||
|
float m_Yaw;
|
||||||
|
|
||||||
|
glm::mat4 m_ProjectionMatrix;
|
||||||
|
glm::mat4 m_ViewMatrix;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // Camera_h__
|
||||||
@@ -11,7 +11,7 @@ namespace Components
|
|||||||
|
|
||||||
struct Model : Component
|
struct Model : Component
|
||||||
{
|
{
|
||||||
std::string ModelFile;
|
const char* ModelFile;
|
||||||
Color Color;
|
Color Color;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -97,6 +97,7 @@
|
|||||||
</Lib>
|
</Lib>
|
||||||
</ItemDefinitionGroup>
|
</ItemDefinitionGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<ClCompile Include="Camera.cpp" />
|
||||||
<ClCompile Include="Engine.h" />
|
<ClCompile Include="Engine.h" />
|
||||||
<ClCompile Include="Frame.cpp" />
|
<ClCompile Include="Frame.cpp" />
|
||||||
<ClCompile Include="GameFrame.cpp" />
|
<ClCompile Include="GameFrame.cpp" />
|
||||||
@@ -117,6 +118,7 @@
|
|||||||
<ClCompile Include="Systems\SoundsSystem.cpp" />
|
<ClCompile Include="Systems\SoundsSystem.cpp" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<ClInclude Include="Camera.h" />
|
||||||
<ClInclude Include="Color.h" />
|
<ClInclude Include="Color.h" />
|
||||||
<ClInclude Include="Component.h" />
|
<ClInclude Include="Component.h" />
|
||||||
<ClInclude Include="Components\Camera.h" />
|
<ClInclude Include="Components\Camera.h" />
|
||||||
|
|||||||
@@ -26,8 +26,24 @@
|
|||||||
<ClCompile Include="Model.cpp" />
|
<ClCompile Include="Model.cpp" />
|
||||||
<ClCompile Include="Engine.h" />
|
<ClCompile Include="Engine.h" />
|
||||||
<ClCompile Include="Texture.cpp" />
|
<ClCompile Include="Texture.cpp" />
|
||||||
|
<ClCompile Include="GUIManager.cpp">
|
||||||
|
<Filter>GUI</Filter>
|
||||||
|
</ClCompile>
|
||||||
<ClCompile Include="Renderer.cpp" />
|
<ClCompile Include="Renderer.cpp" />
|
||||||
<ClCompile Include="ShaderProgram.cpp" />
|
<ClCompile Include="ShaderProgram.cpp" />
|
||||||
|
<ClCompile Include="Frame.cpp">
|
||||||
|
<Filter>GUI</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
<ClCompile Include="TextFrame.cpp">
|
||||||
|
<Filter>GUI</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
<ClCompile Include="MenuFrame.cpp">
|
||||||
|
<Filter>GUI</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
<ClCompile Include="GameFrame.cpp">
|
||||||
|
<Filter>GUI</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
<ClCompile Include="Camera.cpp" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="Component.h" />
|
<ClInclude Include="Component.h" />
|
||||||
@@ -109,7 +125,23 @@
|
|||||||
</ClInclude>
|
</ClInclude>
|
||||||
<ClInclude Include="Renderer.h" />
|
<ClInclude Include="Renderer.h" />
|
||||||
<ClInclude Include="Texture.h" />
|
<ClInclude Include="Texture.h" />
|
||||||
|
<ClInclude Include="GUIManager.h">
|
||||||
|
<Filter>GUI</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="Frame.h">
|
||||||
|
<Filter>GUI</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="TextFrame.h">
|
||||||
|
<Filter>GUI</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="MenuFrame.h">
|
||||||
|
<Filter>GUI</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="GameFrame.h">
|
||||||
|
<Filter>GUI</Filter>
|
||||||
|
</ClInclude>
|
||||||
<ClInclude Include="GameWorld.h" />
|
<ClInclude Include="GameWorld.h" />
|
||||||
|
<ClInclude Include="Camera.h" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Include="Shaders\Fragment.glsl">
|
<None Include="Shaders\Fragment.glsl">
|
||||||
|
|||||||
@@ -142,6 +142,7 @@ bool Model::Loadobj(const char* path, std::vector <glm::vec3> & out_vertices, st
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Model::CreateBuffers( std::vector<glm::vec3> _Vertices, std::vector<glm::vec3> _Normals, std::vector<glm::vec2>_TextureCoords)
|
void Model::CreateBuffers( std::vector<glm::vec3> _Vertices, std::vector<glm::vec3> _Normals, std::vector<glm::vec2>_TextureCoords)
|
||||||
{
|
{
|
||||||
|
|
||||||
@@ -169,16 +170,20 @@ void Model::CreateBuffers( std::vector<glm::vec3> _Vertices, std::vector<glm::ve
|
|||||||
GLERROR("GLEW: BufferFail4");
|
GLERROR("GLEW: BufferFail4");
|
||||||
|
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, VertexBuffer);
|
glBindBuffer(GL_ARRAY_BUFFER, VertexBuffer);
|
||||||
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0);
|
glVertexAttribPointer(0, 1, GL_FLOAT, GL_FALSE, 0, 0);
|
||||||
GLERROR("GLEW: BufferFail5");
|
GLERROR("GLEW: BufferFail5");
|
||||||
|
|
||||||
|
glBindBuffer(GL_ARRAY_BUFFER, NormalBuffer);
|
||||||
|
glVertexAttribPointer(1, 1, GL_FLOAT, GL_FALSE, 0, 0);
|
||||||
|
GLERROR("GLEW: BufferFail5");
|
||||||
|
|
||||||
// glBindBuffer(GL_ARRAY_BUFFER, TextureCoordBuffer);
|
glBindBuffer(GL_ARRAY_BUFFER, TextureCoordBuffer);
|
||||||
// glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, 0, 0);
|
glVertexAttribPointer(2, 1, GL_FLOAT, GL_FALSE, 0, 0);
|
||||||
|
GLERROR("GLEW: BufferFail5");
|
||||||
|
|
||||||
glEnableVertexAttribArray(0);
|
glEnableVertexAttribArray(0);
|
||||||
glEnableVertexAttribArray(1);
|
glEnableVertexAttribArray(1);
|
||||||
/* glEnableVertexAttribArray(2);*/
|
glEnableVertexAttribArray(2);
|
||||||
GLERROR("GLEW: BufferFail5");
|
GLERROR("GLEW: BufferFail5");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -46,6 +46,8 @@ public:
|
|||||||
std::vector <glm::vec3> &out_normals,
|
std::vector <glm::vec3> &out_normals,
|
||||||
std::vector <glm::vec2> & out_TextureCoords
|
std::vector <glm::vec2> & out_TextureCoords
|
||||||
);
|
);
|
||||||
|
|
||||||
|
glm::mat4 GetMatrix();
|
||||||
|
|
||||||
void CreateBuffers(
|
void CreateBuffers(
|
||||||
std::vector<glm::vec3> _Vertices,
|
std::vector<glm::vec3> _Vertices,
|
||||||
|
|||||||
@@ -13,7 +13,9 @@ void Renderer::Initialize()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Create a window
|
// Create a window
|
||||||
m_Window = glfwCreateWindow(1280, 720, "OpenGL", nullptr, nullptr);
|
WIDTH = 1280;
|
||||||
|
HEIGHT = 720;
|
||||||
|
m_Window = glfwCreateWindow(WIDTH, HEIGHT, "OpenGL", nullptr, nullptr);
|
||||||
if (!m_Window) {
|
if (!m_Window) {
|
||||||
LOG_ERROR("GLFW: Failed to create window");
|
LOG_ERROR("GLFW: Failed to create window");
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
@@ -39,6 +41,9 @@ void Renderer::Initialize()
|
|||||||
}
|
}
|
||||||
glEnable(GL_DEPTH_TEST);
|
glEnable(GL_DEPTH_TEST);
|
||||||
|
|
||||||
|
// Create Camera
|
||||||
|
m_Camera = std::make_shared<Camera>(90.f, WIDTH / HEIGHT, 0.01f, 1000.f);
|
||||||
|
|
||||||
LoadContent();
|
LoadContent();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -47,7 +52,21 @@ void Renderer::Draw(double _dt)
|
|||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
glClearColor(1.0f, 1.0f, 0.0f, 1.0f);
|
glClearColor(1.0f, 1.0f, 0.0f, 1.0f);
|
||||||
|
|
||||||
//m_ShaderProgram->Bind();
|
m_ShaderProgram.Bind();
|
||||||
|
|
||||||
|
glm::mat4 cameraMatrix = m_Camera->ProjectionMatrix() * m_Camera->ViewMatrix();
|
||||||
|
|
||||||
|
glm::mat4 MVP;
|
||||||
|
for(int i = 0; i < ModelsToRender.size(); i++)
|
||||||
|
{
|
||||||
|
glActiveTexture(GL_TEXTURE0);
|
||||||
|
glBindTexture(GL_TEXTURE_2D, ModelsToRender[i]->model->texture[0]->texture);
|
||||||
|
MVP = cameraMatrix * ModelsToRender[i]->ModelMatrix;
|
||||||
|
glUniformMatrix4fv(glGetUniformLocation(m_ShaderProgram.GetHandle(), "MVP"), 1, GL_FALSE, glm::value_ptr(MVP));
|
||||||
|
glBindVertexArray(ModelsToRender[i]->model->VAO);
|
||||||
|
glDrawArrays(GL_TRIANGLES, 0, ModelsToRender[i]->model->Vertices.size());
|
||||||
|
}
|
||||||
|
ModelsToRender.clear();
|
||||||
|
|
||||||
glfwSwapBuffers(m_Window);
|
glfwSwapBuffers(m_Window);
|
||||||
}
|
}
|
||||||
@@ -62,9 +81,12 @@ void Renderer::AddTextToDraw()
|
|||||||
//Add to draw shit vector
|
//Add to draw shit vector
|
||||||
}
|
}
|
||||||
|
|
||||||
void Renderer::AddModelToDraw(Model* _model)
|
void Renderer::AddModelToDraw(Model* _model, glm::vec3 _position, glm::quat _orientation)
|
||||||
{
|
{
|
||||||
ModelsToRender.push_back(_model);
|
glm::mat4 RotationMatrix = glm::toMat4(_orientation);
|
||||||
|
glm::mat4 ModelMatrix = glm::translate(glm::mat4(), _position) * RotationMatrix ;
|
||||||
|
// You can now use ModelMatrix to build the MVP matrix
|
||||||
|
ModelsToRender.push_back(new ModelData(_model, ModelMatrix));
|
||||||
}
|
}
|
||||||
|
|
||||||
//Fixa med shaders, lägga in alla verts osv.
|
//Fixa med shaders, lägga in alla verts osv.
|
||||||
@@ -75,4 +97,6 @@ void Renderer::LoadContent()
|
|||||||
m_ShaderProgram.AddShader(std::unique_ptr<Shader>(new FragmentShader("Shaders/Fragment.glsl")));
|
m_ShaderProgram.AddShader(std::unique_ptr<Shader>(new FragmentShader("Shaders/Fragment.glsl")));
|
||||||
m_ShaderProgram.Compile();
|
m_ShaderProgram.Compile();
|
||||||
m_ShaderProgram.Link();
|
m_ShaderProgram.Link();
|
||||||
|
|
||||||
|
projectionMatrix = glm::perspective(45.0f, (float)WIDTH / HEIGHT, 0.01f, 100.0f);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,8 +17,11 @@
|
|||||||
#include <glm/gtc/constants.hpp>
|
#include <glm/gtc/constants.hpp>
|
||||||
#include <glm/gtc/matrix_transform.hpp>
|
#include <glm/gtc/matrix_transform.hpp>
|
||||||
#include <glm/gtc/type_ptr.hpp>
|
#include <glm/gtc/type_ptr.hpp>
|
||||||
|
#include <glm/gtc/quaternion.hpp>
|
||||||
|
#include <glm/gtx/quaternion.hpp>
|
||||||
|
|
||||||
#include "glerror.h"
|
#include "glerror.h"
|
||||||
|
#include "Camera.h"
|
||||||
#include "ShaderProgram.h"
|
#include "ShaderProgram.h"
|
||||||
#include "Model.h"
|
#include "Model.h"
|
||||||
|
|
||||||
@@ -26,8 +29,20 @@ class Renderer
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ShaderProgram m_ShaderProgram;
|
ShaderProgram m_ShaderProgram;
|
||||||
|
glm::mat4 viewMatrix;
|
||||||
|
glm::mat4 projectionMatrix;
|
||||||
|
|
||||||
std::vector<Model*> ModelsToRender;
|
int HEIGHT, WIDTH;
|
||||||
|
|
||||||
|
struct ModelData
|
||||||
|
{
|
||||||
|
Model* model;
|
||||||
|
glm::mat4 ModelMatrix;
|
||||||
|
ModelData(Model* _model, glm::mat4 _modelMatrix) : model(_model), ModelMatrix(_modelMatrix)
|
||||||
|
{}
|
||||||
|
};
|
||||||
|
|
||||||
|
std::vector<ModelData*> ModelsToRender;
|
||||||
|
|
||||||
Renderer();
|
Renderer();
|
||||||
|
|
||||||
@@ -35,17 +50,20 @@ public:
|
|||||||
void Draw(double dt);
|
void Draw(double dt);
|
||||||
void DrawText();
|
void DrawText();
|
||||||
|
|
||||||
void AddModelToDraw(Model*);
|
void AddModelToDraw(Model*, glm::vec3, glm::quat);
|
||||||
void AddTextToDraw();
|
void AddTextToDraw();
|
||||||
|
|
||||||
void LoadContent();
|
void LoadContent();
|
||||||
|
|
||||||
GLFWwindow* GetWindow() const { return m_Window; }
|
GLFWwindow* GetWindow() const { return m_Window; }
|
||||||
|
std::shared_ptr<Camera> GetCamera() const { return m_Camera; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
GLFWwindow* m_Window;
|
GLFWwindow* m_Window;
|
||||||
GLint m_glVersion[2];
|
GLint m_glVersion[2];
|
||||||
GLchar* m_glVendor;
|
GLchar* m_glVendor;
|
||||||
|
|
||||||
|
std::shared_ptr<Camera> m_Camera;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // Renderer_h__
|
#endif // Renderer_h__
|
||||||
@@ -128,6 +128,11 @@ GLuint ShaderProgram::Link()
|
|||||||
return m_ShaderProgramHandle;
|
return m_ShaderProgramHandle;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
GLuint ShaderProgram::GetHandle()
|
||||||
|
{
|
||||||
|
return m_ShaderProgramHandle;
|
||||||
|
}
|
||||||
|
|
||||||
void ShaderProgram::Bind()
|
void ShaderProgram::Bind()
|
||||||
{
|
{
|
||||||
if (m_ShaderProgramHandle == 0)
|
if (m_ShaderProgramHandle == 0)
|
||||||
|
|||||||
@@ -76,6 +76,8 @@ public:
|
|||||||
void Compile();
|
void Compile();
|
||||||
GLuint Link();
|
GLuint Link();
|
||||||
|
|
||||||
|
GLuint GetHandle();
|
||||||
|
|
||||||
void Bind();
|
void Bind();
|
||||||
|
|
||||||
void Unbind();
|
void Unbind();
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
#version 440
|
#version 430
|
||||||
|
|
||||||
uniform mat4 MVP;
|
uniform mat4 MVP;
|
||||||
uniform sampler2D texture0;
|
uniform sampler2D texture0;
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
#version 440
|
#version 430
|
||||||
|
|
||||||
uniform mat4 MVP;
|
uniform mat4 MVP;
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,37 @@
|
|||||||
|
#include "RenderSystem.h"
|
||||||
|
#include "World.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void Systems::RenderSystem::OnComponentCreated( std::string type, std:: shared_ptr<Component> component )
|
||||||
|
{
|
||||||
|
if(type == "Model")
|
||||||
|
{
|
||||||
|
auto modelComponent = std::static_pointer_cast<Components::Model>(component);
|
||||||
|
|
||||||
|
if (m_CachedModels.find(modelComponent->ModelFile) != m_CachedModels.end()) {
|
||||||
|
m_CachedModels[modelComponent->ModelFile] = new Model(modelComponent->ModelFile);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Systems::RenderSystem::UpdateEntity( double dt, EntityID entity, EntityID parent )
|
||||||
|
{
|
||||||
|
auto modelComponent = m_World->GetComponent<Components::Model>(entity, "Model");
|
||||||
|
if (modelComponent == nullptr)
|
||||||
|
return;
|
||||||
|
auto transformComponent = m_World->GetComponent<Components::Transform>(entity, "Transform");
|
||||||
|
if (transformComponent == nullptr)
|
||||||
|
return;
|
||||||
|
|
||||||
|
Model* model = m_CachedModels[modelComponent->ModelFile];
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
m_Renderer->AddModelToDraw(model, transformComponent->Position, transformComponent->Orientation);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,41 @@
|
|||||||
|
#ifndef RenderSystem_h__
|
||||||
|
#define RenderSystem_h__
|
||||||
|
|
||||||
|
#include "System.h"
|
||||||
|
#include "Model.h"
|
||||||
|
#include "Texture.h"
|
||||||
|
#include "Components/Model.h"
|
||||||
|
#include "Components/Transform.h"
|
||||||
|
#include "Renderer.h"
|
||||||
|
#include <unordered_map>
|
||||||
|
|
||||||
|
namespace Systems
|
||||||
|
{
|
||||||
|
|
||||||
|
class RenderSystem : public System
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
RenderSystem(World* world, std::shared_ptr<Renderer> renderer)
|
||||||
|
: System(world), m_Renderer(renderer) {}
|
||||||
|
|
||||||
|
|
||||||
|
std::unordered_map<std::string, Model*> m_CachedModels;
|
||||||
|
|
||||||
|
|
||||||
|
void AddModelToDraw();
|
||||||
|
void OnComponentCreated(std::string type, std:: shared_ptr<Component> component) override;
|
||||||
|
void UpdateEntity(double dt, EntityID entity, EntityID parent) override;
|
||||||
|
void Update(double dt) override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::shared_ptr<Renderer> m_Renderer;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#endif //RenderSystem_h__
|
||||||
Reference in New Issue
Block a user