Ark Server API (ASA) - Wiki
Loading...
Searching...
No Matches
ScaleRotationTranslationMatrix.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/Matrix.h"
8
9
10namespace UE {
11namespace Math {
12
13/** Combined Scale rotation and translation matrix */
14template<typename T>
15struct TScaleRotationTranslationMatrix
16 : public TMatrix<T>
17{
18public:
19 using TMatrix<T>::M;
20
21 /**
22 * Constructor.
23 *
24 * @param Scale scale to apply to matrix
25 * @param Rot rotation
26 * @param Origin translation to apply
27 */
28 TScaleRotationTranslationMatrix(const TVector<T>& Scale, const TRotator<T>& Rot, const TVector<T>& Origin);
29
30 // Conversion to other type.
31 template<typename FArg, TEMPLATE_REQUIRES(!std::is_same_v<T, FArg>)>
32 explicit TScaleRotationTranslationMatrix(const TScaleRotationTranslationMatrix<FArg>& From) : TMatrix<T>(From) {}
33};
34
35namespace
36{
37 template<typename T>
38 void GetSinCos(T& S, T& C, T Degrees)
39 {
40 if (Degrees == 0.f)
41 {
42 S = 0.f;
43 C = 1.f;
44 }
45 else if (Degrees == 90.f)
46 {
47 S = 1.f;
48 C = 0.f;
49 }
50 else if (Degrees == 180.f)
51 {
52 S = 0.f;
53 C = -1.f;
54 }
55 else if (Degrees == 270.f)
56 {
57 S = -1.f;
58 C = 0.f;
59 }
60 else
61 {
62 FMath::SinCos(&S, &C, FMath::DegreesToRadians(Degrees));
63 }
64 }
65}
66
67template<typename T>
68FORCEINLINE TScaleRotationTranslationMatrix<T>::TScaleRotationTranslationMatrix(const TVector<T>& Scale, const TRotator<T>& Rot, const TVector<T>& Origin)
69{
70 T SP, SY, SR;
71 T CP, CY, CR;
72 GetSinCos(SP, CP, (T)Rot.Pitch);
73 GetSinCos(SY, CY, (T)Rot.Yaw);
74 GetSinCos(SR, CR, (T)Rot.Roll);
75
76 M[0][0] = (CP * CY) * Scale.X;
77 M[0][1] = (CP * SY) * Scale.X;
78 M[0][2] = (SP) * Scale.X;
79 M[0][3] = 0.f;
80
81 M[1][0] = (SR * SP * CY - CR * SY) * Scale.Y;
82 M[1][1] = (SR * SP * SY + CR * CY) * Scale.Y;
83 M[1][2] = (- SR * CP) * Scale.Y;
84 M[1][3] = 0.f;
85
86 M[2][0] = ( -( CR * SP * CY + SR * SY ) ) * Scale.Z;
87 M[2][1] = (CY * SR - CR * SP * SY) * Scale.Z;
88 M[2][2] = (CR * CP) * Scale.Z;
89 M[2][3] = 0.f;
90
91 M[3][0] = Origin.X;
92 M[3][1] = Origin.Y;
93 M[3][2] = Origin.Z;
94 M[3][3] = 1.f;
95}
96
97} // namespace Math
98} // namespace UE
99
100UE_DECLARE_LWC_TYPE(ScaleRotationTranslationMatrix, 44);
101
102template<> struct TIsUECoreVariant<FScaleRotationTranslationMatrix44f> { enum { Value = true }; };
103template<> struct TIsUECoreVariant<FScaleRotationTranslationMatrix44d> { enum { Value = true }; };
#define UE_DECLARE_LWC_TYPE(...)
#define FORCEINLINE
Definition Platform.h:644
#define TEMPLATE_REQUIRES(...)