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.
2#include <glm/gtc/matrix_transform.hpp>
3#include <glm/gtc/constants.hpp>
4
5namespace rendering_engine
6{
7
9 :
10 mPosition{ 0.0f, 0.0f },
11 mRotation{ 0.0f },
12 mScale{ 1.0f, 1.0f },
13 mModelMatrix{ 1.0f }
14{
16}
17
18void SceneComponent2D::SetPosition(const glm::vec2& position)
19{
20 mPosition = position;
22}
23
24void SceneComponent2D::SetRotation(float angleDegrees)
25{
26 mRotation = angleDegrees;
28}
29
30void SceneComponent2D::SetScale(const glm::vec2& scale)
31{
32 mScale = scale;
34}
35
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
SceneComponent2D()
Constructs a SceneComponent2D at the origin, with zero rotation and unit scale.
void SetScale(const glm::vec2 &scale)
Sets the scale in each dimension.
void SetRotation(float angleDegrees)
Sets the rotation angle in degrees.
void SetPosition(const glm::vec2 &position)
Sets the position in 2D space.
void UpdateModelMatrix()
Updates the model matrix from the current position, rotation, and scale.