Rendering Engine
0.2.0
Modular Graphics Rendering Engine | v0.2.0
Loading...
Searching...
No Matches
scene_component_2d.cpp
Go to the documentation of this file.
1
#include "
scene_component_2d.hpp
"
2
#include <glm/gtc/matrix_transform.hpp>
3
#include <glm/gtc/constants.hpp>
4
5
namespace
rendering_engine
6
{
7
8
SceneComponent2D::SceneComponent2D
()
9
:
10
mPosition
{ 0.0f, 0.0f },
11
mRotation
{ 0.0f },
12
mScale
{ 1.0f, 1.0f },
13
mModelMatrix
{ 1.0f }
14
{
15
UpdateModelMatrix
();
16
}
17
18
void
SceneComponent2D::SetPosition
(
const
glm::vec2& position)
19
{
20
mPosition
= position;
21
UpdateModelMatrix
();
22
}
23
24
void
SceneComponent2D::SetRotation
(
float
angleDegrees)
25
{
26
mRotation
= angleDegrees;
27
UpdateModelMatrix
();
28
}
29
30
void
SceneComponent2D::SetScale
(
const
glm::vec2& scale)
31
{
32
mScale
= scale;
33
UpdateModelMatrix
();
34
}
35
36
void
SceneComponent2D::UpdateModelMatrix
()
37
{
38
const
float
r = glm::radians(
mRotation
);
39
40
const
glm::mat4 S = glm::scale(glm::mat4(1.0f), glm::vec3(
mScale
, 1.0f));
41
const
glm::mat4 R = glm::rotate(glm::mat4(1.0f), r, glm::vec3(0.0f, 0.0f, 1.0f));
42
const
glm::mat4 T = glm::translate(glm::mat4(1.0f), glm::vec3(
mPosition
, 0.0f));
43
44
mModelMatrix
= T * R * S;
45
}
46
47
}
//rendering_engine
rendering_engine::SceneComponent2D::mRotation
float mRotation
Definition
scene_component_2d.hpp:95
rendering_engine::SceneComponent2D::mModelMatrix
glm::mat4 mModelMatrix
Definition
scene_component_2d.hpp:98
rendering_engine::SceneComponent2D::mPosition
glm::vec2 mPosition
Definition
scene_component_2d.hpp:94
rendering_engine::SceneComponent2D::mScale
glm::vec2 mScale
Definition
scene_component_2d.hpp:96
rendering_engine::SceneComponent2D::SceneComponent2D
SceneComponent2D()
Constructs a SceneComponent2D at the origin, with zero rotation and unit scale.
Definition
scene_component_2d.cpp:8
rendering_engine::SceneComponent2D::SetScale
void SetScale(const glm::vec2 &scale)
Sets the scale in each dimension.
Definition
scene_component_2d.cpp:30
rendering_engine::SceneComponent2D::SetRotation
void SetRotation(float angleDegrees)
Sets the rotation angle in degrees.
Definition
scene_component_2d.cpp:24
rendering_engine::SceneComponent2D::SetPosition
void SetPosition(const glm::vec2 &position)
Sets the position in 2D space.
Definition
scene_component_2d.cpp:18
rendering_engine::SceneComponent2D::UpdateModelMatrix
void UpdateModelMatrix()
Updates the model matrix from the current position, rotation, and scale.
Definition
scene_component_2d.cpp:36
rendering_engine
Definition
actor.hpp:11
scene_component_2d.hpp
RenderingEngine
RenderingLibrary
Source
scene_component_2d.cpp
Generated by
1.14.0