Rendering Engine 0.2.9
Modular Graphics Rendering Engine | v0.2.9
rectangle_2D.cpp
Go to the documentation of this file.
1#include "rectangle_2d.hpp"
2#include "camera_2d.hpp"
3#include "scene.hpp"
4
5namespace rendering_engine
6{
8 :
9 Drawable2D(renderContext, scene),
10 mProperties(properties)
11{}
12
14{
15 const std::string meshName = "Quad2D";
16 const std::string materialName = "Rectangle2D";
17
18 AddRenderBatch(meshName, materialName);
19
21
24}
25
26void Rectangle2D::Update(float deltaTime)
27{
28 Drawable2D::Update(deltaTime);
29}
30
31void Rectangle2D::Draw(const Camera2D& camera)
32{
33 Transformations2D transformations;
34 transformations.model = GetTransform().GetWorldMatrix();
35 transformations.view = camera.GetWorldView();
36 transformations.proj = camera.GetProjectionMatrix();
37
38 for (auto& renderBatch : mRenderBatches)
39 {
40 renderBatch.renderResources->SubmitResources(transformations, renderBatch.materialParameters);
41 }
42}
43
44void Rectangle2D::SetColor(glm::vec4 color)
45{
46 for (auto& renderBatch : mRenderBatches)
47 {
48 renderBatch.materialParameters.SetMaterialVec4("Color", color);
49 }
50}
51
52
53} // namespace rendering_engine
Represents a 2D camera with position, rotation, and zoom control.
Definition: camera_2d.hpp:36
glm::mat4 GetProjectionMatrix() const
Returns the current orthographic projection matrix.
Definition: camera_2d.cpp:30
const glm::mat4 & GetWorldView() const
Gets the world-view (model) matrix for the camera.
Definition: camera_2d.cpp:87
2D drawable component for rendering objects in 2D space.
Definition: drawable_2d.hpp:27
SceneComponent2D & GetTransform()
Access to the underlying SceneComponent2D (transform).
Definition: drawable_2d.cpp:55
void Update(float deltaTime) override
Updates model matrix (and any other logic).
Definition: drawable_2d.cpp:17
void Initialize() override
Initializes render resources.
Definition: drawable_2d.cpp:12
void SetScale(const glm::vec2 &scale)
Sets the quad scale along each axis.
Definition: drawable_2d.cpp:35
std::vector< RenderBatch > mRenderBatches
void AddRenderBatch(std::string meshName, std::string materialName)
Rectangle2D(RenderResourceContext renderContext, Scene &scene, Properties properties)
Constructs the Rectangle2D with a render context.
Definition: rectangle_2D.cpp:7
void Draw(const Camera2D &camera) override
Submits this quad to the renderer for drawing.
void Update(float deltaTime) override
Updates logic (animation, movement, etc.) for this drawable.
void Initialize() override
Initializes render resource pointers (material, mesh, etc.). Must be called after setting material an...
void SetColor(glm::vec4 color)
Sets color.
const glm::mat4 & GetWorldMatrix()
Returns the world transformation matrix.
Base class representing a renderable scene.
Definition: scene.hpp:44
Aggregates pointers to global rendering resource managers.
Contains transformation matrices for 2D rendering.
glm::mat4 view
View (camera) transformation matrix.
glm::mat4 proj
Projection transformation matrix.
glm::mat4 model
Model transformation matrix.