Ark Server API (ASA) - Wiki
Loading...
Searching...
No Matches
RotationTranslationMatrix.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 "Math/UnrealMathUtility.h"
7#include "Math/VectorRegister.h"
8#include "Math/Matrix.h"
9
10namespace UE {
11namespace Math {
12
13/** Combined rotation and translation matrix */
14template<typename T>
15struct TRotationTranslationMatrix
16 : public TMatrix<T>
17{
18public:
19 using TMatrix<T>::M;
20
21 /**
22 * Constructor.
23 *
24 * @param Rot rotation
25 * @param Origin translation to apply
26 */
27 TRotationTranslationMatrix(const TRotator<T>& Rot, const TVector<T>& Origin);
28
29 // Conversion to other type.
30 template<typename FArg, TEMPLATE_REQUIRES(!std::is_same_v<T, FArg>)>
31 explicit TRotationTranslationMatrix(const TRotationTranslationMatrix<FArg>& From) : TMatrix<T>(From) {}
32
33 /** Matrix factory. Return an TMatrix<T> so we don't have type conversion issues in expressions. */
34 static TMatrix<T> Make(const TRotator<T>& Rot, const TVector<T>& Origin)
35 {
36 return TRotationTranslationMatrix(Rot, Origin);
37 }
38};
39
40
41template<typename T>
42FORCEINLINE TRotationTranslationMatrix<T>::TRotationTranslationMatrix(const TRotator<T>& Rot, const TVector<T>& Origin)
43{
45
46 const TVectorRegisterType<T> Angles = MakeVectorRegister(Rot.Pitch, Rot.Yaw, Rot.Roll, 0.0f);
47 const TVectorRegisterType<T> HalfAngles = VectorMultiply(Angles, GlobalVectorConstants::DEG_TO_RAD);
48
49 union { TVectorRegisterType<T> v; T f[4]; } SinAngles, CosAngles;
50 VectorSinCos(&SinAngles.v, &CosAngles.v, &HalfAngles);
51
52 const T SP = SinAngles.f[0];
53 const T SY = SinAngles.f[1];
54 const T SR = SinAngles.f[2];
55 const T CP = CosAngles.f[0];
56 const T CY = CosAngles.f[1];
57 const T CR = CosAngles.f[2];
58
59#else
60
61 T SP, SY, SR;
62 T CP, CY, CR;
63 FMath::SinCos(&SP, &CP, (T)FMath::DegreesToRadians(Rot.Pitch));
64 FMath::SinCos(&SY, &CY, (T)FMath::DegreesToRadians(Rot.Yaw));
65 FMath::SinCos(&SR, &CR, (T)FMath::DegreesToRadians(Rot.Roll));
66
67#endif // PLATFORM_ENABLE_VECTORINTRINSICS
68
69 M[0][0] = CP * CY;
70 M[0][1] = CP * SY;
71 M[0][2] = SP;
72 M[0][3] = 0.f;
73
74 M[1][0] = SR * SP * CY - CR * SY;
75 M[1][1] = SR * SP * SY + CR * CY;
76 M[1][2] = - SR * CP;
77 M[1][3] = 0.f;
78
79 M[2][0] = -( CR * SP * CY + SR * SY );
80 M[2][1] = CY * SR - CR * SP * SY;
81 M[2][2] = CR * CP;
82 M[2][3] = 0.f;
83
84 M[3][0] = Origin.X;
85 M[3][1] = Origin.Y;
86 M[3][2] = Origin.Z;
87 M[3][3] = 1.f;
88}
89
90} // namespace Math
91} // namespace UE
92
93UE_DECLARE_LWC_TYPE(RotationTranslationMatrix, 44);
94
95template<> struct TIsUECoreVariant<FRotationTranslationMatrix44f> { enum { Value = true }; };
96template<> struct TIsUECoreVariant<FRotationTranslationMatrix44d> { enum { Value = true }; };
#define UE_DECLARE_LWC_TYPE(...)
#define PLATFORM_HOLOLENS
Definition Platform.h:65
#define PLATFORM_CPU_ARM_FAMILY
Definition Platform.h:89
#define PLATFORM_ENABLE_VECTORINTRINSICS
Definition Platform.h:162
#define FORCEINLINE
Definition Platform.h:644
#define TEMPLATE_REQUIRES(...)