Ark Server API (ASA) - Wiki
Loading...
Searching...
No Matches
InterpCurvePoint.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 "HAL/UnrealMemory.h"
7#include "Math/UnrealMathUtility.h"
8#include "Math/Color.h"
9#include "Math/Vector2D.h"
10#include "Containers/EnumAsByte.h"
11#include "Math/Vector.h"
12#include "Math/Quat.h"
13#include "Math/TwoVectors.h"
14
16{
17 /** A straight line between two keypoint values. */
19
20 /** A cubic-hermite curve between two keypoints, using Arrive/Leave tangents. These tangents will be automatically
21 updated when points are moved, etc. Tangents are unclamped and will plateau at curve start and end points. */
23
24 /** The out value is held constant until the next key, then will jump to that value. */
26
27 /** A smooth curve just like CIM_Curve, but tangents are not automatically updated so you can have manual control over them (eg. in Curve Editor). */
29
30 /** A curve like CIM_Curve, but the arrive and leave tangents are not forced to be the same, so you can create a 'corner' at this key. */
32
33 /** A cubic-hermite curve between two keypoints, using Arrive/Leave tangents. These tangents will be automatically
34 updated when points are moved, etc. Tangents are clamped and will plateau at curve start and end points. */
36
37 /** Invalid or unknown curve type. */
39};
40
41
42/**
43 * Template for interpolation points.
44 *
45 * Interpolation points are used for describing the shape of interpolation curves.
46 *
47 * @see FInterpCurve
48 * @todo Docs: FInterpCurvePoint needs better function documentation.
49 */
50template< class T > class FInterpCurvePoint
51{
52public:
53
54 /** Float input value that corresponds to this key (eg. time). */
55 float InVal;
56
57 /** Output value of templated type when input is equal to InVal. */
59
60 /** Tangent of curve arrive this point. */
62
63 /** Tangent of curve leaving this point. */
65
66 /** Interpolation mode between this point and the next one. @see EInterpCurveMode */
68
69public:
70
71 /**
72 * Default constructor (no initialization).
73 */
75
76 /**
77 * Constructor
78 *
79 * @param In input value that corresponds to this key
80 * @param Out Output value of templated type
81 * @note uses linear interpolation
82 */
83 FInterpCurvePoint( const float In, const T &Out );
84
85 /**
86 * Constructor
87 *
88 * @param In input value that corresponds to this key
89 * @param Out Output value of templated type
90 * @param InArriveTangent Tangent of curve arriving at this point.
91 * @param InLeaveTangent Tangent of curve leaving from this point.
92 * @param InInterpMode interpolation mode to use
93 */
94 FInterpCurvePoint( const float In, const T &Out, const T &InArriveTangent, const T &InLeaveTangent, const EInterpCurveMode InInterpMode );
95
96 /**
97 * Constructor which initializes all components to zero.
98 *
99 * @param EForceInit Force init enum
100 */
102
103public:
104
105 /** @return true if the key value is using a curve interp mode, otherwise false */
106 FORCEINLINE bool IsCurveKey() const;
107
108public:
109
110 /**
111 * Serializes the Curve Point.
112 *
113 * @param Ar Reference to the serialization archive.
114 * @param Point Reference to the curve point being serialized.
115 *
116 * @return Reference to the Archive after serialization.
117 */
118 friend FArchive& operator<<( FArchive& Ar, FInterpCurvePoint& Point )
119 {
120 Ar << Point.InVal << Point.OutVal;
123 return Ar;
124 }
125
126 /**
127 * Compare equality of two Curve Points
128 */
129 friend bool operator==( const FInterpCurvePoint& Point1, const FInterpCurvePoint& Point2 )
130 {
131 return (Point1.InVal == Point2.InVal &&
136 }
137
138 /**
139 * Compare inequality of two Curve Points
140 */
141 friend bool operator!=(const FInterpCurvePoint& Point1, const FInterpCurvePoint& Point2)
142 {
143 return !(Point1 == Point2);
144 }
145};
146
147
148/* FInterpCurvePoint inline functions
149 *****************************************************************************/
150
151template< class T >
152FORCEINLINE FInterpCurvePoint<T>::FInterpCurvePoint( const float In, const T &Out )
153 : InVal(In)
154 , OutVal(Out)
155{
156 FMemory::Memset( &ArriveTangent, 0, sizeof(T) );
157 FMemory::Memset( &LeaveTangent, 0, sizeof(T) );
158
159 InterpMode = CIM_Linear;
160}
161
162
163template< class T >
164FORCEINLINE FInterpCurvePoint<T>::FInterpCurvePoint( const float In, const T &Out, const T &InArriveTangent, const T &InLeaveTangent, const EInterpCurveMode InInterpMode)
165 : InVal(In)
166 , OutVal(Out)
167 , ArriveTangent(InArriveTangent)
168 , LeaveTangent(InLeaveTangent)
169 , InterpMode(InInterpMode)
170{ }
171
172template< class T >
174{
175 InVal = 0.0f;
176 FMemory::Memset(&OutVal, 0, sizeof(T));
177 FMemory::Memset(&ArriveTangent, 0, sizeof(T));
178 FMemory::Memset(&LeaveTangent, 0, sizeof(T));
179 InterpMode = CIM_Linear;
180}
181
182template< class T >
184{
185 return ((InterpMode == CIM_CurveAuto) || (InterpMode == CIM_CurveAutoClamped) || (InterpMode == CIM_CurveUser) || (InterpMode == CIM_CurveBreak));
186}
187
188/**
189 * Clamps a tangent formed by the specified control point values
190 */
191float ClampFloatTangent( float PrevPointVal, float PrevTime, float CurPointVal, float CurTime, float NextPointVal, float NextTime );
192
193
194/** Computes Tangent for a curve segment */
195template< class T, class U >
196inline void AutoCalcTangent( const T& PrevP, const T& P, const T& NextP, const U& Tension, T& OutTan )
197{
198 OutTan = (1.f - Tension) * ( (P - PrevP) + (NextP - P) );
199}
200
201
202/**
203 * This actually returns the control point not a tangent. This is expected by the CubicInterp function for Quaternions
204 */
205template< class U >
206inline void AutoCalcTangent( const FQuat& PrevP, const FQuat& P, const FQuat& NextP, const U& Tension, FQuat& OutTan )
207{
208 FQuat::CalcTangents(PrevP, P, NextP, Tension, OutTan);
209}
210
211
212/** Computes a tangent for the specified control point. General case, doesn't support clamping. */
213template< class T >
214inline void ComputeCurveTangent( float PrevTime, const T& PrevPoint,
215 float CurTime, const T& CurPoint,
216 float NextTime, const T& NextPoint,
217 float Tension,
218 bool bWantClamping,
219 T& OutTangent )
220{
221 // NOTE: Clamping not supported for non-float vector types (bWantClamping is ignored)
222
223 AutoCalcTangent( PrevPoint, CurPoint, NextPoint, Tension, OutTangent );
224
225 const float PrevToNextTimeDiff = FMath::Max< float >( UE_KINDA_SMALL_NUMBER, NextTime - PrevTime );
226
227 OutTangent /= PrevToNextTimeDiff;
228}
229
230
231/**
232 * Computes a tangent for the specified control point; supports clamping, but only works
233 * with floats or contiguous arrays of floats.
234 */
235template< class T >
236inline void ComputeClampableFloatVectorCurveTangent( float PrevTime, const T& PrevPoint,
237 float CurTime, const T& CurPoint,
238 float NextTime, const T& NextPoint,
239 float Tension,
240 bool bWantClamping,
241 T& OutTangent )
242{
243 // Clamp the tangents if we need to do that
244 if( bWantClamping )
245 {
246 // NOTE: We always treat the type as an array of floats
247 float* PrevPointVal = ( float* )&PrevPoint;
248 float* CurPointVal = ( float* )&CurPoint;
249 float* NextPointVal = ( float* )&NextPoint;
250 float* OutTangentVal = ( float* )&OutTangent;
251 for( int32 CurValPos = 0; CurValPos < sizeof( T ); CurValPos += sizeof( float ) )
252 {
253 // Clamp it!
254 const float ClampedTangent =
255 ClampFloatTangent(
256 *PrevPointVal, PrevTime,
257 *CurPointVal, CurTime,
258 *NextPointVal, NextTime );
259
260 // Apply tension value
261 *OutTangentVal = ( 1.0f - Tension ) * ClampedTangent;
262
263
264 // Advance pointers
265 ++OutTangentVal;
266 ++PrevPointVal;
267 ++CurPointVal;
268 ++NextPointVal;
269 }
270 }
271 else
272 {
273 // No clamping needed
274 AutoCalcTangent( PrevPoint, CurPoint, NextPoint, Tension, OutTangent );
275
276 const float PrevToNextTimeDiff = FMath::Max< float >( UE_KINDA_SMALL_NUMBER, NextTime - PrevTime );
277
278 OutTangent /= PrevToNextTimeDiff;
279 }
280}
281
282
283/** Computes a tangent for the specified control point. Special case for float types; supports clamping. */
284inline void ComputeCurveTangent( float PrevTime, const float& PrevPoint,
285 float CurTime, const float& CurPoint,
286 float NextTime, const float& NextPoint,
287 float Tension,
288 bool bWantClamping,
289 float& OutTangent )
290{
291 ComputeClampableFloatVectorCurveTangent(
292 PrevTime, PrevPoint,
293 CurTime, CurPoint,
294 NextTime, NextPoint,
295 Tension, bWantClamping, OutTangent );
296}
297
298
299/** Computes a tangent for the specified control point. Special case for FVector types; supports clamping. */
300inline void ComputeCurveTangent( float PrevTime, const FVector& PrevPoint,
301 float CurTime, const FVector& CurPoint,
302 float NextTime, const FVector& NextPoint,
303 float Tension,
304 bool bWantClamping,
305 FVector& OutTangent )
306{
307 ComputeClampableFloatVectorCurveTangent(
308 PrevTime, PrevPoint,
309 CurTime, CurPoint,
310 NextTime, NextPoint,
311 Tension, bWantClamping, OutTangent );
312}
313
314
315/** Computes a tangent for the specified control point. Special case for FVector2D types; supports clamping. */
316inline void ComputeCurveTangent( float PrevTime, const FVector2D& PrevPoint,
317 float CurTime, const FVector2D& CurPoint,
318 float NextTime, const FVector2D& NextPoint,
319 float Tension,
320 bool bWantClamping,
321 FVector2D& OutTangent )
322{
323 ComputeClampableFloatVectorCurveTangent(
324 PrevTime, PrevPoint,
325 CurTime, CurPoint,
326 NextTime, NextPoint,
327 Tension, bWantClamping, OutTangent );
328}
329
330
331/** Computes a tangent for the specified control point. Special case for FTwoVectors types; supports clamping. */
332inline void ComputeCurveTangent( float PrevTime, const FTwoVectors& PrevPoint,
333 float CurTime, const FTwoVectors& CurPoint,
334 float NextTime, const FTwoVectors& NextPoint,
335 float Tension,
336 bool bWantClamping,
337 FTwoVectors& OutTangent )
338{
339 ComputeClampableFloatVectorCurveTangent(
340 PrevTime, PrevPoint,
341 CurTime, CurPoint,
342 NextTime, NextPoint,
343 Tension, bWantClamping, OutTangent );
344}
345
346/**
347 * Calculate bounds of float intervals
348 *
349 * @param Start interp curve point at Start
350 * @param End interp curve point at End
351 * @param CurrentMin Input and Output could be updated if needs new interval minimum bound
352 * @param CurrentMax Input and Output could be updated if needs new interval maximmum bound
353 */
354void CurveFloatFindIntervalBounds( const FInterpCurvePoint<float>& Start, const FInterpCurvePoint<float>& End, float& CurrentMin, float& CurrentMax );
355
356
357/**
358 * Calculate bounds of 2D vector intervals
359 *
360 * @param Start interp curve point at Start
361 * @param End interp curve point at End
362 * @param CurrentMin Input and Output could be updated if needs new interval minimum bound
363 * @param CurrentMax Input and Output could be updated if needs new interval maximmum bound
364 */
365void CurveVector2DFindIntervalBounds( const FInterpCurvePoint<FVector2D>& Start, const FInterpCurvePoint<FVector2D>& End, FVector2D& CurrentMin, FVector2D& CurrentMax );
366
367
368/**
369 * Calculate bounds of vector intervals
370 *
371 * @param Start interp curve point at Start
372 * @param End interp curve point at End
373 * @param CurrentMin Input and Output could be updated if needs new interval minimum bound
374 * @param CurrentMax Input and Output could be updated if needs new interval maximmum bound
375 */
376void CurveVectorFindIntervalBounds( const FInterpCurvePoint<FVector>& Start, const FInterpCurvePoint<FVector>& End, FVector& CurrentMin, FVector& CurrentMax );
377
378
379/**
380 * Calculate bounds of twovector intervals
381 *
382 * @param Start interp curve point at Start
383 * @param End interp curve point at End
384 * @param CurrentMin Input and Output could be updated if needs new interval minimum bound
385 * @param CurrentMax Input and Output could be updated if needs new interval maximmum bound
386 */
387void CurveTwoVectorsFindIntervalBounds(const FInterpCurvePoint<FTwoVectors>& Start, const FInterpCurvePoint<FTwoVectors>& End, FTwoVectors& CurrentMin, FTwoVectors& CurrentMax);
388
389
390/**
391 * Calculate bounds of color intervals
392 *
393 * @param Start interp curve point at Start
394 * @param End interp curve point at End
395 * @param CurrentMin Input and Output could be updated if needs new interval minimum bound
396 * @param CurrentMax Input and Output could be updated if needs new interval maximmum bound
397 */
399
400
401template< class T, class U >
402inline void CurveFindIntervalBounds( const FInterpCurvePoint<T>& Start, const FInterpCurvePoint<T>& End, T& CurrentMin, T& CurrentMax, const U& Dummy )
403{ }
404
405
406template< class U >
407inline void CurveFindIntervalBounds( const FInterpCurvePoint<float>& Start, const FInterpCurvePoint<float>& End, float& CurrentMin, float& CurrentMax, const U& Dummy )
408{
409 CurveFloatFindIntervalBounds(Start, End, CurrentMin, CurrentMax);
410}
411
412
413template< class U >
414void CurveFindIntervalBounds( const FInterpCurvePoint<FVector2D>& Start, const FInterpCurvePoint<FVector2D>& End, FVector2D& CurrentMin, FVector2D& CurrentMax, const U& Dummy )
415{
416 CurveVector2DFindIntervalBounds(Start, End, CurrentMin, CurrentMax);
417}
418
419
420template< class U >
421inline void CurveFindIntervalBounds( const FInterpCurvePoint<FVector>& Start, const FInterpCurvePoint<FVector>& End, FVector& CurrentMin, FVector& CurrentMax, const U& Dummy )
422{
423 CurveVectorFindIntervalBounds(Start, End, CurrentMin, CurrentMax);
424}
425
426
427template< class U >
428inline void CurveFindIntervalBounds( const FInterpCurvePoint<FTwoVectors>& Start, const FInterpCurvePoint<FTwoVectors>& End, FTwoVectors& CurrentMin, FTwoVectors& CurrentMax, const U& Dummy )
429{
430 CurveTwoVectorsFindIntervalBounds(Start, End, CurrentMin, CurrentMax);
431}
432
433
434template< class U >
435inline void CurveFindIntervalBounds( const FInterpCurvePoint<FLinearColor>& Start, const FInterpCurvePoint<FLinearColor>& End, FLinearColor& CurrentMin, FLinearColor& CurrentMax, const U& Dummy )
436{
437 CurveLinearColorFindIntervalBounds(Start, End, CurrentMin, CurrentMax);
438}
439
440// Native implementation of NOEXPORT FInterpCurvePoint structures
EForceInit
EInterpCurveMode
Definition Enums.h:6108
void CurveFindIntervalBounds(const FInterpCurvePoint< FTwoVectors > &Start, const FInterpCurvePoint< FTwoVectors > &End, FTwoVectors &CurrentMin, FTwoVectors &CurrentMax, const U &Dummy)
void ComputeClampableFloatVectorCurveTangent(float PrevTime, const T &PrevPoint, float CurTime, const T &CurPoint, float NextTime, const T &NextPoint, float Tension, bool bWantClamping, T &OutTangent)
void CurveFindIntervalBounds(const FInterpCurvePoint< FVector > &Start, const FInterpCurvePoint< FVector > &End, FVector &CurrentMin, FVector &CurrentMax, const U &Dummy)
void ComputeCurveTangent(float PrevTime, const T &PrevPoint, float CurTime, const T &CurPoint, float NextTime, const T &NextPoint, float Tension, bool bWantClamping, T &OutTangent)
void CurveFindIntervalBounds(const FInterpCurvePoint< FVector2D > &Start, const FInterpCurvePoint< FVector2D > &End, FVector2D &CurrentMin, FVector2D &CurrentMax, const U &Dummy)
FInterpCurvePoint< float > FInterpCurvePointFloat
void CurveFindIntervalBounds(const FInterpCurvePoint< float > &Start, const FInterpCurvePoint< float > &End, float &CurrentMin, float &CurrentMax, const U &Dummy)
void ComputeCurveTangent(float PrevTime, const FVector &PrevPoint, float CurTime, const FVector &CurPoint, float NextTime, const FVector &NextPoint, float Tension, bool bWantClamping, FVector &OutTangent)
void CurveTwoVectorsFindIntervalBounds(const FInterpCurvePoint< FTwoVectors > &Start, const FInterpCurvePoint< FTwoVectors > &End, FTwoVectors &CurrentMin, FTwoVectors &CurrentMax)
@ CIM_CurveAutoClamped
@ CIM_Linear
@ CIM_CurveUser
@ CIM_Constant
@ CIM_CurveAuto
@ CIM_CurveBreak
@ CIM_Unknown
void ComputeCurveTangent(float PrevTime, const FVector2D &PrevPoint, float CurTime, const FVector2D &CurPoint, float NextTime, const FVector2D &NextPoint, float Tension, bool bWantClamping, FVector2D &OutTangent)
void AutoCalcTangent(const T &PrevP, const T &P, const T &NextP, const U &Tension, T &OutTan)
float ClampFloatTangent(float PrevPointVal, float PrevTime, float CurPointVal, float CurTime, float NextPointVal, float NextTime)
void CurveVector2DFindIntervalBounds(const FInterpCurvePoint< FVector2D > &Start, const FInterpCurvePoint< FVector2D > &End, FVector2D &CurrentMin, FVector2D &CurrentMax)
FInterpCurvePoint< FVector2D > FInterpCurvePointVector2D
void AutoCalcTangent(const FQuat &PrevP, const FQuat &P, const FQuat &NextP, const U &Tension, FQuat &OutTan)
FInterpCurvePoint< FTwoVectors > FInterpCurvePointTwoVectors
FInterpCurvePoint< FQuat > FInterpCurvePointQuat
void CurveLinearColorFindIntervalBounds(const FInterpCurvePoint< FLinearColor > &Start, const FInterpCurvePoint< FLinearColor > &End, FLinearColor &CurrentMin, FLinearColor &CurrentMax)
void CurveFindIntervalBounds(const FInterpCurvePoint< FLinearColor > &Start, const FInterpCurvePoint< FLinearColor > &End, FLinearColor &CurrentMin, FLinearColor &CurrentMax, const U &Dummy)
void CurveFindIntervalBounds(const FInterpCurvePoint< T > &Start, const FInterpCurvePoint< T > &End, T &CurrentMin, T &CurrentMax, const U &Dummy)
void ComputeCurveTangent(float PrevTime, const float &PrevPoint, float CurTime, const float &CurPoint, float NextTime, const float &NextPoint, float Tension, bool bWantClamping, float &OutTangent)
FInterpCurvePoint< FLinearColor > FInterpCurvePointLinearColor
FInterpCurvePoint< FVector > FInterpCurvePointVector
void CurveFloatFindIntervalBounds(const FInterpCurvePoint< float > &Start, const FInterpCurvePoint< float > &End, float &CurrentMin, float &CurrentMax)
void ComputeCurveTangent(float PrevTime, const FTwoVectors &PrevPoint, float CurTime, const FTwoVectors &CurPoint, float NextTime, const FTwoVectors &NextPoint, float Tension, bool bWantClamping, FTwoVectors &OutTangent)
void CurveVectorFindIntervalBounds(const FInterpCurvePoint< FVector > &Start, const FInterpCurvePoint< FVector > &End, FVector &CurrentMin, FVector &CurrentMax)
#define FORCEINLINE
Definition Platform.h:644
#define UE_KINDA_SMALL_NUMBER
FInterpCurvePoint(const float In, const T &Out, const T &InArriveTangent, const T &InLeaveTangent, const EInterpCurveMode InInterpMode)
friend bool operator==(const FInterpCurvePoint &Point1, const FInterpCurvePoint &Point2)
FORCEINLINE bool IsCurveKey() const
FInterpCurvePoint(const float In, const T &Out)
TEnumAsByte< EInterpCurveMode > InterpMode
FORCEINLINE FInterpCurvePoint(EForceInit)
friend bool operator!=(const FInterpCurvePoint &Point1, const FInterpCurvePoint &Point2)