# Khaotic Engine Reborn: ecs::TransformComponent Class Reference

Loading...
Searching...
No Matches
ecs::TransformComponent Class Reference
Inheritance diagram for ecs::TransformComponent:

## Public Member Functions

| TransformComponent ()
void | SetPosition (XMVECTOR position)
void | SetRotation (XMVECTOR rotation)
void | SetScale (XMVECTOR scale)
XMVECTOR | GetPosition () const
XMVECTOR | GetRotation () const
XMVECTOR | GetScale () const
void | UpdateWorldMatrix ()
XMMATRIX | GetScaleMatrix () const
XMMATRIX | GetRotateMatrix () const
XMMATRIX | GetTranslateMatrix () const
XMMATRIX | GetWorldMatrix () const
void | SetScaleMatrix (XMMATRIX matrix)
void | SetRotateMatrix (XMMATRIX matrix)
void | SetTranslateMatrix (XMMATRIX matrix)
Public Member Functions inherited from ecs::Component
| Component (const Component &)=delete
Component & | operator= (const Component &)=delete
| Component (Component &&)=default
Component & | operator= (Component &&)=default
virtual void | Initialize ()
virtual void | Update (float deltaTime)

## Detailed Description

Definition at line 9 of file transform_component.h.

## Constructor & Destructor Documentation

## TransformComponent()

ecs::TransformComponent::TransformComponent | ( |  | ) |

inline

Builder for the TransformComponent class. Initializes the matrices to identity matrices.

Definition at line 16 of file transform_component.h.

{
m_ScaleMatrix = XMMatrixIdentity();
m_RotateMatrix = XMMatrixIdentity();
m_TranslateMatrix = XMMatrixIdentity();
m_WorldMatrix = XMMatrixIdentity();
}

## Member Function Documentation

## GetPosition()

XMVECTOR ecs::TransformComponent::GetPosition | ( |  | ) | const

inline

Get the position of the object in world space.

Returns
  The position as an XMVECTOR (x, y, z, (w is O.0f)).

Definition at line 66 of file transform_component.h.

{
XMFLOAT4X4 matrix;
XMStoreFloat4x4(&matrix, m_TranslateMatrix);
return XMVectorSet(matrix._41, matrix._42, matrix._43, 0.0f);
}

## GetRotateMatrix()

XMMATRIX ecs::TransformComponent::GetRotateMatrix | ( |  | ) | const

inline

Get the rotation matrix.

Returns
  The rotation matrix as an XMMATRIX.

Definition at line 124 of file transform_component.h.

{ return m_RotateMatrix; }

## GetRotation()

XMVECTOR ecs::TransformComponent::GetRotation | ( |  | ) | const

inline

Get the rotation of the object in world space.

Returns
  The rotation as an XMVECTOR (roll, pitch, yaw, (w is O.0f)).

Definition at line 76 of file transform_component.h.

{
XMFLOAT4X4 matrix;
XMStoreFloat4x4(&matrix, m_RotateMatrix);
float rotationX = atan2f(matrix._32, matrix._33);
float rotationY = atan2f(-matrix._31, sqrtf(matrix._32 * matrix._32 + matrix._33 * matrix._33));
float rotationZ = atan2f(matrix._21, matrix._11);
return XMVectorSet(rotationX, rotationY, rotationZ, 0.0f);
}

## GetScale()

XMVECTOR ecs::TransformComponent::GetScale | ( |  | ) | const

inline

Get the scale of the object in world space.

Returns
  The scale as an XMVECTOR (x, y, z, (w is O.0f)).

Definition at line 89 of file transform_component.h.

{
XMFLOAT4X4 matrix;
XMStoreFloat4x4(&matrix, m_ScaleMatrix);
XMVECTOR row1 = XMLoadFloat3(reinterpret_cast<XMFLOAT3*>(&matrix._11));
XMVECTOR row2 = XMLoadFloat3(reinterpret_cast<XMFLOAT3*>(&matrix._21));
XMVECTOR row3 = XMLoadFloat3(reinterpret_cast<XMFLOAT3*>(&matrix._31));
XMVECTOR scale = XMVectorSet(
XMVectorGetX(XMVector3Length(row1)),
XMVectorGetX(XMVector3Length(row2)),
XMVectorGetX(XMVector3Length(row3)),
0.0f
);
return scale;
}

## GetScaleMatrix()

XMMATRIX ecs::TransformComponent::GetScaleMatrix | ( |  | ) | const

