ACF $AcfVersion:0$
CAffine3d.h
Go to the documentation of this file.
1// SPDX-License-Identifier: LGPL-2.1-or-later OR GPL-2.0-or-later OR GPL-3.0-or-later OR LicenseRef-ACF-Commercial
2#pragma once
3
4
5// ACF includes
6#include <i3d/CVector3d.h>
7#include <i3d/CMatrix3d.h>
8#include <i3d/CQuaternion3d.h>
9
10
11namespace i3d
12{
13
14
21{
22public:
27 CAffine3d();
28
34 CAffine3d(const CMatrix3d& matrix, const CVector3d& translation);
35
39 static CAffine3d GetIdentity();
40
44 static CAffine3d CreateTranslation(const CVector3d& translation);
45
49 static CAffine3d CreateRotation(const CQuaternion3d& rotation);
50
56 static CAffine3d CreateRotation(const CVector3d& axis, double angle);
57
61 static CAffine3d CreateScale(double scale);
62
66 static CAffine3d CreateScale(double sx, double sy, double sz);
67
71 static CAffine3d CreateScale(const CVector3d& scale);
72
76 const CMatrix3d& GetMatrix() const;
77
81 void SetMatrix(const CMatrix3d& matrix);
82
86 const CVector3d& GetTranslation() const;
87
91 void SetTranslation(const CVector3d& translation);
92
96 void Reset();
97
101 CVector3d Transform(const CVector3d& point) const;
102
106 CVector3d TransformDirection(const CVector3d& direction) const;
107
112
117 bool GetInverse(CAffine3d& result) const;
118
122 void Compose(const CAffine3d& other);
123
127 CAffine3d GetComposed(const CAffine3d& other) const;
128
132 bool Serialize(iser::IArchive& archive);
133
134 CAffine3d operator*(const CAffine3d& other) const;
135 CVector3d operator*(const CVector3d& point) const;
136
137 bool operator==(const CAffine3d& other) const;
138 bool operator!=(const CAffine3d& other) const;
139
140private:
141 CMatrix3d m_matrix;
142 CVector3d m_translation;
143};
144
145
146// inline methods
147
149: m_matrix(CMatrix3d::GetIdentity())
150, m_translation(0.0, 0.0, 0.0)
151{
152}
153
154
155inline CAffine3d::CAffine3d(const CMatrix3d& matrix, const CVector3d& translation)
156: m_matrix(matrix)
157, m_translation(translation)
158{
159}
160
161
163{
164 return CAffine3d();
165}
166
167
169{
170 return CAffine3d(CMatrix3d::GetIdentity(), translation);
171}
172
173
175{
176 return CAffine3d(rotation.ToMatrix(), CVector3d(0.0, 0.0, 0.0));
177}
178
179
180inline CAffine3d CAffine3d::CreateRotation(const CVector3d& axis, double angle)
181{
182 return CreateRotation(CQuaternion3d::FromAxisAngle(axis, angle));
183}
184
185
187{
188 return CreateScale(scale, scale, scale);
189}
190
191
192inline CAffine3d CAffine3d::CreateScale(double sx, double sy, double sz)
193{
194 return CAffine3d(CMatrix3d(sx, 0.0, 0.0, 0.0, sy, 0.0, 0.0, 0.0, sz), CVector3d(0.0, 0.0, 0.0));
195}
196
197
199{
200 return CreateScale(scale.GetX(), scale.GetY(), scale.GetZ());
201}
202
203
204inline const CMatrix3d& CAffine3d::GetMatrix() const
205{
206 return m_matrix;
207}
208
209
210inline void CAffine3d::SetMatrix(const CMatrix3d& matrix)
211{
212 m_matrix = matrix;
213}
214
215
217{
218 return m_translation;
219}
220
221
222inline void CAffine3d::SetTranslation(const CVector3d& translation)
223{
224 m_translation = translation;
225}
226
227
228inline void CAffine3d::Reset()
229{
230 m_matrix = CMatrix3d::GetIdentity();
231 m_translation = CVector3d(0.0, 0.0, 0.0);
232}
233
234
235inline CVector3d CAffine3d::Transform(const CVector3d& point) const
236{
237 return m_matrix.GetMultiplied(point) + m_translation;
238}
239
240
242{
243 return m_matrix.GetMultiplied(direction);
244}
245
246
248{
249 // (M1, t1) * (M2, t2) = (M1 * M2, M1 * t2 + t1)
250 return CAffine3d(
251 m_matrix.GetMultiplied(other.m_matrix),
252 m_matrix.GetMultiplied(other.m_translation) + m_translation
253 );
254}
255
256
257inline void CAffine3d::Compose(const CAffine3d& other)
258{
259 *this = GetComposed(other);
260}
261
262
263inline CAffine3d CAffine3d::operator*(const CAffine3d& other) const
264{
265 return GetComposed(other);
266}
267
268
269inline CVector3d CAffine3d::operator*(const CVector3d& point) const
270{
271 return Transform(point);
272}
273
274
275inline bool CAffine3d::operator==(const CAffine3d& other) const
276{
277 return m_matrix == other.m_matrix && m_translation == other.m_translation;
278}
279
280
281inline bool CAffine3d::operator!=(const CAffine3d& other) const
282{
283 return !(*this == other);
284}
285
286
287} // namespace i3d
288
289
Affine transformation in 3D space.
Definition CAffine3d.h:21
static CAffine3d CreateScale(double scale)
Create uniform scale transformation.
Definition CAffine3d.h:186
CVector3d Transform(const CVector3d &point) const
Transform a point.
Definition CAffine3d.h:235
static CAffine3d CreateRotation(const CQuaternion3d &rotation)
Create rotation transformation from quaternion.
Definition CAffine3d.h:174
CAffine3d GetComposed(const CAffine3d &other) const
Compose transformations (returns this * other).
Definition CAffine3d.h:247
void Compose(const CAffine3d &other)
Compose this transformation with another (this = this * other).
Definition CAffine3d.h:257
const CMatrix3d & GetMatrix() const
Get matrix part (rotation/scale).
Definition CAffine3d.h:204
bool Serialize(iser::IArchive &archive)
Serialize this transformation to specified archive.
bool operator==(const CAffine3d &other) const
Definition CAffine3d.h:275
static CAffine3d GetIdentity()
Create identity transformation.
Definition CAffine3d.h:162
void Reset()
Reset to identity transformation.
Definition CAffine3d.h:228
bool GetInverse(CAffine3d &result) const
Get inverse transformation.
CAffine3d GetInverse() const
Get inverse transformation.
static CAffine3d CreateTranslation(const CVector3d &translation)
Create translation transformation.
Definition CAffine3d.h:168
void SetTranslation(const CVector3d &translation)
Set translation part.
Definition CAffine3d.h:222
void SetMatrix(const CMatrix3d &matrix)
Set matrix part.
Definition CAffine3d.h:210
bool operator!=(const CAffine3d &other) const
Definition CAffine3d.h:281
CAffine3d()
Default constructor.
Definition CAffine3d.h:148
CAffine3d operator*(const CAffine3d &other) const
Definition CAffine3d.h:263
CVector3d TransformDirection(const CVector3d &direction) const
Transform a direction vector (ignores translation).
Definition CAffine3d.h:241
const CVector3d & GetTranslation() const
Get translation part.
Definition CAffine3d.h:216
3D-matrix definition.
Definition CMatrix3d.h:18
CVector3d GetMultiplied(const CVector3d &position) const
Definition CMatrix3d.h:179
static const CMatrix3d & GetIdentity()
Definition CMatrix3d.h:299
Quaternion for representing rotations in 3D space.
static CQuaternion3d FromAxisAngle(const CVector3d &axis, double angle)
Construct quaternion from axis and angle.
CMatrix3d ToMatrix() const
Convert quaternion to rotation matrix.
Represents a position or mathematical vector in 3D space with double precision.
Definition CVector3d.h:74
double GetX() const
Gets the X coordinate of the vector.
Definition CVector3d.h:290
double GetY() const
Gets the Y coordinate of the vector.
Definition CVector3d.h:302
double GetZ() const
Gets the Z coordinate of the vector.
Definition CVector3d.h:314
Represents an input/output persistence archive for object serialization.
Definition IArchive.h:164
Contains the 3D objects.
Definition CAffine3d.h:12