UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
CoreSegment.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2#pragma once
3
4#include "Chaos/Core.h"
5
6namespace Chaos
7{
8 template<class T>
10 {
11 public:
13 TCoreSegment(const TVec3<T>& X1, const TVec3<T>& X2)
14 : MPoint(X1)
15 , MAxis(X2 - X1)
16 , MLength(MAxis.SafeNormalize())
17 { }
18 TCoreSegment(const TVec3<T>& X1, const TVec3<T>& Axis, const T Length)
19 : MPoint(X1)
20 , MAxis(Axis)
21 , MLength(Length)
22 { }
23
24 FORCEINLINE bool IsConvex() const { return true; }
25
26 FORCEINLINE const TVec3<T> GetCenter() const { return MPoint + (.5f * MLength * MAxis); }
27
28 FORCEINLINE const TVec3<T>& GetX1() const { return MPoint; }
29
30 FORCEINLINE TVec3<T> GetX2() const { return MPoint + MAxis * MLength; }
31
32 FORCEINLINE const TVec3<T>& GetAxis() const { return MAxis; }
33
34 FORCEINLINE T GetLength() const { return MLength; }
35
36 TVec3<T> Support(const TVec3<T>& Direction, const T Thickness, int32& VertexIndex) const
37 {
38 const T Dot = TVec3<T>::DotProduct(Direction, MAxis);
39 const bool bIsSecond = Dot >= 0;
40 const TVec3<T> FarthestCap = bIsSecond? GetX2() : GetX1(); //orthogonal we choose either
41 VertexIndex = bIsSecond ? 1 : 0;
42 //We want N / ||N|| and to avoid inf
43 //So we want N / ||N|| < 1 / eps => N eps < ||N||, but this is clearly true for all eps < 1 and N > 0
44 T SizeSqr = Direction.SizeSquared();
46 {
47 return FarthestCap;
48 }
49 const TVec3<T> NormalizedDirection = Direction / FMath::Sqrt(SizeSqr);
50 return FarthestCap + (NormalizedDirection * Thickness);
51 }
52
53 FORCEINLINE_DEBUGGABLE TVec3<T> SupportCore(const TVec3<T>& Direction, int32& VertexIndex) const
54 {
55 const T Dot = TVec3<T>::DotProduct(Direction, MAxis);
56 const bool bIsSecond = Dot >= 0;
57 const TVec3<T> FarthestCap = bIsSecond ? GetX2() : GetX1(); //orthogonal we choose either
58 VertexIndex = bIsSecond ? 1 : 0;
59 return FarthestCap;
60 }
61
63 {
64 Ar << MPoint << MAxis;
65
67 Ar << LengthFloat;
68 MLength = (T)LengthFloat;
69 }
70
71 FString ToString() const
72 {
73 return FString::Printf(TEXT("Segment: Point: [%f, %f, %f], Axis: [%f, %f, %f], Length: %f"), MPoint.X, MPoint.Y, MPoint.Z, MAxis.X, MAxis.Y, MAxis.Z, MLength);
74 }
75
77 {
78 TAABB<T,3> Box(MPoint,MPoint);
79 Box.GrowToInclude(GetX2());
80 return Box;
81 }
82
83 private:
84 TVec3<T> MPoint;
85 TVec3<T> MAxis;
86 T MLength;
87 };
88
89 template<class T>
91} // namespace Chaos
#define FORCEINLINE
Definition AndroidPlatform.h:140
#define FORCEINLINE_DEBUGGABLE
Definition CoreMiscDefines.h:74
#define TEXT(x)
Definition Platform.h:1272
FPlatformTypes::int32 int32
A 32-bit signed integer.
Definition Platform.h:1125
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
Definition AABB.h:37
Definition CoreSegment.h:10
TCoreSegment(const TVec3< T > &X1, const TVec3< T > &X2)
Definition CoreSegment.h:13
FORCEINLINE_DEBUGGABLE TVec3< T > SupportCore(const TVec3< T > &Direction, int32 &VertexIndex) const
Definition CoreSegment.h:53
FString ToString() const
Definition CoreSegment.h:71
FORCEINLINE TVec3< T > GetX2() const
Definition CoreSegment.h:30
TCoreSegment()
Definition CoreSegment.h:12
FORCEINLINE bool IsConvex() const
Definition CoreSegment.h:24
FORCEINLINE T GetLength() const
Definition CoreSegment.h:34
TVec3< T > Support(const TVec3< T > &Direction, const T Thickness, int32 &VertexIndex) const
Definition CoreSegment.h:36
FORCEINLINE const TVec3< T > & GetX1() const
Definition CoreSegment.h:28
FORCEINLINE TAABB< T, 3 > BoundingBox() const
Definition CoreSegment.h:76
TCoreSegment(const TVec3< T > &X1, const TVec3< T > &Axis, const T Length)
Definition CoreSegment.h:18
FORCEINLINE void Serialize(FArchive &Ar)
Definition CoreSegment.h:62
FORCEINLINE const TVec3< T > & GetAxis() const
Definition CoreSegment.h:32
FORCEINLINE const TVec3< T > GetCenter() const
Definition CoreSegment.h:26
Definition Vector.h:1000
FORCEINLINE T SizeSquared() const
Definition Vector.h:1067
Definition Archive.h:1208
Definition SkeletalMeshComponent.h:307
float FRealSingle
Definition Real.h:14
Definition NumericLimits.h:41