Skip to content

Class Transform2D

ClassList > Transform2D

2D transform component for sprites and UI elements.More...

  • #include <Transform.h>

Inherits the following classes: Transform

Inherited by the following classes: NodeEditor, Nodes

Public Types inherited from Transform

See Transform

Type Name
enum TransType
Flags for enabling/disabling transform components.

Public Attributes

Type Name
glm::mat3 o_InvTransform = { 1.0f }
Cached inverse world transform matrix (3x3)
glm::mat3 o_Transform = { 1.0f }
Cached world transform matrix (3x3)
glm::vec2 o_position = { 0.0f }
World position (X, Y)
float o_rot = { 0.0f }
Rotation angle in radians (counterclockwise)
glm::vec2 o_scale = { 1.0f }
Local scale (non-uniform allowed)

Public Attributes inherited from Transform

See Transform

Type Name
bool is_TransF_changed = true
Transform matrix needs recomputation.
bool is_Uniform_changed = true
Uniform (non-scaled) transform needs recomputation.
bool is_invTransF_changed = true
Inverse transform needs recomputation.
bool is_invUniform_changed = true
Inverse uniform transform needs recomputation.
bool use_position = { true }
Enable position component in transform computation.
bool use_rotation = { true }
Enable rotation component in transform computation.
bool use_scale = { true }
Enable scale component in transform computation.

Public Functions

Type Name
virtual bool ApplyAllTransform () override
Recomputes transform and all parent transforms.
virtual bool ApplyTransform (bool _forced=false) override
Recomputes transform matrix if dirty.
Transform2D * GetChildTransPtr ()
Returns pointer to first child transform.
virtual bool GetInvTransform () override const
Computes inverse transform matrix.
Transform2D * GetParentTransPtr ()
Returns pointer to parent transform.
Transform2D * GetTransformPtr ()
Returns pointer to this transform.
void LookAt (const glm::vec2 & tar)
Orients transform to look at target position.
void Move (const glm::vec2 & d_pos)
Translates position by offset.
void SetParent (Transform2D * _p_trans, bool _keep_offset=true)
Sets parent transform for hierarchy.
bool SetPos (const glm::vec2 & pos)
Sets world position.
bool SetRot (float rot)
Sets rotation angle.
bool SetScale (const glm::vec2 & scale)
Sets local scale.
void Spin (float angle)
Rotates by angle.
void Trans (const glm::mat3 & _trans)
Applies transformation matrix to current transform.
Transform2D ()
Constructs a Transform2D with identity values.
virtual void UnsetParent (bool _keep_offset=true) override
Removes parent transform relationship.
void Zoom (float scale)
Scales by factor (uniform).
void Zoom (const glm::vec2 & scale)
Scales by factor (non-uniform).
virtual int _debug () override const
Debug utility for transform state inspection.
~Transform2D ()
Destroys the Transform2D .

Public Functions inherited from Transform

See Transform

Type Name
virtual bool ApplyAllTransform () = 0
Recomputes transform and all parent transforms.
virtual bool ApplyTransform (bool _forced=false) = 0
Recomputes transform matrix if dirty.
virtual bool GetInvTransform () const = 0
Computes inverse transform matrix.
virtual void UnsetParent (bool _keep_offset=true) = 0
Removes parent transform relationship.
void UseTranformComp (bool _enable, TransType _type)
Enables or disables specific transform components.
virtual int _debug () const = 0
Debug utility for transform state inspection.

Detailed Description

Transform2D provides position, rotation (single angle), and scale in 2D space. Supports hierarchical parent-child relationships for UI layouts and sprite hierarchies. Transform matrices are 3x3 (mat3) for 2D homogeneous coordinates.

Coordinate System: * 2D plane: X (horizontal), Y (vertical) * Rotation: counterclockwise angle in radians * Transform order: Translate * Rotate * Scale

Note:

Mutable members support const correctness while caching computed matrices.

Note:

Parent-child pointers are non-owning (scene graph owns objects).

Public Attributes Documentation

variable o_InvTransform

Cached inverse world transform matrix (3x3)

glm::mat3 Transform2D::o_InvTransform;


variable o_Transform

Cached world transform matrix (3x3)

glm::mat3 Transform2D::o_Transform;


