ProtoTracer  1.0
Real-time 3D rendering and animation engine
Loading...
Searching...
No Matches
RampFilter.cpp
Go to the documentation of this file.
1#include "RampFilter.h"
2
4 increment = 0.05f;
5 filter = 0.0f;
6 epsilon = 0.01f;
7}
8
9RampFilter::RampFilter(int frames, float epsilon) {
10 increment = 1.0f / float(frames);
11 this->epsilon = epsilon;
12}
13
14float RampFilter::Filter(float value) {
15 if (Mathematics::IsClose(value, filter, increment / 2.0f)) return filter;
16
17 if (value > filter + epsilon) {
18 filter = filter + increment < 1.0f ? filter + increment : 1.0f;
19 } else if (value < filter - epsilon) {
20 filter = filter - increment > 0.0f ? filter - increment : 0.0f;
21 }
22
23 return filter;
24}
25
26void RampFilter::SetIncrement(float increment) {
27 this->increment = increment;
28}
29
30void RampFilter::SetFrames(int frames) {
31 increment = 1.0f / float(frames);
32}
Provides a class for smooth value transitions using a ramp filter.
static bool IsClose(float v1, float v2, float epsilon)
Checks if two values are close within a specified epsilon.
void SetIncrement(float increment)
Sets the increment for each transition step.
float epsilon
A small tolerance to determine when to stop adjusting.
Definition RampFilter.h:28
float Filter(float value)
Applies the ramp filter to the specified target value.
float filter
The current filtered value.
Definition RampFilter.h:27
float increment
The step size for each frame of the transition.
Definition RampFilter.h:26
RampFilter()
Default constructor for RampFilter.
Definition RampFilter.cpp:3
void SetFrames(int frames)
Sets the number of frames for a complete transition.