Skip to main content

ComposeTransformComponent.ixx File

Component for managing local and world transformations of a GameObject. More...

Included Headers

Namespaces Index

namespacehelios
namespaceengine

Main engine module aggregating core infrastructure and game systems. More...

namespacemodules

Domain-specific components and systems. More...

namespacespatial
namespacetransform

Transform components and systems for spatial state management. More...

namespacecomponents

Transform state components for spatial management. More...

Classes Index

classComposeTransformComponent

Component that holds transformation data (position, rotation, scale). More...

Description

Component for managing local and world transformations of a GameObject.

File Listing

The file content with the documentation metadata removed is:

1/**
2 * @file ComposeTransformComponent.ixx
3 * @brief Component for managing local and world transformations of a GameObject.
4 */
5module;
6
7export module helios.engine.modules.spatial.transform.components.ComposeTransformComponent;
8
9import helios.math.types;
10
11import helios.core.spatial.Transform;
12
14
15 /**
16 * @brief Component that holds transformation data (position, rotation, scale).
17 *
18 * @details The ComposeTransformComponent manages the spatial state of a GameObject.
19 * It stores the local transform (relative to parent) and the computed world transform.
20 * Changes to local properties mark the component as dirty, signaling systems to
21 * recompute the world transform.
22 */
24
25 /**
26 * @brief The local transformation (translation, rotation, scale).
27 */
29
30 /**
31 * @brief Flag indicating if the transform has changed since the last update.
32 */
33 bool isDirty_= true;
34
35 /**
36 * @brief The computed world transformation matrix.
37 */
39
40 /**
41 * @brief Whether this component is enabled.
42 */
43 bool isEnabled_ = true;
44
45 public:
46
47 /**
48 * @brief Checks whether this component is enabled.
49 *
50 * @return True if enabled, false otherwise.
51 */
52 [[nodiscard]] bool isEnabled() const noexcept {
53 return isEnabled_;
54 }
55
56 /**
57 * @brief Enables this component.
58 */
59 void enable() noexcept {
60 isEnabled_ = true;
61 }
62
63 /**
64 * @brief Disables this component.
65 */
66 void disable() noexcept {
67 isEnabled_ = false;
68 }
69
70 /**
71 * @brief Default constructor.
72 */
74
75 /**
76 * @brief Copy constructor.
77 *
78 * @param other The component to copy from.
79 */
81 transform_(other.transform_),
82 worldTransform_(other.worldTransform_),
83 isDirty_(true){}
84
87 ComposeTransformComponent& operator=(ComposeTransformComponent&&) noexcept = default;
88
89 /**
90 * @brief Checks if the transform is dirty.
91 *
92 * @return True if the transform has changed, false otherwise.
93 */
94 [[nodiscard]] bool isDirty() const noexcept {
95 return isDirty_;
96 }
97
98 /**
99 * @brief Clears the dirty flag.
100 */
101 void clearDirty() noexcept {
102 isDirty_ = false;
103 }
104
105 /**
106 * @brief Resets the dirty flag to true when acquired.
107 *
108 * Makes sure the transform is considered after the component was acquired.
109 */
110 void onAcquire() noexcept {
111 isDirty_ = true;
112 }
113
114 /**
115 * @brief Resets the dirty flag to true when released.
116 *
117 * Makes sure the entities dirty-state is reset to the default state.
118 */
119 void onRelease() noexcept {
120 isDirty_ = true;
121 }
122
123 /**
124 * @brief Returns the local transformation matrix.
125 *
126 * @return The 4x4 matrix representing local translation, rotation, and scale.
127 */
128 [[nodiscard]] helios::math::mat4f localTransform() const noexcept {
129 return transform_.transform();
130 }
131
132
133 /**
134 * @brief Sets the local scale.
135 *
136 * @param scale The new scale vector.
137 * @return Reference to this component for chaining.
138 */
140 transform_.setScale(scale);
141 isDirty_ = true;
142 return *this;
143 };
144
145
146 /**
147 * @brief Sets the local rotation matrix.
148 *
149 * @param rotation The new rotation matrix.
150 * @return Reference to this component for chaining.
151 */
153 transform_.setRotation(rotation);
154 isDirty_ = true;
155 return *this;
156 };
157
158
159 /**
160 * @brief Sets the local translation (position).
161 *
162 * @param translation The new position vector.
163 * @return Reference to this component for chaining.
164 */
166 transform_.setTranslation(translation);
167 isDirty_ = true;
168 return *this;
169 };
170
171 /**
172 * @brief Translates the component locally by a delta vector.
173 *
174 * @param translation The vector to add to the current position.
175 * @return Reference to this component for chaining.
176 */
178 transform_.setTranslation(transform_.translation() + translation);
179 isDirty_ = true;
180 return *this;
181 };
182
183 /**
184 * @brief Returns the local translation vector.
185 *
186 * @return The position relative to the parent.
187 */
188 [[nodiscard]] helios::math::vec3f localTranslation() const noexcept {
189 return transform_.translation();
190 }
191
192
193 /**
194 * @brief Returns the local rotation matrix.
195 *
196 * @return The rotation relative to the parent.
197 */
198 [[nodiscard]] helios::math::mat4f localRotation() const noexcept {
199 return transform_.rotation();
200 }
201
202
203 /**
204 * @brief Returns the local scaling vector.
205 *
206 * @return The scale relative to the parent.
207 */
208 [[nodiscard]] helios::math::vec3f localScaling() const noexcept {
209 return transform_.scaling();
210 }
211
212 /**
213 * @brief Sets the world transform matrix directly.
214 *
215 * @param m The new world transform matrix.
216 */
217 void setWorldTransform(const helios::math::mat4f& m) noexcept {
218 isDirty_ = true;
219 worldTransform_ = m;
220 }
221
222 /**
223 * @brief Returns the current world transform matrix.
224 *
225 * @return Const reference to the world transform.
226 */
228 return worldTransform_;
229 }
230
231 /**
232 * @brief Extracts the world translation from the world transform.
233 *
234 * @return The global position vector.
235 */
237 return worldTransform_.translation();
238 }
239 };
240
241}
242

Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.15.0.