The Table Engine
Transform Class Reference

Component for handling the transformation of game objects. More...

#include <transform.h>

+ Inheritance diagram for Transform:
+ Collaboration diagram for Transform:

Public Member Functions

 Transform ()
 Default constructor. More...
 
 Transform (int x, int y)
 Constructor that initializes the Transform with position. More...
 
 ~Transform ()
 Destructor. More...
 
SDL_Rect * getScreenRect ()
 Get the SDL_Rect describing the position and size on the screen. More...
 
Vec2 getWorldPosition ()
 Get the world space position of the Transform. More...
 
Vec2 getScreenPosition ()
 Get the screen space position calculated from world space. More...
 
Vec2 getScreenSize ()
 Get the size of the Transform in screen space. More...
 
void setWorldPosition (float x, float y)
 Set the world space position of the Transform. More...
 
void setWorldPosition (Vec2 pos)
 Set the world space position of the Transform using a Vec2. More...
 
void updateWorldPosition (float dx, float dy)
 Update the world position by a delta value. More...
 
void updateWorldPosition (Vec2 dpos)
 Update the world position by a delta position. More...
 
void setWorldSize (float w, float h)
 Set the world space size of the Transform. More...
 
void setWorldSize (Vec2 size)
 Set the world space size of the Transform using a Vec2. More...
 
void update ()
 Render function for the Transform component, handling visual updates. More...
 
- Public Member Functions inherited from Component
 Component ()
 Default constructor for the Component. More...
 
 Component (std::string name)
 Constructs a Component with a specified name. More...
 
virtual ~Component ()
 Virtual destructor for safe polymorphic use. More...
 
std::string getName ()
 Retrieves the name of the component. More...
 
GameObjectgetOwner ()
 Retrieves the GameObject that owns this component. More...
 
void setName (std::string name)
 Sets the name of the component. More...
 
void setOwner (GameObject *owner)
 Sets the GameObject owner of this component. More...
 
virtual void input ()
 Virtual method for handling input, intended to be overridden by derived components. More...
 
virtual void render ()
 Virtual method for rendering, intended to be overridden by derived components. More...
 

Private Attributes

SDL_Rect * mTransform
 Holds position and size relative to the screen. More...
 
Vec2 mPosition
 Position in world space. More...
 
Vec2 mSize
 Size in world space. More...
 

Additional Inherited Members

- Protected Attributes inherited from Component
std::string m_name
 Name of the component, useful for identification or debugging. More...
 
GameObjectm_owner
 Pointer to the GameObject that owns this component. More...
 

Detailed Description

Component for handling the transformation of game objects.

This class manages both the world and screen transformations of game objects, allowing them to be positioned and sized accurately in the game world.

Definition at line 23 of file transform.h.

Constructor & Destructor Documentation

◆ Transform() [1/2]

Transform::Transform ( )

Default constructor.

Definition at line 9 of file transform.cpp.

◆ Transform() [2/2]

Transform::Transform ( int  x,
int  y 
)

Constructor that initializes the Transform with position.

Parameters
xInitial x-coordinate of the world position.
yInitial y-coordinate of the world position.

Definition at line 16 of file transform.cpp.

◆ ~Transform()

Transform::~Transform ( )

Destructor.

Definition at line 24 of file transform.cpp.

Member Function Documentation

◆ getScreenPosition()

Vec2 Transform::getScreenPosition ( )

Get the screen space position calculated from world space.

Returns
A Vec2 object representing the screen position.

Definition at line 39 of file transform.cpp.

◆ getScreenRect()

SDL_Rect * Transform::getScreenRect ( )

Get the SDL_Rect describing the position and size on the screen.

Returns
Pointer to an SDL_Rect struct representing the screen rectangle.

Definition at line 29 of file transform.cpp.

◆ getScreenSize()

Vec2 Transform::getScreenSize ( )

Get the size of the Transform in screen space.

Returns
A Vec2 object representing the screen size.

Definition at line 44 of file transform.cpp.

◆ getWorldPosition()

Vec2 Transform::getWorldPosition ( )

Get the world space position of the Transform.

Returns
A Vec2 object representing the world position.

Definition at line 34 of file transform.cpp.

◆ setWorldPosition() [1/2]

void Transform::setWorldPosition ( float  x,
float  y 
)

Set the world space position of the Transform.

Parameters
xNew x-coordinate of the world position.
yNew y-coordinate of the world position.

Definition at line 49 of file transform.cpp.

◆ setWorldPosition() [2/2]

void Transform::setWorldPosition ( Vec2  pos)

Set the world space position of the Transform using a Vec2.

Parameters
posVec2 representing the new world position.

Definition at line 54 of file transform.cpp.

◆ setWorldSize() [1/2]

void Transform::setWorldSize ( float  w,
float  h 
)

Set the world space size of the Transform.

Parameters
wWidth in world space.
hHeight in world space.

Definition at line 59 of file transform.cpp.

◆ setWorldSize() [2/2]

void Transform::setWorldSize ( Vec2  size)

Set the world space size of the Transform using a Vec2.

Parameters
sizeVec2 representing the new size in world space.

Definition at line 64 of file transform.cpp.

◆ update()

void Transform::update ( )
virtual

Render function for the Transform component, handling visual updates.

Reimplemented from Component.

Definition at line 81 of file transform.cpp.

◆ updateWorldPosition() [1/2]

void Transform::updateWorldPosition ( float  dx,
float  dy 
)

Update the world position by a delta value.

Parameters
dxChange in the x-coordinate.
dyChange in the y-coordinate.

Definition at line 69 of file transform.cpp.

◆ updateWorldPosition() [2/2]

void Transform::updateWorldPosition ( Vec2  dpos)

Update the world position by a delta position.

Parameters
dposVec2 representing the change in position.

Definition at line 75 of file transform.cpp.

Member Data Documentation

◆ mPosition

Vec2 Transform::mPosition
private

Position in world space.

Definition at line 26 of file transform.h.

◆ mSize

Vec2 Transform::mSize
private

Size in world space.

Definition at line 27 of file transform.h.

◆ mTransform

SDL_Rect* Transform::mTransform
private

Holds position and size relative to the screen.

Definition at line 25 of file transform.h.


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