UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
TransformTypes.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5#include "CoreMinimal.h"
6#include "VectorTypes.h"
7#include "Quaternion.h"
8
9namespace UE
10{
11namespace Geometry
12{
13
14using namespace UE::Math;
15
28template<typename RealType>
30{
31protected:
35
36public:
37
44
51
58
65
72
79
87
91 operator FTransform3f() const
92 {
94 }
95
99 operator FTransform3d() const
100 {
102 }
103
108 {
109 return Rotation;
110 }
111
116 {
117 return (FRotator)Rotation;
118 }
119
127
132 {
133 return Translation;
134 }
135
143
148 {
149 return Scale3D;
150 }
151
156 {
157 return Scale3D;
158 }
159
167
171 RealType GetDeterminant() const
172 {
173 return Scale3D.X * Scale3D.Y * Scale3D.Z;
174 }
175
180 {
181 return (TMathUtil<RealType>::Abs(Scale3D.X - Scale3D.Y) > Tolerance)
182 || (TMathUtil<RealType>::Abs(Scale3D.X - Scale3D.Z) > Tolerance)
183 || (TMathUtil<RealType>::Abs(Scale3D.Y - Scale3D.Z) > Tolerance);
184 }
185
197
200 {
201 // Note: Could also return true if there is a non-uniform scale aligned with the rotation axis ...
202 return Scale3D.AllComponentsEqual(Tolerance) || Rotation.IsIdentity(Tolerance);
203 }
204
205
206 // The following templates perform vector-type-conversion variants.
207 // This allows applying a float transform to double vector and vice-versa.
208 // Whether this should be allowed is debatable. However in practice it is extremely rare to convert an
209 // entire float transform to a double transform in order to apply to a double vector, which is the only
210 // case where this conversion is an issue
211
212
216 template<typename RealType2>
218 {
219 if constexpr (std::is_same_v<RealType, RealType2>)
220 {
221 //Transform using QST is following
222 //QST(P) = Q.Rotate(S*P) + T where Q = quaternion, S = scale, T = translation
223 return Rotation * (Scale3D*P) + Translation;
224 }
225 else
226 {
228 }
229 }
230
234 template<typename RealType2>
236 {
237 if constexpr (std::is_same_v<RealType, RealType2>)
238 {
239 return Rotation * (Scale3D*V);
240 }
241 else
242 {
244 }
245 }
246
250 template<typename RealType2>
252 {
253 if constexpr (std::is_same_v<RealType, RealType2>)
254 {
255 return Rotation * V;
256 }
257 else
258 {
260 }
261 }
262
268 template<typename RealType2>
270 {
271 if constexpr (std::is_same_v<RealType, RealType2>)
272 {
273 // transform normal by a safe inverse scale + normalize, and a standard rotation
274 const TVector<RealType>& S = Scale3D;
275 RealType DetSign = FMathd::SignNonZero(S.X * S.Y * S.Z); // we only need to multiply by the sign of the determinant, rather than divide by it, since we normalize later anyway
278 }
279 else
280 {
282 }
283 }
284
285
289 template<typename RealType2>
291 {
292 if constexpr (std::is_same_v<RealType, RealType2>)
293 {
294 return GetSafeScaleReciprocal(Scale3D) * Rotation.InverseMultiply(P - Translation);
295 }
296 else
297 {
299 }
300 }
301
305 template<typename RealType2>
307 {
308 if constexpr (std::is_same_v<RealType, RealType2>)
309 {
310 return GetSafeScaleReciprocal(Scale3D) * Rotation.InverseMultiply(V);
311 }
312 else
313 {
315 }
316 }
317
318
322 template<typename RealType2>
324 {
325 if constexpr (std::is_same_v<RealType, RealType2>)
326 {
327 return Rotation.InverseMultiply(V);
328 }
329 else
330 {
332 }
333 }
334
335
340 template<typename RealType2>
342 {
343 if constexpr (std::is_same_v<RealType, RealType2>)
344 {
346 }
347 else
348 {
350 }
351 }
352
353
360
361
368
374 {
375 for (int j = 0; j < 3; ++j)
376 {
377 RealType Value = Scale3D[j];
379 {
381 Scale3D[j] = Value;
382 }
383 }
384 }
385
386
387
389 {
391 if (TMathUtil<RealType>::Abs(InScale.X) <= Tolerance)
392 {
393 SafeReciprocalScale.X = (RealType)0;
394 }
395 else
396 {
397 SafeReciprocalScale.X = (RealType)1 / InScale.X;
398 }
399
400 if (TMathUtil<RealType>::Abs(InScale.Y) <= Tolerance)
401 {
402 SafeReciprocalScale.Y = (RealType)0;
403 }
404 else
405 {
406 SafeReciprocalScale.Y = (RealType)1 / InScale.Y;
407 }
408
409 if (TMathUtil<RealType>::Abs(InScale.Z) <= Tolerance)
410 {
411 SafeReciprocalScale.Z = (RealType)0;
412 }
413 else
414 {
415 SafeReciprocalScale.Z = (RealType)1 / InScale.Z;
416 }
417
418 return SafeReciprocalScale;
419 }
420};
423
424
425} // end namespace UE::Geometry
426} // end namespace UE
@ Normal
Definition AndroidInputInterface.h:116
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
UE::Math::TTransform< float > FTransform3f
Definition MathFwd.h:79
UE::Math::TTransform< double > FTransform3d
Definition MathFwd.h:66
Definition MathUtil.h:150
static RealType Abs(const RealType Value)
Definition MathUtil.h:215
static RealType SignNonZero(const RealType Value)
Definition MathUtil.h:240
Definition TransformTypes.h:30
TTransformSRT3(const TQuaternion< RealType > &RotationIn, const UE::Math::TVector< RealType > &TranslationIn, const UE::Math::TVector< RealType > &ScaleIn)
Definition TransformTypes.h:45
TTransformSRT3(const UE::Math::TVector< RealType > &TranslationIn)
Definition TransformTypes.h:59
static TTransformSRT3< RealType > Identity()
Definition TransformTypes.h:83
TVector< RealType2 > TransformVector(const UE::Math::TVector< RealType2 > &V) const
Definition TransformTypes.h:235
void SetRotation(const TQuaternion< RealType > &RotationIn)
Definition TransformTypes.h:123
const TQuaternion< RealType > & GetRotation() const
Definition TransformTypes.h:107
const TVector< RealType > & GetScale3D() const
Definition TransformTypes.h:155
bool CanRepresentInverse(RealType Tolerance=TMathUtil< RealType >::ZeroTolerance) const
Definition TransformTypes.h:199
TVector< RealType2 > TransformNormal(const UE::Math::TVector< RealType2 > &Normal) const
Definition TransformTypes.h:269
bool HasNonUniformScale(RealType Tolerance=TMathUtil< RealType >::ZeroTolerance) const
Definition TransformTypes.h:179
void ClampMinimumScale(RealType MinimumScale=TMathUtil< RealType >::ZeroTolerance)
Definition TransformTypes.h:373
static TVector< RealType > GetSafeScaleReciprocal(const TVector< RealType > &InScale, RealType Tolerance=TMathUtil< RealType >::ZeroTolerance)
Definition TransformTypes.h:388
TQuaternion< RealType > Rotation
Definition TransformTypes.h:32
const TVector< RealType > & GetTranslation() const
Definition TransformTypes.h:131
TVector< RealType2 > InverseTransformVector(const UE::Math::TVector< RealType2 > &V) const
Definition TransformTypes.h:306
void SetScale(const UE::Math::TVector< RealType > &ScaleIn)
Definition TransformTypes.h:163
UE::Math::TRay< RealType > InverseTransformRay(const UE::Math::TRay< RealType > &Ray) const
Definition TransformTypes.h:362
TVector< RealType2 > InverseTransformVectorNoScale(const UE::Math::TVector< RealType2 > &V) const
Definition TransformTypes.h:323
TTransformSRT3()
Definition TransformTypes.h:38
TTransformSRT3(const TQuaternion< RealType > &RotationIn, const UE::Math::TVector< RealType > &TranslationIn)
Definition TransformTypes.h:52
TVector< RealType2 > InverseTransformNormal(const UE::Math::TVector< RealType2 > &Normal) const
Definition TransformTypes.h:341
FRotator GetRotator() const
Definition TransformTypes.h:115
TTransformSRT3(const FTransform3d &Transform)
Definition TransformTypes.h:73
TVector< RealType > Scale3D
Definition TransformTypes.h:34
UE::Math::TRay< RealType > TransformRay(const UE::Math::TRay< RealType > &Ray) const
Definition TransformTypes.h:354
TVector< RealType2 > TransformVectorNoScale(const UE::Math::TVector< RealType2 > &V) const
Definition TransformTypes.h:251
TTransformSRT3< RealType > InverseUnsafe(RealType Tolerance=TMathUtil< RealType >::ZeroTolerance) const
Definition TransformTypes.h:190
TTransformSRT3(const FTransform3f &Transform)
Definition TransformTypes.h:66
const TVector< RealType > & GetScale() const
Definition TransformTypes.h:147
RealType GetDeterminant() const
Definition TransformTypes.h:171
TVector< RealType2 > InverseTransformPosition(const UE::Math::TVector< RealType2 > &P) const
Definition TransformTypes.h:290
TVector< RealType > Translation
Definition TransformTypes.h:33
TVector< RealType2 > TransformPosition(const TVector< RealType2 > &P) const
Definition TransformTypes.h:217
void SetTranslation(const UE::Math::TVector< RealType > &TranslationIn)
Definition TransformTypes.h:139
TTransformSRT3< double > FTransformSRT3d
Definition TransformTypes.h:422
TTransformSRT3< float > FTransformSRT3f
Definition TransformTypes.h:421
Definition Sphere.cpp:10
Definition AdvancedWidgetsModule.cpp:13
Definition Quaternion.h:22
static TQuaternion< RealType > Identity()
Definition Quaternion.h:59
TQuaternion< RealType > Inverse() const
Definition Quaternion.h:386
Definition Ray.h:19
TVector< T > Origin
Definition Ray.h:24
TVector< T > Direction
Definition Ray.h:27
Definition Vector.h:51
static TVector< T > One()
Definition Vector.h:115
T Z
Definition Vector.h:68
static TVector< T > Zero()
Definition Vector.h:112
T Y
Definition Vector.h:65
UE_FORCEINLINE_HINT bool AllComponentsEqual(T Tolerance=UE_KINDA_SMALL_NUMBER) const
Definition Vector.h:1607
T X
Definition Vector.h:62