Plasma Engine  2.0
Loading...
Searching...
No Matches
Curve1D.h
1#pragma once
2
3#include <Foundation/Basics.h>
4#include <Foundation/Containers/HybridArray.h>
5#include <Foundation/Math/Color.h>
6#include <Foundation/Math/Vec2.h>
7#include <Foundation/Types/Enum.h>
8
10class plStreamReader;
11
12struct PL_FOUNDATION_DLL plCurveTangentMode
13{
14 using StorageType = plUInt8;
15
16 enum Enum
17 {
18 Bezier,
19 FixedLength,
20 Linear,
21 // Constant,
22 Auto,
23 Default = Auto
24 };
25};
26
28class PL_FOUNDATION_DLL plCurve1D
29{
30public:
33 {
34 PL_DECLARE_POD_TYPE();
35
37
40
45
46 plEnum<plCurveTangentMode> m_TangentModeLeft;
47 plEnum<plCurveTangentMode> m_TangentModeRight;
48
49 plUInt16 m_uiOriginalIndex;
50
51 PL_ALWAYS_INLINE bool operator<(const ControlPoint& rhs) const { return m_Position.x < rhs.m_Position.x; }
52 };
53
54public:
55 plCurve1D();
56
58 void Clear();
59
61 bool IsEmpty() const;
62
64 ControlPoint& AddControlPoint(double fPos);
65
70 void RecomputeExtents();
71
76 void QueryExtents(double& ref_fMinx, double& ref_fMaxx) const;
77
81 void QueryExtremeValues(double& ref_fMinVal, double& ref_fMaxVal) const;
82
84 plUInt32 GetNumControlPoints() const;
85
87 const ControlPoint& GetControlPoint(plUInt32 uiIdx) const { return m_ControlPoints[uiIdx]; }
88
91 ControlPoint& ModifyControlPoint(plUInt32 uiIdx) { return m_ControlPoints[uiIdx]; }
92
95 void SortControlPoints();
96
102 double Evaluate(double fPosition) const;
103
110 double ConvertNormalizedPos(double fPos) const;
111
115 double NormalizeValue(double value) const;
116
118 plUInt64 GetHeapMemoryUsage() const;
119
121 void Save(plStreamWriter& inout_stream) const;
122
124 void Load(plStreamReader& inout_stream);
125
129 void CreateLinearApproximation(double fMaxError = 0.01, plUInt8 uiMaxSubDivs = 8);
130
131 const plHybridArray<plVec2d, 24>& GetLinearApproximation() const { return m_LinearApproximation; }
132
134 void ClampTangents();
135
139 void ApplyTangentModes();
140
142 void MakeFixedLengthTangentLeft(plUInt32 uiCpIdx);
144 void MakeFixedLengthTangentRight(plUInt32 uiCpIdx);
146 void MakeLinearTangentLeft(plUInt32 uiCpIdx);
148 void MakeLinearTangentRight(plUInt32 uiCpIdx);
149
150 void MakeAutoTangentLeft(plUInt32 uiCpIdx);
151 void MakeAutoTangentRight(plUInt32 uiCpIdx);
152
153private:
154 void RecomputeLinearApproxExtremes();
155 void ApproximateMinMaxValues(const ControlPoint& lhs, const ControlPoint& rhs, double& fMinY, double& fMaxY);
156 void ApproximateCurve(
157 const plVec2d& p0, const plVec2d& p1, const plVec2d& p2, const plVec2d& p3, double fMaxErrorX, double fMaxErrorY, plInt32 iSubDivLeft);
158 void ApproximateCurvePiece(const plVec2d& p0, const plVec2d& p1, const plVec2d& p2, const plVec2d& p3, double tLeft, const plVec2d& pLeft,
159 double tRight, const plVec2d& pRight, double fMaxErrorX, double fMaxErrorY, plInt32 iSubDivLeft);
160 plInt32 FindApproxControlPoint(double x) const;
161
162 double m_fMinX, m_fMaxX;
163 double m_fMinY, m_fMaxY;
164 plHybridArray<ControlPoint, 8> m_ControlPoints;
165 plHybridArray<plVec2d, 24> m_LinearApproximation;
166};
A 1D curve for animating a single value over time.
Definition Curve1D.h:29
const ControlPoint & GetControlPoint(plUInt32 uiIdx) const
Const access to a control point.
Definition Curve1D.h:87
ControlPoint & ModifyControlPoint(plUInt32 uiIdx)
Non-const access to a control point. If you modify the position, SortControlPoints() has to be called...
Definition Curve1D.h:91
A hybrid array uses in-place storage to handle the first few elements without any allocation....
Definition HybridArray.h:12
Interface for binary in (read) streams.
Definition Stream.h:22
Interface for binary out (write) streams.
Definition Stream.h:107
Stores position and tangents to control spline interpolation.
Definition Curve1D.h:33
plVec2d m_Position
The position (x,y) of the control point.
Definition Curve1D.h:39
plVec2 m_RightTangent
The tangent for the curve segment to the right that affects the spline interpolation.
Definition Curve1D.h:44
plVec2 m_LeftTangent
The tangent for the curve segment to the left that affects the spline interpolation.
Definition Curve1D.h:42
Definition Curve1D.h:13
A custom enum implementation that allows to define the underlying storage type to control its memory ...
Definition Enum.h:37