41 static_assert(std::is_floating_point_v<T>,
"TQuat only supports float and double types.");
90 template<
typename DummyT = T UE_REQUIRES(std::is_arithmetic_v<T>)>
253 template<
typename FArg UE_REQUIRES(std::is_arithmetic_v<FArg>)>
256#if PLATFORM_ENABLE_VECTORINTRINSICS
277 template<
typename FArg UE_REQUIRES(std::is_arithmetic_v<FArg>)>
280#if PLATFORM_ENABLE_VECTORINTRINSICS
295 template<
typename FArg UE_REQUIRES(std::is_arithmetic_v<FArg>)>
298#if PLATFORM_ENABLE_VECTORINTRINSICS
320 template<
typename FArg UE_REQUIRES(std::is_arithmetic_v<FArg>)>
323#if PLATFORM_ENABLE_VECTORINTRINSICS
588#if ENABLE_NAN_DIAGNOSTIC
720 if constexpr (std::is_same_v<T, float>)
731 template<
typename FArg UE_REQUIRES(!std::is_same_v<T, FArg>)>
733 :
TQuat<T>((T)From.
X, (T)From.
Y, (T)From.
Z, (T)From.
W)
747 return Ar <<
F.X <<
F.Y <<
F.Z <<
F.W;
754 return Ar <<
F.X <<
F.Y <<
F.Z <<
F.W;
761 Ar <<
X <<
Y <<
Z << W;
770#if !defined(_MSC_VER) || defined(__clang__)
788#if !(UE_BUILD_SHIPPING || UE_BUILD_TEST)
802 const T
tr = M.
M[0][0] + M.
M[1][1] + M.
M[2][2];
806 T
InvS = FMath::InvSqrt(
tr + T(1.f));
807 this->W = T(T(0.5f) * (T(1.f) /
InvS));
810 this->X = ((M.
M[1][2] - M.
M[2][1]) * s);
811 this->Y = ((M.
M[2][0] - M.
M[0][2]) * s);
812 this->Z = ((M.
M[0][1] - M.
M[1][0]) * s);
819 if (M.
M[1][1] > M.
M[0][0])
822 if (M.
M[2][2] > M.
M[i][i])
825 static constexpr int32 nxt[3] = { 1, 2, 0 };
829 s = M.
M[i][i] - M.
M[j][j] - M.
M[k][k] + T(1.0f);
831 T
InvS = FMath::InvSqrt(s);
834 qt[i] = T(0.5f) * (T(1.f) /
InvS);
838 qt[3] = (M.
M[j][k] - M.
M[k][j]) * s;
839 qt[j] = (M.
M[i][j] + M.
M[j][i]) * s;
840 qt[k] = (M.
M[i][k] + M.
M[k][i]) * s;
847 DiagnosticCheckNaN();
855 *
this =
R.Quaternion();
856 DiagnosticCheckNaN();
862 return RotateVector(V);
888 DiagnosticCheckNaN();
895 return FString::Printf(
TEXT(
"X=%.9f Y=%.9f Z=%.9f W=%.9f"),
X,
Y,
Z, W);
909 DiagnosticCheckNaN();
925 DiagnosticCheckNaN();
932#if PLATFORM_ENABLE_VECTORINTRINSICS
945#if PLATFORM_ENABLE_VECTORINTRINSICS
956 DiagnosticCheckNaN();
965#if PLATFORM_ENABLE_VECTORINTRINSICS
977#if PLATFORM_ENABLE_VECTORINTRINSICS
987#if PLATFORM_ENABLE_VECTORINTRINSICS
996 return (FMath::Abs(
X - Q.
X) <= Tolerance && FMath::Abs(
Y - Q.
Y) <= Tolerance && FMath::Abs(
Z - Q.
Z) <= Tolerance && FMath::Abs(W - Q.
W) <= Tolerance)
997 || (FMath::Abs(
X + Q.
X) <= Tolerance && FMath::Abs(
Y + Q.
Y) <= Tolerance && FMath::Abs(
Z + Q.
Z) <= Tolerance && FMath::Abs(W + Q.
W) <= Tolerance);
1010#if PLATFORM_ENABLE_VECTORINTRINSICS
1021 DiagnosticCheckNaN();
1033 Result.DiagnosticCheckNaN();
1047 DiagnosticCheckNaN();
1057 return Q.operator*(
Scale);
1064 return Q.operator*(
Scale);
1070 return X == Q->
X &&
Y == Q->
Y &&
Z == Q->
Z && W == Q->
W;
1076#if PLATFORM_ENABLE_VECTORINTRINSICS
1081 return X == Q.
X &&
Y == Q.
Y &&
Z == Q.
Z && W == Q.
W;
1089#if PLATFORM_ENABLE_VECTORINTRINSICS
1094 return X != Q.
X ||
Y != Q.
Y ||
Z != Q.
Z || W != Q.
W;
1102 return X * Q.
X +
Y * Q.
Y +
Z * Q.
Z + W * Q.
W;
1109#if PLATFORM_ENABLE_VECTORINTRINSICS
1143 Result.Normalize(Tolerance);
1151#if PLATFORM_ENABLE_VECTORINTRINSICS
1164 return FMath::Sqrt(
X *
X +
Y *
Y +
Z *
Z + W * W);
1170 return (
X *
X +
Y *
Y +
Z *
Z + W * W);
1176 return T(2.0) * FMath::Acos(W);
1184 Axis = GetRotationAxis();
1191 Axis = GetRotationAxis();
1212#if PLATFORM_ENABLE_VECTORINTRINSICS
1268#if PLATFORM_ENABLE_VECTORINTRINSICS
1279 const T Bias = FMath::FloatSelect(
DotResult, T(1.0f), T(-1.0f));
1291 Result.EnforceShortestArcWith(
OtherQuat);
1298 return RotateVector(
TVector<T>(1.f, 0.f, 0.f));
1305 return RotateVector(
TVector<T>(0.f, 1.f, 0.f));
1312 return RotateVector(
TVector<T>(0.f, 0.f, 1.f));
1352 return (FMath::Abs(
cosom) < 0.9999999f) ? FMath::Acos(
cosom)*(1.f /
UE_PI) : 0.0f;
1377 const T Bias = FMath::FloatSelect(
DotResult, T(1.0f), T(-1.0f));
1396 return (!FMath::IsFinite(
X) ||
1397 !FMath::IsFinite(
Y) ||
1398 !FMath::IsFinite(
Z) ||
1413 static_assert(
sizeof(
TQuat<T>) ==
sizeof(T[4]),
"Unexpected padding in TQuat");
1422 Euler[0] = FMath::Atan2(
R31,
R32);
1423 Euler[1] = FMath::Asin(
R21);
1424 Euler[2] = FMath::Atan2(
R11,
R12);
1435 return {Euler[0], -Euler[1], -Euler[2]};
1484 return QuatType::Slerp(
A,
B, (T)
Alpha);
1493 QuatType::Slerp_NotNormalized(
P00,
P10, (T)
FracX),
1494 QuatType::Slerp_NotNormalized(
P01,
P11, (T)
FracX),
1504 return QuatType::Squad(P0, T0, P1, T1, (T)
A);
#define checkSlow(expr)
Definition AssertionMacros.h:332
#define ensure( InExpression)
Definition AssertionMacros.h:464
#define checkf(expr, format,...)
Definition AssertionMacros.h:315
bool bSuccess
Definition ConvexDecomposition3.cpp:819
EForceInit
Definition CoreMiscDefines.h:154
@ ForceInitToZero
Definition CoreMiscDefines.h:156
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
#define UE_SERIALIZE_VARIANT_FROM_MISMATCHED_TAG(AR_OR_SLOT, ALIAS, TYPE, ALT_TYPE)
Definition LargeWorldCoordinatesSerializer.h:9
#define UE_DECLARE_LWC_TYPE(...)
Definition LargeWorldCoordinates.h:27
#define logOrEnsureNanError(_FormatString_,...)
Definition LogMacros.h:436
#define DECLARE_INTRINSIC_TYPE_LAYOUT(T)
Definition MemoryLayout.h:760
@ LARGE_WORLD_COORDINATES
USkinnedMeshComponent float
Definition SkinnedMeshComponent.h:60
FORCEINLINE VectorRegister4Float VectorSubtract(const VectorRegister4Float &Vec1, const VectorRegister4Float &Vec2)
Definition UnrealMathFPU.h:731
FORCEINLINE uint32 VectorAnyGreaterThan(const VectorRegister4Float &Vec1, const VectorRegister4Float &Vec2)
Definition UnrealMathFPU.h:1917
FORCEINLINE VectorRegister4Float VectorDot4(const VectorRegister4Float &Vec1, const VectorRegister4Float &Vec2)
Definition UnrealMathFPU.h:901
FORCEINLINE VectorRegister4Float VectorSetFloat1(float F)
Definition UnrealMathFPU.h:518
FORCEINLINE void VectorQuaternionMultiply(VectorRegister4Float *RESTRICT Result, const VectorRegister4Float *RESTRICT Quat1, const VectorRegister4Float *RESTRICT Quat2)
Definition UnrealMathFPU.h:1431
FORCEINLINE VectorRegister4Float VectorDivide(const VectorRegister4Float &Vec1, const VectorRegister4Float &Vec2)
Definition UnrealMathFPU.h:834
FORCEINLINE VectorRegister4Float VectorMultiply(const VectorRegister4Float &Vec1, const VectorRegister4Float &Vec2)
Definition UnrealMathFPU.h:758
FORCEINLINE VectorRegister4Float VectorLoadFloat1(const float *Ptr)
Definition UnrealMathFPU.h:468
VectorRegister4Float VectorLoadAligned(const float *Ptr)
Definition UnrealMathFPU.h:451
FORCEINLINE VectorRegister4Float VectorSelect(const VectorRegister4Float &Mask, const VectorRegister4Float &Vec1, const VectorRegister4Float &Vec2)
Definition UnrealMathFPU.h:1105
FORCEINLINE VectorRegister4Float VectorCompareGE(const VectorRegister4Float &Vec1, const VectorRegister4Float &Vec2)
Definition UnrealMathFPU.h:1000
FORCEINLINE VectorRegister4Float VectorSet_W0(const VectorRegister4Float &Vec)
Definition UnrealMathFPU.h:1391
FORCEINLINE int32 VectorMaskBits(const VectorRegister4Float &Vec1)
Definition UnrealMathFPU.h:1075
FORCEINLINE VectorRegister4Float VectorNegate(const VectorRegister4Float &Vec)
Definition UnrealMathFPU.h:687
FORCEINLINE VectorRegister4Float VectorAbs(const VectorRegister4Float &Vec)
Definition UnrealMathFPU.h:661
FORCEINLINE VectorRegister4Float VectorAdd(const VectorRegister4Float &Vec1, const VectorRegister4Float &Vec2)
Definition UnrealMathFPU.h:704
void VectorStoreAligned(const VectorRegister4Float &Vec, float *Ptr)
Definition UnrealMathFPU.h:534
FORCEINLINE VectorRegister4Float VectorQuaternionMultiply2(const VectorRegister4Float &Quat1, const VectorRegister4Float &Quat2)
Definition UnrealMathFPU.h:1517
FORCEINLINE void VectorStoreFloat3(const VectorRegister4Float &Vec, float *Dst)
Definition UnrealMathFPU.h:594
FORCEINLINE VectorRegister4Float VectorCompareEQ(const VectorRegister4Float &Vec1, const VectorRegister4Float &Vec2)
Definition UnrealMathFPU.h:923
FORCEINLINE VectorRegister4Float VectorCompareNE(const VectorRegister4Float &Vec1, const VectorRegister4Float &Vec2)
Definition UnrealMathFPU.h:948
#define UE_PI
Definition UnrealMathUtility.h:129
#define UE_SMALL_NUMBER
Definition UnrealMathUtility.h:130
#define UE_THRESH_QUAT_NORMALIZED
Definition UnrealMathUtility.h:215
#define UE_KINDA_SMALL_NUMBER
Definition UnrealMathUtility.h:131
FORCEINLINE VectorRegister4Float VectorNormalizeSafe(VectorRegister4Float Vector, VectorRegister4Float DefaultValue)
Definition UnrealMathVectorCommon.h.inl:425
FORCEINLINE VectorRegister4Float VectorOne(void)
Definition UnrealMathVectorCommon.h.inl:21
FORCEINLINE VectorRegister4Float VectorQuaternionInverse(VectorRegister4Float NormalizedQuat)
Definition UnrealMathVectorCommon.h.inl:723
FORCEINLINE VectorRegister4Float VectorReciprocalSqrtAccurate(VectorRegister4Float Vec)
Definition UnrealMathVectorCommon.h.inl:375
typename UE::Math::VectorRegisterPrivate::TVectorRegisterTypeHelper< T >::Type TVectorRegisterType
Definition VectorRegister.h:49
Definition Archive.h:1208
UE_FORCEINLINE_HINT bool IsLoading() const
Definition Archive.h:236
UE_FORCEINLINE_HINT FPackageFileVersion UEVer() const
Definition Archive.h:204
Definition NameTypes.h:617
constexpr VectorRegister4Float ThreshQuatNormalized
Definition UnrealMathVectorConstants.h.inl:54
constexpr VectorRegister4Float Float1000
Definition UnrealMathVectorConstants.h.inl:44
constexpr VectorRegister4Float Float0001
Definition UnrealMathVectorConstants.h.inl:43
uint32 GetTypeHash(const TBox< T > &Box)
Definition Box.h:1008
FArchive & operator<<(FArchive &Ar, TBoxSphereBounds< float, float > &Bounds)
Definition BoxSphereBounds.h:396
UE_FORCEINLINE_HINT TQuat< T > operator*(const float Scale, const TQuat< T > &Q)
Definition Quat.h:1055
Definition AdvancedWidgetsModule.cpp:13
static CORE_API uint32 MemCrc_DEPRECATED(const void *Data, int32 Length, uint32 CRC=0)
Definition Crc.cpp:592
static constexpr void SinCos(std::decay_t< T > *ScalarSin, std::decay_t< T > *ScalarCos, T Value)
Definition UnrealMathUtility.h:753
static CORE_API bool Value(const TCHAR *Stream, const TCHAR *Match, FName &Name)
Definition Parse.cpp:584
@ Value
Definition Array.h:46
static UE_FORCEINLINE_HINT QuatType CubicInterp(const QuatType &P0, const QuatType &T0, const QuatType &P1, const QuatType &T1, const U &A)
Definition Quat.h:1502
static QuatType BiLerp(const QuatType &P00, const QuatType &P10, const QuatType &P01, const QuatType &P11, const U &FracX, const U &FracY)
Definition Quat.h:1488
static UE_FORCEINLINE_HINT QuatType Lerp(const QuatType &A, const QuatType &B, const U &Alpha)
Definition Quat.h:1482
Definition UnrealMathUtility.h:261
static constexpr bool Value
Definition UnrealMathUtility.h:262
Definition IsFloatingPoint.h:12
Definition IsPODType.h:12
@ Value
Definition IsPODType.h:13
Definition IsUECoreType.h:19
@ Value
Definition IsUECoreType.h:20
T M[4][4]
Definition Matrix.h:49
TVector< T > GetScaledAxis(EAxis::Type Axis) const
Definition Matrix.inl:647
static TQuat MakeFromLUFEuler(const TTuple< T, T, T > &InLUFEuler)
Definition Quat.h:1439
void ToAxisAndAngle(TVector< T > &Axis, float &Angle) const
Definition Quat.h:1181
T operator|(const TQuat< T > &Q) const
Definition Quat.h:1100
void ToAxisAndAngle(TVector< T > &Axis, double &Angle) const
Definition Quat.h:1188
static TQuat< T > FastLerp(const TQuat< T > &A, const TQuat< T > &B, const T Alpha)
Definition Quat.h:1373
static CORE_API TQuat< T > Slerp_NotNormalized(const TQuat< T > &Quat1, const TQuat< T > &Quat2, T Slerp)
Definition UnrealMath.cpp:1226
UE_FORCEINLINE_HINT TVector< T > GetUpVector() const
Definition Quat.h:1329
TQuat< T > operator-() const
Definition Quat.h:975
bool SerializeFromMismatchedTag(FName StructTag, FArchive &Ar)
Definition Quat.h:718
static CORE_API TQuat< T > FindBetweenNormals(const TVector< T > &Normal1, const TVector< T > &Normal2)
Definition UnrealMath.cpp:1440
static UE_FORCEINLINE_HINT TQuat< T > FindBetween(const TVector< T > &Vector1, const TVector< T > &Vector2)
Definition Quat.h:616
static CORE_API TQuat< T > FindBetweenVectors(const TVector< T > &Vector1, const TVector< T > &Vector2)
Definition UnrealMath.cpp:1447
CORE_API TRotator< T > Rotator() const
static CORE_API TQuat< T > SlerpFullPath_NotNormalized(const TQuat< T > &quat1, const TQuat< T > &quat2, T Alpha)
Definition UnrealMath.cpp:1258
TQuat(T V)
Definition Quat.h:91
static CORE_API TQuat< T > MakeFromEuler(const TVector< T > &Euler)
Definition UnrealMath.cpp:787
UE_FORCEINLINE_HINT TVector< T > GetAxisZ() const
Definition Quat.h:1310
UE_FORCEINLINE_HINT TVector< T > Vector() const
Definition Quat.h:1335
TVectorRegisterType< T > QuatVectorRegister
Definition Quat.h:46
TVector< T > UnrotateVector(TVector< T > V) const
Definition Quat.h:1254
static UE_FORCEINLINE_HINT TQuat< T > MakeFromVectorRegister(QuatVectorRegister V)
Definition Quat.h:110
static UE_FORCEINLINE_HINT TQuat< T > MakeFromRotator(const TRotator< T > &R)
Definition Quat.h:122
static TQuat< T > MakeFromRotationVector(const TVector< T > &RotationVector)
Definition Quat.h:1203
UE_FORCEINLINE_HINT void DiagnosticCheckNaN(const TCHAR *Message) const
Definition Quat.h:608
bool ContainsNaN() const
Definition Quat.h:1394
TQuat(QuatVectorRegister V)
Definition Quat.h:885
bool Serialize(FArchive &Ar)
Definition Quat.h:712
TQuat< T > GetNormalized(T Tolerance=UE_SMALL_NUMBER) const
Definition Quat.h:1140
UE_FORCEINLINE_HINT TVector< T > GetRightVector() const
Definition Quat.h:1323
bool Identical(const TQuat *Q, const uint32 PortFlags) const
Definition Quat.h:1068
TQuat< T > Inverse() const
Definition Quat.h:1264
UE_FORCEINLINE_HINT TVector< T > GetAxisX() const
Definition Quat.h:1296
bool operator!=(const TQuat< T > &Q) const
Definition Quat.h:1087
static T Error(const TQuat< T > &Q1, const TQuat< T > &Q2)
Definition Quat.h:1349
TQuat< T > operator-(const TQuat< T > &Q) const
Definition Quat.h:963
TQuat(T InX, T InY, T InZ, T InW)
Definition Quat.h:874
static CORE_API TQuat< T > SquadFullPath(const TQuat< T > &quat1, const TQuat< T > &tang1, const TQuat< T > &quat2, const TQuat< T > &tang2, T Alpha)
Definition UnrealMath.cpp:1292
static UE_FORCEINLINE_HINT TQuat< T > Slerp(const TQuat< T > &Quat1, const TQuat< T > &Quat2, T Slerp)
Definition Quat.h:660
TQuat< T > operator+(const TQuat< T > &Q) const
Definition Quat.h:930
CORE_API bool NetSerialize(FArchive &Ar, class UPackageMap *Map, bool &bOutSuccess)
Definition UnrealMath.cpp:1320
TVector< T > RotateVector(TVector< T > V) const
Definition Quat.h:1238
void EnforceShortestArcWith(const TQuat< T > &OtherQuat)
Definition Quat.h:1276
bool IsNormalized() const
Definition Quat.h:1149
T AngularDistance(const TQuat< T > &Q) const
Definition Quat.h:1230
CORE_API TVector< T > Euler() const
Definition UnrealMath.cpp:1314
UE_FORCEINLINE_HINT TMatrix< T > ToMatrix() const
Definition Quat.h:1341
TQuat< T > operator*=(const TQuat< T > &Q)
Definition Quat.h:1040
static TQuat< T > FastBilerp(const TQuat< T > &P00, const TQuat< T > &P10, const TQuat< T > &P01, const TQuat< T > &P11, T FracX, T FracY)
Definition Quat.h:1383
UE_FORCEINLINE_HINT TVector< T > GetForwardVector() const
Definition Quat.h:1317
bool InitFromString(const FString &InSourceString)
Definition Quat.h:899
UE_FORCEINLINE_HINT TVector< T > GetAxisY() const
Definition Quat.h:1303
CORE_API T GetTwistAngle(const TVector< T > &TwistAxis) const
Definition UnrealMath.cpp:816
UE_FORCEINLINE_HINT T GetAngle() const
Definition Quat.h:1174
UE_FORCEINLINE_HINT TQuat(EForceInit)
Definition Quat.h:869
TQuat(TVector< T > Axis, T AngleRad)
Definition Quat.h:914
UE_FORCEINLINE_HINT void DiagnosticCheckNaN() const
Definition Quat.h:607
TQuat< T > GetShortestArcWith(const TQuat< T > &OtherQuat) const
Definition Quat.h:1288
static UE_FORCEINLINE_HINT TQuat< T > SlerpFullPath(const TQuat< T > &quat1, const TQuat< T > &quat2, T Alpha)
Definition Quat.h:677
TVector< T > GetRotationAxis() const
Definition Quat.h:1210
TQuat(const TQuat< FArg > &From)
Definition Quat.h:732
static CORE_API const TQuat< T > Identity
Definition Quat.h:63
CORE_API void ToSwingTwist(const TVector< T > &InTwistAxis, TQuat< T > &OutSwing, TQuat< T > &OutTwist) const
Definition UnrealMath.cpp:793
CORE_API TQuat< T > Log() const
Definition UnrealMath.cpp:1454
static T ErrorAutoNormalize(const TQuat< T > &A, const TQuat< T > &B)
Definition Quat.h:1357
TQuat< T > operator*(const FArg Scale) const
Definition Quat.h:278
UE_FORCEINLINE_HINT T Size() const
Definition Quat.h:1162
TQuat< T > operator/=(const FArg Scale)
Definition Quat.h:296
FString ToString() const
Definition Quat.h:893
UE_FORCEINLINE_HINT bool IsIdentity(T Tolerance=UE_SMALL_NUMBER) const
Definition Quat.h:1002
TTuple< T, T, T > ToLUFEuler() const
Definition Quat.h:1418
TQuat< T > operator-=(const TQuat< T > &Q)
Definition Quat.h:1008
TQuat(const TRotator< T > &R)
Definition Quat.h:853
TQuat< T > operator*=(const FArg Scale)
Definition Quat.h:254
CORE_API TQuat< T > Exp() const
Definition UnrealMath.cpp:1483
TQuat< T > operator+=(const TQuat< T > &Q)
Definition Quat.h:943
T FReal
Definition Quat.h:45
bool operator==(const TQuat< T > &Q) const
Definition Quat.h:1074
TVector< T > ToRotationVector() const
Definition Quat.h:1195
static CORE_API TQuat< T > Squad(const TQuat< T > &quat1, const TQuat< T > &tang1, const TQuat< T > &quat2, const TQuat< T > &tang2, T Alpha)
Definition UnrealMath.cpp:1280
bool Equals(const TQuat< T > &Q, T Tolerance=UE_KINDA_SMALL_NUMBER) const
Definition Quat.h:985
void Normalize(T Tolerance=UE_SMALL_NUMBER)
Definition Quat.h:1107
TVector< T > operator*(const TVector< T > &V) const
Definition Quat.h:860
static CORE_API void CalcTangents(const TQuat< T > &PrevP, const TQuat< T > &P, const TQuat< T > &NextP, T Tension, TQuat< T > &OutTan)
Definition UnrealMath.cpp:1302
TQuat(const TMatrix< T > &M)
Definition Quat.h:777
TQuat< T > operator*(const TQuat< T > &Q) const
Definition Quat.h:1028
UE_FORCEINLINE_HINT T SizeSquared() const
Definition Quat.h:1168
TQuat< T > operator/(const FArg Scale) const
Definition Quat.h:321
static UE_FORCEINLINE_HINT TVector< T > CrossProduct(const TVector< T > &A, const TVector< T > &B)
Definition Vector.h:1541