UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
TransformCalculus3D.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/Vector.h"
7#include "Math/Rotator.h"
8#include "Math/Matrix.h"
11#include "Math/Quat.h"
12#include "Math/ScaleMatrix.h"
14
15
17// Transform calculus for 3D types. Since UE4 already has existing 3D transform
18// types, this is mostly a set of adapter overloads for the primitive operations
19// requires by the transform calculus framework.
20//
21// The following types are adapted.
22// * float/double -> represents a uniform scale.
23// * TScale<T> -> represents a 3D non-uniform scale.
24// * UE::Math::TVector<T> -> represents a 3D translation.
25// * UE::Math::TRotator<T> -> represents a pure rotation.
26// * UE::Math::TQuat<T> -> represents a pure rotation.
27// * UE::Math::TMatrix<T> -> represents a general 3D homogeneous transform.
28//
30
37template<typename T>
38class TScale
39{
40 static_assert(std::is_floating_point_v<T>, "T must be floating point");
41
42public:
44
46 [[nodiscard]] TScale() :Scale(1.0f) {}
48 [[nodiscard]] explicit TScale(T InScale) :Scale(InScale) {}
50 template<typename VType>
53 [[nodiscard]] const Vector3Type& GetVector() const
54 {
55 return Scale;
56 }
58 [[nodiscard]] TScale Concatenate(const TScale& RHS) const
59 {
60 return TScale(Scale * RHS.GetVector());
61 }
64 {
65 return TScale(Vector3Type(1.0f / Scale.X, 1.0f / Scale.Y, 1.0f / Scale.Z));
66 }
67private:
69 Vector3Type Scale;
70};
71
75typedef FScale3f FScale3D; // Default type, for backwards compat
76
79{
80 return Transform.Rotator();
81}
83{
84 return Transform.Rotator();
85}
86
88// UE::Math::TMatrix<T> Support
90
98template<typename TransformType>
99inline auto ToMatrix(const TransformType& Transform) -> decltype(Transform.ToMatrix())
100{
101 return Transform.ToMatrix();
102}
103
114
119
130
135
150
165
180
195
202template<>
204{
205 template<typename OtherTransformType>
207 {
209 }
210};
211
212template<>
214{
215 template<typename OtherTransformType>
217 {
219 }
220};
221
223template<typename T> struct ConcatenateRules<float , TScale<T> > { typedef TScale<T> ResultType; };
224template<typename T> struct ConcatenateRules<double , TScale<T> > { typedef TScale<T> ResultType; };
225template<typename T> struct ConcatenateRules<TScale<T> , float > { typedef TScale<T> ResultType; };
226template<typename T> struct ConcatenateRules<TScale<T> , double > { typedef TScale<T> ResultType; };
227template<typename T> struct ConcatenateRules<float , UE::Math::TVector<T> > { typedef UE::Math::TMatrix<T> ResultType; };
228template<typename T> struct ConcatenateRules<double , UE::Math::TVector<T> > { typedef UE::Math::TMatrix<T> ResultType; };
229template<typename T> struct ConcatenateRules<UE::Math::TVector<T> , float > { typedef UE::Math::TMatrix<T> ResultType; };
230template<typename T> struct ConcatenateRules<UE::Math::TVector<T> , double > { typedef UE::Math::TMatrix<T> ResultType; };
231template<typename T> struct ConcatenateRules<float , UE::Math::TRotator<T> > { typedef UE::Math::TMatrix<T> ResultType; };
232template<typename T> struct ConcatenateRules<double , UE::Math::TRotator<T> > { typedef UE::Math::TMatrix<T> ResultType; };
233template<typename T> struct ConcatenateRules<UE::Math::TRotator<T> , float > { typedef UE::Math::TMatrix<T> ResultType; };
234template<typename T> struct ConcatenateRules<UE::Math::TRotator<T> , double > { typedef UE::Math::TMatrix<T> ResultType; };
235template<typename T> struct ConcatenateRules<float , UE::Math::TQuat<T> > { typedef UE::Math::TMatrix<T> ResultType; };
236template<typename T> struct ConcatenateRules<double , UE::Math::TQuat<T> > { typedef UE::Math::TMatrix<T> ResultType; };
237template<typename T> struct ConcatenateRules<UE::Math::TQuat<T> , float > { typedef UE::Math::TMatrix<T> ResultType; };
238template<typename T> struct ConcatenateRules<UE::Math::TQuat<T> , double > { typedef UE::Math::TMatrix<T> ResultType; };
239template<typename T> struct ConcatenateRules<float , UE::Math::TMatrix<T> > { typedef UE::Math::TMatrix<T> ResultType; };
240template<typename T> struct ConcatenateRules<double , UE::Math::TMatrix<T> > { typedef UE::Math::TMatrix<T> ResultType; };
241template<typename T> struct ConcatenateRules<UE::Math::TMatrix<T> , float > { typedef UE::Math::TMatrix<T> ResultType; };
242template<typename T> struct ConcatenateRules<UE::Math::TMatrix<T> , double > { typedef UE::Math::TMatrix<T> ResultType; };
243template<typename T> struct ConcatenateRules<TScale<T> , UE::Math::TVector<T> > { typedef UE::Math::TMatrix<T> ResultType; };
244template<typename T> struct ConcatenateRules<UE::Math::TVector<T> , TScale<T> > { typedef UE::Math::TMatrix<T> ResultType; };
245template<typename T> struct ConcatenateRules<TScale<T> , UE::Math::TRotator<T> > { typedef UE::Math::TMatrix<T> ResultType; };
246template<typename T> struct ConcatenateRules<UE::Math::TRotator<T> , TScale<T> > { typedef UE::Math::TMatrix<T> ResultType; };
247template<typename T> struct ConcatenateRules<TScale<T> , UE::Math::TQuat<T> > { typedef UE::Math::TMatrix<T> ResultType; };
248template<typename T> struct ConcatenateRules<UE::Math::TQuat<T> , TScale<T> > { typedef UE::Math::TMatrix<T> ResultType; };
249template<typename T> struct ConcatenateRules<TScale<T> , UE::Math::TMatrix<T> > { typedef UE::Math::TMatrix<T> ResultType; };
250template<typename T> struct ConcatenateRules<UE::Math::TMatrix<T> , TScale<T> > { typedef UE::Math::TMatrix<T> ResultType; };
251template<typename T> struct ConcatenateRules<UE::Math::TVector<T> , UE::Math::TRotator<T> > { typedef UE::Math::TMatrix<T> ResultType; };
252template<typename T> struct ConcatenateRules<UE::Math::TRotator<T> , UE::Math::TVector<T> > { typedef UE::Math::TMatrix<T> ResultType; };
253template<typename T> struct ConcatenateRules<UE::Math::TVector<T> , UE::Math::TQuat<T> > { typedef UE::Math::TMatrix<T> ResultType; };
254template<typename T> struct ConcatenateRules<UE::Math::TQuat<T> , UE::Math::TVector<T> > { typedef UE::Math::TMatrix<T> ResultType; };
255template<typename T> struct ConcatenateRules<UE::Math::TVector<T> , UE::Math::TMatrix<T> > { typedef UE::Math::TMatrix<T> ResultType; };
256template<typename T> struct ConcatenateRules<UE::Math::TMatrix<T> , UE::Math::TVector<T> > { typedef UE::Math::TMatrix<T> ResultType; };
257template<typename T> struct ConcatenateRules<UE::Math::TRotator<T> , UE::Math::TQuat<T> > { typedef UE::Math::TQuat<T> ResultType; };
258template<typename T> struct ConcatenateRules<UE::Math::TQuat<T> , UE::Math::TRotator<T> > { typedef UE::Math::TQuat<T> ResultType; };
259template<typename T> struct ConcatenateRules<UE::Math::TRotator<T> , UE::Math::TMatrix<T> > { typedef UE::Math::TMatrix<T> ResultType; };
260template<typename T> struct ConcatenateRules<UE::Math::TMatrix<T> , UE::Math::TRotator<T> > { typedef UE::Math::TMatrix<T> ResultType; };
261template<typename T> struct ConcatenateRules<UE::Math::TQuat<T> , UE::Math::TMatrix<T> > { typedef UE::Math::TMatrix<T> ResultType; };
262template<typename T> struct ConcatenateRules<UE::Math::TMatrix<T> , UE::Math::TQuat<T> > { typedef UE::Math::TMatrix<T> ResultType; };
263
265// Concatenate overloads.
266//
267// Since these are existing UE4 types, we cannot rely on the default
268// template that calls member functions. Instead, we provide direct overloads.
270
271
272namespace UE
273{
274namespace Math
275{
276
284template<typename T>
286{
287 return LHS * RHS;
288}
289
290
298template<typename T>
300{
301 return LHS + RHS;
302}
303
304
315template<typename T>
317{
318 return RHS * LHS;
319}
320
321} // namespace UE::Math
322} // namespace UE
323
331template<typename T>
337
338
340// Inverse overloads.
341//
342// Since these are existing UE4 types, we cannot rely on the default
343// template that calls member functions. Instead, we provide direct overloads.
345
353template<typename T>
358
366template<typename T>
372
380template<typename T>
385
393template<typename T>
398
400// TransformPoint overloads.
401//
402// Since these are existing UE4 types, we cannot rely on the default
403// template that calls member functions. Instead, we provide direct overloads.
405
409template<typename T>
411{
412 return Transform.TransformPosition(Point);
413}
414
418template<typename T>
423
427template<typename T>
432
436template<typename T>
441
445template<typename T>
450
454template<typename T>
459
463template<typename T>
468
472template<typename T>
474{
475 return Transform.GetVector() * Point;
476}
477
481template<typename T>
483{
484 return Transform.GetVector() * Vector;
485}
486
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
UE::Math::TMatrix< double > FMatrix44d
Definition MathFwd.h:64
UE::Math::TMatrix< float > FMatrix44f
Definition MathFwd.h:77
USkinnedMeshComponent float
Definition SkinnedMeshComponent.h:60
UE::Math::TRotator< T > Concatenate(const UE::Math::TRotator< T > &LHS, const UE::Math::TRotator< T > &RHS)
Definition TransformCalculus3D.h:332
UE::Math::TVector< T > TransformVector(const UE::Math::TQuat< T > &Transform, const UE::Math::TVector< T > &Vector)
Definition TransformCalculus3D.h:428
auto ToMatrix(const TransformType &Transform) -> decltype(Transform.ToMatrix())
Definition TransformCalculus3D.h:99
FScale3f FScale3D
Definition TransformCalculus3D.h:75
TScale< double > FScale3d
Definition TransformCalculus3D.h:74
UE::Math::TVector< T > TransformPoint(const UE::Math::TMatrix< T > &Transform, const UE::Math::TVector< T > &Point)
Definition TransformCalculus3D.h:410
TScale< float > FScale3f
Definition TransformCalculus3D.h:73
decltype(auto) TransformCast(const TransformType &Transform)
Definition TransformCalculus.h:262
Definition TransformCalculus3D.h:39
const Vector3Type & GetVector() const
Definition TransformCalculus3D.h:53
TScale()
Definition TransformCalculus3D.h:46
TScale Concatenate(const TScale &RHS) const
Definition TransformCalculus3D.h:58
UE::Math::TVector< T > Vector3Type
Definition TransformCalculus3D.h:43
TScale Inverse() const
Definition TransformCalculus3D.h:63
TScale(T InScale)
Definition TransformCalculus3D.h:48
TScale(const UE::Math::TVector< VType > &InScale)
Definition TransformCalculus3D.h:51
UE::Math::TVector2< T > Concatenate(const UE::Math::TVector2< T > &LHS, const UE::Math::TVector2< T > &RHS)
Definition TransformCalculus2D.h:45
Definition AdvancedWidgetsModule.cpp:13
UE::Math::TMatrix< T > ResultType
Definition TransformCalculus3D.h:249
UE::Math::TMatrix< T > ResultType
Definition TransformCalculus3D.h:247
UE::Math::TMatrix< T > ResultType
Definition TransformCalculus3D.h:245
UE::Math::TMatrix< T > ResultType
Definition TransformCalculus3D.h:243
TScale< T > ResultType
Definition TransformCalculus3D.h:226
TScale< T > ResultType
Definition TransformCalculus3D.h:225
UE::Math::TMatrix< T > ResultType
Definition TransformCalculus3D.h:250
UE::Math::TMatrix< T > ResultType
Definition TransformCalculus3D.h:262
UE::Math::TMatrix< T > ResultType
Definition TransformCalculus3D.h:260
UE::Math::TMatrix< T > ResultType
Definition TransformCalculus3D.h:256
UE::Math::TMatrix< T > ResultType
Definition TransformCalculus3D.h:242
UE::Math::TMatrix< T > ResultType
Definition TransformCalculus3D.h:241
UE::Math::TMatrix< T > ResultType
Definition TransformCalculus3D.h:248
UE::Math::TMatrix< T > ResultType
Definition TransformCalculus3D.h:261
UE::Math::TQuat< T > ResultType
Definition TransformCalculus3D.h:258
UE::Math::TMatrix< T > ResultType
Definition TransformCalculus3D.h:254
UE::Math::TMatrix< T > ResultType
Definition TransformCalculus3D.h:238
UE::Math::TMatrix< T > ResultType
Definition TransformCalculus3D.h:237
UE::Math::TMatrix< T > ResultType
Definition TransformCalculus3D.h:246
UE::Math::TMatrix< T > ResultType
Definition TransformCalculus3D.h:259
UE::Math::TQuat< T > ResultType
Definition TransformCalculus3D.h:257
UE::Math::TMatrix< T > ResultType
Definition TransformCalculus3D.h:252
UE::Math::TMatrix< T > ResultType
Definition TransformCalculus3D.h:234
UE::Math::TMatrix< T > ResultType
Definition TransformCalculus3D.h:233
UE::Math::TMatrix< T > ResultType
Definition TransformCalculus3D.h:244
UE::Math::TMatrix< T > ResultType
Definition TransformCalculus3D.h:255
UE::Math::TMatrix< T > ResultType
Definition TransformCalculus3D.h:253
UE::Math::TMatrix< T > ResultType
Definition TransformCalculus3D.h:251
UE::Math::TMatrix< T > ResultType
Definition TransformCalculus3D.h:230
UE::Math::TMatrix< T > ResultType
Definition TransformCalculus3D.h:229
TScale< T > ResultType
Definition TransformCalculus3D.h:224
UE::Math::TMatrix< T > ResultType
Definition TransformCalculus3D.h:240
UE::Math::TMatrix< T > ResultType
Definition TransformCalculus3D.h:236
UE::Math::TMatrix< T > ResultType
Definition TransformCalculus3D.h:232
UE::Math::TMatrix< T > ResultType
Definition TransformCalculus3D.h:228
TScale< T > ResultType
Definition TransformCalculus3D.h:223
UE::Math::TMatrix< T > ResultType
Definition TransformCalculus3D.h:239
UE::Math::TMatrix< T > ResultType
Definition TransformCalculus3D.h:235
UE::Math::TMatrix< T > ResultType
Definition TransformCalculus3D.h:231
UE::Math::TMatrix< T > ResultType
Definition TransformCalculus3D.h:227
Definition TransformCalculus.h:273
static auto Convert(const OtherTransformType &Transform) -> decltype((FMatrix44d) ToMatrix(Transform))
Definition TransformCalculus3D.h:216
static auto Convert(const OtherTransformType &Transform) -> decltype((FMatrix44f) ToMatrix(Transform))
Definition TransformCalculus3D.h:206
Definition TransformCalculus.h:238
TMatrix< T > Inverse() const
Definition Matrix.inl:384
Definition Quat.h:39
TQuat< T > Inverse() const
Definition Quat.h:1264
Definition RotationMatrix.h:19
static TMatrix< T > Make(TRotator< T > const &Rot)
Definition RotationMatrix.h:33
static CORE_API TRotator MakeFromEuler(const TVector< T > &Euler)
Definition UnrealMath.cpp:559
Definition ScaleMatrix.h:18
Definition TranslationMatrix.h:16
Definition Vector.h:51
T Z
Definition Vector.h:68
T Y
Definition Vector.h:65
T X
Definition Vector.h:62