Rendering Engine 0.2.0
Modular Graphics Rendering Engine | v0.2.0
Loading...
Searching...
No Matches
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).
virtual ~SceneComponent ()=default
 Destructor.
void UpdateWorldMatrix ()
 Updates the world transformation matrix from the current position, rotation, and scale.
const glm::mat4 & GetWorldMatrix () const
 Returns the world transformation matrix (model matrix).
void SetPosition (const glm::vec3 &position)
 Sets the position of the component in world space.
void SetRotation (const glm::quat &rotation)
 Sets the rotation using a quaternion.
void SetRotation (const glm::vec3 &rotation)
 Sets the rotation using Euler angles (in degrees).
void SetScale (const glm::vec3 &scale)
 Sets the scale for each dimension.
const glm::vec3 & GetPosition () const
 Gets the current position.
const glm::quat & GetRotationQuat () const
 Gets the current rotation as a quaternion.
const glm::vec3 & GetRotation () const
 Gets the current rotation as Euler angles (in radians).
const glm::vec3 & GetScale () const
 Gets the current scale.
glm::vec3 GetForward () const
 Returns the forward (local X+) direction vector in world space.
glm::vec3 GetRight () const
 Returns the right (local Y+) direction vector in world space.
glm::vec3 GetUp () const
 Returns the up (local Z+) direction vector in world space.
 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 mWorldMatrix

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 41 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{
14}

◆ ~SceneComponent()

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

Destructor.

◆ SceneComponent() [2/2]

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

Member Function Documentation

◆ 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 59 of file scene_component.cpp.

60{
61 return glm::rotate(mRotation, axes::ForwardVector);
62}
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 99 of file scene_component.hpp.

99{ 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 64 of file scene_component.cpp.

65{
66 return glm::rotate(mRotation, axes::RightVector);
67}
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 114 of file scene_component.hpp.

114{ 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 105 of file scene_component.hpp.

105{ 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 120 of file scene_component.hpp.

120{ 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 69 of file scene_component.cpp.

70{
71 return glm::rotate(mRotation, axes::UpVector);
72}
static const glm::vec3 UpVector

◆ GetWorldMatrix()

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

Returns the world transformation matrix (model matrix).

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

Definition at line 21 of file scene_component.cpp.

22{
23 return mWorldMatrix;
24}

◆ 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 26 of file scene_component.cpp.

27{
28 mPosition = position;
30}
void UpdateWorldMatrix()
Updates the world transformation matrix from the current position, rotation, and scale.

◆ 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 32 of file scene_component.cpp.

33{
34 mRotation = rotation;
35 mEulerRotation = glm::eulerAngles(rotation); // radians
37}

◆ 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 44 of file scene_component.cpp.

45{
46 mEulerRotation = glm::radians(rotation);
47 mRotation = glm::angleAxis(-rotation.y, axes::UpVector)// Yaw
48 * glm::angleAxis(-rotation.x, axes::RightVector) // Pitch
49 * glm::angleAxis(-rotation.z, axes::ForwardVector);// Roll
51}

◆ 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 53 of file scene_component.cpp.

54{
55 mScale = scale;
57}

◆ UpdateWorldMatrix()

void rendering_engine::SceneComponent::UpdateWorldMatrix ( )

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 16 of file scene_component.cpp.

17{
18 // T * R * S
19 mWorldMatrix = glm::translate(glm::mat4(1.0f), mPosition) * glm::toMat4(mRotation) * glm::scale(glm::mat4(1.0f), mScale);
20}

Member Data Documentation

◆ mEulerRotation

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

Definition at line 149 of file scene_component.hpp.

◆ mPosition

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

Definition at line 147 of file scene_component.hpp.

◆ mRotation

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

Definition at line 148 of file scene_component.hpp.

◆ mScale

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

Definition at line 150 of file scene_component.hpp.

◆ mWorldMatrix

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

Definition at line 152 of file scene_component.hpp.


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