Ark Server API (ASA) - Wiki
Loading...
Searching...
No Matches
DualQuat.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/Vector.h"
8#include "Math/Quat.h"
9#include "Math/Transform.h"
10
11/** Dual quaternion class */
12namespace UE
13{
14namespace Math
15{
16
17template<typename T>
18struct TDualQuat
19{
20public:
21 using FReal = T;
22
23 /** rotation or real part */
24 TQuat<T> R;
25 /** half trans or dual part */
26 TQuat<T> D;
27
28 // Constructors
29 TDualQuat(const TQuat<T> &InR, const TQuat<T> &InD)
30 : R(InR)
31 , D(InD)
32 {}
33
34 TDualQuat(const TTransform<T> &Transform)
35 {
36 TVector<T> V = Transform.GetTranslation()*0.5f;
37 *this = TDualQuat<T>(TQuat<T>(0, 0, 0, 1), TQuat<T>(V.X, V.Y, V.Z, 0.f)) * TDualQuat<T>(Transform.GetRotation(), TQuat<T>(0, 0, 0, 0));
38 }
39
40 // Conversion to other type.
41 template<typename FArg, TEMPLATE_REQUIRES(!std::is_same_v<T, FArg>)>
42 explicit TDualQuat(const TDualQuat<FArg>& From) : TDualQuat<T>(TQuat<T>(From.R), TQuat<T>(From.D)) {}
43
44 /** Dual quat addition */
45 TDualQuat<T> operator+(const TDualQuat<T> &B) const
46 {
47 return{ R + B.R, D + B.D };
48 }
49
50 /** Dual quat product */
51 TDualQuat<T> operator*(const TDualQuat<T> &B) const
52 {
53 return{ R*B.R, D*B.R + B.D*R };
54 }
55
56 /** Scale dual quat */
57 TDualQuat<T> operator*(const T S) const
58 {
59 return{ R*S, D*S };
60 }
61
62 /** Return normalized dual quat */
63 TDualQuat<T> Normalized() const
64 {
65 T MinV = 1.0f / FMath::Sqrt(R | R);
66 return{ R*MinV, D*MinV };
67 }
68
69 /** Convert dual quat to transform */
70 TTransform<T> AsFTransform(TVector<T> Scale = TVector<T>(1.0f, 1.0f, 1.0f))
71 {
72 TQuat<T> TQ = D*TQuat<T>(-R.X, -R.Y, -R.Z, R.W);
73 return TTransform<T>(R, TVector<T>(TQ.X, TQ.Y, TQ.Z)*2.0f, Scale);
74 }
75};
76
77} // namespace UE::Math
78} // namespace UE
79
81
82template<> struct TIsUECoreVariant<FDualQuat4f> { enum { Value = true }; };
83template<> struct TIsUECoreVariant<FDualQuat4d> { enum { Value = true }; };
#define UE_DECLARE_LWC_TYPE(...)
#define TEMPLATE_REQUIRES(...)