Gamedev Framework (gf)  0.17.0
A C++14 framework for 2D games
Curves.h
1 /*
2  * Gamedev Framework (gf)
3  * Copyright (C) 2016-2019 Julien Bernard
4  *
5  * This software is provided 'as-is', without any express or implied
6  * warranty. In no event will the authors be held liable for any damages
7  * arising from the use of this software.
8  *
9  * Permission is granted to anyone to use this software for any purpose,
10  * including commercial applications, and to alter it and redistribute it
11  * freely, subject to the following restrictions:
12  *
13  * 1. The origin of this software must not be misrepresented; you must not
14  * claim that you wrote the original software. If you use this software
15  * in a product, an acknowledgment in the product documentation would be
16  * appreciated but is not required.
17  * 2. Altered source versions must be plainly marked as such, and must not be
18  * misrepresented as being the original software.
19  * 3. This notice may not be removed or altered from any source distribution.
20  */
21 #ifndef GF_CURVES_H
22 #define GF_CURVES_H
23 
24 #include <vector>
25 
26 #include "Curve.h"
27 #include "Polyline.h"
28 #include "Portability.h"
29 
30 namespace gf {
31 #ifndef DOXYGEN_SHOULD_SKIP_THIS
32 inline namespace v1 {
33 #endif
34 
40  class GF_API Line : public Curve {
41  public:
48  Line(Vector2f p0, Vector2f p1);
49 
50  virtual std::size_t getPointCount() const override;
51 
52  virtual Vector2f getPoint(std::size_t index) const override;
53 
54  private:
55  Vector2f m_p0;
56  Vector2f m_p1;
57  };
58 
64  class GF_API QuadraticBezierCurve : public Curve {
65  public:
74  QuadraticBezierCurve(Vector2f p0, Vector2f p1, Vector2f p2, std::size_t pointCount = 20);
75 
76  virtual std::size_t getPointCount() const override;
77 
78  virtual Vector2f getPoint(std::size_t index) const override;
79 
80  private:
81  std::size_t m_pointCount;
82  Vector2f m_p0;
83  Vector2f m_p1;
84  Vector2f m_p2;
85  };
86 
92  class GF_API CubicBezierCurve : public Curve {
93  public:
103  CubicBezierCurve(Vector2f p0, Vector2f p1, Vector2f p2, Vector2f p3, std::size_t pointCount = 30);
104 
105  virtual std::size_t getPointCount() const override;
106 
107  virtual Vector2f getPoint(std::size_t index) const override;
108 
109  private:
110  std::size_t m_pointCount;
111  Vector2f m_p0;
112  Vector2f m_p1;
113  Vector2f m_p2;
114  Vector2f m_p3;
115  };
116 
122  class GF_API SplineCurve : public Curve {
123  public:
133  enum Type {
137  };
138 
145  SplineCurve(Type type = Centripetal, std::size_t pointCount = 30);
146 
152  void setControlPoints(const Polyline& line);
153 
154  virtual std::size_t getPointCount() const override;
155 
156  virtual Vector2f getPoint(std::size_t index) const override;
157 
158  private:
159  Type m_type;
160  std::size_t m_pointCount;
161  std::vector<Vector2f> m_points;
162  };
163 
170  class GF_API CompoundCurve : public Curve {
171  public:
177  CompoundCurve(Vector2f origin = Vector2f(0, 0));
178 
185  CompoundCurve& setOrigin(Vector2f origin);
186 
192  CompoundCurve& lineTo(Vector2f p1);
193 
201  CompoundCurve& quadraticCurveTo(Vector2f p1, Vector2f p2, std::size_t pointCount = 20);
202 
211  CompoundCurve& cubicCurveTo(Vector2f p1, Vector2f p2, Vector2f p3, std::size_t pointCount = 30);
212 
218  void close();
219 
227  CompoundCurve& clear(Vector2f origin = Vector2f(0, 0));
228 
229  virtual std::size_t getPointCount() const override;
230 
231  virtual Vector2f getPoint(std::size_t index) const override;
232 
233  private:
234  std::vector<Vector2f> m_points;
235  };
236 
237 
238 
239 #ifndef DOXYGEN_SHOULD_SKIP_THIS
240 }
241 #endif
242 }
243 
244 #endif // GF_CURVES_H
A compound curve.
Definition: Curves.h:170
Type
The type of the spline.
Definition: Curves.h:133
A uniform spline ( )
Definition: Curves.h:134
A polyline.
Definition: Polyline.h:45
A uniform spline ( )
Definition: Curves.h:135
A line.
Definition: Curves.h:40
A Catmull–Rom spline.
Definition: Curves.h:122
A quadratic Bézier curve.
Definition: Curves.h:64
A curve is a one dimension object.
Definition: Curve.h:52
Vector< float, 2 > Vector2f
A float vector with 2 components.
Definition: Vector.h:1117
The namespace for gf classes.
Definition: Action.h:35
A cubic Bézier curve.
Definition: Curves.h:92
A uniform spline ( )
Definition: Curves.h:136