CUGL 1.3
Cornell University Game Library
CURotateAction.h
1 //
2 // CURotateAction.h
3 // Cornell University Game Library (CUGL)
4 //
5 // This module provides support for the rotation actions. Rotation can specified
6 // as either the end angle or the rotation amount.
7 //
8 // These classes use our standard shared-pointer architecture.
9 //
10 // 1. The constructor does not perform any initialization; it just sets all
11 // attributes to their defaults.
12 //
13 // 2. All initialization takes place via init methods, which can fail if an
14 // object is initialized more than once.
15 //
16 // 3. All allocation takes place via static constructors which return a shared
17 // pointer.
18 //
19 // CUGL MIT License:
20 // This software is provided 'as-is', without any express or implied
21 // warranty. In no event will the authors be held liable for any damages
22 // arising from the use of this software.
23 //
24 // Permission is granted to anyone to use this software for any purpose,
25 // including commercial applications, and to alter it and redistribute it
26 // freely, subject to the following restrictions:
27 //
28 // 1. The origin of this software must not be misrepresented; you must not
29 // claim that you wrote the original software. If you use this software
30 // in a product, an acknowledgment in the product documentation would be
31 // appreciated but is not required.
32 //
33 // 2. Altered source versions must be plainly marked as such, and must not
34 // be misrepresented as being the original software.
35 //
36 // 3. This notice may not be removed or altered from any source distribution.
37 //
38 // Author: Sophie Huang and Walker White
39 // Version: 3/12/17
40 //
41 #ifndef __CU_ROTATE_ACTION_H__
42 #define __CU_ROTATE_ACTION_H__
43 
44 #include "CUAction.h"
45 
46 namespace cugl {
47 
48 #pragma mark -
49 #pragma mark RotateBy
50 
67 class RotateBy : public Action {
68 protected:
70  float _delta;
71 
72 public:
73 #pragma mark Constructors
74 
80  RotateBy() : _delta(0) {}
81 
85  ~RotateBy() { dispose(); }
86 
92  void dispose() { _delta = 0; }
93 
101  bool init() {
102  return init(0.0f, 0.0f);
103  }
104 
116  bool init(float delta) {
117  return init(delta, 0.0f);
118  }
119 
132  bool init(float delta, float time);
133 
134 #pragma mark Static Constructors
135 
142  static std::shared_ptr<RotateBy> alloc() {
143  std::shared_ptr<RotateBy> result = std::make_shared<RotateBy>();
144  return (result->init() ? result : nullptr);
145  }
146 
158  static std::shared_ptr<RotateBy> alloc(float delta) {
159  std::shared_ptr<RotateBy> result = std::make_shared<RotateBy>();
160  return (result->init(delta) ? result : nullptr);
161  }
162 
175  static std::shared_ptr<RotateBy> alloc(float delta, float time) {
176  std::shared_ptr<RotateBy> result = std::make_shared<RotateBy>();
177  return (result->init(delta, time) ? result : nullptr);
178  }
179 
180 #pragma mark Attributes
181 
189  float getDelta() const { return _delta; }
190 
199  void setDelta(float delta) { _delta = delta; }
200 
201 #pragma mark Animation Methods
202 
207  virtual std::shared_ptr<Action> clone() override;
208 
219  virtual void update(const std::shared_ptr<Node>& target, Uint64* state, float dt) override;
220 
221 #pragma mark Debugging Methods
222 
232  virtual std::string toString(bool verbose = false) const override;
233 };
234 
235 
236 #pragma mark -
237 #pragma mark RotateTo
238 
254 class RotateTo : public Action {
255 protected:
257  float _angle;
258 
259 public:
260 #pragma mark Constructors
261 
267  RotateTo() : _angle(0) {}
268 
273 
279  void dispose() { _angle = 0; }
280 
290  bool init() {
291  return init(0.0f, 0.0f);
292  }
293 
306  bool init(float angle) {
307  return init(angle, 0.0f);
308  }
309 
323  bool init(float angle, float time);
324 
325 #pragma mark Static Constructors
326 
335  static std::shared_ptr<RotateTo> alloc() {
336  std::shared_ptr<RotateTo> result = std::make_shared<RotateTo>();
337  return (result->init() ? result : nullptr);
338  }
339 
352  static std::shared_ptr<RotateTo> alloc(float angle) {
353  std::shared_ptr<RotateTo> result = std::make_shared<RotateTo>();
354  return (result->init(angle) ? result : nullptr);
355  }
356 
370  static std::shared_ptr<RotateTo> alloc(float angle, float time) {
371  std::shared_ptr<RotateTo> result = std::make_shared<RotateTo>();
372  return (result->init(angle,time) ? result : nullptr);
373  }
374 
375 #pragma mark Attributes
376 
384  float getAngle() const { return _angle; }
385 
394  void setAngle(float angle) { _angle = angle; }
395 
396 #pragma mark Animation Methods
397 
402  virtual std::shared_ptr<Action> clone() override;
403 
413  virtual void load(const std::shared_ptr<Node>& target, Uint64* state) override;
414 
425  virtual void update(const std::shared_ptr<Node>& target, Uint64* state, float dt) override;
426 
427 #pragma mark Debugging Methods
428 
438  virtual std::string toString(bool verbose = false) const override;
439 };
440 
441 }
442 #endif /* __CU_ROTATE_ACTION_H__ */
cugl::Action
Definition: CUAction.h:70
cugl::RotateTo::~RotateTo
~RotateTo()
Definition: CURotateAction.h:272
cugl::RotateBy::_delta
float _delta
Definition: CURotateAction.h:70
cugl::RotateBy::clone
virtual std::shared_ptr< Action > clone() override
cugl::RotateBy::alloc
static std::shared_ptr< RotateBy > alloc()
Definition: CURotateAction.h:142
cugl::RotateBy::init
bool init(float delta)
Definition: CURotateAction.h:116
cugl::RotateBy::alloc
static std::shared_ptr< RotateBy > alloc(float delta, float time)
Definition: CURotateAction.h:175
cugl::RotateTo::_angle
float _angle
Definition: CURotateAction.h:257
cugl::RotateTo::alloc
static std::shared_ptr< RotateTo > alloc(float angle, float time)
Definition: CURotateAction.h:370
cugl::RotateTo::RotateTo
RotateTo()
Definition: CURotateAction.h:267
cugl::RotateTo::setAngle
void setAngle(float angle)
Definition: CURotateAction.h:394
cugl::RotateTo::alloc
static std::shared_ptr< RotateTo > alloc(float angle)
Definition: CURotateAction.h:352
cugl::RotateTo::init
bool init()
Definition: CURotateAction.h:290
cugl::RotateTo::clone
virtual std::shared_ptr< Action > clone() override
cugl::RotateTo::init
bool init(float angle)
Definition: CURotateAction.h:306
cugl::RotateBy::alloc
static std::shared_ptr< RotateBy > alloc(float delta)
Definition: CURotateAction.h:158
cugl::RotateTo::update
virtual void update(const std::shared_ptr< Node > &target, Uint64 *state, float dt) override
cugl::RotateTo::dispose
void dispose()
Definition: CURotateAction.h:279
cugl::RotateBy::toString
virtual std::string toString(bool verbose=false) const override
cugl::RotateBy::getDelta
float getDelta() const
Definition: CURotateAction.h:189
cugl::RotateBy::init
bool init()
Definition: CURotateAction.h:101
cugl::RotateTo::load
virtual void load(const std::shared_ptr< Node > &target, Uint64 *state) override
cugl::RotateBy::~RotateBy
~RotateBy()
Definition: CURotateAction.h:85
cugl::RotateBy::RotateBy
RotateBy()
Definition: CURotateAction.h:80
cugl::RotateBy::update
virtual void update(const std::shared_ptr< Node > &target, Uint64 *state, float dt) override
cugl::RotateBy::dispose
void dispose()
Definition: CURotateAction.h:92
cugl::RotateTo::toString
virtual std::string toString(bool verbose=false) const override
cugl::RotateTo::getAngle
float getAngle() const
Definition: CURotateAction.h:384
cugl::RotateBy
Definition: CURotateAction.h:67
cugl::RotateTo::alloc
static std::shared_ptr< RotateTo > alloc()
Definition: CURotateAction.h:335
cugl::RotateBy::setDelta
void setDelta(float delta)
Definition: CURotateAction.h:199
cugl::RotateTo
Definition: CURotateAction.h:254