variable o_position

World position (X, Y)

glm::vec2 Transform2D::o_position;


variable o_rot

Rotation angle in radians (counterclockwise)

float Transform2D::o_rot;


variable o_scale

Local scale (non-uniform allowed)

glm::vec2 Transform2D::o_scale;


Public Functions Documentation

function ApplyAllTransform

Recomputes transform and all parent transforms.

virtual bool Transform2D::ApplyAllTransform () override

Returns:

True if any recomputation occurred

Implements Transform::ApplyAllTransform


function ApplyTransform

Recomputes transform matrix if dirty.

virtual bool Transform2D::ApplyTransform (
    bool _forced=false
) override

Parameters:

  • _forced If true, recompute even if not dirty

Returns:

True if recomputation occurred

Implements Transform::ApplyTransform


function GetChildTransPtr

Returns pointer to first child transform.

inline Transform2D * Transform2D::GetChildTransPtr () 

Returns:

Non-owning pointer to child Transform2D, or nullptr if no children


function GetInvTransform

Computes inverse transform matrix.

virtual bool Transform2D::GetInvTransform () override const

Returns:

True if inverse was recomputed

Implements Transform::GetInvTransform


function GetParentTransPtr

Returns pointer to parent transform.

inline Transform2D * Transform2D::GetParentTransPtr () 

Returns:

Non-owning pointer to parent Transform2D, or nullptr if no parent


function GetTransformPtr

Returns pointer to this transform.

inline Transform2D * Transform2D::GetTransformPtr () 

Returns:

Non-owning pointer to Transform2D


function LookAt

Orients transform to look at target position.

void Transform2D::LookAt (
    const glm::vec2 & tar
) 

Parameters:

  • tar Target position to face

Note:

Sets rotation to face target from current position.


function Move

Translates position by offset.

void Transform2D::Move (
    const glm::vec2 & d_pos
) 

Parameters:

  • d_pos Delta position to add

function SetParent

Sets parent transform for hierarchy.

void Transform2D::SetParent (
    Transform2D * _p_trans,
    bool _keep_offset=true
) 

Parameters:

  • _p_trans Pointer to new parent transform
  • _keep_offset If true, maintains world position; if false, becomes local to parent

function SetPos

Sets world position.

bool Transform2D::SetPos (
    const glm::vec2 & pos
) 

Parameters:

  • pos New position in 2D space

Returns:

True if position changed


function SetRot

Sets rotation angle.

bool Transform2D::SetRot (
    float rot
) 

Parameters:

  • rot New rotation in radians (counterclockwise)

Returns:

True if rotation changed


function SetScale

Sets local scale.

bool Transform2D::SetScale (
    const glm::vec2 & scale
) 

Parameters:

  • scale New scale (per-axis)

Returns:

True if scale changed


function Spin

Rotates by angle.

void Transform2D::Spin (
    float angle
) 

Parameters:

  • angle Rotation angle in radians (counterclockwise)

function Trans

Applies transformation matrix to current transform.

void Transform2D::Trans (
    const glm::mat3 & _trans
) 

Parameters:

  • _trans Transformation to apply (3x3 matrix)

Note:

Multiplies current transform: Transform = Transform * _trans


function Transform2D

Constructs a Transform2D with identity values.

Transform2D::Transform2D () 


function UnsetParent

Removes parent transform relationship.

virtual void Transform2D::UnsetParent (
    bool _keep_offset=true
) override

Parameters:

  • _keep_offset If true, maintains world position; if false, resets to origin

Implements Transform::UnsetParent


function Zoom [1/2]

Scales by factor (uniform).

void Transform2D::Zoom (
    float scale
) 

Parameters:

  • scale Uniform scale multiplier

function Zoom [2/2]

Scales by factor (non-uniform).

void Transform2D::Zoom (
    const glm::vec2 & scale
) 

Parameters:

  • scale Per-axis scale multiplier

function _debug

Debug utility for transform state inspection.

virtual int Transform2D::_debug () override const

Returns:

Debug status code

Implements Transform::_debug


function ~Transform2D

Destroys the Transform2D .

Transform2D::~Transform2D () 



The documentation for this class was generated from the following file src/compo/Transform.h