Rendering Engine 0.2.9
Modular Graphics Rendering Engine | v0.2.9
rendering_engine::SceneComponent2D Class Reference

Represents a hierarchical 2D transform component. More...

#include <scene_component_2d.hpp>

Public Member Functions

 SceneComponent2D ()
 Constructs a SceneComponent2D with identity transform. More...
 
virtual ~SceneComponent2D ()=default
 Destructor. More...
 
void SetPosition (const glm::vec2 &position)
 Sets the local position of this component. More...
 
void SetRotation (float angleDegrees)
 Sets the rotation angle in degrees. More...
 
void SetScale (const glm::vec2 &scale)
 Sets the scale in each dimension. More...
 
const glm::vec2 & GetPosition () const
 Gets the current position. More...
 
float GetRotation () const
 Gets the current rotation angle (in degrees). More...
 
const glm::vec2 & GetScale () const
 Gets the current scale. More...
 
glm::vec2 GetWorldPosition () const
 Returns the world-space position of this component. More...
 
float GetWorldRotation () const
 Returns the accumulated world-space rotation. More...
 
glm::vec2 GetWorldScale () const
 Returns the accumulated world-space scale. More...
 
const glm::mat4 & GetWorldMatrix ()
 Returns the world transformation matrix. More...
 
void UpdateLocalMatrix ()
 Recomputes the local transformation matrix. More...
 
void UpdateWorldMatrix ()
 Recomputes the world transformation matrix. More...
 
void AttachTo (SceneComponent2D *parent)
 Attaches this scene component to a parent scene component. More...
 
 SceneComponent2D (const SceneComponent2D &rhs)=delete
 
SceneComponent2Doperator= (const SceneComponent2D &rhs)=delete
 

Protected Attributes

glm::vec2 mPosition
 
float mRotation
 
glm::vec2 mScale
 
glm::mat4 mLocalMatrix
 
glm::mat4 mWorldMatrix
 
SceneComponent2DmParent
 
bool bIsDirty
 

Detailed Description

Represents a hierarchical 2D transform component.

SceneComponent2D stores local 2D transformation state:

  • Position (x, y)
  • Rotation (degrees, counterclockwise around Z-axis)
  • Scale (x, y)

It supports parent-child relationships, allowing hierarchical transform propagation. When attached to a parent component, its world transform is computed as:

World = ParentWorld * Local

The engine uses a left-handed coordinate system:

  • X+ : Right
  • Y+ : Up

Transform order is:

M = T * R * S

which results in object-space vertices being scaled, then rotated, then translated when applied.

The component uses a dirty-flag mechanism. World matrices are recomputed lazily when requested.

Note
  • This component operates strictly in the 2D domain.
  • Rotation is always around the Z-axis.
  • Ownership and lifetime are managed externally (e.g., by Actor2D).
See also
Actor2D

Definition at line 51 of file scene_component_2d.hpp.

Constructor & Destructor Documentation

◆ SceneComponent2D() [1/2]

rendering_engine::SceneComponent2D::SceneComponent2D ( )

Constructs a SceneComponent2D with identity transform.

Initial state:

  • Position = (0, 0)
  • Rotation = 0 degrees
  • Scale = (1, 1)
  • No parent attached

Definition at line 8 of file scene_component_2d.cpp.

◆ ~SceneComponent2D()

virtual rendering_engine::SceneComponent2D::~SceneComponent2D ( )
virtualdefault

Destructor.

◆ SceneComponent2D() [2/2]

rendering_engine::SceneComponent2D::SceneComponent2D ( const SceneComponent2D rhs)
delete

Member Function Documentation

◆ AttachTo()

void rendering_engine::SceneComponent2D::AttachTo ( SceneComponent2D parent)

Attaches this scene component to a parent scene component.

After attachment, this component's transform becomes relative to the parent. The world transformation is computed by combining the parent's world transform with this component's local transform.

Passing nullptr detaches the component and makes it a root-level component.

Parameters
parentPointer to the parent SceneComponent2D, or nullptr to detach.

Definition at line 101 of file scene_component_2d.cpp.

102{
103 mParent = parent;
104
105 bIsDirty = true;
106}

◆ GetPosition()

const glm::vec2 & rendering_engine::SceneComponent2D::GetPosition ( ) const
inline

Gets the current position.

Returns
The position as glm::vec2.

Definition at line 96 of file scene_component_2d.hpp.

96{ return mPosition; }

◆ GetRotation()

float rendering_engine::SceneComponent2D::GetRotation ( ) const
inline

Gets the current rotation angle (in degrees).

Returns
The rotation angle (degrees).

Definition at line 102 of file scene_component_2d.hpp.

102{ return mRotation; }

◆ GetScale()

const glm::vec2 & rendering_engine::SceneComponent2D::GetScale ( ) const
inline

Gets the current scale.

Returns
The scale as glm::vec2.

Definition at line 108 of file scene_component_2d.hpp.

108{ return mScale; }

◆ GetWorldMatrix()

const glm::mat4 & rendering_engine::SceneComponent2D::GetWorldMatrix ( )

Returns the world transformation matrix.

If the component is marked dirty, the world matrix will be recomputed before returning.

Returns
4x4 world transformation matrix.

Definition at line 62 of file scene_component_2d.cpp.

63{
64 if (bIsDirty)
65 {
67 }
68 return mWorldMatrix;
69}
void UpdateWorldMatrix()
Recomputes the world transformation matrix.

◆ GetWorldPosition()

