Rendering Engine 0.2.0
Modular Graphics Rendering Engine | v0.2.0
Loading...
Searching...
No Matches
scene_component_2d.hpp
Go to the documentation of this file.
1// This file is part of the Rendering Engine project.
2// Author: Alexander Obzherin <alexanderobzherin@gmail.com>
3// Copyright (c) 2025 Alexander Obzherin
4// Distributed under the terms of the zlib License. See LICENSE.md for details.
5
6#pragma once
7
8#include <glm/glm.hpp>
9#include <glm/gtc/matrix_transform.hpp>
10
11namespace rendering_engine
12{
13/**
14 * @class SceneComponent2D
15 * @brief Represents a 2D transformable scene component with position, rotation, and scale.
16 *
17 * SceneComponent2D holds position (in 2D), rotation (in degrees, counterclockwise), and scale.
18 * It provides methods to set and get each component and maintains the current model matrix.
19 *
20 * The engine uses a left-handed coordinate system:
21 * - X+ : Right
22 * - Y+ : Up
23 *
24 * The model matrix is updated automatically after any property change, and can be used to transform object-local
25 * coordinates into world (scene) coordinates.
26 *
27 * Transform order is: scale, then rotate, then translate (S→R→T), matching typical 2D graphics pipelines.
28 */
30{
31public:
32 /**
33 * @brief Constructs a SceneComponent2D at the origin, with zero rotation and unit scale.
34 */
36
37 /**
38 * @brief Destructor.
39 */
40 virtual ~SceneComponent2D() = default;
41
42 /**
43 * @brief Sets the position in 2D space.
44 * @param position New position as glm::vec2.
45 */
46 void SetPosition(const glm::vec2& position);
47
48 /**
49 * @brief Sets the rotation angle in degrees.
50 * @param angleDegrees Angle in degrees (counterclockwise).
51 */
52 void SetRotation(float angleDegrees);
53
54 /**
55 * @brief Sets the scale in each dimension.
56 * @param scale New scale as glm::vec2.
57 */
58 void SetScale(const glm::vec2& scale);
59
60 /**
61 * @brief Gets the current position.
62 * @return The position as glm::vec2.
63 */
64 const glm::vec2& GetPosition() const { return mPosition; }
65
66 /**
67 * @brief Gets the current rotation angle (in degrees).
68 * @return The rotation angle (degrees).
69 */
70 float GetRotation() const { return mRotation; }
71
72 /**
73 * @brief Gets the current scale.
74 * @return The scale as glm::vec2.
75 */
76 const glm::vec2& GetScale() const { return mScale; }
77
78 /**
79 * @brief Gets the model matrix for this component.
80 * @return The model matrix as glm::mat4.
81 *
82 * @note Use this to transform object-local coordinates into world (scene) coordinates.
83 */
84 const glm::mat4& GetModelMatrix() const { return mModelMatrix; }
85
86 /**
87 * @brief Updates the model matrix from the current position, rotation, and scale.
88 * @details Called automatically after property changes, but can be called manually if needed.
89 * @see SetPosition(), SetRotation(), SetScale()
90 */
91 void UpdateModelMatrix();
92
93protected:
94 glm::vec2 mPosition;
95 float mRotation;
96 glm::vec2 mScale;
97
98 glm::mat4 mModelMatrix;
99};
100
101} // namespace rendering_engine
virtual ~SceneComponent2D()=default
Destructor.
const glm::vec2 & GetScale() const
Gets the current scale.
SceneComponent2D()
Constructs a SceneComponent2D at the origin, with zero rotation and unit scale.
const glm::vec2 & GetPosition() const
Gets the current position.
void SetScale(const glm::vec2 &scale)
Sets the scale in each dimension.
float GetRotation() const
Gets the current rotation angle (in degrees).
const glm::mat4 & GetModelMatrix() const
Gets the model matrix for this component.
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.