UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
FrameTypes.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3
4#pragma once
5
6#include "VectorTypes.h"
7#include "VectorUtil.h"
8#include "Quaternion.h"
9#include "TransformTypes.h"
10
11namespace UE
12{
13namespace Geometry
14{
15
16using namespace UE::Math;
17
25template<typename RealType>
26struct TFrame3
27{
32
37
46
55
64
71 {
73 Rotation.SetFromTo(TVector<RealType>::UnitZ(), SetZ);
74 }
75
88
90 explicit TFrame3(const FTransform& Transform)
91 {
92 Origin = TVector<RealType>(Transform.GetTranslation());
94 }
95
97 explicit TFrame3(const FPlane& Plane)
98 {
100 Origin = (RealType)Plane.W * TVector<RealType>(Normal);
102 }
103
104
111
113 template<typename RealType2>
115 {
116 Origin = static_cast<TVector<RealType>>(OtherFrame.Origin);
117 Rotation = static_cast<TQuaternion<RealType>>(OtherFrame.Rotation);
118 }
119
120
125 TVector<RealType> GetAxis(int AxisIndex) const
126 {
127 switch (AxisIndex)
128 {
129 case 0:
130 return Rotation.AxisX();
131 case 1:
132 return Rotation.AxisY();
133 case 2:
134 return Rotation.AxisZ();
135 default:
136 checkNoEntry();
137 return TVector<RealType>::Zero(); // compiler demands a return value
138 }
139 }
140
145 {
146 Rotation.GetAxes(X, Y, Z);
147 }
148
151 {
152 return Rotation.AxisX();
153 }
154
157 {
158 return Rotation.AxisY();
159 }
160
163 {
164 return Rotation.AxisZ();
165 }
166
169 {
171 }
172
179
182 {
183 return FPlane((FVector)Origin, (FVector)Z());
184 }
185
191
198
200 TVector<RealType> PointAt(RealType X, RealType Y, RealType Z) const
201 {
202 return Rotation * TVector<RealType>(X,Y,Z) + Origin;
203 }
204
210
213 {
214 return Rotation.InverseMultiply((Point-Origin));
215 }
221
222
225 {
226 return Rotation.InverseMultiply(Vector);
227 }
233
234
237 {
238 return Rotation.Inverse() * Quat;
239 }
245
246
249 {
251 }
257
258
261 {
262 return TFrame3<RealType>(ToFramePoint(Frame.Origin), ToFrame(Frame.Rotation));
263 }
266 {
267 return TFrame3<RealType>(FromFramePoint(Frame.Origin), FromFrame(Frame.Rotation));
268 }
269
270
271
272
280 {
281 int Axis0 = 0, Axis1 = 1;
282 if (PlaneNormalAxis == 0)
283 {
284 Axis0 = 2;
285 }
286 else if (PlaneNormalAxis == 1)
287 {
288 Axis1 = 2;
289 }
291 RealType U = LocalPos.Dot(GetAxis(Axis0));
292 RealType V = LocalPos.Dot(GetAxis(Axis1));
293 return TVector2<RealType>(U, V);
294 }
295
296
297
305 {
307 if (PlaneNormalAxis == 0)
308 {
309 PlanePos[0] = 0; PlanePos[2] = PosUV[0];
310 }
311 else if (PlaneNormalAxis == 1)
312 {
313 PlanePos[1] = 0; PlanePos[2] = PosUV[1];
314 }
315 return Rotation*PlanePos + Origin;
316 }
317
318
319
333
334
335
336
341 {
342 TQuaternion<RealType> NewRotation = Quat * Rotation;
343 if (NewRotation.Normalize() > 0 )
344 {
345 Rotation = NewRotation;
346 }
347 else
348 {
349 checkSlow(false);
350 }
351 }
352
353
362
363
368 {
370 Rotate(XForm.GetRotation());
371 }
372
373
379 void AlignAxis(int AxisIndex, const TVector<RealType>& ToDirection)
380 {
383 }
384
385
393 {
394 //@todo PlaneAngleSigned does acos() and then SetAxisAngleD() does cos/sin...can we optimize this?
395 TVector<RealType> AxisVec = GetAxis(AxisIndex);
400 }
401
402
419 RealType UpDotTolerance = (RealType)0.707)
420 {
423
424 // decide if we should use Fallback (polar-cap) axis or main (equator-region) axis
427 FallbackAxis : UpAxis;
428
429 // figure out which PerpAxis is closer to target, and align that one to +/- TargetAxis (whichever is smaller rotation)
432 RealType UseSign = Dots[UseAxis] < 0 ? -1 : 1;
434 }
435
436
446 {
448 RealType PlaneD = -Origin.Dot(Normal);
449 RealType NormalDot = RayDirection.Dot(Normal);
451 {
453 return false;
454 }
455 RealType t = -( RayOrigin.Dot(Normal) + PlaneD) / NormalDot;
456 if (t < 0)
457 {
459 return false;
460 }
461 HitPointOut = RayOrigin + t * RayDirection;
462 return true;
463 }
464
465};
466
467template <typename T>
469{
470 return TFrame3<T>(
471 UE::Geometry::Lerp(A.Origin, B.Origin, Alpha),
472 TQuaternion<T>(A.Rotation, B.Rotation, Alpha));
473}
474
475
476
479
480} // end namespace UE::Geometry
481} // end namespace UE
@ Normal
Definition AndroidInputInterface.h:116
#define checkSlow(expr)
Definition AssertionMacros.h:332
#define check(expr)
Definition AssertionMacros.h:314
#define checkNoEntry()
Definition AssertionMacros.h:316
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
UE::Math::TTransform< double > FTransform
Definition MathFwd.h:53
UE::Math::TPlane< double > FPlane
Definition MathFwd.h:52
Definition MathUtil.h:150
static RealType Abs(const RealType Value)
Definition MathUtil.h:215
Definition TransformTypes.h:30
const TQuaternion< RealType > & GetRotation() const
Definition TransformTypes.h:107
TVector< RealType2 > TransformPosition(const TVector< RealType2 > &P) const
Definition TransformTypes.h:217
RealType PlaneAngleSignedD(const TVector< RealType > &VFrom, const TVector< RealType > &VTo, const TVector< RealType > &PlaneN)
Definition VectorUtil.h:280
bool EpsilonEqual(RealType A, RealType B, RealType Epsilon)
Definition VectorUtil.h:151
TFrame3< float > FFrame3f
Definition FrameTypes.h:477
TFrame3< T > Lerp(const TFrame3< T > &A, const TFrame3< T > &B, T Alpha)
Definition FrameTypes.h:468
TFrame3< double > FFrame3d
Definition FrameTypes.h:478
Definition Sphere.cpp:10
Definition AdvancedWidgetsModule.cpp:13
Definition NumericLimits.h:41
Definition FrameTypes.h:27
void ConstrainedAlignPerpAxes(int PerpAxis1=0, int PerpAxis2=1, int NormalAxis=2, const TVector< RealType > &UpAxis=TVector< RealType >::UnitZ(), const TVector< RealType > &FallbackAxis=TVector< RealType >::UnitX(), RealType UpDotTolerance=(RealType) 0.707)
Definition FrameTypes.h:416
void Transform(const FTransform &XForm)
Definition FrameTypes.h:357
TVector< RealType > FromFrameVector(const TVector< RealType > &Vector) const
Definition FrameTypes.h:229
TFrame3()
Definition FrameTypes.h:41
TTransformSRT3< RealType > ToTransform() const
Definition FrameTypes.h:187
FPlane ToFPlane() const
Definition FrameTypes.h:181
void ConstrainedAlignAxis(int AxisIndex, const TVector< RealType > &ToDirection, const TVector< RealType > &AroundVector)
Definition FrameTypes.h:392
void GetAxes(TVector< RealType > &X, TVector< RealType > &Y, TVector< RealType > &Z) const
Definition FrameTypes.h:144
TVector< RealType > X() const
Definition FrameTypes.h:150
TFrame3< RealType > ToFrame(const TFrame3< RealType > &Frame) const
Definition FrameTypes.h:260
TFrame3(const TVector< RealType > &OriginIn, const TQuaternion< RealType > RotationIn)
Definition FrameTypes.h:59
void Rotate(const TQuaternion< RealType > &Quat)
Definition FrameTypes.h:340
TVector< RealType > PointAt(const TVector< RealType > &Point) const
Definition FrameTypes.h:206
TVector< RealType > GetAxis(int AxisIndex) const
Definition FrameTypes.h:125
TVector< RealType > Origin
Definition FrameTypes.h:31
TFrame3(const FTransform &Transform)
Definition FrameTypes.h:90
TVector< RealType > Z() const
Definition FrameTypes.h:162
TFrame3(const FVector &OriginIn, const FQuat &RotationIn)
Definition FrameTypes.h:106
TQuaternion< RealType > ToFrame(const TQuaternion< RealType > &Quat) const
Definition FrameTypes.h:236
TVector2< RealType > ToPlaneUV(const TVector< RealType > &Pos, int PlaneNormalAxis=2) const
Definition FrameTypes.h:279
TVector< RealType > ToFramePoint(const TVector< RealType > &Point) const
Definition FrameTypes.h:212
TRay< RealType > ToFrame(const TRay< RealType > &Ray) const
Definition FrameTypes.h:248
void AlignAxis(int AxisIndex, const TVector< RealType > &ToDirection)
Definition FrameTypes.h:379
void Transform(const TTransformSRT3< RealType > &XForm)
Definition FrameTypes.h:367
TRay< RealType > FromFrame(const TRay< RealType > &Ray) const
Definition FrameTypes.h:253
TVector< RealType > ToFrameVector(const TVector< RealType > &Vector) const
Definition FrameTypes.h:224
bool RayPlaneIntersection(const TVector< RealType > &RayOrigin, const TVector< RealType > &RayDirection, int PlaneNormalAxis, UE::Math::TVector< RealType > &HitPointOut) const
Definition FrameTypes.h:445
FTransform ToFTransform() const
Definition FrameTypes.h:168
TQuaternion< RealType > Rotation
Definition FrameTypes.h:36
TVector< RealType > FromFramePoint(const TVector< RealType > &Point) const
Definition FrameTypes.h:217
TVector< RealType > Y() const
Definition FrameTypes.h:156
TFrame3< RealType > FromFrame(const TFrame3< RealType > &Frame) const
Definition FrameTypes.h:265
TFrame3(const TFrame3< RealType2 > &OtherFrame)
Definition FrameTypes.h:114
TFrame3(const TVector< RealType > &OriginIn, const TVector< RealType > &X, const TVector< RealType > &Y, const TVector< RealType > &Z)
Definition FrameTypes.h:83
TVector< RealType > PointAt(RealType X, RealType Y, RealType Z) const
Definition FrameTypes.h:200
FTransform ToInverseFTransform() const
Definition FrameTypes.h:174
TVector< RealType > ToPlane(const TVector< RealType > &Pos, int PlaneNormalAxis=2) const
Definition FrameTypes.h:326
TVector< RealType > FromPlaneUV(const TVector2< RealType > &PosUV, int PlaneNormalAxis=2) const
Definition FrameTypes.h:304
TFrame3(const TVector< RealType > &OriginIn, const TVector< RealType > &SetZ)
Definition FrameTypes.h:70
TTransformSRT3< RealType > ToInverseTransform() const
Definition FrameTypes.h:193
TFrame3(const FPlane &Plane)
Definition FrameTypes.h:97
TFrame3(const TVector< RealType > &OriginIn)
Definition FrameTypes.h:50
TQuaternion< RealType > FromFrame(const TQuaternion< RealType > &Quat) const
Definition FrameTypes.h:241
Definition MatrixTypes.h:17
Definition Quaternion.h:22
static TQuaternion< RealType > Identity()
Definition Quaternion.h:59
void SetAxisAngleD(const TVector< RealType > &Axis, RealType AngleDeg)
Definition Quaternion.h:400
TQuaternion< RealType > Inverse() const
Definition Quaternion.h:386
RealType Normalize(const RealType epsilon=0)
Definition Quaternion.h:235
Definition Ray.h:19
TVector< T > Origin
Definition Ray.h:24
TVector< T > Direction
Definition Ray.h:27
TQuat< T > GetRotation() const
Definition TransformNonVectorized.h:1109
UE_FORCEINLINE_HINT TVector< T > TransformPosition(const TVector< T > &V) const
Definition TransformNonVectorized.h:1423
Definition Vector2D.h:38
Definition Vector.h:51
static TVector< T > Zero()
Definition Vector.h:112
UE_FORCEINLINE_HINT T Dot(const TVector< T > &V) const
Definition Vector.h:1553