Oxygen Engine
Modern C++ 3D Engine using OpenGL
Loading...
Searching...
No Matches
oe::util::Curve< V, T, CurveSettingsType > Struct Template Reference

General purpose curve (can be used for color gradients, animations, etc...) More...

#include <OxygenEngine/util/curve.h>

Public Types

using PointType = typename CurveSettingsType::PointType< V, T >
 Type used as a point on the curve.
 
using ContainerType = typename CurveSettingsType::PointStorageType< PointType >
 Type used to store all points.
 

Public Member Functions

constexpr V eval (const T x) const noexcept
 Compute a value on the curve based on its control points.
 

Public Attributes

ContainerType control_points
 Points of the curve.
 

Detailed Description

template<CurveValueConcept V, CurvePositionConcept T = float, typename CurveSettingsType = CurveSettings>
struct oe::util::Curve< V, T, CurveSettingsType >

General purpose curve (can be used for color gradients, animations, etc...)

Example curve with int as values

{.position = 0.0, .value = 52, .interpolation = CurveInterpolation::LINEAR},
{.position = 0.5, .value = 27, .interpolation = CurveInterpolation::DIRECT},
{.position = 0.8, .value = 14, .interpolation = CurveInterpolation::HOLD_LAST},
{.position = 1.0, .value = 64, .interpolation = CurveInterpolation::LINEAR},
});
int32_t result = curve.eval(0.25);
// Will return 27 because final interpolation between 0.0 and 0.5 is set to CurveInterpolation::DIRECT
@ HOLD_LAST
Hold last value.
@ DIRECT
No interpolation, directly switch to this value.
@ LINEAR
Do a linear interpolation between last value and this one.
General purpose curve (can be used for color gradients, animations, etc...)
Definition curve.h:157
constexpr V eval(const T x) const noexcept
Compute a value on the curve based on its control points.
Definition curve.h:175

You can use any type for V, but you need to make sure the class satisfies oe::util::CurveValueConcept

Note
It is assumed the container is filled with ascending point position
See also
multiple_windows example for an example of Curve usage to change color depending of the time
CurveSettings to customize Point storage / add more interpolation easings

Member Function Documentation

◆ eval()

template<CurveValueConcept V, CurvePositionConcept T = float, typename CurveSettingsType = CurveSettings>
constexpr V oe::util::Curve< V, T, CurveSettingsType >::eval ( const T  x) const
inlineconstexprnoexcept

Compute a value on the curve based on its control points.

Parameters
xvalue of the position (any value accepted)
  • If x is lower than the first curve point position, the first point value is returned
  • If x is greater than the last curve point position, the last point value is returned
  • Otherwise an interpolation is done between the points (A,B) found around x
    • interpolation options are taken from the point B
Returns
Interpolated value

The documentation for this struct was generated from the following file: