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

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

#include <scene_component.hpp>

Public Member Functions

 SceneComponent ()
 Constructs a SceneComponent with default transform (origin, identity rotation, unit scale). More...
 
virtual ~SceneComponent ()=default
 Destructor. More...
 
void UpdateLocalMatrix ()
 Updates the world transformation matrix from the current position, rotation, and scale. More...
 
void UpdateWorldMatrix ()
 
const glm::mat4 & GetWorldMatrix ()
 Returns the world transformation matrix (model matrix). More...
 
void SetPosition (const glm::vec3 &position)
 Sets the position of the component in world space. More...
 
void SetRotation (const glm::quat &rotation)
 Sets the rotation using a quaternion. More...
 
void SetRotation (const glm::vec3 &rotation)
 Sets the rotation using Euler angles (in degrees). More...
 
void SetScale (const glm::vec3 &scale)
 Sets the scale for each dimension. More...
 
const glm::vec3 & GetPosition () const
 Gets the current position. More...
 
const glm::quat & GetRotationQuat () const
 Gets the current rotation as a quaternion. More...
 
const glm::vec3 & GetRotation () const
 Gets the current rotation as Euler angles (in radians). More...
 
const glm::vec3 & GetScale () const
 Gets the current scale. More...
 
glm::vec3 GetForward () const
 Returns the forward (local X+) direction vector in world space. More...
 
glm::vec3 GetRight () const
 Returns the right (local Y+) direction vector in world space. More...
 
glm::vec3 GetUp () const
 Returns the up (local Z+) direction vector in world space. More...
 
glm::vec3 GetWorldPosition () const
 Returns the world-space position of this component. More...
 
glm::quat GetWorldRotation () const
 Returns the world-space rotation of this component. More...
 
glm::vec3 GetWorldScale () const
 Returns the world-space scale of this component. More...
 
void AttachTo (SceneComponent *parent)
 Attaches this scene component to a parent scene component. More...
 
 SceneComponent (const SceneComponent &rhs)=delete
 
SceneComponentoperator= (const SceneComponent &rhs)=delete
 

Protected Attributes

glm::vec3 mPosition
 
glm::quat mRotation
 
glm::vec3 mEulerRotation
 
glm::vec3 mScale
 
glm::mat4 mLocalMatrix
 
glm::mat4 mWorldMatrix
 
SceneComponentmParent
 
bool bIsDirty
 

Detailed Description

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

SceneComponent holds the core kinematic properties required for positioning and orienting objects in a 3D scene. It provides methods to set and get position, rotation (as both quaternion and Euler angles, in radians), and scale. The world transformation matrix is updated automatically when any of these properties change. Axis direction vectors (forward, right, up) are derived from the current rotation.

Note
  • Euler angles are expected in radians, using the convention (pitch, yaw, roll). The rendering engine uses a left-handed coordinate system:
    • X+ : Forward (world forward direction)
    • Y+ : Right
    • Z+ : Up
  • Copy and assignment are disabled for this class.

Definition at line 42 of file scene_component.hpp.

Constructor & Destructor Documentation

◆ SceneComponent() [1/2]

rendering_engine::SceneComponent::SceneComponent ( )

Constructs a SceneComponent with default transform (origin, identity rotation, unit scale).

Definition at line 6 of file scene_component.cpp.

7 :
8 mPosition{ 0.0f },
9 mRotation{ 1.0f, 0.0f, 0.0f, 0.0f },
10 mEulerRotation{ 0.0f },
11 mScale{ 1.0f, 1.0f, 1.0f },
12 mWorldMatrix{ 1.0f },
13 mParent(nullptr),
14 bIsDirty(true)
15{
16}

◆ ~SceneComponent()

virtual rendering_engine::SceneComponent::~SceneComponent ( )
virtualdefault

Destructor.

◆ SceneComponent() [2/2]

rendering_engine::SceneComponent::SceneComponent ( const SceneComponent rhs)
delete

Member Function Documentation

◆ AttachTo()

void rendering_engine::SceneComponent::AttachTo ( SceneComponent 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 SceneComponent, or nullptr to detach.

Definition at line 130 of file scene_component.cpp.

131{
132 mParent = parent;
133
134 bIsDirty = true;
135}

◆ GetForward()

glm::vec3 rendering_engine::SceneComponent::GetForward ( ) const

Returns the forward (local X+) direction vector in world space.

Returns
The forward direction as a glm::vec3.
See also
rendering_engine::axes::ForwardVector

Definition at line 91 of file scene_component.cpp.

92{
93 return glm::rotate(mRotation, axes::ForwardVector);
94}
static const glm::vec3 ForwardVector

◆ GetPosition()

const glm::vec3 & rendering_engine::SceneComponent::GetPosition ( ) const
inline

Gets the current position.

Returns
The position as a glm::vec3.

Definition at line 102 of file scene_component.hpp.

102{ return mPosition; }

◆ GetRight()

glm::vec3 rendering_engine::SceneComponent::GetRight ( ) const

Returns the right (local Y+) direction vector in world space.

Returns
The right direction as a glm::vec3.
See also
rendering_engine::axes::RightVector

Definition at line 96 of file scene_component.cpp.

97{
98 return glm::rotate(mRotation, axes::RightVector);
99}
static const glm::vec3 RightVector

◆ GetRotation()

const glm::vec3 & rendering_engine::SceneComponent::GetRotation ( ) const
inline

Gets the current rotation as Euler angles (in radians).

Returns
Euler angles (pitch, yaw, roll), where:
  • pitch: rotation around the Right (Y) axis
  • yaw: rotation around the Up (Z) axis
  • roll: rotation around the Forward (X) axis

Definition at line 117 of file scene_component.hpp.

117{ return mEulerRotation; }

◆ GetRotationQuat()

const glm::quat & rendering_engine::SceneComponent::GetRotationQuat ( ) const
inline

Gets the current rotation as a quaternion.

Returns
The rotation as a glm::quat.

Definition at line 108 of file scene_component.hpp.

108{ return mRotation; }

◆ GetScale()

const glm::vec3 & rendering_engine::SceneComponent::GetScale ( ) const
inline

Gets the current scale.

Returns
The scale as a glm::vec3.

Definition at line 123 of file scene_component.hpp.

123{ return mScale; }

◆ GetUp()

glm::vec3 rendering_engine::SceneComponent::GetUp ( ) const

Returns the up (local Z+) direction vector in world space.

Returns
The up direction as a glm::vec3.
See also
rendering_engine::axes::UpVector

Definition at line 101 of file scene_component.cpp.

102{
103 return glm::rotate(mRotation, axes::UpVector);
104}
static const glm::vec3 UpVector

◆ GetWorldMatrix()

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

Returns the world transformation matrix (model matrix).

Returns
The current world/model matrix (glm::mat4).

Definition at line 44 of file scene_component.cpp.

45{
46 if (bIsDirty)
47 {
49 }
50 return mWorldMatrix;
51}

◆ GetWorldPosition()

glm::vec3 rendering_engine::SceneComponent::GetWorldPosition ( ) const

Returns the world-space position of this component.

Returns
World-space position extracted from the world matrix.

Definition at line 106 of file scene_component.cpp.

107{
108 const glm::mat4& world = const_cast<SceneComponent*>(this)->GetWorldMatrix();
109 return glm::vec3(world[3]);
110}
const glm::mat4 & GetWorldMatrix()
Returns the world transformation matrix (model matrix).
SceneComponent()
Constructs a SceneComponent with default transform (origin, identity rotation, unit scale).

◆ GetWorldRotation()

glm::quat rendering_engine::SceneComponent::GetWorldRotation ( ) const

Returns the world-space rotation of this component.

Returns
World-space rotation as a quaternion.
Note
Result is reliable for uniform scale.

Definition at line 112 of file scene_component.cpp.

113{
114 // Extract rotation from the upper-left 3x3 matrix
115 const glm::mat4& world = const_cast<SceneComponent*>(this)->GetWorldMatrix();
116 glm::mat3 rotationMatrix(world);
117 return glm::quat_cast(rotationMatrix);
118}

◆ GetWorldScale()

glm::vec3 rendering_engine::SceneComponent::GetWorldScale ( ) const

Returns the world-space scale of this component.

Returns
World-space scale extracted from the world matrix.

Definition at line 120 of file scene_component.cpp.

121{
122 const glm::mat4& world = const_cast<SceneComponent*>(this)->GetWorldMatrix();
123 return glm::vec3(
124 glm::length(glm::vec3(world[0])),
125 glm::length(glm::vec3(world[1])),
126 glm::length(glm::vec3(world[2]))
127 );
128}

◆ operator=()

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

◆ SetPosition()

void rendering_engine::SceneComponent::SetPosition ( const glm::vec3 &  position)

Sets the position of the component in world space.

Parameters
positionThe new position as a glm::vec3.

Definition at line 53 of file scene_component.cpp.

54{
55 mPosition = position;
56
57 bIsDirty = true;
58}

◆ SetRotation() [1/2]

void rendering_engine::SceneComponent::SetRotation ( const glm::quat &  rotation)

Sets the rotation using a quaternion.

Parameters
rotationThe rotation as a glm::quat.
Note
Automatically updates the internal Euler angles (in radians).

Definition at line 60 of file scene_component.cpp.

61{
62 mRotation = rotation;
63 mEulerRotation = glm::eulerAngles(rotation); // radians
64
65 bIsDirty = true;
66}

◆ SetRotation() [2/2]

void rendering_engine::SceneComponent::SetRotation ( const glm::vec3 &  rotation)

Sets the rotation using Euler angles (in degrees).

Parameters
rotationEuler angles in degrees: (pitch, yaw, roll).
  • pitch: rotation around the Right (Y) axis
  • yaw: rotation around the Up (Z) axis
  • roll: rotation around the Forward (X) axis
Note
Angles are converted internally to radians.

Definition at line 73 of file scene_component.cpp.

74{
75 mEulerRotation = rotation;
76 const glm::vec3 radians = glm::radians(rotation);
77 mRotation = glm::angleAxis(-radians.y, axes::UpVector)// Yaw
78 * glm::angleAxis(-radians.x, axes::RightVector) // Pitch
79 * glm::angleAxis(-radians.z, axes::ForwardVector);// Roll
80
81 bIsDirty = true;
82}

◆ SetScale()

void rendering_engine::SceneComponent::SetScale ( const glm::vec3 &  scale)

Sets the scale for each dimension.

Parameters
scaleThe new scale as a glm::vec3.

Definition at line 84 of file scene_component.cpp.

85{
86 mScale = scale;
87
88 bIsDirty = true;
89}

◆ UpdateLocalMatrix()

void rendering_engine::SceneComponent::UpdateLocalMatrix ( )

Updates the world transformation matrix from the current position, rotation, and scale.

Normally called automatically after setters; call manually if you modify transform members directly.

Definition at line 18 of file scene_component.cpp.

19{
20 if (!bIsDirty)
21 {
22 return;
23 }
24 // T * R * S
26 glm::translate(glm::mat4(1.0f), mPosition) *
27 glm::toMat4(mRotation) *
28 glm::scale(glm::mat4(1.0f), mScale);
29}

◆ UpdateWorldMatrix()

void rendering_engine::SceneComponent::UpdateWorldMatrix ( )

Definition at line 30 of file scene_component.cpp.

31{
33
34 if (mParent)
35 {
37 }
38 else
39 {
41 }
42 bIsDirty = false;
43}
void UpdateLocalMatrix()
Updates the world transformation matrix from the current position, rotation, and scale.

Member Data Documentation

◆ bIsDirty

bool rendering_engine::SceneComponent::bIsDirty
protected

Definition at line 192 of file scene_component.hpp.

◆ mEulerRotation

glm::vec3 rendering_engine::SceneComponent::mEulerRotation
protected

Definition at line 185 of file scene_component.hpp.

◆ mLocalMatrix

glm::mat4 rendering_engine::SceneComponent::mLocalMatrix
protected

Definition at line 188 of file scene_component.hpp.

◆ mParent

SceneComponent* rendering_engine::SceneComponent::mParent
protected

Definition at line 191 of file scene_component.hpp.

◆ mPosition

glm::vec3 rendering_engine::SceneComponent::mPosition
protected

Definition at line 183 of file scene_component.hpp.

◆ mRotation

glm::quat rendering_engine::SceneComponent::mRotation
protected

Definition at line 184 of file scene_component.hpp.

◆ mScale

glm::vec3 rendering_engine::SceneComponent::mScale
protected

Definition at line 186 of file scene_component.hpp.

◆ mWorldMatrix

glm::mat4 rendering_engine::SceneComponent::mWorldMatrix
protected

Definition at line 189 of file scene_component.hpp.


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