Camera component and RenderQueue changes
This commit is contained in:
@@ -40,7 +40,7 @@ public:
|
||||
m_TexturePressed = resourceName;
|
||||
}
|
||||
|
||||
void Draw(RenderQueueCollection& rq) override
|
||||
void Draw(RenderScene& rq) override
|
||||
{
|
||||
if (m_Texture == nullptr && !m_TextureReleased.empty()) {
|
||||
SetTexture(m_TextureReleased);
|
||||
|
||||
@@ -212,7 +212,7 @@ public:
|
||||
|
||||
virtual void Update(double dt) { }
|
||||
|
||||
void DrawLayered(RenderQueueCollection& rq)
|
||||
void DrawLayered(RenderScene& rq)
|
||||
{
|
||||
if (this->Hidden())
|
||||
return;
|
||||
@@ -232,7 +232,7 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
virtual void Draw(RenderQueueCollection& rq) { }
|
||||
virtual void Draw(RenderScene& rq) { }
|
||||
|
||||
protected:
|
||||
::EventBroker* m_EventBroker;
|
||||
|
||||
@@ -16,7 +16,7 @@ public:
|
||||
void EnableScissor() { m_ScissorEnabled = true; }
|
||||
void DisableScissor() { m_ScissorEnabled = false; }
|
||||
|
||||
void Draw(RenderQueueCollection& rq) override
|
||||
void Draw(RenderScene& rq) override
|
||||
{
|
||||
if (m_Texture == nullptr)
|
||||
return;
|
||||
|
||||
@@ -26,11 +26,6 @@ public:
|
||||
glm::quat Orientation() const { return m_Orientation; }
|
||||
void SetOrientation(glm::quat 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; }
|
||||
glm::mat4 ViewMatrix() const { return m_ViewMatrix; }
|
||||
|
||||
@@ -46,11 +41,10 @@ public:
|
||||
float FarClip() const { return m_FarClip; }
|
||||
void SetFarClip(float val);
|
||||
|
||||
|
||||
void UpdateViewMatrix();
|
||||
void UpdateProjectionMatrix();
|
||||
|
||||
private:
|
||||
void UpdateViewMatrix();
|
||||
void UpdateProjectionMatrix();
|
||||
|
||||
glm::vec3 m_Position;
|
||||
glm::quat m_Orientation;
|
||||
|
||||
@@ -17,7 +17,7 @@ public:
|
||||
void InitializeFrameBuffers();
|
||||
void InitializeShaderPrograms();
|
||||
|
||||
void Draw(RenderQueueCollection& rq);
|
||||
void Draw(RenderFrame& rf);
|
||||
|
||||
//Getters
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ class DummyRenderer : public IRenderer
|
||||
{
|
||||
public:
|
||||
virtual void Initialize() override;
|
||||
virtual void Draw(RenderQueueCollection& rq) override;
|
||||
virtual void Draw(RenderFrame& rq) override;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -3,16 +3,16 @@
|
||||
|
||||
#include "../Core/EventBroker.h"
|
||||
#include "../Core/Entity.h"
|
||||
#include <string.h>
|
||||
|
||||
namespace Events
|
||||
{
|
||||
|
||||
/** Thrown Every frame, use functions to pick*/
|
||||
struct SetCamera : Event
|
||||
{
|
||||
public:
|
||||
SetCamera() { };
|
||||
EntityID Entity;
|
||||
std::string Name;
|
||||
|
||||
private:
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ public:
|
||||
}
|
||||
virtual void Initialize() = 0;
|
||||
virtual void Update(double dt) = 0;
|
||||
virtual void Draw(RenderQueueCollection& rq) = 0;
|
||||
virtual void Draw(RenderFrame& rq) = 0;
|
||||
|
||||
protected:
|
||||
Rectangle m_Resolution = Rectangle(1280, 720);
|
||||
|
||||
@@ -18,7 +18,7 @@ public:
|
||||
void InitializeFrameBuffers();
|
||||
void InitializeShaderPrograms();
|
||||
|
||||
void Draw(RenderQueueCollection& rq);
|
||||
void Draw(RenderFrame& rf);
|
||||
|
||||
|
||||
//Getters
|
||||
|
||||
@@ -39,9 +39,7 @@ struct ModelJob : RenderJob
|
||||
unsigned int ShaderID = 0;
|
||||
unsigned int TextureID = 0;
|
||||
|
||||
//TODO: RENDERER: Not sure if the best solution for pickingColor to entity link is this
|
||||
EntityID Entity;
|
||||
|
||||
glm::mat4 Matrix;
|
||||
const Texture* DiffuseTexture;
|
||||
const Texture* NormalTexture;
|
||||
@@ -165,7 +163,7 @@ private:
|
||||
int m_Size = 0;
|
||||
};
|
||||
|
||||
struct RenderQueueCollection
|
||||
struct RenderScene
|
||||
{
|
||||
RenderQueue Forward;
|
||||
RenderQueue Lights;
|
||||
@@ -184,4 +182,38 @@ struct RenderQueueCollection
|
||||
}
|
||||
};
|
||||
|
||||
class RenderFrame
|
||||
{
|
||||
public:
|
||||
|
||||
void Add(RenderScene &scene)
|
||||
{
|
||||
RenderScenes.push_back(std::shared_ptr<RenderScene>(new RenderScene(scene)));
|
||||
m_Size++;
|
||||
}
|
||||
|
||||
void Clear()
|
||||
{
|
||||
RenderScenes.clear();
|
||||
m_Size = 0;
|
||||
}
|
||||
|
||||
int Size() const { return m_Size; }
|
||||
std::list<std::shared_ptr<RenderScene>>::const_iterator begin()
|
||||
{
|
||||
return RenderScenes.begin();
|
||||
}
|
||||
|
||||
std::list<std::shared_ptr<RenderScene>>::const_iterator end()
|
||||
{
|
||||
return RenderScenes.end();
|
||||
}
|
||||
|
||||
std::list<std::shared_ptr<RenderScene>> RenderScenes;
|
||||
|
||||
|
||||
private:
|
||||
int m_Size = 0;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -12,10 +12,11 @@
|
||||
#include "../Input/EInputCommand.h"
|
||||
#include "Camera.h"
|
||||
|
||||
|
||||
class RenderSystem : public ImpureSystem
|
||||
{
|
||||
public:
|
||||
RenderSystem(EventBroker* eventBrokerer, RenderQueueCollection* renderQueues);
|
||||
RenderSystem(EventBroker* eventBrokerer, RenderFrame* renderFrame);
|
||||
|
||||
virtual void Update(World* world, double dt) override;
|
||||
|
||||
@@ -26,9 +27,14 @@ public:
|
||||
|
||||
|
||||
private:
|
||||
RenderQueueCollection* m_RenderQueues;
|
||||
World* m_World = nullptr;
|
||||
|
||||
RenderFrame* m_RenderFrame;
|
||||
bool m_SwitchCamera = false;
|
||||
Camera* m_Camera = nullptr;
|
||||
Camera* m_DefaultCamera = nullptr;
|
||||
|
||||
std::list<ComponentWrapper> m_CameraComponents;
|
||||
|
||||
EventRelay<RenderSystem, Events::SetCamera> m_ESetCamera;
|
||||
bool OnSetCamera(const Events::SetCamera &event);
|
||||
@@ -37,13 +43,12 @@ private:
|
||||
void SwitchCamera(EntityID entity);
|
||||
|
||||
void Initialize();
|
||||
void UpdateViewMatrix(ComponentWrapper& cameraTransform);
|
||||
void UpdateProjectionMatrix(ComponentWrapper& cameraComponent);
|
||||
glm::mat4 m_ViewMatrix;
|
||||
glm::mat4 m_ProjectionMatrix;
|
||||
|
||||
glm::mat4 ModelMatrix(World* world, EntityID entity);
|
||||
void FillModels(World* world, RenderQueue* renderQueue);
|
||||
glm::mat4 ModelMatrix(EntityID entity);
|
||||
void FillModels(RenderQueue* renderQueue);
|
||||
|
||||
EventRelay<RenderSystem, Events::InputCommand> m_EInputCommand;
|
||||
bool OnInputCommand(const Events::InputCommand& e);
|
||||
|
||||
@@ -27,7 +27,7 @@ public:
|
||||
|
||||
virtual void Initialize() override;
|
||||
virtual void Update(double dt) override;
|
||||
virtual void Draw(RenderQueueCollection& rq) override;
|
||||
virtual void Draw(RenderFrame& rf) override;
|
||||
|
||||
private:
|
||||
//----------------------Variables----------------------//
|
||||
|
||||
+1
-1
@@ -38,7 +38,7 @@ private:
|
||||
GUI::Frame* m_FrameStack;
|
||||
World* m_World;
|
||||
SystemPipeline* m_SystemPipeline;
|
||||
RenderQueueCollection* m_RenderQueues;
|
||||
RenderFrame* m_RenderFrame;
|
||||
|
||||
EventRelay<Game, Events::InputCommand> m_EInputCommand;
|
||||
bool debugOnInputCommand(const Events::InputCommand& e);
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<c:Camera>
|
||||
<Name>cam</Name>
|
||||
<AspectRatio>1.77</AspectRatio>
|
||||
<FOV>60.0</FOV>
|
||||
<NearClip>0.01</NearClip>
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
</xs:annotation>
|
||||
<xs:complexType>
|
||||
<xs:all>
|
||||
<xs:element name="Name" type="t:string" minOccurs="0"/>
|
||||
<xs:element name="AspectRatio" type="t:double" minOccurs="0"/>
|
||||
<xs:element name="FOV" type="t:double" minOccurs="0"/>
|
||||
<xs:element name="NearClip" type="t:double" minOccurs="0"/>
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
<Resource>Models/Camera.obj</Resource>
|
||||
</c:Model>
|
||||
<c:Camera>
|
||||
<Name>MainCamera</Name>
|
||||
</c:Camera>
|
||||
</Components>
|
||||
</Entity>
|
||||
@@ -30,6 +31,7 @@
|
||||
<Resource>Models/Camera.obj</Resource>
|
||||
</c:Model>
|
||||
<c:Camera>
|
||||
<Name>ActionCamera</Name>
|
||||
</c:Camera>
|
||||
</Components>
|
||||
</Entity>
|
||||
|
||||
@@ -64,15 +64,6 @@ void Camera::SetOrientation(glm::quat val)
|
||||
|
||||
void Camera::UpdateProjectionMatrix()
|
||||
{
|
||||
// m_ProjectionMatrix = glm::ortho(
|
||||
// -16.f,
|
||||
// 16.f,
|
||||
// -9.f,
|
||||
// 9.f,
|
||||
// m_NearClip,
|
||||
// m_FarClip
|
||||
// );
|
||||
|
||||
m_ProjectionMatrix = glm::perspective(m_FOV, m_AspectRatio, m_NearClip, m_FarClip);
|
||||
}
|
||||
|
||||
|
||||
@@ -25,40 +25,40 @@ void DrawScenePass::InitializeShaderPrograms()
|
||||
|
||||
}
|
||||
|
||||
void DrawScenePass::Draw(RenderQueueCollection& rq)
|
||||
void DrawScenePass::Draw(RenderFrame& rf)
|
||||
{
|
||||
//glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
GLERROR("Renderer::Draw PickingPass");
|
||||
|
||||
DrawScenePassState state;
|
||||
for (auto scene : rf.RenderScenes) {
|
||||
scene->Forward.Jobs.sort(DrawScenePass::DepthSort);
|
||||
|
||||
rq.Forward.Jobs.sort(DrawScenePass::DepthSort);
|
||||
for (auto &job : scene->Forward) {
|
||||
auto modelJob = std::dynamic_pointer_cast<ModelJob>(job);
|
||||
if (modelJob) {
|
||||
GLuint ShaderHandle = m_BasicForwardProgram->GetHandle();
|
||||
|
||||
//TODO: Render: Add code for more jobs than modeljobs.
|
||||
for (auto &job : rq.Forward) {
|
||||
auto modelJob = std::dynamic_pointer_cast<ModelJob>(job);
|
||||
if (modelJob) {
|
||||
GLuint ShaderHandle = m_BasicForwardProgram->GetHandle();
|
||||
m_BasicForwardProgram->Bind();
|
||||
//TODO: Kolla upp "header/include/common" shader saken så man slipper skicka in asmycket uniforms
|
||||
glUniformMatrix4fv(glGetUniformLocation(ShaderHandle, "Matrix"), 1, GL_FALSE, glm::value_ptr(modelJob->Matrix));
|
||||
glUniform4fv(glGetUniformLocation(ShaderHandle, "Color"), 1, glm::value_ptr(modelJob->Color));
|
||||
|
||||
m_BasicForwardProgram->Bind();
|
||||
//TODO: Kolla upp "header/include/common" shader saken så man slipper skicka in asmycket uniforms
|
||||
glUniformMatrix4fv(glGetUniformLocation(ShaderHandle, "Matrix"), 1, GL_FALSE, glm::value_ptr(modelJob->Matrix));
|
||||
glUniform4fv(glGetUniformLocation(ShaderHandle, "Color"), 1, glm::value_ptr(modelJob->Color));
|
||||
//TODO: Renderer: bättre textur felhantering samt fler texturer stöd
|
||||
if (modelJob->DiffuseTexture != nullptr) {
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(GL_TEXTURE_2D, modelJob->DiffuseTexture->m_Texture);
|
||||
} else {
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(GL_TEXTURE_2D, m_WhiteTexture->m_Texture);
|
||||
}
|
||||
|
||||
//TODO: Renderer: bättre textur felhantering samt fler texturer stöd
|
||||
if (modelJob->DiffuseTexture != nullptr) {
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(GL_TEXTURE_2D, modelJob->DiffuseTexture->m_Texture);
|
||||
} else {
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(GL_TEXTURE_2D, m_WhiteTexture->m_Texture);
|
||||
glBindVertexArray(modelJob->Model->VAO);
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, modelJob->Model->ElementBuffer);
|
||||
glDrawElementsBaseVertex(GL_TRIANGLES, modelJob->EndIndex - modelJob->StartIndex + 1, GL_UNSIGNED_INT, 0, modelJob->StartIndex);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
glBindVertexArray(modelJob->Model->VAO);
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, modelJob->Model->ElementBuffer);
|
||||
glDrawElementsBaseVertex(GL_TRIANGLES, modelJob->EndIndex - modelJob->StartIndex + 1, GL_UNSIGNED_INT, 0, modelJob->StartIndex);
|
||||
|
||||
continue;
|
||||
}
|
||||
}
|
||||
GLERROR("DrawScene Error");
|
||||
|
||||
@@ -42,7 +42,7 @@ void DummyRenderer::Initialize()
|
||||
glfwSwapInterval(m_VSYNC);
|
||||
}
|
||||
|
||||
void DummyRenderer::Draw(RenderQueueCollection& rq)
|
||||
void DummyRenderer::Draw(RenderFrame& rq)
|
||||
{
|
||||
glClearColor(255.f / 255, 163.f / 255, 176.f / 255, 0.f);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
|
||||
@@ -43,7 +43,7 @@ void PickingPass::InitializeShaderPrograms()
|
||||
m_PickingProgram->Link();
|
||||
}
|
||||
|
||||
void PickingPass::Draw(RenderQueueCollection& rq)
|
||||
void PickingPass::Draw(RenderFrame& rf)
|
||||
{
|
||||
m_PickingColorsToEntity.clear();
|
||||
PickingPassState* state = new PickingPassState(m_PickingBuffer.GetHandle());
|
||||
@@ -57,34 +57,38 @@ void PickingPass::Draw(RenderQueueCollection& rq)
|
||||
|
||||
std::map<EntityID, glm::vec2> entityColors;
|
||||
|
||||
for (auto &job : rq.Forward) {
|
||||
auto modelJob = std::dynamic_pointer_cast<ModelJob>(job);
|
||||
for(auto scene : rf.RenderScenes)
|
||||
{
|
||||
for (auto &job : scene->Forward) {
|
||||
auto modelJob = std::dynamic_pointer_cast<ModelJob>(job);
|
||||
|
||||
if (modelJob) {
|
||||
int pickColor[2] = { r, g };
|
||||
auto color = entityColors.find(modelJob->Entity);
|
||||
if (color != entityColors.end()) {
|
||||
pickColor[0] = color->second[0];
|
||||
pickColor[1] = color->second[1];
|
||||
} else {
|
||||
entityColors[modelJob->Entity] = glm::vec2(pickColor[0], pickColor[1]);
|
||||
if (r + 10 > 255) {
|
||||
r = 0;
|
||||
g += 1;
|
||||
if (modelJob) {
|
||||
int pickColor[2] = { r, g };
|
||||
auto color = entityColors.find(modelJob->Entity);
|
||||
if (color != entityColors.end()) {
|
||||
pickColor[0] = color->second[0];
|
||||
pickColor[1] = color->second[1];
|
||||
} else {
|
||||
r += 1;
|
||||
entityColors[modelJob->Entity] = glm::vec2(pickColor[0], pickColor[1]);
|
||||
if (r + 10 > 255) {
|
||||
r = 0;
|
||||
g += 1;
|
||||
} else {
|
||||
r += 1;
|
||||
}
|
||||
}
|
||||
m_PickingColorsToEntity[glm::vec2(pickColor[0], pickColor[1])] = modelJob->Entity;
|
||||
|
||||
glUniformMatrix4fv(glGetUniformLocation(ShaderHandle, "Matrix"), 1, GL_FALSE, glm::value_ptr(modelJob->Matrix));
|
||||
glUniform2fv(glGetUniformLocation(ShaderHandle, "PickingColor"), 1, glm::value_ptr(glm::vec2(pickColor[0], pickColor[1])));
|
||||
|
||||
glBindVertexArray(modelJob->Model->VAO);
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, modelJob->Model->ElementBuffer);
|
||||
glDrawElementsBaseVertex(GL_TRIANGLES, modelJob->EndIndex - modelJob->StartIndex + 1, GL_UNSIGNED_INT, nullptr, modelJob->StartIndex);
|
||||
}
|
||||
m_PickingColorsToEntity[glm::vec2(pickColor[0], pickColor[1])] = modelJob->Entity;
|
||||
|
||||
glUniformMatrix4fv(glGetUniformLocation(ShaderHandle, "Matrix"), 1, GL_FALSE, glm::value_ptr(modelJob->Matrix));
|
||||
glUniform2fv(glGetUniformLocation(ShaderHandle, "PickingColor"), 1, glm::value_ptr(glm::vec2(pickColor[0], pickColor[1])));
|
||||
|
||||
glBindVertexArray(modelJob->Model->VAO);
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, modelJob->Model->ElementBuffer);
|
||||
glDrawElementsBaseVertex(GL_TRIANGLES, modelJob->EndIndex - modelJob->StartIndex + 1, GL_UNSIGNED_INT, nullptr, modelJob->StartIndex);
|
||||
}
|
||||
}
|
||||
|
||||
m_PickingBuffer.Unbind();
|
||||
GLERROR("PickingPass Error");
|
||||
|
||||
@@ -92,15 +96,15 @@ void PickingPass::Draw(RenderQueueCollection& rq)
|
||||
int fbWidth;
|
||||
int fbHeight;
|
||||
glfwGetFramebufferSize(m_Renderer->Window(), &fbWidth, &fbHeight);
|
||||
/* Events::Picking pickEvent = Events::Picking(
|
||||
Events::Picking pickEvent = Events::Picking(
|
||||
&m_PickingBuffer,
|
||||
&m_DepthBuffer,
|
||||
m_Renderer->Camera()->ProjectionMatrix(),
|
||||
m_Renderer->Camera()->ViewMatrix(),
|
||||
Rectangle(fbWidth, fbHeight),
|
||||
&m_PickingColorsToEntity);*/
|
||||
&m_PickingColorsToEntity);
|
||||
|
||||
//m_EventBroker->Publish(pickEvent);
|
||||
m_EventBroker->Publish(pickEvent);
|
||||
|
||||
delete state;
|
||||
}
|
||||
|
||||
@@ -1,29 +1,56 @@
|
||||
#include "Rendering/RenderSystem.h"
|
||||
#include "Rendering/DebugCameraInputController.h"
|
||||
|
||||
RenderSystem::RenderSystem(EventBroker* eventBrokerer, RenderQueueCollection* renderQueues)
|
||||
RenderSystem::RenderSystem(EventBroker* eventBrokerer, RenderFrame* renderFrame)
|
||||
:ImpureSystem(eventBrokerer)
|
||||
{
|
||||
m_RenderQueues = renderQueues;
|
||||
m_RenderFrame = renderFrame;
|
||||
Initialize();
|
||||
EVENT_SUBSCRIBE_MEMBER(m_ESetCamera, &RenderSystem::OnSetCamera);
|
||||
EVENT_SUBSCRIBE_MEMBER(m_EInputCommand, &RenderSystem::OnInputCommand);
|
||||
|
||||
|
||||
m_DefaultCamera = new Camera(1.77f /* should be based on width and height */, glm::radians(45.f), 0.01f, 5000.f);
|
||||
m_DefaultCamera->SetPosition(glm::vec3(0, 0, 10));
|
||||
if (m_Camera == nullptr) {
|
||||
m_Camera = m_DefaultCamera;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool RenderSystem::OnSetCamera(const Events::SetCamera &event)
|
||||
{
|
||||
m_CurrentCamera = event.Entity;
|
||||
auto cameras = m_World->GetComponents("Camera");
|
||||
|
||||
if (cameras != nullptr) {
|
||||
for (auto it = cameras->begin(); it != cameras->end(); it++) {
|
||||
if ((std::string)(*it)["Name"] == event.Name) {
|
||||
SwitchCamera((*it).EntityID);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void RenderSystem::SwitchCamera(EntityID entity)
|
||||
{
|
||||
m_CurrentCamera = entity;
|
||||
m_SwitchCamera = false;
|
||||
LOG_INFO("Switched to camera %i", m_CurrentCamera);
|
||||
if(m_World->HasComponent(entity, "Camera")) {
|
||||
if (m_World->HasComponent(m_CurrentCamera, "Model")) {
|
||||
m_World->GetComponent(m_CurrentCamera, "Model")["Visible"] = true;
|
||||
}
|
||||
|
||||
if (m_World->HasComponent(entity, "Model")) {
|
||||
m_World->GetComponent(entity, "Model")["Visible"] = false;
|
||||
}
|
||||
|
||||
m_CurrentCamera = entity;
|
||||
m_SwitchCamera = false;
|
||||
|
||||
LOG_INFO("Switched to %s", m_World->GetComponent(m_CurrentCamera, "Camera")["Name"]);
|
||||
} else {
|
||||
LOG_ERROR("Entity %i does not have a CameraComponent", entity);
|
||||
m_SwitchCamera = false;
|
||||
}
|
||||
}
|
||||
|
||||
void RenderSystem::Initialize()
|
||||
@@ -31,24 +58,21 @@ void RenderSystem::Initialize()
|
||||
|
||||
}
|
||||
|
||||
void RenderSystem::UpdateViewMatrix(ComponentWrapper& cameraTransform)
|
||||
{
|
||||
glm::quat orientation = glm::quat((glm::vec3)cameraTransform["Orientation"]);
|
||||
glm::vec3 position = cameraTransform["Position"];
|
||||
|
||||
m_ViewMatrix = glm::toMat4(glm::inverse(orientation)) * glm::translate(-position);
|
||||
}
|
||||
|
||||
void RenderSystem::UpdateProjectionMatrix(ComponentWrapper& cameraComponent)
|
||||
{
|
||||
double fov = (double&)cameraComponent["FOV"];
|
||||
double aspectRatio = (double&)cameraComponent["AspectRatio"];
|
||||
double nearClip = (double&)cameraComponent["NearClip"];
|
||||
double farClip = (double&)cameraComponent["FarClip"];
|
||||
double fov = cameraComponent["FOV"];
|
||||
double aspectRatio = cameraComponent["AspectRatio"];
|
||||
double nearClip = cameraComponent["NearClip"];
|
||||
double farClip = cameraComponent["FarClip"];
|
||||
|
||||
double fovY = atan(tan(glm::radians(fov)/2.0) * aspectRatio) * 2.0;
|
||||
m_ProjectionMatrix = glm::perspective(fovY, aspectRatio, nearClip, farClip);
|
||||
|
||||
|
||||
m_Camera->SetFOV(fovY);
|
||||
m_Camera->SetAspectRatio(aspectRatio);
|
||||
m_Camera->SetNearClip(nearClip);
|
||||
m_Camera->SetFarClip(farClip);
|
||||
m_Camera->UpdateProjectionMatrix();
|
||||
}
|
||||
|
||||
glm::vec3 RenderSystem::AbsolutePosition(World* world, EntityID entity)
|
||||
@@ -95,20 +119,19 @@ glm::vec3 RenderSystem::AbsoluteScale(World* world, EntityID entity)
|
||||
return scale;
|
||||
}
|
||||
|
||||
|
||||
glm::mat4 RenderSystem::ModelMatrix(World* world, EntityID entity)
|
||||
glm::mat4 RenderSystem::ModelMatrix(EntityID entity)
|
||||
{
|
||||
glm::vec3 position = AbsolutePosition(world, entity);
|
||||
glm::quat orientation = AbsoluteOrientation(world, entity);
|
||||
glm::vec3 scale = AbsoluteScale(world, entity);
|
||||
glm::vec3 position = AbsolutePosition(m_World, entity);
|
||||
glm::quat orientation = AbsoluteOrientation(m_World, entity);
|
||||
glm::vec3 scale = AbsoluteScale(m_World, entity);
|
||||
|
||||
glm::mat4 modelMatrix = glm::translate(glm::mat4(), position) * glm::toMat4(orientation) * glm::scale(scale);
|
||||
return modelMatrix;
|
||||
}
|
||||
|
||||
void RenderSystem::FillModels(World* world, RenderQueue* renderQueue)
|
||||
void RenderSystem::FillModels(RenderQueue* renderQueue)
|
||||
{
|
||||
auto models = world->GetComponents("Model");
|
||||
auto models = m_World->GetComponents("Model");
|
||||
if (models == nullptr) {
|
||||
return;
|
||||
}
|
||||
@@ -140,7 +163,7 @@ void RenderSystem::FillModels(World* world, RenderQueue* renderQueue)
|
||||
job.Model = model;
|
||||
job.StartIndex = texGroup.StartIndex;
|
||||
job.EndIndex = texGroup.EndIndex;
|
||||
job.Matrix = m_ProjectionMatrix * m_ViewMatrix * (model->m_Matrix * ModelMatrix(world, modelC.EntityID));
|
||||
job.Matrix = m_Camera->ProjectionMatrix() * m_Camera->ViewMatrix() * (model->m_Matrix * ModelMatrix(modelC.EntityID));
|
||||
job.Color = color;
|
||||
job.Entity = modelC.EntityID;
|
||||
|
||||
@@ -156,7 +179,7 @@ void RenderSystem::FillModels(World* world, RenderQueue* renderQueue)
|
||||
job.Model = model;
|
||||
job.StartIndex = texGroup.StartIndex;
|
||||
job.EndIndex = texGroup.EndIndex;
|
||||
job.Matrix = m_ProjectionMatrix * m_ViewMatrix * (model->m_Matrix * ModelMatrix(world, modelC.EntityID));
|
||||
job.Matrix = m_Camera->ProjectionMatrix() * m_Camera->ViewMatrix() * (model->m_Matrix * ModelMatrix(modelC.EntityID));
|
||||
job.Color = color;
|
||||
job.Entity = modelC.EntityID;
|
||||
|
||||
@@ -176,9 +199,10 @@ bool RenderSystem::OnInputCommand(const Events::InputCommand& e)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void RenderSystem::Update(World* world, double dt)
|
||||
{
|
||||
m_World = world;
|
||||
|
||||
m_EventBroker->Process<RenderSystem>();
|
||||
static DebugCameraInputController<RenderSystem> firstPersonInputController(m_EventBroker, -1);
|
||||
|
||||
@@ -201,34 +225,42 @@ void RenderSystem::Update(World* world, double dt)
|
||||
ComponentWrapper& cameraTransform = world->GetComponent(m_CurrentCamera, "Transform");
|
||||
|
||||
firstPersonInputController.SetOrientation(glm::quat((glm::vec3)cameraTransform["Orientation"]));
|
||||
firstPersonInputController.SetPosition((glm::vec3)cameraTransform["Position"]);
|
||||
firstPersonInputController.SetPosition(cameraTransform["Position"]);
|
||||
}
|
||||
}
|
||||
|
||||
if(world->HasComponent(m_CurrentCamera, "Camera") && world->HasComponent(m_CurrentCamera, "Transform")) {
|
||||
|
||||
ComponentWrapper& cameraComponent = world->GetComponent(m_CurrentCamera, "Camera");
|
||||
ComponentWrapper& cameraTransform = world->GetComponent(m_CurrentCamera, "Transform");
|
||||
|
||||
firstPersonInputController.Update(dt);
|
||||
(glm::vec3&)cameraTransform["Orientation"] = glm::eulerAngles(firstPersonInputController.Orientation());
|
||||
(glm::vec3&)cameraTransform["Position"] = firstPersonInputController.Position();
|
||||
if(world->GetParent(m_CurrentCamera) == 1) { // world is entity 1, is this ok?
|
||||
firstPersonInputController.Update(dt);
|
||||
(glm::vec3&)cameraTransform["Orientation"] = glm::eulerAngles(firstPersonInputController.Orientation());
|
||||
(glm::vec3&)cameraTransform["Position"] = firstPersonInputController.Position();
|
||||
}
|
||||
|
||||
glm::vec3 position = AbsolutePosition(world, m_CurrentCamera);
|
||||
glm::quat orientation = AbsoluteOrientation(world, m_CurrentCamera);
|
||||
|
||||
m_Camera->SetPosition(position);
|
||||
m_Camera->SetOrientation(orientation);
|
||||
|
||||
UpdateProjectionMatrix(cameraComponent);
|
||||
UpdateViewMatrix(cameraTransform);
|
||||
m_Camera->UpdateViewMatrix();
|
||||
} else {
|
||||
m_ProjectionMatrix = glm::perspective(glm::radians(40.f), 1.77f, 0.05f, 5000.f);
|
||||
m_ViewMatrix = glm::mat4();
|
||||
m_Camera = m_DefaultCamera;
|
||||
|
||||
auto cameras = world->GetComponents("Camera");
|
||||
|
||||
if (cameras != nullptr) {
|
||||
ComponentWrapper& cameraC = *cameras->begin();
|
||||
m_CurrentCamera = cameraC.EntityID;
|
||||
SwitchCamera(cameraC.EntityID);
|
||||
world->GetComponent(m_CurrentCamera, "Model")["Visible"] = false;
|
||||
}
|
||||
}
|
||||
|
||||
m_RenderQueues->Clear();
|
||||
FillModels(world, &m_RenderQueues->Forward);
|
||||
m_RenderFrame->Clear();
|
||||
RenderScene* rs = new RenderScene();
|
||||
rs->Camera = m_Camera;
|
||||
FillModels(&rs->Forward);
|
||||
m_RenderFrame->Add(*rs);
|
||||
}
|
||||
|
||||
@@ -90,14 +90,14 @@ void Renderer::Update(double dt)
|
||||
m_ImGuiRenderPass->Update(dt);
|
||||
}
|
||||
|
||||
void Renderer::Draw(RenderQueueCollection& rq)
|
||||
void Renderer::Draw(RenderFrame& rf)
|
||||
{
|
||||
m_PickingPass->Draw(rq);
|
||||
//DrawScreenQuad(m_PickingPass->PickingTexture());
|
||||
m_Camera = (*rf.begin())->Camera;
|
||||
m_PickingPass->Draw(rf);
|
||||
|
||||
glClearColor(255.f / 255, 163.f / 255, 176.f / 255, 1.f);
|
||||
|
||||
m_DrawScenePass->Draw(rq);
|
||||
m_DrawScenePass->Draw(rf);
|
||||
GLERROR("Renderer::Draw m_DrawScenePass->Draw");
|
||||
m_ImGuiRenderPass->Draw();
|
||||
glfwSwapBuffers(m_Window);
|
||||
|
||||
+3
-3
@@ -47,14 +47,14 @@ Game::Game(int argc, char* argv[])
|
||||
ResourceManager::Load<EntityXMLFile>(mapToLoad)->PopulateWorld(m_World);
|
||||
}
|
||||
|
||||
m_RenderQueues = new RenderQueueCollection();
|
||||
m_RenderFrame = new RenderFrame();
|
||||
|
||||
// Create system pipeline
|
||||
m_SystemPipeline = new SystemPipeline(m_EventBroker);
|
||||
m_SystemPipeline->AddSystem<RaptorCopterSystem>();
|
||||
m_SystemPipeline->AddSystem<PlayerSystem>();
|
||||
m_SystemPipeline->AddSystem<EditorSystem>(m_Renderer);
|
||||
m_SystemPipeline->AddSystem<RenderSystem>(m_RenderQueues);
|
||||
m_SystemPipeline->AddSystem<RenderSystem>(m_RenderFrame);
|
||||
|
||||
m_LastTime = glfwGetTime();
|
||||
|
||||
@@ -91,7 +91,7 @@ void Game::Tick()
|
||||
m_Renderer->Update(dt);
|
||||
|
||||
GLERROR("Game::Tick m_RenderQueueFactory->Update");
|
||||
m_Renderer->Draw(*m_RenderQueues);
|
||||
m_Renderer->Draw(*m_RenderFrame);
|
||||
GLERROR("Game::Tick m_Renderer->Draw");
|
||||
m_EventBroker->Swap();
|
||||
m_EventBroker->Clear();
|
||||
|
||||
Reference in New Issue
Block a user