inline

Get the scale matrix.

Returns
  The scale matrix as an XMMATRIX.

Definition at line 119 of file transform_component.h.

{ return m_ScaleMatrix; }

## GetTranslateMatrix()

XMMATRIX ecs::TransformComponent::GetTranslateMatrix | ( |  | ) | const

inline

Get the translation matrix.

Returns
  The translation matrix as an XMMATRIX.

Definition at line 129 of file transform_component.h.

{ return m_TranslateMatrix; }

## GetWorldMatrix()

XMMATRIX ecs::TransformComponent::GetWorldMatrix | ( |  | ) | const

inline

Get the world matrix. This matrix combines scale, rotation, and translation to represent the object's position in world space.

Returns
  The world matrix as an XMMATRIX.

Definition at line 135 of file transform_component.h.

{ return m_WorldMatrix; }

## SetPosition()

void ecs::TransformComponent::SetPosition | ( | XMVECTOR | position | ) |

inline

Set the position of the object in world space.

Parameters

  position |

Definition at line 29 of file transform_component.h.

{
XMFLOAT4X4 matrix;
XMStoreFloat4x4(&matrix, m_TranslateMatrix);
matrix._41 = XMVectorGetX(position);
matrix._42 = XMVectorGetY(position);
matrix._43 = XMVectorGetZ(position);
m_TranslateMatrix = XMLoadFloat4x4(&matrix);
UpdateWorldMatrix();
}
ecs::TransformComponent::UpdateWorldMatrix
void UpdateWorldMatrix()
Definition transform_component.h:111

## SetRotateMatrix()

void ecs::TransformComponent::SetRotateMatrix | ( | XMMATRIX | matrix | ) |

inline

Set the rotation matrix directly. This method allows setting the rotation matrix without modifying the individual rotation components.

Parameters

  matrix | The rotation matrix to set as an XMMATRIX.

Definition at line 148 of file transform_component.h.

{ m_RotateMatrix = matrix; UpdateWorldMatrix(); }

## SetRotation()

void ecs::TransformComponent::SetRotation | ( | XMVECTOR | rotation | ) |

inline

Set the rotation of the object in world space.

Parameters

  rotation | The rotation as an XMVECTOR (roll, pitch, yaw).

Definition at line 43 of file transform_component.h.

{
m_RotateMatrix = XMMatrixRotationRollPitchYawFromVector(rotation);
UpdateWorldMatrix();
}

## SetScale()

void ecs::TransformComponent::SetScale | ( | XMVECTOR | scale | ) |

inline

Set the scale of the object in world space.

Parameters

  scale | The scale as an XMVECTOR (x, y, z).

Definition at line 52 of file transform_component.h.

{
XMFLOAT4X4 matrix;
XMStoreFloat4x4(&matrix, m_ScaleMatrix);
matrix._11 = XMVectorGetX(scale);
matrix._22 = XMVectorGetY(scale);
matrix._33 = XMVectorGetZ(scale);
m_ScaleMatrix = XMLoadFloat4x4(&matrix);
UpdateWorldMatrix();
}

## SetScaleMatrix()

void ecs::TransformComponent::SetScaleMatrix | ( | XMMATRIX | matrix | ) |

inline

Set the scale matrix directly. This method allows setting the scale matrix without modifying the individual scale components.

Parameters

  matrix | The scale matrix to set as an XMMATRIX.

Definition at line 142 of file transform_component.h.

{ m_ScaleMatrix = matrix; UpdateWorldMatrix(); }

## SetTranslateMatrix()

void ecs::TransformComponent::SetTranslateMatrix | ( | XMMATRIX | matrix | ) |

inline

Set the translation matrix directly. This method allows setting the translation matrix without modifying the individual translation components.

Parameters

  matrix | The translation matrix to set as an XMMATRIX.

Definition at line 154 of file transform_component.h.

{ m_TranslateMatrix = matrix; UpdateWorldMatrix(); }

## UpdateWorldMatrix()

void ecs::TransformComponent::UpdateWorldMatrix | ( |  | ) |

inline

Update the world matrix based on the current scale, rotation, and translation matrices. This method is called whenever one of the matrices is modified.

Definition at line 111 of file transform_component.h.

{
m_WorldMatrix = m_ScaleMatrix * m_RotateMatrix * m_TranslateMatrix;
}

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

- enginecustom/src/inc/system/ecs/components/transform_component.h