Skip to main content

ScaleSystem Class

System that applies scaling to entities based on their ScaleComponent. More...

Declaration

class helios::engine::game::systems::physics::ScaleSystem { ... }

Base class

classSystem

Abstract base class for game systems. More...

Public Member Functions Index

voidonAdd (helios::engine::game::GameWorld *gameWorld) noexcept override

Called when the system is added to a GameWorld. More...

voidupdate (helios::engine::game::UpdateContext &updateContext) noexcept override

Updates scale for all entities with dirty ScaleComponents. More...

Description

System that applies scaling to entities based on their ScaleComponent.

This system converts the desired world-space dimensions from ScaleComponent into scale factors relative to the model's original AABB. It handles unit conversion (e.g., centimeters to meters) based on the ScaleComponent's unit.

Required components:

  • ScaleComponent (desired dimensions and unit)
  • ModelAabbComponent (original model bounds)
  • TransformComponent (receives scale updates)

Definition at line 40 of file ScaleSystem.ixx.

Public Member Functions

onAdd()

void helios::engine::game::systems::physics::ScaleSystem::onAdd (helios::engine::game::GameWorld * gameWorld)
inline noexcept virtual

Called when the system is added to a GameWorld.

Parameters
gameWorld

Pointer to the GameWorld this system belongs to.

Definition at line 49 of file ScaleSystem.ixx.

49 void onAdd(helios::engine::game::GameWorld* gameWorld) noexcept override {
50 System::onAdd(gameWorld);
51 }

Reference helios::engine::game::System::onAdd.

update()

void helios::engine::game::systems::physics::ScaleSystem::update (helios::engine::game::UpdateContext & updateContext)
inline noexcept virtual

Updates scale for all entities with dirty ScaleComponents.

For each entity with the required components, calculates the scale factor needed to resize the model from its original dimensions to the desired world-space dimensions.

Parameters
updateContext

Context containing deltaTime and other frame data.

Definition at line 62 of file ScaleSystem.ixx.

62 void update(helios::engine::game::UpdateContext& updateContext) noexcept override {
63
64 for (auto [entity, mab, wsc, tc] : gameWorld_->find<
68 >().each()) {
69
70 if (!wsc->isDirty()) {
71 continue;
72 }
73
74 // Get current model size and desired size
75 auto cscale = mab->aabb().size();
76 auto wscale = wsc->scaling();
77
78 auto currentScale = tc->localScaling();
79
80 auto unit = wsc->unit();
81
82 // Calculate scale factors: desired_size / current_size
83 // Convert desired size to engine units (meters)
84 auto scale = helios::math::vec3f{
85 wscale[0] != 0 && cscale[0] != 0 ? helios::core::units::from(wscale[0], unit) / cscale[0] : currentScale[0],
86 wscale[1] != 0 && cscale[1] != 0 ? helios::core::units::from(wscale[1], unit) / cscale[1] : currentScale[1],
87 wscale[2] != 0 && cscale[2] != 0 ? helios::core::units::from(wscale[2], unit) / cscale[2] : currentScale[2]
88 };
89
90 tc->setLocalScale(scale);
91 }
92 }

References helios::core::units::from and helios::engine::game::System::gameWorld_.


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


Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.15.0.