ezEngine  Release 25.03
ezCurve1D Class Reference

A 1D curve for animating a single value over time. More...

#include <Curve1D.h>

Classes

struct  ControlPoint
 Stores position and tangents to control spline interpolation. More...
 

Public Member Functions

void Clear ()
 Removes all control points.
 
bool IsEmpty () const
 Checks whether the curve has any control point.
 
ControlPointAddControlPoint (double fPos)
 Appends a control point. SortControlPoints() must be called to before evaluating the curve.
 
void RecomputeExtents ()
 Updates the min/max X value that can be retrieved through GetExtents(). More...
 
void QueryExtents (double &ref_fMinx, double &ref_fMaxx) const
 returns the min and max position value across all control points. More...
 
void QueryExtremeValues (double &ref_fMinVal, double &ref_fMaxVal) const
 Returns the min and max Y value across the curve. For this information to be available, the linear approximation of the curve must have been computed, otherwise stale values will be returned.
 
ezUInt32 GetNumControlPoints () const
 Returns the number of control points.
 
const ControlPointGetControlPoint (ezUInt32 uiIdx) const
 Const access to a control point.
 
ControlPointModifyControlPoint (ezUInt32 uiIdx)
 Non-const access to a control point. If you modify the position, SortControlPoints() has to be called before evaluating the curve.
 
void SortControlPoints ()
 Sorts the control point arrays by their position. The CPs have to be sorted before calling Evaluate(), otherwise the result will be wrong.
 
double Evaluate (double fPosition) const
 Evaluates the curve at the given position (x coordinate) and returns the value Y value at that point. More...
 
double ConvertNormalizedPos (double fPos) const
 Takes the normalized x coordinate [0;1] and converts it into a valid position on the curve. More...
 
double NormalizeValue (double value) const
 Takes a value (typically returned by Evaluate()) and normalizes it into [0;1] range. More...
 
ezUInt64 GetHeapMemoryUsage () const
 How much heap memory the curve uses.
 
void Save (ezStreamWriter &inout_stream) const
 Stores the current state in a stream.
 
void Load (ezStreamReader &inout_stream)
 Restores the state from a stream.
 
void CreateLinearApproximation (double fMaxError=0.01, ezUInt8 uiMaxSubDivs=8)
 Pre-computes sample points for linear interpolation that approximate the curve within the allowed error threshold. More...
 
const ezHybridArray< ezVec2d, 24 > & GetLinearApproximation () const
 
void ClampTangents ()
 Adjusts the tangents such that the curve cannot make loopings.
 
void ApplyTangentModes ()
 Adjusts the tangents in accordance to the specified tangent modes at each control point. More...
 
void MakeFixedLengthTangentLeft (ezUInt32 uiCpIdx)
 Typically called by ApplyTangentModes() for specific control points. Control points must be in sorted order.
 
void MakeFixedLengthTangentRight (ezUInt32 uiCpIdx)
 Typically called by ApplyTangentModes() for specific control points. Control points must be in sorted order.
 
void MakeLinearTangentLeft (ezUInt32 uiCpIdx)
 Typically called by ApplyTangentModes() for specific control points. Control points must be in sorted order.
 
void MakeLinearTangentRight (ezUInt32 uiCpIdx)
 Typically called by ApplyTangentModes() for specific control points. Control points must be in sorted order.
 
void MakeAutoTangentLeft (ezUInt32 uiCpIdx)
 
void MakeAutoTangentRight (ezUInt32 uiCpIdx)
 

Detailed Description

A 1D curve for animating a single value over time.

Member Function Documentation

◆ ApplyTangentModes()

void ezCurve1D::ApplyTangentModes ( )

Adjusts the tangents in accordance to the specified tangent modes at each control point.

Note
All control points must already be in sorted order, so call SortControlPoints() first if necessary.

◆ ConvertNormalizedPos()

double ezCurve1D::ConvertNormalizedPos ( double  fPos) const

Takes the normalized x coordinate [0;1] and converts it into a valid position on the curve.

Note
This only works when the curve extents are available. See QueryExtents() and RecomputeExtents().
See also
RecomputeExtents
QueryExtents

◆ CreateLinearApproximation()

void ezCurve1D::CreateLinearApproximation ( double  fMaxError = 0.01,
ezUInt8  uiMaxSubDivs = 8 
)

Pre-computes sample points for linear interpolation that approximate the curve within the allowed error threshold.

Note
All control points must already be in sorted order, so call SortControlPoints() first if necessary.
Todo:
Since we do this, we actually don't need the linear approximation anymore and could just evaluate the full curve

◆ Evaluate()

double ezCurve1D::Evaluate ( double  fPosition) const

Evaluates the curve at the given position (x coordinate) and returns the value Y value at that point.

This uses the linear approximation of the curve, so CreateLinearApproximation() must have been called first.

See also
CreateLinearApproximation

◆ NormalizeValue()

double ezCurve1D::NormalizeValue ( double  value) const

Takes a value (typically returned by Evaluate()) and normalizes it into [0;1] range.

Note
This only works when the linear approximation of the curve has been computed first.

◆ QueryExtents()

void ezCurve1D::QueryExtents ( double &  ref_fMinx,
double &  ref_fMaxx 
) const

returns the min and max position value across all control points.

The returned values are only up to date if either SortControlPoints() or RecomputeExtents() was called before. Otherwise they will contain stale values.

◆ RecomputeExtents()

void ezCurve1D::RecomputeExtents ( )

Updates the min/max X value that can be retrieved through GetExtents().

This is automatically done when SortControlPoints() is called. It can be called manually, if the information is required without sorting.


The documentation for this class was generated from the following files: