Skip to main content

Transform.ixx File

Represents a 3D transformation consisting of translation, rotation and scale. More...

Included Headers

Namespaces Index

namespacehelios
namespacecore

Core utilities shared across the helios engine. More...

namespacespatial

Spatial transformation utilities. More...

Classes Index

classTransform

Represents a 3D transformation consisting of translation, rotation and scale. More...

Description

Represents a 3D transformation consisting of translation, rotation and scale.

File Listing

The file content with the documentation metadata removed is:

1/**
2 * @file Transform.ixx
3 * @brief Represents a 3D transformation consisting of translation, rotation
4 * and scale.
5 */
6module;
7
8
9export module helios.core.spatial.Transform;
10
11import helios.math.types;
12import helios.math.transform;
13
14
15export namespace helios::core::spatial {
16
17 /**
18 * @brief Represents a 3D transformation consisting of translation, rotation
19 * and scale.
20 *
21 * This class encapsulates the components of a local transform for SceneNodes.
22 * It uses lazy evaluation to compute the final transform.
23 * The current scale, translation and rotation is queryable.
24 * Changing the transformation is always considered against an
25 * "origin" of an object, that is, a 4x4 identity matrix
26 *
27 * @todo use quaternions for rotation
28 */
29 class Transform {
30
31 private:
32 /**
33 * @brief Flag indicating whether this Transform needs to recompute
34 * its transformation matrix.
35 */
36 mutable bool needsUpdate_ = true;
37
38 /**
39 * @brief The rotation component of the transformation, stored as a 4x4 matrix.
40 */
42
43 /**
44 * @brief The scaling component of the transformation, stored as a 3D vector.
45 */
47
48 /**
49 * @brief The translation component of the transformation, stored as a 3D vector.
50 */
52
53 /**
54 * @brief The cached 4x4 matrix, computed from scale, rotation and translation
55 * (in this order: T * (R * S)).
56 */
58
59 /**
60 * @brief Internal helper function to compute the full 4x4 affine transformation
61 * matrix.
62 *
63 * @return The newly computed transformation matrix.
64 */
65 helios::math::mat4f updateCache() const {
66 needsUpdate_ = false;
67 return math::translate(
69 translation_) *
70 (rotation_ * helios::math::mat4f(scale_)
71 );
72 }
73
74 public:
75 ~Transform() = default;
76
77 /**
78 * @brief Constructs a new Transform object with the default identity transformation,
79 * i.e. scale (1, 1, 1), rotation 4x4_id, translate (0, 0, 0).
80 */
81 Transform() = default;
82
83 /**
84 * @brief Constructs a new Transformation matrix from the specified rotation, scale and translation.
85 *
86 * @param rotation The initial rotation matrix.
87 * @param scale The initial scaling vector.
88 * @param translation The initial translation vector.
89 */
93 ) noexcept :
94 rotation_(rotation),
95 scale_(scale),
96 translation_(translation),
97 needsUpdate_(true)
98 {}
99
100 /**
101 * @brief Sets the rotation component of this Transform.
102 * Marks this Transform object as dirty.
103 *
104 * @param rotation A const ref to the new rotation matrix.
105 */
106 void setRotation(const math::mat4f& rotation) noexcept {
107 rotation_ = rotation;
108 needsUpdate_ = true;
109 }
110
111 /**
112 * @brief Sets the translation component of this Transform.
113 * Marks this Transform object as dirty.
114 *
115 * @param translation A const ref to the new translation vector.
116 */
117 void setTranslation(const math::vec3f& translation) noexcept {
118 translation_ = translation;
119 needsUpdate_ = true;
120 }
121
122 /**
123 * @brief Sets the scale component of this Transform.
124 * Marks this Transform object as dirty.
125 *
126 * @param scale A const ref to the new scale vector.
127 */
128 void setScale(const math::vec3f& scale) noexcept {
129 scale_ = scale;
130 needsUpdate_ = true;
131 }
132
133 /**
134 * @brief Returns the current rotation component of this Transform object.
135 *
136 * @return The current 4x4 rotation matrix.
137 */
138 [[nodiscard]] helios::math::mat4f rotation() const noexcept {
139 return rotation_;
140 }
141
142 /**
143 * @brief Returns the current translation component of this Transform object.
144 *
145 * @return The current 3D translation vector.
146 */
147 [[nodiscard]] helios::math::vec3f translation() const noexcept {
148 return translation_;
149 }
150
151 /**
152 * @brief Returns the current scale component of this Transform object.
153 *
154 * @return The current 3D scale vector.
155 */
156 [[nodiscard]] helios::math::vec3f scaling() const noexcept {
157 return scale_;
158 }
159
160 /**
161 * @brief Returns the 4x4 transformation matrix combined from scale, rotation, and translation.
162 *
163 * @return The current 4x4 affine transformation matrix.
164 */
165 [[nodiscard]] helios::math::mat4f transform() const noexcept {
166 if (needsUpdate_) {
167 cached_ = updateCache();
168 }
169 return cached_;
170 }
171
172 /**
173 * @brief Checks whether this Transform needs to be updated, e.g. because the
174 * various components changed.
175 *
176 * @return true if this Transform is considered to be dirty, otherwise
177 * false.
178 */
179 [[nodiscard]] bool needsUpdate() const noexcept {
180 return needsUpdate_;
181 }
182
183 };
184
185};

Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.15.0.