5#include "Math/Vector.h"
9
10
37
38
39
40 explicit TRay<T>( EForceInit )
47
48
49
50
51
52
53 TRay(
const TVector<T>& Origin,
const TVector<T>& Direction,
bool bDirectionIsNormalized =
false)
55 this->Origin = Origin;
56 this->Direction = Direction;
57 if (bDirectionIsNormalized ==
false)
59 this->Direction.Normalize();
65
66
69 Origin = TVector<T>::ZeroVector;
70 Direction = TVector<T>(0, 0, 1);
74
75
76
77
78
79 bool operator==(
const TRay<T>& Other )
const
81 return (Origin == Other.Origin) && (Direction == Other.Direction);
85
86
87
88
89
90 bool operator!=(
const TRay<T>& Other )
const
92 return !(*
this == Other);
99
100
101
102
103
104 TVector<T> PointAt(T RayParameter)
const
106 return Origin + RayParameter * Direction;
110
111
112
113
114
115 T GetParameter(
const TVector<T>& Point)
const
117 return TVector<T>::DotProduct((Point - Origin), Direction);
121
122
123
124
125
126 T DistSquared(
const TVector<T>& Point)
const
128 T RayParameter = TVector<T>::DotProduct((Point - Origin), Direction);
129 if (RayParameter < 0)
131 return TVector<T>::DistSquared(Origin, Point);
135 TVector<T> ProjectionPt = Origin + RayParameter * Direction;
136 return TVector<T>::DistSquared(ProjectionPt, Point);
141
142
143
144
145
146 T Dist(
const TVector<T>& Point)
const
148 return FMath::Sqrt(DistSquared(Point));
152
153
154
155
156 TVector<T> ClosestPoint(
const TVector<T>& Point)
const
158 T RayParameter = TVector<T>::DotProduct((Point - Origin), Direction);
159 if (RayParameter < 0)
165 return Origin + RayParameter * Direction;
174
175
176
177
178 FString ToString()
const
180 return FString::Printf(
TEXT(
"Origin=(%s), Direction=(%s)"), *Origin.ToString(), *Direction.ToString());
184
185
186
187
188
189
190
191 friend FArchive& operator<<( FArchive& Ar, TRay<T>& Ray )
193 return Ar << Ray.Origin << Ray.Direction;
197 bool Serialize(FArchive& Ar)
203 bool SerializeFromMismatchedTag(FName StructTag, FArchive& Ar);
207 explicit TRay(
const TRay<FArg>& From) : TRay<T>(TVector<T>(From.Origin), TVector<T>(From.Direction),
true) {}
215template<>
struct TIsPODType<FRay3f> {
enum {
Value =
true }; };
216template<>
struct TIsPODType<FRay3d> {
enum {
Value =
true }; };
217template<>
struct TIsUECoreVariant<FRay3f> {
enum { Value =
true }; };
218template<>
struct TIsUECoreVariant<FRay3d> {
enum { Value =
true }; };
223inline bool FRay3f::SerializeFromMismatchedTag(FName StructTag, FArchive& Ar)
229inline bool FRay3d::SerializeFromMismatchedTag(FName StructTag, FArchive& Ar)
#define UE_DECLARE_LWC_TYPE(...)
#define UE_SERIALIZE_VARIANT_FROM_MISMATCHED_TAG(AR_OR_SLOT, ALIAS, TYPE, ALT_TYPE)
#define TEMPLATE_REQUIRES(...)