UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
AnimInterpFilter.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3/*=============================================================================
4 InterpFilter.h
5=============================================================================*/
6
7#pragma once
8
9#include "CoreMinimal.h"
10#include "Engine/EngineTypes.h"
11
12//======================================================================================================================
13struct UE_DEPRECATED(5.0, "FFIRFilter is no longer used or supported") FFIRFilter
14{
15public:
17 {
18 }
19
21 {
23 }
24
26 {
27 if ( WindowLen > 0 )
28 {
29 FilterData.AddZeroed(WindowLen);
30 Coefficients.AddZeroed(WindowLen);
31 CurrentStack = 0;
32 }
33 else
34 {
35 FilterData.Reset();
36 Coefficients.Reset();
37 CurrentStack = 0;
38 }
39 }
40
41 void CalculateCoefficient(EFilterInterpolationType InterpolationType);
42 float GetFilteredData(float Input);
43 bool IsValid() const { return FilterData.Num() > 0; }
44 float LastOutput;
45private:
46
47 // CurrentStack is latest till CurrentStack + 1 is oldest
48 // note that this works in reverse order with Coefficient
49 TArray<float> FilterData;
50 // n-1 is latest till 0 is oldest
51 TArray<float> Coefficients;
53
54 float GetStep() const
55 {
56 check( IsValid() );
57 return 1.f/(float)Coefficients.Num();
58 }
59
60 float GetInterpolationCoefficient (EFilterInterpolationType InterpolationType, int32 CoefficientIndex) const;
61 float CalculateFilteredOutput() const;
62};
63
64//======================================================================================================================
66{
67 float Input;
68 float Time;
69
71 {
72 }
73
74 FFilterData(const float InInput, const float InTime)
75 : Input(InInput)
76 , Time(InTime)
77 {
78 }
79
80 void EnsureTimeIsValid(const float CurrentTime, const float ValidationWindow)
81 {
82 if (Diff(CurrentTime) > ValidationWindow)
83 {
84 Time = 0.f;
85 }
86 }
87
88 bool IsValid() const
89 {
90 return (Time > 0.f);
91 }
92
93 float Diff(const float InTime) const
94 {
95 return (InTime - Time);
96 }
97
98 void SetInput(const float InData, const float InTime)
99 {
100 Input = InData;
101 Time = InTime;
102 }
103};
104
105//======================================================================================================================
107{
108public:
110 {
111 }
112
118
120 float InMinValue, float InMaxValue, float InMaxSpeed, bool bInClamp)
121 {
122 InterpolationType = InInterpolationType;
123 FilterData.Empty();
124 CurrentStackIndex = 0;
125 WindowDuration = InWindowDuration;
126 DampingRatio = InDampingRatio;
127 MinValue = InMinValue;
128 MaxValue = InMaxValue;
129 MaxSpeed = InMaxSpeed;
130 bClamp = bInClamp;
131 CurrentTime = 0.f;
132 LastOutput = 0.f;
133 }
134
135 // These parameters can be modified at runtime without needing to re-initialize
136 void SetParams(float InDampingRatio, float InMinValue, float InMaxValue, float InMaxSpeed, bool bInClamp)
137 {
138 DampingRatio = InDampingRatio;
139 MinValue = InMinValue;
140 MaxValue = InMaxValue;
141 MaxSpeed = InMaxSpeed;
142 bClamp = bInClamp;
143 }
144
145 // This adds Input to the stack representing an update of DeltaTime, and returns the new filtered value.
146 ENGINE_API float UpdateAndGetFilteredData(float Input, float DeltaTime);
147
148 // Wraps the internal state by steps of Range so that it is as close as possible to Input
149 ENGINE_API void WrapToValue(float Input, float Range);
150
151 // Sets internal state to the specified value
152 ENGINE_API void SetToValue(float Input);
153
154 // Filter is considered valid if the WindowDuration is > 0
155 bool IsValid() const { return WindowDuration > 0.f; }
156
158 {
159 WindowDuration = InWindowDuration;
160 }
161
162#if WITH_EDITOR
164 {
165 return InterpolationType != InType || WindowDuration != InWindowDuration;
166 }
167#endif // WITH_EDITOR
168
170
171private:
172 EFilterInterpolationType InterpolationType;
173 int32 CurrentStackIndex;
174 float WindowDuration;
175 float DampingRatio;
176 float MinValue;
177 float MaxValue;
178 float MaxSpeed;
179 bool bClamp;
180 float CurrentTime;
181 TArray<FFilterData> FilterData;
182
183 ENGINE_API float GetInterpolationCoefficient(const FFilterData& Data) const;
184 ENGINE_API float CalculateFilteredOutput();
185 ENGINE_API int32 GetSafeCurrentStackIndex();
186 ENGINE_API void RefreshValidFilters();
187};
#define check(expr)
Definition AssertionMacros.h:314
#define UE_DEPRECATED(Version, Message)
Definition CoreMiscDefines.h:302
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
EFilterInterpolationType
Definition EngineTypes.h:1250
USkinnedMeshComponent float
Definition SkinnedMeshComponent.h:60
Definition Array.h:670
UE_REWRITE SizeType Num() const
Definition Array.h:1144
void Empty(SizeType Slack=0)
Definition Array.h:2273
Definition AnimInterpFilter.h:107
float LastOutput
Definition AnimInterpFilter.h:169
void Initialize(float InWindowDuration, EFilterInterpolationType InInterpolationType, float InDampingRatio, float InMinValue, float InMaxValue, float InMaxSpeed, bool bInClamp)
Definition AnimInterpFilter.h:119
FFIRFilterTimeBased(float InWindowDuration, EFilterInterpolationType InInterpolationType, float InDampingRatio, float InMin, float InMax, float InMaxSpeed, bool bInClamp)
Definition AnimInterpFilter.h:113
void SetParams(float InDampingRatio, float InMinValue, float InMaxValue, float InMaxSpeed, bool bInClamp)
Definition AnimInterpFilter.h:136
void SetWindowDuration(float InWindowDuration)
Definition AnimInterpFilter.h:157
ENGINE_API void SetToValue(float Input)
Definition AnimInterpFilter.cpp:182
ENGINE_API float UpdateAndGetFilteredData(float Input, float DeltaTime)
Definition AnimInterpFilter.cpp:192
bool IsValid() const
Definition AnimInterpFilter.h:155
ENGINE_API void WrapToValue(float Input, float Range)
Definition AnimInterpFilter.cpp:143
FFIRFilterTimeBased()
Definition AnimInterpFilter.h:109
Definition AnimInterpFilter.h:66
float Time
Definition AnimInterpFilter.h:68
void EnsureTimeIsValid(const float CurrentTime, const float ValidationWindow)
Definition AnimInterpFilter.h:80
float Diff(const float InTime) const
Definition AnimInterpFilter.h:93
FFilterData(const float InInput, const float InTime)
Definition AnimInterpFilter.h:74
void SetInput(const float InData, const float InTime)
Definition AnimInterpFilter.h:98
bool IsValid() const
Definition AnimInterpFilter.h:88
float Input
Definition AnimInterpFilter.h:67
FFilterData()
Definition AnimInterpFilter.h:70