glm::vec2 rendering_engine::SceneComponent2D::GetWorldPosition ( ) const

Returns the world-space position of this component.

Extracted from the world transformation matrix.

Returns
World position as glm::vec2.

Definition at line 38 of file scene_component_2d.cpp.

39{
40 const glm::mat4& world = const_cast<SceneComponent2D*>(this)->GetWorldMatrix();
41 return glm::vec2(world[3]);
42}
SceneComponent2D()
Constructs a SceneComponent2D with identity transform.
const glm::mat4 & GetWorldMatrix()
Returns the world transformation matrix.

◆ GetWorldRotation()

float rendering_engine::SceneComponent2D::GetWorldRotation ( ) const

Returns the accumulated world-space rotation.

If attached to a parent, this includes parent rotation.

Returns
World rotation angle in degrees.

Definition at line 44 of file scene_component_2d.cpp.

45{
46 const glm::mat4& world = const_cast<SceneComponent2D*>(this)->GetWorldMatrix();
47
48 float angle = atan2(world[1][0], world[0][0]);
49 return glm::degrees(angle);
50}

◆ GetWorldScale()

glm::vec2 rendering_engine::SceneComponent2D::GetWorldScale ( ) const

Returns the accumulated world-space scale.

If attached to a parent, this includes parent scaling.

Returns
World scale as glm::vec2.

Definition at line 52 of file scene_component_2d.cpp.

53{
54 const glm::mat4& world = const_cast<SceneComponent2D*>(this)->GetWorldMatrix();
55
56 return glm::vec2(
57 glm::length(glm::vec2(world[0])),
58 glm::length(glm::vec2(world[1]))
59 );
60}

◆ operator=()

SceneComponent2D & rendering_engine::SceneComponent2D::operator= ( const SceneComponent2D rhs)
delete

◆ SetPosition()

void rendering_engine::SceneComponent2D::SetPosition ( const glm::vec2 &  position)

Sets the local position of this component.

Marks the component as dirty so that world transformation will be recalculated when needed.

Parameters
positionLocal position in 2D space.

Definition at line 20 of file scene_component_2d.cpp.

21{
22 mPosition = position;
23 bIsDirty = true;
24}

◆ SetRotation()

void rendering_engine::SceneComponent2D::SetRotation ( float  angleDegrees)

Sets the rotation angle in degrees.

Parameters
angleDegreesAngle in degrees (counterclockwise).

Definition at line 26 of file scene_component_2d.cpp.

27{
28 mRotation = angleDegrees;
29 bIsDirty = true;
30}

◆ SetScale()

void rendering_engine::SceneComponent2D::SetScale ( const glm::vec2 &  scale)

Sets the scale in each dimension.

Parameters
scaleNew scale as glm::vec2.

Definition at line 32 of file scene_component_2d.cpp.

33{
34 mScale = scale;
35 bIsDirty = true;
36}

◆ UpdateLocalMatrix()

void rendering_engine::SceneComponent2D::UpdateLocalMatrix ( )

Recomputes the local transformation matrix.

The local matrix is constructed as:

Local = T * R * S

This method does not compute the world matrix. Called internally by UpdateWorldMatrix().

Definition at line 71 of file scene_component_2d.cpp.

72{
73 if (!bIsDirty)
74 {
75 return;
76 }
77 const float r = glm::radians(mRotation);
78
79 const glm::mat4 S = glm::scale(glm::mat4(1.0f), glm::vec3(mScale, 1.0f));
80 const glm::mat4 R = glm::rotate(glm::mat4(1.0f), r, glm::vec3(0.0f, 0.0f, 1.0f));
81 const glm::mat4 T = glm::translate(glm::mat4(1.0f), glm::vec3(mPosition, 0.0f));
82
83 mLocalMatrix = T * R * S;
84}

◆ UpdateWorldMatrix()

void rendering_engine::SceneComponent2D::UpdateWorldMatrix ( )

Recomputes the world transformation matrix.

Combines parent world matrix (if any) with the local matrix:

World = ParentWorld * Local

Clears the dirty flag after update.

Definition at line 86 of file scene_component_2d.cpp.

87{
89
90 if (mParent)
91 {
93 }
94 else
95 {
97 }
98 bIsDirty = false;
99}
void UpdateLocalMatrix()
Recomputes the local transformation matrix.

Member Data Documentation

◆ bIsDirty

bool rendering_engine::SceneComponent2D::bIsDirty
protected

Definition at line 190 of file scene_component_2d.hpp.

◆ mLocalMatrix

glm::mat4 rendering_engine::SceneComponent2D::mLocalMatrix
protected

Definition at line 186 of file scene_component_2d.hpp.

◆ mParent

SceneComponent2D* rendering_engine::SceneComponent2D::mParent
protected

Definition at line 189 of file scene_component_2d.hpp.

◆ mPosition

glm::vec2 rendering_engine::SceneComponent2D::mPosition
protected

Definition at line 182 of file scene_component_2d.hpp.

◆ mRotation

float rendering_engine::SceneComponent2D::mRotation
protected

Definition at line 183 of file scene_component_2d.hpp.

◆ mScale

glm::vec2 rendering_engine::SceneComponent2D::mScale
protected

Definition at line 184 of file scene_component_2d.hpp.

◆ mWorldMatrix

glm::mat4 rendering_engine::SceneComponent2D::mWorldMatrix
protected

Definition at line 187 of file scene_component_2d.hpp.


The documentation for this class was generated from the following files: