Render position of the cube based on the transform component, fixed some compile issues with the previous commit

This commit is contained in:
Nigel Barink 2022-10-23 14:36:23 +02:00
parent 99eb5282e5
commit adf2331ab1
8 changed files with 32 additions and 12 deletions

View File

@ -1,5 +1,7 @@
#pragma once #pragma once
#include "../BarinkEngine.h" #include "../BarinkEngine.h"
#include "../Graphics/Memory/Buffer.h"
#include "../Graphics/Memory/VertexArray.h"
#include <vector> #include <vector>
class RenderSurface class RenderSurface
{ {

View File

@ -1,9 +1,11 @@
#include "Renderer.h" #include "Renderer.h"
#include "../Scene/Components.h" #include "../Scene/Components.h"
#include "../Graphics/Memory/VertexArray.h"
#include "../Graphics/Memory/Buffer.h"
#include <glad/glad.h> #include <glad/glad.h>
float Angle = 0.0; float Angle = 0.0;
Camera cam = Camera(glm::vec3(16.0f, 0.0f, 0.0f), glm::vec3(0.0f, 0.0f, 0.0f), 90.0f); Camera cam = Camera(glm::vec3(12.0f, 0.0f, 0.0f), glm::vec3(0.0f, 0.0f, 0.0f), 90.0f);
glm::mat4 projection = glm::perspective(glm::radians(cam.Zoom), (800.0f / 600.0f), 0.001f, 100.0f); glm::mat4 projection = glm::perspective(glm::radians(cam.Zoom), (800.0f / 600.0f), 0.001f, 100.0f);
BarinkEngine::Renderer::Renderer(){} BarinkEngine::Renderer::Renderer(){}
@ -56,7 +58,7 @@ void BarinkEngine::Renderer::Render(Scene& scene)
renderComponent.shader.setUniformVec3("Color", renderComponent.color); renderComponent.shader.setUniformVec3("Color", renderComponent.color);
renderComponent.shader.setUniformMat4("M", glm::mat4(1.0f)); renderComponent.shader.setUniformMat4("M", trans.transform);
renderComponent.shader.setUniformMat4("V", cam.GetViewMatrix()); renderComponent.shader.setUniformMat4("V", cam.GetViewMatrix());
renderComponent.shader.setUniformMat4("P", projection); renderComponent.shader.setUniformMat4("P", projection);

View File

@ -9,7 +9,6 @@
#include "Primitives/Camera.h" #include "Primitives/Camera.h"
#include "Renderable.h" #include "Renderable.h"
#include "GPUBucket.h"
#include "Memory/Framebuffer.h" #include "Memory/Framebuffer.h"
#include "../Scene/Components.h" #include "../Scene/Components.h"

View File

@ -8,13 +8,13 @@ namespace BarinkEngine {
}; };
struct TransformComponent { struct TransformComponent {
glm::mat4& transform = glm::mat4(1.0f); glm::mat4 transform = glm::mat4(1.0f);
}; };
struct CameraComponent { struct CameraComponent {
glm::mat4& view; glm::mat4 view;
}; };

View File

@ -15,8 +15,8 @@ public:
} }
template<class T> template<class T>
T* GetComponent() { T& GetComponent() {
return m_scene->m_registry.try_get<T>(m_entity); return m_scene->m_registry.get<T>(m_entity);
} }
private: private:

View File

@ -4,4 +4,4 @@ Node::Node(const std::string& name)
: name(name), parent(nullptr), children(std::vector<Node*>()) {} : name(name), parent(nullptr), children(std::vector<Node*>()) {}
Group::Group(const std::string& name ) Group::Group(const std::string& name )
: Node(name), transform(Transform()) {} : Node(name) {}

View File

@ -1,7 +1,6 @@
#pragma once #pragma once
#include <string> #include <string>
#include <vector> #include <vector>
#include "../../Graphics/Transform.h"
class Node { class Node {
public: public:
@ -19,6 +18,5 @@ class Node {
class Group : public Node { class Group : public Node {
public: public:
Group(const std::string& name); Group(const std::string& name);
Transform& transform;
}; };

View File

@ -30,10 +30,29 @@ void Start() {
renderable = object->renderable; renderable = object->renderable;
render3DComponent.mesh = *renderable->mesh; render3DComponent.mesh = *renderable->mesh;
cube.GetComponent<BarinkEngine::TransformComponent>()
.transform = glm::rotate(glm::mat4(1.0f), 32.0f, glm::vec3(0.5f,1.0f,0.0f));
// Create a second cube
auto cube2 = scene.AddEntity((std::string&)"Cube2");
auto& cube2Render = cube2.AddComponent<BarinkEngine::Render3DComponent>();
cube2Render.mesh = *renderable->mesh;
cube2Render.color = glm::vec3(0.0f, 1.0f, 0.0f);
auto& cube2Trans = cube2.GetComponent<BarinkEngine::TransformComponent>();
cube2Trans.transform = glm::translate( glm::mat4(1.0f), glm::vec3(1.0f,0.0f, 5.0f));
renderer.Prepare(scene); renderer.Prepare(scene);
} }
/* /*
* Runs every frame * Runs every frame
* - Use to draw Immediate mode graphics (Not meant for HUD's ) * - Use to draw Immediate mode graphics (Not meant for HUD's )
@ -45,9 +64,9 @@ void ImmediateGraphicsDraw()
ImGui::Begin("Render edit"); ImGui::Begin("Render edit");
auto a = cube.GetComponent<BarinkEngine::Render3DComponent>(); auto& a = cube.GetComponent<BarinkEngine::Render3DComponent>();
ImGui::DragFloat3("Color", &a->color[0], 0.01f, 0.0f, 1.0f); ImGui::DragFloat3("Color", &a.color[0], 0.01f, 0.0f, 1.0f);
ImGui::End(); ImGui::End();