From c640ac574b62934d39a9e91f4d51f0493c84f4a4 Mon Sep 17 00:00:00 2001 From: Nigel Barink Date: Tue, 16 May 2023 20:18:26 +0200 Subject: [PATCH] Fixed translation issue with Imguizmo --- Editor/src/AssetManagement/AssetRegistry.cpp | 5 +- Editor/src/AssetManagement/AssetRegistry.h | 2 +- Editor/src/EditorCamera.h | 13 +- Editor/src/EditorLayer.h | 37 ++-- YoggieEngine/src/Graphics/Primitives/Camera.h | 26 +++ YoggieEngine/src/Graphics/Renderer.cpp | 186 +++++++++++++++++- YoggieEngine/src/Graphics/Renderer.h | 184 +---------------- YoggieEngine/src/Scene/Components.h | 51 ++--- 8 files changed, 262 insertions(+), 242 deletions(-) diff --git a/Editor/src/AssetManagement/AssetRegistry.cpp b/Editor/src/AssetManagement/AssetRegistry.cpp index d49332c..c235de2 100644 --- a/Editor/src/AssetManagement/AssetRegistry.cpp +++ b/Editor/src/AssetManagement/AssetRegistry.cpp @@ -84,11 +84,12 @@ YoggieEngine::Mesh* AssetRegistry::LoadFromAssetFile(const std::filesystem::path } +/* + YoggieEngine::Renderable* AssetRegistry::LoadFromSource(const std::filesystem::path srcPath, const std::filesystem::path assetFolder) { - /* * auto model = (YoggieEngine::ModelImporter()).Import(srcPath.string()); YoggieEngine::Mesh* exportMesh = model->renderable->mesh; std::filesystem::path MeshFileName = assetFolder / srcPath.filename().replace_extension(".mesh"); @@ -134,6 +135,6 @@ YoggieEngine::Renderable* AssetRegistry::LoadFromSource(const std::filesystem::p return model->renderable; - */ return nullptr; } + */ diff --git a/Editor/src/AssetManagement/AssetRegistry.h b/Editor/src/AssetManagement/AssetRegistry.h index 9bc3565..81932b7 100644 --- a/Editor/src/AssetManagement/AssetRegistry.h +++ b/Editor/src/AssetManagement/AssetRegistry.h @@ -18,7 +18,7 @@ public: static YoggieEngine::Mesh* LoadFromAssetFile(const std::filesystem::path assetPath); - static YoggieEngine::Renderable* LoadFromSource(const std::filesystem::path srcPath, const std::filesystem::path assetFolder); +// static YoggieEngine::Renderable* LoadFromSource(const std::filesystem::path srcPath, const std::filesystem::path assetFolder); private: int unique_number = 0; diff --git a/Editor/src/EditorCamera.h b/Editor/src/EditorCamera.h index 128f672..b3064f7 100644 --- a/Editor/src/EditorCamera.h +++ b/Editor/src/EditorCamera.h @@ -8,22 +8,11 @@ public: Right = glm::vec3(-1.0f, 0.0f, 0.0f); Up = glm::vec3(0.0f, 1.0f, 0.0f); - - view = glm::translate(glm::mat4(1.0f), Position) * glm::toMat4(glm::quat(Rotation)); } - void Update() { - - view = glm::translate(glm::mat4(1.0f), Position) * glm::toMat4(glm::quat(Rotation)); - } - - glm::vec3 Position = glm::vec3(0.0f); - glm::vec3 Rotation = glm::vec3(0.0f); private: - - - + glm::vec3 Front; glm::vec3 Right; glm::vec3 Up; diff --git a/Editor/src/EditorLayer.h b/Editor/src/EditorLayer.h index 61055c3..bf7aa77 100644 --- a/Editor/src/EditorLayer.h +++ b/Editor/src/EditorLayer.h @@ -21,6 +21,7 @@ #include "../../YoggieEngine/src/Graphics/Memory/Buffer.h" using namespace YoggieEngine; + class EditorLayer : public Layer { public: @@ -60,8 +61,7 @@ public: //Console console = Console(); } - glm::vec3 cameraPosition = glm::vec3(0.0f, 0.0f, -5.0f); - glm::vec3 cameraRotation = glm::vec3(0.0f); + void OnUpdate() override { scene.Update(); /* @@ -113,8 +113,7 @@ public: } - camera->view = glm::translate(glm::mat4(1.0f), cameraPosition) * glm::toMat4(glm::quat(cameraRotation)); - + renderer.Render(scene, *camera); @@ -215,11 +214,13 @@ public: switch (result) { case(NFD_OKAY): // Import Model - + /* AssetRegistry::LoadFromSource( path, "build/Debug/Assets"//project.get()->GetProjectDirectory() / "Assets" ); + */ + break; case(NFD_CANCEL): break; @@ -373,7 +374,7 @@ public: | ImGuiWindowFlags_NoCollapse; ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2{ 0,0 }); ImGui::Begin("SceneView",nullptr,viewportWindowFlags); - + // spdlog::info("{0}x{1}", ImGui::GetWindowWidth(), ImGui::GetWindowHeight()); ImGui::Image((ImTextureID)(intptr_t)renderer.getCurrentFrameBuffer().GetColourAttachment(), ImVec2{(float)ImGui::GetWindowWidth(),(float)ImGui::GetWindowHeight()}); @@ -391,21 +392,23 @@ public: ImGuizmo::SetRect(ImGui::GetWindowPos().x, ImGui::GetWindowPos().y, ImGui::GetWindowWidth(), ImGui::GetWindowHeight()); - const auto& ProjMatrix = camera->projection; - - const glm::mat4& viewMatrix = ((EditorCamera*)camera)->view; - glm::mat4 cameraView = glm::inverse(viewMatrix); - glm::mat4 cameraDelta = glm::mat4(1.0f); - - + const auto& ProjMatrix = camera->getProjection(ImGui::GetWindowWidth(), ImGui::GetWindowHeight()); + const glm::mat4& viewMatrix = glm::inverse(camera->getTransform()); auto& tc = Selected.GetComponent(); auto transform = tc.GetTransform(); - ImGuizmo::Manipulate(glm::value_ptr(cameraView), glm::value_ptr(ProjMatrix), activeOperation, ImGuizmo::WORLD, glm::value_ptr(transform), nullptr, nullptr); - if(ImGuizmo::IsUsing()) + ImGuizmo::Manipulate( + glm::value_ptr(viewMatrix), + glm::value_ptr(ProjMatrix), + activeOperation, ImGuizmo::LOCAL, glm::value_ptr(transform)); + if (ImGuizmo::IsUsing()) + { tc.Decompose(transform); + } + + } @@ -415,7 +418,7 @@ public: ImGui::Begin("EditorCamera"); - ImGui::SliderFloat3("position", glm::value_ptr(cameraPosition), -50, 50); + ImGui::SliderFloat3("position", glm::value_ptr(camera->Position), -50, 50); ImGui::End(); @@ -469,7 +472,7 @@ private: char* path = nullptr; Texture Logo; Renderer renderer; - Camera* camera = new EditorCamera(); + EditorCamera* camera = new EditorCamera(); Mesh cube ; void LoadLastOrEmptyProject() { diff --git a/YoggieEngine/src/Graphics/Primitives/Camera.h b/YoggieEngine/src/Graphics/Primitives/Camera.h index e84c950..ee8ae01 100644 --- a/YoggieEngine/src/Graphics/Primitives/Camera.h +++ b/YoggieEngine/src/Graphics/Primitives/Camera.h @@ -1,11 +1,37 @@ #pragma once +#include + namespace YoggieEngine { class Camera { public: Camera() { + projection = glm::perspective(glm::radians(90.0f), 800.0f / 600.0f, 0.001f, 1000.0f); + //projection[3][1] *= -1; + } + + glm::mat4 getTransform() const { + + auto transform = glm::translate(glm::mat4(1.0f), Position) + * glm::toMat4(glm::quat(Rotation)) + * glm::scale(glm::mat4(1.0f), glm::vec3(1.0f)); + + return glm::inverse(transform); + } + + glm::mat4& getProjection(float width, float height) { + + //projection[3][1] *= -1; + + return projection; } + glm::vec3 Position = glm::vec3(0.0f); + glm::vec3 Rotation = glm::vec3(0.0f); + + + + private: glm::mat4 view; glm::mat4 projection; diff --git a/YoggieEngine/src/Graphics/Renderer.cpp b/YoggieEngine/src/Graphics/Renderer.cpp index c28a000..f4282b3 100644 --- a/YoggieEngine/src/Graphics/Renderer.cpp +++ b/YoggieEngine/src/Graphics/Renderer.cpp @@ -4,6 +4,12 @@ #include "../Scene/Components.h" #include "../Graphics/Memory/Buffer.h" #include "../Graphics/Memory/VertexArray.h" +#include "Renderable.h" +#include "Memory/Framebuffer.h" +#include "../Scene/Components.h" +#include"../Scene/Scene.h" +#include "Primitives/Camera.h" +#include "OpenglAPI.h" namespace YoggieEngine { unsigned int quadVAO = 0; @@ -66,7 +72,7 @@ float skyboxVertices[]{ Renderer::Renderer() : - m_framebuffer(960, 540), + m_framebuffer(800, 600), gBufferShader("build/Debug/Shaders/deferred/geometry.vert", "build/Debug/Shaders/deferred/geometry.frag"), lightingPassShader("build/Debug/Shaders/deferred/lightPass.vert", "build/Debug/Shaders/deferred/lightPass.frag"), SkyboxShader("build/Debug/Shaders/Cubemaps/Skybox.vert", "build/Debug/Shaders/Cubemaps/Skybox.frag"), @@ -74,8 +80,8 @@ Renderer::Renderer() : forwardShader("build/Debug/Shaders/forward/geometry.vert", "build/Debug/Shaders/forward/geometry.frag"), postProcessingShader("build/Debug/Shaders/forward/postprocessing.vert", "build/Debug/Shaders/forward/postprocessing.frag") { - width = 960; - height = 540; + width = 800; + height = 600; glEnable(GL_DEPTH_TEST); CreateGBuffer(); @@ -142,6 +148,180 @@ void Renderer::CreateGBuffer() { } +void Renderer::Render(Scene& scene , Camera MainCamera){ + int oldviewport[4]; + glGetIntegerv(GL_VIEWPORT, oldviewport); + glViewport(0, 0, width, height); + + + glBindFramebuffer(GL_FRAMEBUFFER, gBuffer); + glClearColor(0.0f, 0.0f, 0.0f, 1.0f); + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + + // Render skybox if the scene has one + + SkyboxShader.Use(); + SkyboxShader.setUniformMat4("projection", MainCamera.getProjection(width, height)); + SkyboxShader.setUniformMat4("view", glm::inverse( glm::mat4(glm::mat3(MainCamera.getTransform())))); + + if (!skyboxVAO) { + unsigned int VBO; + glGenVertexArrays(1, &skyboxVAO); + glGenBuffers(1, &VBO); + glBindVertexArray(skyboxVAO); + glBindBuffer(GL_ARRAY_BUFFER, VBO); + glBufferData(GL_ARRAY_BUFFER, sizeof(skyboxVertices), &skyboxVertices, GL_STATIC_DRAW); + glEnableVertexAttribArray(0); + glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), (void*)0); + + } + + OpenGLApi::DrawCubeMap(skyboxVAO, skybox); + + + + + auto renderables = scene.getReg().view(); + gBufferShader.Use(); + for (auto renderable : renderables) { + auto entity = Entity(renderable, &scene); + auto& renderComponent = entity.GetComponent(); + auto& transform = entity.GetComponent(); + + // Geometry pass + gBufferShader.setUniformVec3("Color", renderComponent.color); + gBufferShader.setUniformMat4("Model", transform.GetTransform()); + gBufferShader.setUniformMat4("View", glm::inverse(MainCamera.getTransform())); + gBufferShader.setUniformMat4("Projection", MainCamera.getProjection(width, height)); + OpenGLApi::DrawTriangles(renderComponent); + + + } + + // Light pass + glBindFramebuffer(GL_FRAMEBUFFER, m_framebuffer.GetId()); + lightingPassShader.Use(); + lightingPassShader.setUniformInt("gPosition", 0); + lightingPassShader.setUniformInt("gNormal", 1); + lightingPassShader.setUniformInt("gColorSpec", 2); + + glActiveTexture(GL_TEXTURE0); + glBindTexture(GL_TEXTURE_2D, gPosition); + + glActiveTexture(GL_TEXTURE1); + glBindTexture(GL_TEXTURE_2D, gNormal); + + glActiveTexture(GL_TEXTURE2); + glBindTexture(GL_TEXTURE_2D, gColorSpec); + + auto lights = scene.getReg().view(); + unsigned int lightnr = 0; + for (auto light : lights) { + auto lightComponent = Entity(light, &scene).GetComponent(); + auto transformComponent = Entity(light, &scene).GetComponent(); + + auto name = "lights[" + std::to_string(lightnr) + "]"; + lightingPassShader.setUniformVec3(name + ".Position", transformComponent.Position); + lightingPassShader.setUniformVec3(name + ".Color", lightComponent.Color); + + const float linear = 0.7f; + const float quadratic = 1.8f; + lightingPassShader.setUniformFloat(name + ".Linear", linear); + lightingPassShader.setUniformFloat(name + ".Quadratic", quadratic); + + lightnr++; + + } + + if (quadVAO == 0) + { + float quadVertices[] = { + -1.0f, 1.0f, 0.0f, 0.0f, -1.0f, + -1.0f, -1.0f, 0.0f, 0.0f, 0.0f, + 1.0f, 1.0f, 0.0f, 1.0f, -1.0f, + 1.0f, -1.0f, 0.0f, 1.0f, 0.0f, + }; + unsigned int quadVBO; + // setup plane VAO ; + glGenVertexArrays(1, &quadVAO); + glGenBuffers(1, &quadVBO); + glBindVertexArray(quadVAO); + glBindBuffer(GL_ARRAY_BUFFER, quadVBO); + glBufferData(GL_ARRAY_BUFFER, sizeof(quadVertices), &quadVertices, GL_STATIC_DRAW); + glEnableVertexAttribArray(0); + glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 5 * sizeof(float), (void*)0); + glEnableVertexAttribArray(1); + glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 5 * sizeof(float), (void*)(3 * sizeof(float))); + } + + glBindVertexArray(quadVAO); + glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); + glBindVertexArray(0); + + + // Copy GBuffer + glBindFramebuffer(GL_READ_FRAMEBUFFER, gBuffer); + glBindFramebuffer(GL_DRAW_BUFFER, m_framebuffer.GetId()); + glBlitFramebuffer(0, 0, width, height, 0, 0, width, height, GL_DEPTH_BUFFER_BIT, GL_NEAREST); + + + if (transparentVAO == 0) { + unsigned int transparentVBO; + float transparentVertices[] = { + // positions // texture Coords (swapped y coordinates because texture is flipped upside down) + 0.0f, 0.5f, 0.0f, 0.0f, 1.0f, + 0.0f, -0.5f, 0.0f, 0.0f, 0.0f, + 1.0f, -0.5f, 0.0f, 1.0f, 0.0f, + + 0.0f, 0.5f, 0.0f, 0.0f, 1.0f, + 1.0f, -0.5f, 0.0f, 1.0f, 0.0f, + 1.0f, 0.5f, 0.0f, 1.0f, 1.0f + }; + + glGenVertexArrays(1, &transparentVAO); + glGenBuffers(1, &transparentVBO); + glBindVertexArray(transparentVAO); + glBindBuffer(GL_ARRAY_BUFFER, transparentVBO); + glBufferData(GL_ARRAY_BUFFER, sizeof(transparentVertices), transparentVertices, GL_STATIC_DRAW); + glEnableVertexAttribArray(0); + glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 5 * sizeof(float), (void*)0); + glEnableVertexAttribArray(1); + glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 5 * sizeof(float), (void*)(3 * sizeof(float))); + glBindVertexArray(0); + + } + + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + + BlendingShader.Use(); + glBindVertexArray(transparentVAO); + glActiveTexture(GL_TEXTURE0); + glBindTexture(GL_TEXTURE_2D, grassTexture.GetID()); + + BlendingShader.setUniformMat4("V", glm::inverse(MainCamera.getTransform())); + BlendingShader.setUniformMat4("P", MainCamera.getProjection(width, height)); + for (unsigned int i = 0; i < vegetation.size(); i++) { + + auto translation = glm::translate(glm::mat4(1.0f), vegetation[i]); + BlendingShader.setUniformMat4("M", translation); + glDrawArrays(GL_TRIANGLES, 0, 6); + + } + + glBindVertexArray(0); + + glDisable(GL_BLEND); + + + + + + glBindFramebuffer(GL_FRAMEBUFFER, 0); + glViewport(oldviewport[0], oldviewport[1], oldviewport[2], oldviewport[3]); +} + + Renderer::~Renderer(){} diff --git a/YoggieEngine/src/Graphics/Renderer.h b/YoggieEngine/src/Graphics/Renderer.h index 52821c8..d0f5711 100644 --- a/YoggieEngine/src/Graphics/Renderer.h +++ b/YoggieEngine/src/Graphics/Renderer.h @@ -2,13 +2,8 @@ #include "GLFW/glfw3.h" #include #include "../PerfCounter.h" - -#include "Renderable.h" +#include "../Scene/Scene.h" #include "Memory/Framebuffer.h" -#include "../Scene/Components.h" -#include"../Scene/Scene.h" -#include "Primitives/Camera.h" -#include "OpenglAPI.h" namespace YoggieEngine { @@ -35,182 +30,7 @@ namespace YoggieEngine { OpenGLApi::DrawTriangles(renderComponent); */ - void Render(Scene& scene, Camera MainCamera) { - - MainCamera.projection = glm::perspective(glm::radians(65.0f), ((float)width/(float)height), 0.0001f, 1000.0f); - int oldviewport[4]; - glGetIntegerv(GL_VIEWPORT, oldviewport); - glViewport(0, 0, width, height); - - - glBindFramebuffer(GL_FRAMEBUFFER, gBuffer); - glClearColor(0.0f, 0.0f, 0.0f, 1.0f); - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - - // Render skybox if the scene has one - - SkyboxShader.Use(); - SkyboxShader.setUniformMat4("projection", MainCamera.projection); - SkyboxShader.setUniformMat4("view", glm::mat4(glm::mat3(MainCamera.view))); - - if (!skyboxVAO) { - unsigned int VBO; - glGenVertexArrays(1, &skyboxVAO); - glGenBuffers(1, &VBO); - glBindVertexArray(skyboxVAO); - glBindBuffer(GL_ARRAY_BUFFER, VBO); - glBufferData(GL_ARRAY_BUFFER, sizeof(skyboxVertices), &skyboxVertices, GL_STATIC_DRAW); - glEnableVertexAttribArray(0); - glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), (void*)0); - - } - - OpenGLApi::DrawCubeMap( skyboxVAO, skybox); - - - - - auto renderables = scene.getReg().view(); - gBufferShader.Use(); - for (auto renderable : renderables) { - auto entity = Entity(renderable, &scene); - auto& renderComponent = entity.GetComponent(); - auto& transform = entity.GetComponent(); - - // Geometry pass - gBufferShader.setUniformVec3("Color", renderComponent.color); - gBufferShader.setUniformMat4("Model", transform.GetTransform()); - gBufferShader.setUniformMat4("View", MainCamera.view); - gBufferShader.setUniformMat4("Projection", MainCamera.projection); - OpenGLApi::DrawTriangles(renderComponent); - - - } - - // Light pass - glBindFramebuffer(GL_FRAMEBUFFER, m_framebuffer.GetId()); - lightingPassShader.Use(); - lightingPassShader.setUniformInt("gPosition", 0); - lightingPassShader.setUniformInt("gNormal", 1); - lightingPassShader.setUniformInt("gColorSpec", 2); - - glActiveTexture(GL_TEXTURE0); - glBindTexture(GL_TEXTURE_2D, gPosition); - - glActiveTexture(GL_TEXTURE1); - glBindTexture(GL_TEXTURE_2D, gNormal); - - glActiveTexture(GL_TEXTURE2); - glBindTexture(GL_TEXTURE_2D, gColorSpec); - - auto lights = scene.getReg().view(); - unsigned int lightnr = 0; - for (auto light : lights) { - auto lightComponent = Entity(light, &scene).GetComponent(); - auto transformComponent = Entity(light, &scene).GetComponent(); - - auto name = "lights[" + std::to_string(lightnr) + "]"; - lightingPassShader.setUniformVec3(name + ".Position",transformComponent.Position ); - lightingPassShader.setUniformVec3(name + ".Color", lightComponent.Color); - - const float linear = 0.7f; - const float quadratic = 1.8f; - lightingPassShader.setUniformFloat(name + ".Linear", linear); - lightingPassShader.setUniformFloat(name + ".Quadratic", quadratic); - - lightnr++; - - } - - if (quadVAO == 0) - { - float quadVertices[] = { - -1.0f, 1.0f, 0.0f, 0.0f, 1.0f, - -1.0f, -1.0f, 0.0f, 0.0f, 0.0f, - 1.0f, 1.0f, 0.0f, 1.0f, 1.0f, - 1.0f, -1.0f, 0.0f, 1.0f, 0.0f, - }; - unsigned int quadVBO; - // setup plane VAO ; - glGenVertexArrays(1, &quadVAO); - glGenBuffers(1, &quadVBO); - glBindVertexArray(quadVAO); - glBindBuffer(GL_ARRAY_BUFFER, quadVBO); - glBufferData(GL_ARRAY_BUFFER, sizeof(quadVertices), &quadVertices, GL_STATIC_DRAW); - glEnableVertexAttribArray(0); - glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 5 * sizeof(float), (void*)0); - glEnableVertexAttribArray(1); - glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 5 * sizeof(float), (void*)(3 * sizeof(float))); - } - - glBindVertexArray(quadVAO); - glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); - glBindVertexArray(0); - - - // Copy GBuffer - glBindFramebuffer(GL_READ_FRAMEBUFFER, gBuffer); - glBindFramebuffer(GL_DRAW_BUFFER, m_framebuffer.GetId()); - glBlitFramebuffer(0, 0, width, height, 0, 0, width, height, GL_DEPTH_BUFFER_BIT, GL_NEAREST); - - - if (transparentVAO == 0) { - unsigned int transparentVBO; - float transparentVertices[] = { - // positions // texture Coords (swapped y coordinates because texture is flipped upside down) - 0.0f, 0.5f, 0.0f, 0.0f, 1.0f, - 0.0f, -0.5f, 0.0f, 0.0f, 0.0f, - 1.0f, -0.5f, 0.0f, 1.0f, 0.0f, - - 0.0f, 0.5f, 0.0f, 0.0f, 1.0f, - 1.0f, -0.5f, 0.0f, 1.0f, 0.0f, - 1.0f, 0.5f, 0.0f, 1.0f, 1.0f - }; - - glGenVertexArrays(1, &transparentVAO); - glGenBuffers(1, &transparentVBO); - glBindVertexArray(transparentVAO); - glBindBuffer(GL_ARRAY_BUFFER, transparentVBO); - glBufferData(GL_ARRAY_BUFFER, sizeof(transparentVertices), transparentVertices, GL_STATIC_DRAW); - glEnableVertexAttribArray(0); - glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 5 * sizeof(float), (void*)0); - glEnableVertexAttribArray(1); - glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 5 * sizeof(float), (void*)(3 * sizeof(float))); - glBindVertexArray(0); - - } - - glEnable(GL_BLEND); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - - BlendingShader.Use(); - glBindVertexArray(transparentVAO); - glActiveTexture(GL_TEXTURE0); - glBindTexture(GL_TEXTURE_2D, grassTexture.GetID()); - - BlendingShader.setUniformMat4("V", MainCamera.view); - BlendingShader.setUniformMat4("P", MainCamera.projection); - for (unsigned int i = 0; i < vegetation.size(); i++) { - - auto translation = glm::translate(glm::mat4(1.0f), vegetation[i]) ; - BlendingShader.setUniformMat4("M", translation); - glDrawArrays(GL_TRIANGLES, 0, 6); - - } - - glBindVertexArray(0); - - glDisable(GL_BLEND); - - - - - - glBindFramebuffer(GL_FRAMEBUFFER, 0); - glViewport(oldviewport[0], oldviewport[1], oldviewport[2], oldviewport[3]); - - - } + void Render(Scene& scene, Camera MainCamera); void setCurrentFrameBuffer(const Framebuffer& fb); void setClearColor(const glm::vec3& ClearColor); diff --git a/YoggieEngine/src/Scene/Components.h b/YoggieEngine/src/Scene/Components.h index 4a42e03..cd22ff7 100644 --- a/YoggieEngine/src/Scene/Components.h +++ b/YoggieEngine/src/Scene/Components.h @@ -18,32 +18,34 @@ namespace YoggieEngine { glm::mat4 LocalTransform = glm::mat4(1.0f); glm::mat4 GetTransform() const { + glm::mat4 rotation = glm::toMat4(glm::quat(Rotation)); - - - return glm::translate(glm::mat4(1.0f), Position) * glm::toMat4(glm::quat(Rotation)) * glm::scale(glm::mat4(1.0f), Scale); - } - - void Decompose(glm::mat4 transformationMatrix) { - glm::mat4& tm = transformationMatrix; + auto transform = glm::translate(glm::mat4(1.0f), Position)* rotation + * glm::scale(glm::mat4(1.0f), Scale); - auto& a = tm[0][0]; - auto& b = tm[1][0]; - auto& c = tm[2][0]; - auto& d = tm[3][0]; - auto& e = tm[0][1]; - auto& f = tm[1][1]; - auto& g = tm[2][1]; - auto& h = tm[3][1]; + return transform; + } - auto& i = tm[0][2]; - auto& j = tm[1][2]; - auto& k = tm[2][2]; - auto& l = tm[3][2]; + void Decompose(glm::mat4& transformationMatrix) { - Position = glm::vec3(d, h, l); + auto& a = transformationMatrix[0][0]; + auto& b = transformationMatrix[1][0]; + auto& c = transformationMatrix[2][0]; + auto& d = transformationMatrix[3][0]; + + auto& e = transformationMatrix[0][1]; + auto& f = transformationMatrix[1][1]; + auto& g = transformationMatrix[2][1]; + auto& h = transformationMatrix[3][1]; + + auto& i = transformationMatrix[0][2]; + auto& j = transformationMatrix[1][2]; + auto& k = transformationMatrix[2][2]; + auto& l = transformationMatrix[3][2]; + + Position = glm::vec3(transformationMatrix[3]); d = 0; h = 0; l = 0; @@ -67,12 +69,12 @@ namespace YoggieEngine { k /= sz; - auto w = glm::sqrt(1 + tm[0][0] + tm[1][1] + tm[2][2]) / 2; + auto w = glm::sqrt(1 + transformationMatrix[0][0] + transformationMatrix[1][1] + transformationMatrix[2][2]) / 2; - auto x = (tm[2][1] - tm[1][2]) / (4 * w); - auto y = (tm[0][2] - tm[2][0]) / (4 * w); - auto z = (tm[1][0] - tm[0][1]) / (4 * w); + auto x = (transformationMatrix[2][1] - transformationMatrix[1][2]) / (4 * w); + auto y = (transformationMatrix[0][2] - transformationMatrix[2][0]) / (4 * w); + auto z = (transformationMatrix[1][0] - transformationMatrix[0][1]) / (4 * w); auto rot = glm::quat(w, x, y, z); @@ -127,7 +129,6 @@ namespace YoggieEngine { struct Render3DComponent { - Renderable* renderable; unsigned int VAO = 0; unsigned int IBO = 0;