Ark Server API (ASA) - Wiki
Loading...
Searching...
No Matches
QuatRotationTranslationMatrix.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5#include "CoreTypes.h"
6#include "Misc/AssertionMacros.h"
7#include "Math/Vector.h"
8#include "Math/Matrix.h"
9#include "Math/Quat.h"
10
11namespace UE {
12namespace Math {
13
14/** Rotation and translation matrix using quaternion rotation */
15template <typename T>
17 : public TMatrix<T>
18{
19public:
20 using TMatrix<T>::M;
21
22 /** Constructor
23 *
24 * @param Q rotation
25 * @param Origin translation to apply
26 */
27 TQuatRotationTranslationMatrix(const TQuat<T>& Q, const TVector<T>& Origin);
28
29 // Conversion to other type.
30 template<typename FArg, TEMPLATE_REQUIRES(!std::is_same_v<T, FArg>)>
32
33 /** Matrix factory. Return an FMatrix so we don't have type conversion issues in expressions. */
34 static TMatrix<T> Make(const TQuat<T>& Q, const TVector<T>& Origin)
35 {
37 }
38};
39
40
41/** Rotation matrix using quaternion rotation */
42template<typename T>
45{
46public:
48
49 /** Constructor
50 *
51 * @param Q rotation
52 */
53 TQuatRotationMatrix(const TQuat<T>& Q)
55 {
56 }
57
58 // Conversion to other type.
59 template<typename FArg, TEMPLATE_REQUIRES(!std::is_same_v<T, FArg>)>
61
62 /** Matrix factory. Return an FMatrix so we don't have type conversion issues in expressions. */
63 static TMatrix<T> Make(const TQuat<T>& Q)
64 {
65 return TQuatRotationMatrix<T>(Q);
66 }
67};
68
69
70template<typename T>
72{
74 // Make sure Quaternion is normalized
75 check( Q.IsNormalized() );
76#endif
77 const T x2 = Q.X + Q.X; const T y2 = Q.Y + Q.Y; const T z2 = Q.Z + Q.Z;
78 const T xx = Q.X * x2; const T xy = Q.X * y2; const T xz = Q.X * z2;
79 const T yy = Q.Y * y2; const T yz = Q.Y * z2; const T zz = Q.Z * z2;
80 const T wx = Q.W * x2; const T wy = Q.W * y2; const T wz = Q.W * z2;
81
82 M[0][0] = 1.0f - (yy + zz); M[1][0] = xy - wz; M[2][0] = xz + wy; M[3][0] = Origin.X;
83 M[0][1] = xy + wz; M[1][1] = 1.0f - (xx + zz); M[2][1] = yz - wx; M[3][1] = Origin.Y;
84 M[0][2] = xz - wy; M[1][2] = yz + wx; M[2][2] = 1.0f - (xx + yy); M[3][2] = Origin.Z;
85 M[0][3] = 0.0f; M[1][3] = 0.0f; M[2][3] = 0.0f; M[3][3] = 1.0f;
86}
87
88} // namespace Math
89} // namespace UE
90
91UE_DECLARE_LWC_TYPE(QuatRotationTranslationMatrix, 44);
92UE_DECLARE_LWC_TYPE(QuatRotationMatrix, 44);
93
94template<> struct TIsUECoreVariant<FQuatRotationTranslationMatrix44f> { enum { Value = true }; };
95template<> struct TIsUECoreVariant<FQuatRotationTranslationMatrix44d> { enum { Value = true }; };
96template<> struct TIsUECoreVariant<FQuatRotationMatrix44f> { enum { Value = true }; };
97template<> struct TIsUECoreVariant<FQuatRotationMatrix44d> { enum { Value = true }; };
#define UE_BUILD_TEST
Definition Build.h:23
#define UE_BUILD_SHIPPING
Definition Build.h:4
#define WITH_EDITORONLY_DATA
#define UE_DECLARE_LWC_TYPE(...)
#define FORCEINLINE
Definition Platform.h:644
#define TEMPLATE_REQUIRES(...)
Definition Vector.h:40
Definition json.hpp:4518
TQuatRotationMatrix(const TQuatRotationMatrix< FArg > &From)
static TMatrix< T > Make(const TQuat< T > &Q)
TQuatRotationTranslationMatrix(const TQuatRotationTranslationMatrix< FArg > &From)
TQuatRotationTranslationMatrix(const TQuat< T > &Q, const TVector< T > &Origin)
static TMatrix< T > Make(const TQuat< T > &Q, const TVector< T > &Origin)