Rendering Engine 0.2.0
Modular Graphics Rendering Engine | v0.2.0
Loading...
Searching...
No Matches
rendering_engine::SceneComponent2D Class Reference

Represents a 2D transformable scene component with position, rotation, and scale. More...

#include <scene_component_2d.hpp>

Public Member Functions

 SceneComponent2D ()
 Constructs a SceneComponent2D at the origin, with zero rotation and unit scale.
virtual ~SceneComponent2D ()=default
 Destructor.
void SetPosition (const glm::vec2 &position)
 Sets the position in 2D space.
void SetRotation (float angleDegrees)
 Sets the rotation angle in degrees.
void SetScale (const glm::vec2 &scale)
 Sets the scale in each dimension.
const glm::vec2 & GetPosition () const
 Gets the current position.
float GetRotation () const
 Gets the current rotation angle (in degrees).
const glm::vec2 & GetScale () const
 Gets the current scale.
const glm::mat4 & GetModelMatrix () const
 Gets the model matrix for this component.
void UpdateModelMatrix ()
 Updates the model matrix from the current position, rotation, and scale.

Protected Attributes

glm::vec2 mPosition
float mRotation
glm::vec2 mScale
glm::mat4 mModelMatrix

Detailed Description

Represents a 2D transformable scene component with position, rotation, and scale.

SceneComponent2D holds position (in 2D), rotation (in degrees, counterclockwise), and scale. It provides methods to set and get each component and maintains the current model matrix.

The engine uses a left-handed coordinate system:

  • X+ : Right
  • Y+ : Up

The model matrix is updated automatically after any property change, and can be used to transform object-local coordinates into world (scene) coordinates.

Transform order is: scale, then rotate, then translate (S→R→T), matching typical 2D graphics pipelines.

Definition at line 29 of file scene_component_2d.hpp.

Constructor & Destructor Documentation

◆ SceneComponent2D()

rendering_engine::SceneComponent2D::SceneComponent2D ( )

Constructs a SceneComponent2D at the origin, with zero rotation and unit scale.

Definition at line 8 of file scene_component_2d.cpp.

9 :
10 mPosition{ 0.0f, 0.0f },
11 mRotation{ 0.0f },
12 mScale{ 1.0f, 1.0f },
13 mModelMatrix{ 1.0f }
14{
16}
void UpdateModelMatrix()
Updates the model matrix from the current position, rotation, and scale.

◆ ~SceneComponent2D()

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

Destructor.

Member Function Documentation

◆ GetModelMatrix()

const glm::mat4 & rendering_engine::SceneComponent2D::GetModelMatrix ( ) const
inline

Gets the model matrix for this component.

Returns
The model matrix as glm::mat4.
Note
Use this to transform object-local coordinates into world (scene) coordinates.

Definition at line 84 of file scene_component_2d.hpp.

84{ return mModelMatrix; }

◆ GetPosition()

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

Gets the current position.

Returns
The position as glm::vec2.

Definition at line 64 of file scene_component_2d.hpp.

64{ 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 70 of file scene_component_2d.hpp.

70{ 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 76 of file scene_component_2d.hpp.

76{ return mScale; }

◆ SetPosition()

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

Sets the position in 2D space.

Parameters
positionNew position as glm::vec2.

Definition at line 18 of file scene_component_2d.cpp.

19{
20 mPosition = position;
22}

◆ SetRotation()

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

Sets the rotation angle in degrees.

Parameters
angleDegreesAngle in degrees (counterclockwise).

Definition at line 24 of file scene_component_2d.cpp.

25{
26 mRotation = angleDegrees;
28}

◆ 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 30 of file scene_component_2d.cpp.

31{
32 mScale = scale;
34}

◆ UpdateModelMatrix()

void rendering_engine::SceneComponent2D::UpdateModelMatrix ( )

Updates the model matrix from the current position, rotation, and scale.

Called automatically after property changes, but can be called manually if needed.

See also
SetPosition(), SetRotation(), SetScale()

Definition at line 36 of file scene_component_2d.cpp.

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}

Member Data Documentation

◆ mModelMatrix

glm::mat4 rendering_engine::SceneComponent2D::mModelMatrix
protected

Definition at line 98 of file scene_component_2d.hpp.

◆ mPosition

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

Definition at line 94 of file scene_component_2d.hpp.

◆ mRotation

float rendering_engine::SceneComponent2D::mRotation
protected

Definition at line 95 of file scene_component_2d.hpp.

◆ mScale

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

Definition at line 96 of file scene_component_2d.hpp.


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