SA_Maths
Sapphire Suite's C++ Maths Library
Loading...
Searching...
No Matches
Transform.hpp
Go to the documentation of this file.
1// Copyright (c) 2023 Sapphire Development Team. All Rights Reserved.
2
3#pragma once
4
5#ifndef SAPPHIRE_MATHS_TRANSFORM_GUARD
6#define SAPPHIRE_MATHS_TRANSFORM_GUARD
7
8#include <SA/Maths/Debug.hpp>
9
12
23namespace SA
24{
31 template <typename T, template <typename> typename... Args>
32 struct Tr : public Args<T>...
33 {
35 using Type = T;
36
37
44 template <template <typename> typename Comp>
45 static constexpr bool HasComponent() noexcept;
46
47
48 //{ Equals
49
55 bool IsZero() const noexcept;
56
62 bool IsIdentity() const noexcept;
63
72 bool Equals(const Tr& _other, T _epsilon = std::numeric_limits<T>::epsilon()) const noexcept;
73
74
82 bool operator==(const Tr& _rhs) const noexcept;
83
91 bool operator!=(const Tr& _rhs) const noexcept;
92
93 //}
94
95
96 //{ Transformation
97
103 template <typename TrFunc = TrRotateAxisFunctor>
104 Vec3<T> Right(TrFunc _functor = TrFunc()) const;
105
111 template <typename TrFunc = TrRotateAxisFunctor>
112 Vec3<T> Up(TrFunc _functor = TrFunc()) const;
113
119 template <typename TrFunc = TrRotateAxisFunctor>
120 Vec3<T> Forward(TrFunc _functor = TrFunc()) const;
121
122
129 template <typename TrFunc = TrTRSMatrixFunctor>
130 Mat4<T> Matrix(TrFunc _functor = TrFunc()) const noexcept;
131
132 //}
133
134
135 //{ Lerp
136
148 static Tr Lerp(const Tr& _start, const Tr& _end, float _alpha) noexcept;
149
161 static Tr LerpUnclamped(const Tr& _start, const Tr& _end, float _alpha) noexcept;
162
163 //}
164
165
166 //{ Operators
167
175 template <template <typename> typename... InArgs>
176 Tr operator*(const Tr<T, InArgs...>& _rhs) const;
177
185 template <template <typename> typename... InArgs>
186 Tr operator/(const Tr<T, InArgs...>& _rhs) const;
187
195 template <template <typename> typename... InArgs>
196 Tr& operator*=(const Tr<T, InArgs...>& _rhs);
197
205 template <template <typename> typename... InArgs>
206 Tr& operator/=(const Tr<T, InArgs...>& _rhs);
207
208 //}
209
210
211 //{ Cast
212
221 template <typename TOut, template <typename> typename... ArgsOut>
222 operator Tr<TOut, ArgsOut...>() const noexcept;
223
224 //}
225
226 private:
227
228 //{ Packed
229
230 template <typename CurrT, typename... PArgs>
231 bool IsZeroPacked() const noexcept;
232
233 template <typename CurrT, typename... PArgs>
234 bool IsIdentityPacked() const noexcept;
235
236 template <typename CurrT, typename... PArgs>
237 bool EqualsPacked(const Tr& _other, T _epsilon) const noexcept;
238
239
240 template <typename CurrT, typename... PArgs>
241 void LerpUnclampedPacked(const Tr& _start, const Tr& _end, float _alpha) noexcept;
242
243
244 template <typename TrIn, typename CurrT, typename... PArgs>
245 void MultiplyPacked(const Tr& _lhs, const TrIn& _rhs) noexcept;
246
247 template <typename TrIn, typename CurrT, typename... PArgs>
248 void DividePacked(const Tr& _lhs, const TrIn& _rhs) noexcept;
249
250 //}
251
252
253 #if SA_LOGGER_IMPL
254
255 template <typename CurrT, typename... PArgs>
256 std::string ToStringPacked() const noexcept;
257
258 public:
259
260 std::string ToString() const noexcept;
261
262 #endif
263 };
264
265
266#if SA_LOGGER_IMPL
267
280 template <typename T, template <typename> typename... Args>
281 std::string ToString(const Tr<T, Args...>& _tr) { return _tr.ToString(); }
282
283#endif
284
285
286//{ Aliases
287
288//{ Tr aliases
289
291 template <typename T>
293
295 template <typename T>
297
299 template <typename T>
301
303 template <typename T>
305
307 template <typename T>
309
311 template <typename T>
313
315 template <typename T>
317
318//{ Float
319
322
325
328
331
334
337
340
341//}
342
343
344//{ Double
345
348
351
354
357
360
363
366
367//}
368
369//}
370
371
372//{ Transform aliases
373
375 template <typename T, template <typename> typename... Args>
376 using Transform = Tr<T, Args...>;
377
379 template <typename T>
381
383 template <typename T>
385
387 template <typename T>
389
391 template <typename T>
393
395 template <typename T>
397
399 template <typename T>
401
403 template <typename T>
405
406//{ Float
407
410
413
416
419
422
425
428
429//}
430
431
432//{ Double
433
436
439
442
445
448
451
454
455//}
456
457//}
458
459//}
460
461}
462
470#include <SA/Maths/Transform/Transform.inl>
471
472#endif // GUARD
Maths module Debug compatibility definition.
Transform rotate axis functor definition.
Transform TRS Matrix functor definition.
Compute rotated axis from transform. Functor implementation.
Definition TransformRotateAxisFunctor.hpp:31
Compute TRS Matrix from Transform. Order is applied from right to left: (T * (R * S))....
Definition TransformTRSMatrixFunctor.hpp:35
Matrix 4x4 Sapphire-Maths class.
Definition Matrix4.hpp:68
Transform Sapphire's class.
Definition Transform.hpp:33
bool IsZero() const noexcept
Whether this transform is a zero transform.
Vec3< T > Up(TrFunc _functor=TrFunc()) const
Getter of up vector (Y axis) of this transform.
Mat4< T > Matrix(TrFunc _functor=TrFunc()) const noexcept
Compute matrix from transform Use default TRS order application.
T Type
Transform type alias.
Definition Transform.hpp:35
bool Equals(const Tr &_other, T _epsilon=std::numeric_limits< T >::epsilon()) const noexcept
Compare 2 transform.
Vec3< T > Right(TrFunc _functor=TrFunc()) const
Getter of right vector (X axis) of this transform.
static Tr LerpUnclamped(const Tr &_start, const Tr &_end, float _alpha) noexcept
Unclamped Lerp from _start to _end at _alpha.
bool IsIdentity() const noexcept
Whether this transform is an identity transform.
Vec3< T > Forward(TrFunc _functor=TrFunc()) const
Getter of forward vector (Z axis) of this transform.
static Tr Lerp(const Tr &_start, const Tr &_end, float _alpha) noexcept
Clamped Lerp from _start to _end at _alpha.
static constexpr bool HasComponent() noexcept
compile-time HasComponent.
Vector 3 Sapphire-Maths class.
Definition Vector3.hpp:43