Gamedev Framework (gf)  0.11.0
A C++14 framework for 2D games
Curves.h
1 /*
2  * Gamedev Framework (gf)
3  * Copyright (C) 2016-2018 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 "Portability.h"
28 
29 namespace gf {
30 #ifndef DOXYGEN_SHOULD_SKIP_THIS
31 inline namespace v1 {
32 #endif
33 
39  class GF_API Line : public Curve {
40  public:
47  Line(Vector2f p0, Vector2f p1);
48 
49  virtual std::size_t getPointCount() const override;
50 
51  virtual Vector2f getPoint(std::size_t index) const override;
52 
53  private:
54  Vector2f m_p0;
55  Vector2f m_p1;
56  };
57 
63  class GF_API QuadraticBezierCurve : public Curve {
64  public:
73  QuadraticBezierCurve(Vector2f p0, Vector2f p1, Vector2f p2, std::size_t pointCount = 20);
74 
75  virtual std::size_t getPointCount() const override;
76 
77  virtual Vector2f getPoint(std::size_t index) const override;
78 
79  private:
80  std::size_t m_pointCount;
81  Vector2f m_p0;
82  Vector2f m_p1;
83  Vector2f m_p2;
84  };
85 
91  class GF_API CubicBezierCurve : public Curve {
92  public:
102  CubicBezierCurve(Vector2f p0, Vector2f p1, Vector2f p2, Vector2f p3, std::size_t pointCount = 30);
103 
104  virtual std::size_t getPointCount() const override;
105 
106  virtual Vector2f getPoint(std::size_t index) const override;
107 
108  private:
109  std::size_t m_pointCount;
110  Vector2f m_p0;
111  Vector2f m_p1;
112  Vector2f m_p2;
113  Vector2f m_p3;
114  };
115 
122  class GF_API CompoundCurve : public Curve {
123  public:
129  CompoundCurve(Vector2f origin = Vector2f(0, 0));
130 
137  CompoundCurve& setOrigin(Vector2f origin);
138 
144  CompoundCurve& lineTo(Vector2f p1);
145 
153  CompoundCurve& quadraticCurveTo(Vector2f p1, Vector2f p2, std::size_t pointCount = 20);
154 
163  CompoundCurve& cubicCurveTo(Vector2f p1, Vector2f p2, Vector2f p3, std::size_t pointCount = 30);
164 
170  void close();
171 
179  CompoundCurve& clear(Vector2f origin = Vector2f(0, 0));
180 
181  virtual std::size_t getPointCount() const override;
182 
183  virtual Vector2f getPoint(std::size_t index) const override;
184 
185  private:
186  std::vector<Vector2f> m_points;
187  };
188 
189 #ifndef DOXYGEN_SHOULD_SKIP_THIS
190 }
191 #endif
192 }
193 
194 #endif // GF_CURVES_H
A compound curve.
Definition: Curves.h:122
A line.
Definition: Curves.h:39
A quadratic Bézier curve.
Definition: Curves.h:63
A curve is a one dimension object.
Definition: Curve.h:52
Vector< float, 2 > Vector2f
A float vector with 2 components.
Definition: Vector.h:1107
The namespace for gf classes.
Definition: Action.h:35
A cubic Bézier curve.
Definition: Curves.h:91