CUGL 1.3
Cornell University Game Library
CUEasingBezier.h
1 //
2 // CUEasingBezier.h
3 // Cornell University Game Library (CUGL)
4 //
5 // This module provides easing function support for sophisticated tweening.
6 // This module provides a single class that can represent any bezier easing
7 // function. This provides the user with more flexibility than the
8 // EasingFunction factory.
9 //
10 // These classe uses our standard shared-pointer architecture.
11 //
12 // 1. The constructor does not perform any initialization; it just sets all
13 // attributes to their defaults.
14 //
15 // 2. All initialization takes place via init methods, which can fail if an
16 // object is initialized more than once.
17 //
18 // 3. All allocation takes place via static constructors which return a shared
19 // pointer.
20 //
21 // CUGL MIT License:
22 // This software is provided 'as-is', without any express or implied
23 // warranty. In no event will the authors be held liable for any damages
24 // arising from the use of this software.
25 //
26 // Permission is granted to anyone to use this software for any purpose,
27 // including commercial applications, and to alter it and redistribute it
28 // freely, subject to the following restrictions:
29 //
30 // 1. The origin of this software must not be misrepresented; you must not
31 // claim that you wrote the original software. If you use this software
32 // in a product, an acknowledgment in the product documentation would be
33 // appreciated but is not required.
34 //
35 // 2. Altered source versions must be plainly marked as such, and must not
36 // be misrepresented as being the original software.
37 //
38 // 3. This notice may not be removed or altered from any source distribution.
39 //
40 // Author: Sophie Huang and Walker White
41 // Version: 3/12/17
42 //
43 #ifndef __CU_EASING_BEZIER_H__
44 #define __CU_EASING_BEZIER_H__
45 
46 #include <cugl/math/CUVec2.h>
47 #include "CUEasingFunction.h"
48 #include <vector>
49 #include <memory>
50 
51 namespace cugl {
52 
65 class EasingBezier : public std::enable_shared_from_this<EasingBezier> {
66 #pragma mark -
67 #pragma mark Internal Helpers
68 protected:
75 
77  std::vector<float> _rootset;
78 
89  void solveQuadraticEquation(float a, float b, float c);
90 
102  void solveCubicEquation(float a, float b, float c, float d);
103 
104 
105 #pragma mark -
106 #pragma mark Constructors
107 public:
114  EasingBezier();
115 
120 
126  void dispose();
127 
133  bool init() {
135  }
136 
147  bool init(EasingFunction::Type type);
148 
163  bool init(float x1, float y1, float x2, float y2);
164 
177  bool init(const Vec2& p1, const Vec2& p2) {
178  return init(p1.x,p1.y,p2.x,p2.y);
179  }
180 
181 #pragma mark -
182 #pragma mark Static Constructors
183 
188  static std::shared_ptr<EasingBezier> alloc() {
189  std::shared_ptr<EasingBezier> result = std::make_shared<EasingBezier>();
190  return (result->init() ? result : nullptr);
191  }
192 
203  static std::shared_ptr<EasingBezier> alloc(EasingFunction::Type type) {
204  std::shared_ptr<EasingBezier> result = std::make_shared<EasingBezier>();
205  return (result->init(type) ? result : nullptr);
206  }
207 
222  static std::shared_ptr<EasingBezier> alloc(float x1, float y1, float x2, float y2) {
223  std::shared_ptr<EasingBezier> result = std::make_shared<EasingBezier>();
224  return (result->init(x1,y1,x2,y2) ? result : nullptr);
225  }
226 
239  static std::shared_ptr<EasingBezier> alloc(const Vec2& p1, const Vec2& p2) {
240  std::shared_ptr<EasingBezier> result = std::make_shared<EasingBezier>();
241  return (result->init(p1,p2) ? result : nullptr);
242  }
243 
244 #pragma mark -
245 #pragma mark Easing Support
246 
254  float evaluate(float t);
255 
264  std::function<float(float)> getEvaluator();
265 
266 };
267 
268 }
269 
270 #endif /* __CU_EASING_BEZIER_H__ */
cugl::EasingBezier::solveCubicEquation
void solveCubicEquation(float a, float b, float c, float d)
cugl::EasingBezier::dispose
void dispose()
cugl::EasingFunction::Type::LINEAR
cugl::EasingBezier::~EasingBezier
~EasingBezier()
Definition: CUEasingBezier.h:119
cugl::Vec2::x
float x
Definition: CUVec2.h:66
cugl::EasingBezier::_c3
Vec2 _c3
Definition: CUEasingBezier.h:74
cugl::EasingBezier::getEvaluator
std::function< float(float)> getEvaluator()
cugl::EasingBezier::alloc
static std::shared_ptr< EasingBezier > alloc(EasingFunction::Type type)
Definition: CUEasingBezier.h:203
cugl::EasingBezier::_rootset
std::vector< float > _rootset
Definition: CUEasingBezier.h:77
cugl::EasingBezier
Definition: CUEasingBezier.h:65
cugl::EasingBezier::alloc
static std::shared_ptr< EasingBezier > alloc(const Vec2 &p1, const Vec2 &p2)
Definition: CUEasingBezier.h:239
cugl::EasingBezier::_c2
Vec2 _c2
Definition: CUEasingBezier.h:72
cugl::Vec2::y
float y
Definition: CUVec2.h:68
cugl::EasingBezier::solveQuadraticEquation
void solveQuadraticEquation(float a, float b, float c)
cugl::EasingBezier::_c1
Vec2 _c1
Definition: CUEasingBezier.h:70
cugl::Vec2
Definition: CUVec2.h:61
cugl::EasingBezier::evaluate
float evaluate(float t)
cugl::EasingBezier::alloc
static std::shared_ptr< EasingBezier > alloc()
Definition: CUEasingBezier.h:188
cugl::EasingFunction::Type
Type
Definition: CUEasingFunction.h:66
cugl::EasingBezier::alloc
static std::shared_ptr< EasingBezier > alloc(float x1, float y1, float x2, float y2)
Definition: CUEasingBezier.h:222
cugl::EasingBezier::init
bool init(const Vec2 &p1, const Vec2 &p2)
Definition: CUEasingBezier.h:177
cugl::EasingBezier::init
bool init()
Definition: CUEasingBezier.h:133
cugl::EasingBezier::EasingBezier
EasingBezier()