Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/raoulkdev/MiniECS/llms.txt

Use this file to discover all available pages before exploring further.

TransformModule is a built-in Module that tracks a Unit’s spatial data in 2D space. It stores position, rotation, and scale as glm::vec2 values from the GLM math library, and prints those values to stdout when start() is called via its lifecycle override. Attach it to any Unit in your scene to give that Unit a trackable location and orientation in 2D world space.

Class Definition

TransformModule inherits from Module and extends it with three public glm::vec2 fields and a start() override. The constructor is inherited directly from the base class via using Module::Module.
class TransformModule : public Module {
public:
    using Module::Module;
    glm::vec2 position;
    glm::vec2 rotation;
    glm::vec2 scale;
    void start() override;
};

Fields

position

Type: glm::vec2The Unit’s 2D position in world space. Components are x and y. Default-initialized to {0, 0}.

rotation

Type: glm::vec2The Unit’s 2D rotation values. Components are x and y. Default-initialized to {0, 0}.

scale

Type: glm::vec2The Unit’s 2D scale values. Components are x and y. Default-initialized to {0, 0}.

The start() Override

When start() is called, it prints the current values of all three transform fields to stdout in a single formatted line. The output follows this pattern:
Update / Transform -> Position: 22.5, 33.4, Rotation: 0, 0, Scale: 0, 0
The implementation reads directly from the position, rotation, and scale fields, so any modifications made before the scene is played are reflected in the output.

Attaching TransformModule to a Unit

Call addModule on a Unit pointer, passing MiniECS::ModuleType::Transform as the argument. The module is constructed and stored internally by the Unit.
unit->addModule(MiniECS::ModuleType::Transform);
When working with a named Unit retrieved from a scene, the pattern is:
scene.getUnitByName("u1")->addModule(MiniECS::ModuleType::Transform);

Retrieving and Modifying Transform Data

Use getModule<MiniECS::TransformModule>() on the Unit to obtain a raw pointer to the attached TransformModule. Always check for nullptr before accessing fields — the module may not be attached.
auto* transform = scene.getUnitByName("u1")->getModule<MiniECS::TransformModule>();
if (transform) {
    transform->position = {22.5f, 33.4f};
}
The rotation and scale fields are modified the same way:
transform->rotation = {0.0f, 45.0f};
transform->scale    = {1.0f, 1.0f};

GLM Dependency

TransformModule includes GLM using a hardcoded absolute path at the top of TransformModule.h:
#include "/opt/homebrew/include/glm/glm.hpp" // Change this to where you have GLM
This path is specific to a Homebrew installation on macOS. You must update it to match the location of GLM on your system before the project will compile. See the Building page for instructions on locating or installing GLM and updating this include path.

Expected Output

Given a Unit with position set to {22.5f, 33.4f} and all other fields at their default {0, 0} values, TransformModule produces the following output when start() is called:
Update / Transform -> Position: 22.5, 33.4, Rotation: 0, 0, Scale: 0, 0

Build docs developers (and LLMs) love