Render position of the cube based on the transform component, fixed some compile issues with the previous commit
This commit is contained in:
parent
99eb5282e5
commit
adf2331ab1
@ -1,5 +1,7 @@
|
||||
#pragma once
|
||||
#include "../BarinkEngine.h"
|
||||
#include "../Graphics/Memory/Buffer.h"
|
||||
#include "../Graphics/Memory/VertexArray.h"
|
||||
#include <vector>
|
||||
class RenderSurface
|
||||
{
|
||||
|
@ -1,9 +1,11 @@
|
||||
#include "Renderer.h"
|
||||
#include "../Scene/Components.h"
|
||||
#include "../Graphics/Memory/VertexArray.h"
|
||||
#include "../Graphics/Memory/Buffer.h"
|
||||
#include <glad/glad.h>
|
||||
|
||||
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);
|
||||
|
||||
BarinkEngine::Renderer::Renderer(){}
|
||||
@ -56,7 +58,7 @@ void BarinkEngine::Renderer::Render(Scene& scene)
|
||||
|
||||
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("P", projection);
|
||||
|
||||
|
@ -9,7 +9,6 @@
|
||||
|
||||
#include "Primitives/Camera.h"
|
||||
#include "Renderable.h"
|
||||
#include "GPUBucket.h"
|
||||
#include "Memory/Framebuffer.h"
|
||||
#include "../Scene/Components.h"
|
||||
|
||||
|
@ -8,13 +8,13 @@ namespace BarinkEngine {
|
||||
};
|
||||
|
||||
struct TransformComponent {
|
||||
glm::mat4& transform = glm::mat4(1.0f);
|
||||
glm::mat4 transform = glm::mat4(1.0f);
|
||||
|
||||
};
|
||||
|
||||
|
||||
struct CameraComponent {
|
||||
glm::mat4& view;
|
||||
glm::mat4 view;
|
||||
|
||||
};
|
||||
|
||||
|
@ -15,8 +15,8 @@ public:
|
||||
}
|
||||
|
||||
template<class T>
|
||||
T* GetComponent() {
|
||||
return m_scene->m_registry.try_get<T>(m_entity);
|
||||
T& GetComponent() {
|
||||
return m_scene->m_registry.get<T>(m_entity);
|
||||
}
|
||||
|
||||
private:
|
||||
|
@ -4,4 +4,4 @@ Node::Node(const std::string& name)
|
||||
: name(name), parent(nullptr), children(std::vector<Node*>()) {}
|
||||
|
||||
Group::Group(const std::string& name )
|
||||
: Node(name), transform(Transform()) {}
|
||||
: Node(name) {}
|
||||
|
@ -1,7 +1,6 @@
|
||||
#pragma once
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "../../Graphics/Transform.h"
|
||||
|
||||
class Node {
|
||||
public:
|
||||
@ -19,6 +18,5 @@ class Node {
|
||||
class Group : public Node {
|
||||
public:
|
||||
Group(const std::string& name);
|
||||
Transform& transform;
|
||||
|
||||
};
|
||||
|
@ -30,10 +30,29 @@ void Start() {
|
||||
renderable = object->renderable;
|
||||
|
||||
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);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Runs every frame
|
||||
* - Use to draw Immediate mode graphics (Not meant for HUD's )
|
||||
@ -45,9 +64,9 @@ void ImmediateGraphicsDraw()
|
||||
|
||||
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();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user