From e7f02f14a074d9dc6873779779c18567e00fd13b Mon Sep 17 00:00:00 2001 From: viktorljung Date: Thu, 14 Jan 2016 11:12:02 +0100 Subject: [PATCH] Added Transform.h that holds all the AbsoluteTransformation functions. Camera now working better with scenes. Changed Modeljob Matrix to only hold the model matrix instad of all matrix info --- include/Engine/Core/Transform.h | 62 +++++++++++++++++++ include/Engine/Editor/EditorSystem.h | 2 +- include/Engine/Rendering/DrawScenePass.h | 2 +- include/Engine/Rendering/PickingPass.h | 2 +- include/Engine/Rendering/RenderQueue.h | 2 +- include/Engine/Rendering/RenderSystem.h | 9 +-- include/Engine/Rendering/Renderer.h | 2 +- resources/Shaders/BasicForward.frag.glsl | 1 - resources/Shaders/BasicForward.vert.glsl | 6 +- resources/Shaders/Picking.frag.glsl | 3 - resources/Shaders/Picking.vert.glsl | 6 +- src/Engine/Editor/EditorSystem.cpp | 14 ++--- src/Engine/Rendering/DrawScenePass.cpp | 49 +++++++-------- src/Engine/Rendering/PickingPass.cpp | 15 ++--- src/Engine/Rendering/RenderSystem.cpp | 76 +++--------------------- src/Engine/Rendering/Renderer.cpp | 17 +++--- 16 files changed, 135 insertions(+), 133 deletions(-) create mode 100644 include/Engine/Core/Transform.h diff --git a/include/Engine/Core/Transform.h b/include/Engine/Core/Transform.h new file mode 100644 index 00000000..c43e4386 --- /dev/null +++ b/include/Engine/Core/Transform.h @@ -0,0 +1,62 @@ +#ifndef Transform_h__ +#define Transform_h__ + +#include "../GLM.h" +#include "World.h" + +static class Transform +{ +public: + static glm::vec3 AbsolutePosition(World* world, EntityID entity) + { + glm::vec3 position; + + while (entity != EntityID_Invalid) { + ComponentWrapper transform = world->GetComponent(entity, "Transform"); + EntityID parent = world->GetParent(entity); + position += AbsoluteOrientation(world, parent) * (glm::vec3)transform["Position"]; + entity = parent; + } + + return position; + }; + + static glm::quat AbsoluteOrientation(World* world, EntityID entity) + { + glm::quat orientation; + + while (entity != EntityID_Invalid) { + ComponentWrapper transform = world->GetComponent(entity, "Transform"); + orientation = glm::quat((glm::vec3)transform["Orientation"]) * orientation; + entity = world->GetParent(entity); + } + + return orientation; + }; + + static glm::vec3 AbsoluteScale(World* world, EntityID entity) + { + glm::vec3 scale(1.f); + + while (entity != EntityID_Invalid) { + ComponentWrapper transform = world->GetComponent(entity, "Transform"); + scale *= (glm::vec3)transform["Scale"]; + entity = world->GetParent(entity); + } + + return scale; + }; + + static glm::mat4 ModelMatrix(EntityID entity, World* world) + { + glm::vec3 position = Transform::AbsolutePosition(world, entity); + glm::quat orientation = Transform::AbsoluteOrientation(world, entity); + glm::vec3 scale = Transform::AbsoluteScale(world, entity); + + glm::mat4 modelMatrix = glm::translate(glm::mat4(), position) * glm::toMat4(orientation) * glm::scale(scale); + return modelMatrix; + } + +}; + +#endif \ No newline at end of file diff --git a/include/Engine/Editor/EditorSystem.h b/include/Engine/Editor/EditorSystem.h index 08b3c6a4..32eea363 100644 --- a/include/Engine/Editor/EditorSystem.h +++ b/include/Engine/Editor/EditorSystem.h @@ -9,7 +9,7 @@ #include "../Core/ConfigFile.h" #include "../Input/EInputCommand.h" #include "../Rendering/IRenderer.h" -#include "../Rendering/RenderSystem.h" +#include "../Core/Transform.h" #include "../Core/EFileDropped.h" #include "../Core/EntityFilePreprocessor.h" #include "../Core/EntityFileParser.h" diff --git a/include/Engine/Rendering/DrawScenePass.h b/include/Engine/Rendering/DrawScenePass.h index 4200383f..ca2463cf 100644 --- a/include/Engine/Rendering/DrawScenePass.h +++ b/include/Engine/Rendering/DrawScenePass.h @@ -17,7 +17,7 @@ public: void InitializeFrameBuffers(); void InitializeShaderPrograms(); - void Draw(RenderFrame& rf); + void Draw(RenderScene& scene); //Getters diff --git a/include/Engine/Rendering/PickingPass.h b/include/Engine/Rendering/PickingPass.h index 08a06b0e..01613651 100644 --- a/include/Engine/Rendering/PickingPass.h +++ b/include/Engine/Rendering/PickingPass.h @@ -19,7 +19,7 @@ public: void InitializeFrameBuffers(); void InitializeShaderPrograms(); - void Draw(RenderFrame& rf); + void Draw(RenderScene& scene); //Getters diff --git a/include/Engine/Rendering/RenderQueue.h b/include/Engine/Rendering/RenderQueue.h index cd008340..dba34c3e 100644 --- a/include/Engine/Rendering/RenderQueue.h +++ b/include/Engine/Rendering/RenderQueue.h @@ -52,7 +52,7 @@ struct RenderScene ::Camera* Camera; std::list> ForwardJobs; std::list> LightJobs; - Rectangle ViewPort; + Rectangle Viewport; void Clear() { diff --git a/include/Engine/Rendering/RenderSystem.h b/include/Engine/Rendering/RenderSystem.h index 473fae0b..93e7233f 100644 --- a/include/Engine/Rendering/RenderSystem.h +++ b/include/Engine/Rendering/RenderSystem.h @@ -13,6 +13,7 @@ #include "Camera.h" #include "ModelJob.h" #include "Renderer.h" +#include "../Core/Transform.h" class RenderSystem : public ImpureSystem { @@ -21,12 +22,6 @@ public: virtual void Update(World* world, double dt) override; - static glm::vec3 AbsolutePosition(World* world, EntityID entity); - static glm::quat AbsoluteOrientation(World* world, EntityID entity); - static glm::vec3 AbsoluteScale(World* world, EntityID entity); - - - private: World* m_World = nullptr; const IRenderer* m_Renderer = nullptr; @@ -44,13 +39,11 @@ private: void switchCamera(EntityID entity); - void initialize(); void updateCamera(World* world, double dt); void updateProjectionMatrix(ComponentWrapper& cameraComponent); glm::mat4 m_ViewMatrix; glm::mat4 m_ProjectionMatrix; - glm::mat4 ModelMatrix(EntityID entity, World* world); void fillModels(std::list>& jobs, World* world); EventRelay m_EInputCommand; diff --git a/include/Engine/Rendering/Renderer.h b/include/Engine/Rendering/Renderer.h index b5a5c1b5..6dd7e250 100644 --- a/include/Engine/Rendering/Renderer.h +++ b/include/Engine/Rendering/Renderer.h @@ -26,7 +26,7 @@ public: virtual void Initialize() override; virtual void Update(double dt) override; - virtual void Draw(RenderFrame& rf) override; + virtual void Draw(RenderFrame& frame) override; virtual PickData Pick(glm::vec2 screenCoord) override; diff --git a/resources/Shaders/BasicForward.frag.glsl b/resources/Shaders/BasicForward.frag.glsl index 9ca4db99..dc04f59f 100644 --- a/resources/Shaders/BasicForward.frag.glsl +++ b/resources/Shaders/BasicForward.frag.glsl @@ -1,6 +1,5 @@ #version 430 -uniform mat4 Matrix; uniform vec4 Color; uniform sampler2D texture0; diff --git a/resources/Shaders/BasicForward.vert.glsl b/resources/Shaders/BasicForward.vert.glsl index a7fe2d9f..96f081f4 100644 --- a/resources/Shaders/BasicForward.vert.glsl +++ b/resources/Shaders/BasicForward.vert.glsl @@ -1,6 +1,8 @@ #version 430 -uniform mat4 Matrix; +uniform mat4 M; +uniform mat4 V; +uniform mat4 P; layout(location = 0) in vec3 Position; layout(location = 1) in vec3 Normal; @@ -23,7 +25,7 @@ out VertexData{ void main() { - gl_Position = Matrix * vec4(Position, 1.0); + gl_Position = P * V * M * vec4(Position, 1.0); Output.Position = Position; Output.TextureCoordinate = TextureCoords; diff --git a/resources/Shaders/Picking.frag.glsl b/resources/Shaders/Picking.frag.glsl index 8c95ead3..59f761f9 100644 --- a/resources/Shaders/Picking.frag.glsl +++ b/resources/Shaders/Picking.frag.glsl @@ -1,8 +1,5 @@ #version 430 -uniform mat4 M; -uniform mat4 V; -uniform mat4 P; uniform vec2 PickingColor; in VertexData{ diff --git a/resources/Shaders/Picking.vert.glsl b/resources/Shaders/Picking.vert.glsl index e9680bd1..b2857cea 100644 --- a/resources/Shaders/Picking.vert.glsl +++ b/resources/Shaders/Picking.vert.glsl @@ -1,6 +1,8 @@ #version 430 -uniform mat4 Matrix; +uniform mat4 M; +uniform mat4 V; +uniform mat4 P; layout(location = 0) in vec3 Position; layout(location = 1) in vec3 Normal; @@ -20,7 +22,7 @@ out VertexData{ void main() { - gl_Position = Matrix * vec4(Position, 1.0); + gl_Position = P * V* M * vec4(Position, 1.0); Output.Position = Position; } \ No newline at end of file diff --git a/src/Engine/Editor/EditorSystem.cpp b/src/Engine/Editor/EditorSystem.cpp index 80c4991a..73050781 100644 --- a/src/Engine/Editor/EditorSystem.cpp +++ b/src/Engine/Editor/EditorSystem.cpp @@ -159,7 +159,7 @@ bool EditorSystem::OnMouseMove(const Events::MouseMove& e) EntityID parent = m_World->GetParent(m_Selection); glm::quat inverseParentOrientation; //if (parent != 0) { - inverseParentOrientation = glm::inverse(RenderSystem::AbsoluteOrientation(m_World, parent)); + inverseParentOrientation = glm::inverse(Transform::AbsoluteOrientation(m_World, parent)); //} (glm::vec3&)m_World->GetComponent(m_Selection, "Transform")["Position"] += inverseParentOrientation * movement; } else if (m_WidgetSpace == WidgetSpace::Local) { @@ -178,7 +178,7 @@ bool EditorSystem::OnMouseMove(const Events::MouseMove& e) // parentOrientation = RenderSystem::AbsoluteOrientation(m_World, parent); //} glm::vec3& selectionOrientation = m_World->GetComponent(m_Selection, "Transform")["Orientation"]; - glm::quat currentOrientation = RenderSystem::AbsoluteOrientation(m_World, m_Selection); + glm::quat currentOrientation = Transform::AbsoluteOrientation(m_World, m_Selection); //glm::quat currentOrientation = parentOrientation * glm::quat(selectionOrientation); glm::quat deltaOrientation(finalMovement); selectionOrientation = glm::eulerAngles(glm::inverse(parentOrientation) * (deltaOrientation * currentOrientation)); @@ -321,10 +321,10 @@ void EditorSystem::updateWidget() if (m_Selection != EntityID_Invalid) { auto widgetTransform = m_World->GetComponent(m_Widget, "Transform"); - glm::vec3 selectionPosition = RenderSystem::AbsolutePosition(m_World, m_Selection); + glm::vec3 selectionPosition = Transform::AbsolutePosition(m_World, m_Selection); widgetTransform["Position"] = selectionPosition; if (m_WidgetSpace == WidgetSpace::Local) { - widgetTransform["Orientation"] = glm::eulerAngles(RenderSystem::AbsoluteOrientation(m_World, m_Selection)); + widgetTransform["Orientation"] = glm::eulerAngles(Transform::AbsoluteOrientation(m_World, m_Selection)); } } } @@ -359,7 +359,7 @@ void EditorSystem::setWidgetMode(WidgetMode newMode) if (m_Selection != EntityID_Invalid) { if (m_WidgetSpace == WidgetSpace::Local) { auto selectionTransform = m_World->GetComponent(m_Selection, "Transform"); - widgetTransform["Orientation"] = glm::eulerAngles(RenderSystem::AbsoluteOrientation(m_World, m_Selection)); + widgetTransform["Orientation"] = glm::eulerAngles(Transform::AbsoluteOrientation(m_World, m_Selection)); } } } else if (newMode == WidgetMode::Scale) { @@ -370,7 +370,7 @@ void EditorSystem::setWidgetMode(WidgetMode newMode) m_World->GetComponent(m_WidgetOrigin, "Model")["Resource"] = "Models/ScaleWidgetOrigin.obj"; if (m_Selection != EntityID_Invalid) { auto selectionTransform = m_World->GetComponent(m_Selection, "Transform"); - widgetTransform["Orientation"] = glm::eulerAngles(RenderSystem::AbsoluteOrientation(m_World, m_Selection)); + widgetTransform["Orientation"] = glm::eulerAngles(Transform::AbsoluteOrientation(m_World, m_Selection)); } } else if (newMode == WidgetMode::Rotate) { m_World->GetComponent(m_WidgetX, "Model")["Resource"] = "Models/RotationWidgetX.obj"; @@ -379,7 +379,7 @@ void EditorSystem::setWidgetMode(WidgetMode newMode) if (m_Selection != EntityID_Invalid) { auto selectionTransform = m_World->GetComponent(m_Selection, "Transform"); if (m_WidgetSpace == WidgetSpace::Local) { - widgetTransform["Orientation"] = glm::eulerAngles(RenderSystem::AbsoluteOrientation(m_World, m_Selection)); + widgetTransform["Orientation"] = glm::eulerAngles(Transform::AbsoluteOrientation(m_World, m_Selection)); } } } diff --git a/src/Engine/Rendering/DrawScenePass.cpp b/src/Engine/Rendering/DrawScenePass.cpp index eb585aff..5e5d32a7 100644 --- a/src/Engine/Rendering/DrawScenePass.cpp +++ b/src/Engine/Rendering/DrawScenePass.cpp @@ -23,40 +23,41 @@ void DrawScenePass::InitializeShaderPrograms() m_BasicForwardProgram->Link(); } -void DrawScenePass::Draw(RenderFrame& rf) +void DrawScenePass::Draw(RenderScene& scene) { //glBindFramebuffer(GL_FRAMEBUFFER, 0); GLERROR("Renderer::Draw PickingPass"); DrawScenePassState state; - for (auto scene : rf.RenderScenes) { - for (auto &job : scene->ForwardJobs) { - auto modelJob = std::dynamic_pointer_cast(job); - if (modelJob) { - GLuint ShaderHandle = m_BasicForwardProgram->GetHandle(); + for (auto &job : scene.ForwardJobs) { + auto modelJob = std::dynamic_pointer_cast(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, "M"), 1, GL_FALSE, glm::value_ptr(modelJob->Matrix)); + glUniformMatrix4fv(glGetUniformLocation(ShaderHandle, "V"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ViewMatrix())); + glUniformMatrix4fv(glGetUniformLocation(ShaderHandle, "P"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ProjectionMatrix())); + 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); - } - - 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; + //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; } } + GLERROR("DrawScene Error"); } diff --git a/src/Engine/Rendering/PickingPass.cpp b/src/Engine/Rendering/PickingPass.cpp index 95110aa4..e6a8842d 100644 --- a/src/Engine/Rendering/PickingPass.cpp +++ b/src/Engine/Rendering/PickingPass.cpp @@ -43,7 +43,7 @@ void PickingPass::InitializeShaderPrograms() m_PickingProgram->Link(); } -void PickingPass::Draw(RenderFrame& rf) +void PickingPass::Draw(RenderScene& scene) { m_PickingColorsToEntity.clear(); PickingPassState* state = new PickingPassState(m_PickingBuffer.GetHandle()); @@ -57,11 +57,9 @@ void PickingPass::Draw(RenderFrame& rf) std::map entityColors; - for(auto scene : rf.RenderScenes) - { - m_Camera = scene->Camera; + m_Camera = scene.Camera; - for (auto &job : scene->ForwardJobs) { + for (auto &job : scene.ForwardJobs) { auto modelJob = std::dynamic_pointer_cast(job); if (modelJob) { @@ -81,7 +79,10 @@ void PickingPass::Draw(RenderFrame& rf) } m_PickingColorsToEntity[glm::vec2(pickColor[0], pickColor[1])] = modelJob->Entity; - glUniformMatrix4fv(glGetUniformLocation(ShaderHandle, "Matrix"), 1, GL_FALSE, glm::value_ptr(modelJob->Matrix)); + + glUniformMatrix4fv(glGetUniformLocation(ShaderHandle, "M"), 1, GL_FALSE, glm::value_ptr(modelJob->Matrix)); + glUniformMatrix4fv(glGetUniformLocation(ShaderHandle, "V"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ViewMatrix())); + glUniformMatrix4fv(glGetUniformLocation(ShaderHandle, "P"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ProjectionMatrix())); glUniform2fv(glGetUniformLocation(ShaderHandle, "PickingColor"), 1, glm::value_ptr(glm::vec2(pickColor[0], pickColor[1]))); glBindVertexArray(modelJob->Model->VAO); @@ -89,7 +90,7 @@ void PickingPass::Draw(RenderFrame& rf) glDrawElementsBaseVertex(GL_TRIANGLES, modelJob->EndIndex - modelJob->StartIndex + 1, GL_UNSIGNED_INT, nullptr, modelJob->StartIndex); } } - } + m_PickingBuffer.Unbind(); GLERROR("PickingPass Error"); diff --git a/src/Engine/Rendering/RenderSystem.cpp b/src/Engine/Rendering/RenderSystem.cpp index 5bcdb384..7c570953 100644 --- a/src/Engine/Rendering/RenderSystem.cpp +++ b/src/Engine/Rendering/RenderSystem.cpp @@ -5,7 +5,6 @@ RenderSystem::RenderSystem(EventBroker* eventBrokerer, const IRenderer* renderer { m_Renderer = renderer; m_RenderFrame = renderFrame; - initialize(); EVENT_SUBSCRIBE_MEMBER(m_ESetCamera, &RenderSystem::OnSetCamera); EVENT_SUBSCRIBE_MEMBER(m_EInputCommand, &RenderSystem::OnInputCommand); @@ -52,11 +51,6 @@ void RenderSystem::switchCamera(EntityID entity) } } -void RenderSystem::initialize() -{ - -} - void RenderSystem::updateProjectionMatrix(ComponentWrapper& cameraComponent) { double fov = cameraComponent["FOV"]; @@ -74,56 +68,6 @@ void RenderSystem::updateProjectionMatrix(ComponentWrapper& cameraComponent) m_Camera->UpdateProjectionMatrix(); } -glm::vec3 RenderSystem::AbsolutePosition(World* world, EntityID entity) -{ - glm::vec3 position; - - while (entity != EntityID_Invalid) { - ComponentWrapper transform = world->GetComponent(entity, "Transform"); - EntityID parent = world->GetParent(entity); - position += AbsoluteOrientation(world, parent) * (glm::vec3)transform["Position"]; - entity = parent; - } - - return position; -} - -glm::quat RenderSystem::AbsoluteOrientation(World* world, EntityID entity) -{ - glm::quat orientation; - - while (entity != EntityID_Invalid) { - ComponentWrapper transform = world->GetComponent(entity, "Transform"); - orientation = glm::quat((glm::vec3)transform["Orientation"]) * orientation; - entity = world->GetParent(entity); - } - - return orientation; -} - -glm::vec3 RenderSystem::AbsoluteScale(World* world, EntityID entity) -{ - glm::vec3 scale(1.f); - - while (entity != EntityID_Invalid) { - ComponentWrapper transform = world->GetComponent(entity, "Transform"); - scale *= (glm::vec3)transform["Scale"]; - entity = world->GetParent(entity); - } - - return scale; -} - -glm::mat4 RenderSystem::ModelMatrix(EntityID entity, World* world) -{ - glm::vec3 position = AbsolutePosition(world, entity); - glm::quat orientation = AbsoluteOrientation(world, entity); - glm::vec3 scale = AbsoluteScale(world, entity); - - glm::mat4 modelMatrix = glm::translate(glm::mat4(), position) * glm::toMat4(orientation) * glm::scale(scale); - return modelMatrix; -} - void RenderSystem::fillModels(std::list>& jobs, World* world) { auto models = world->GetComponents("Model"); @@ -146,11 +90,10 @@ void RenderSystem::fillModels(std::list>& jobs, World model = ResourceManager::Load<::Model>("Models/Core/Error.obj"); } - glm::mat4 modelMatrix = ModelMatrix(modelComponent.EntityID, world); - glm::mat4 matrix = m_Camera->ProjectionMatrix() * m_Camera->ViewMatrix() * (model->m_Matrix * modelMatrix); + glm::mat4 modelMatrix = Transform::ModelMatrix(modelComponent.EntityID, world); for (auto texGroup : model->TextureGroups) { - std::shared_ptr modelJob = std::shared_ptr(new ModelJob(model, m_Camera, matrix, texGroup, modelComponent)); + std::shared_ptr modelJob = std::shared_ptr(new ModelJob(model, m_Camera, modelMatrix, texGroup, modelComponent)); jobs.push_back(modelJob); } } @@ -175,12 +118,11 @@ void RenderSystem::Update(World* world, double dt) //Only supports opaque geometry atm m_RenderFrame->Clear(); - RenderScene* rs = new RenderScene(); - rs->Camera = m_Camera; - rs->ViewPort = Rectangle(1280, 720); - fillModels(rs->ForwardJobs, world); - m_RenderFrame->Add(*rs); - delete rs; + RenderScene rs; + rs.Camera = m_Camera; + rs.Viewport = Rectangle(1280, 720); + fillModels(rs.ForwardJobs, world); + m_RenderFrame->Add(rs); } void RenderSystem::updateCamera(World* world, double dt) @@ -218,8 +160,8 @@ void RenderSystem::updateCamera(World* world, double 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); + glm::vec3 position = Transform::AbsolutePosition(world, m_CurrentCamera); + glm::quat orientation = Transform::AbsoluteOrientation(world, m_CurrentCamera); m_Camera->SetPosition(position); m_Camera->SetOrientation(orientation); diff --git a/src/Engine/Rendering/Renderer.cpp b/src/Engine/Rendering/Renderer.cpp index e60d3d11..01e52929 100644 --- a/src/Engine/Rendering/Renderer.cpp +++ b/src/Engine/Rendering/Renderer.cpp @@ -89,15 +89,18 @@ void Renderer::Update(double dt) m_ImGuiRenderPass->Update(dt); } -void Renderer::Draw(RenderFrame& rf) +void Renderer::Draw(RenderFrame& frame) { - m_Camera = (*rf.begin())->Camera; // Fix this with some better solution - m_PickingPass->Draw(rf); - - glClearColor(255.f / 255, 163.f / 255, 176.f / 255, 1.f); + for (auto scene : frame.RenderScenes){ + m_Camera = scene->Camera; // remove renderer camera when Editor uses the render scene cameras. + m_PickingPass->Draw(*scene); + + glClearColor(255.f / 255, 163.f / 255, 176.f / 255, 1.f); + + m_DrawScenePass->Draw(*scene); + GLERROR("Renderer::Draw m_DrawScenePass->Draw"); + } - m_DrawScenePass->Draw(rf); - GLERROR("Renderer::Draw m_DrawScenePass->Draw"); m_ImGuiRenderPass->Draw(); glfwSwapBuffers(m_Window); }