RioEngine  0.1
My first attempt to create a 3D WYSIWYG Game Engine
cactioninterval.h
Go to the documentation of this file.
1 //--------------------------------------------------------------- @License begins
2 // cocos2d for iPhone: http://www.cocos2d-iphone.org
3 // -> This file was ported to C++ by Leopoldo Lomas Flores just for fun.
4 // I suggest you get the official C++ version of this file from:
5 // http://www.cocos2d-x.org/
6 //
7 // Copyright (c) 2008-2011 Ricardo Quesada
8 // Copyright (c) 2011 Zynga Inc.
9 // Copyright (c) 2013-2014 Cocos2D Authors
10 //
11 // Permission is hereby granted, free of charge, to any person obtaining a copy
12 // of this software and associated documentation files (the "Software"), to deal
13 // in the Software without restriction, including without limitation the rights
14 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15 // copies of the Software, and to permit persons to whom the Software is
16 // furnished to do so, subject to the following conditions:
17 //
18 // The above copyright notice and this permission notice shall be included in
19 // all copies or substantial portions of the Software.
20 //
21 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
27 // THE SOFTWARE.
28 //--------------------------------------------------------------- @License ends
29 
30 #ifndef RIOENGINE_CENGINE_CACTIONINTERVAL_H_
31 #define RIOENGINE_CENGINE_CACTIONINTERVAL_H_
32 
33 #include "bullet/btBulletDynamicsCommon.h"
34 #include "cengine/fastdelegate.h"
35 #include "cengine/caction.h"
36 
37 class CGameObject;
38 
40  Q_OBJECT
41 public:
43  explicit CActionInterval(float duration);
44 
45  virtual void initWithDuration(float duration);
46  virtual void startWithTarget(CGameObject* target);
47  virtual bool isDone();
48  virtual void step(float dt);
49  virtual CActionInterval* reverse();
50 
51 private:
52  float m_elapsed;
53  bool m_firstTick;
54 };
55 
56 class CDelayTime : public CActionInterval {
57 public:
59  CDelayTime(float duration);
60 };
61 
62 class CMoveTo : public CActionInterval {
63 public:
65  CMoveTo(float duration, btVector3& position);
66 
67  virtual void startWithTarget(CGameObject* target);
68  virtual void update(float t);
69 
70 protected:
71  btVector3 m_endPosition;
72  btVector3 m_startPosition;
73  btVector3 m_delta;
74 };
75 
76 class CMoveBy : public CMoveTo {
77 public:
78  CMoveBy() : CMoveTo() {}
79  CMoveBy(float duration, btVector3& position);
80 
81  virtual void startWithTarget(CGameObject* target);
82  virtual CActionInterval* reverse();
83 };
84 
85 class CRotateTo : public CActionInterval {
86 public:
87  CRotateTo() { RE_ASSERT(false); /*Default constructor not supported*/ }
88  CRotateTo(float duration, btVector3& angle);
89 
90  virtual void initWithDuration(float duration, btVector3& angle);
91  virtual void startWithTarget(CGameObject* target);
92  virtual void update(float t);
93 
94 private:
95  btVector3 m_dstAngle;
96  btQuaternion m_startAngle;
97  btVector3 m_diffAngle;
98 };
99 
100 class CRotateBy : public CRotateTo {
101 public:
102  CRotateBy() { RE_ASSERT(false); /*Default constructor not supported*/ }
103  CRotateBy(float duration, btVector3& angle);
104 
105  virtual void initWithDuration(float duration, btVector3& angle);
106  virtual void startWithTarget(CGameObject* target);
107  virtual void update(float t);
108 
109 private:
110  btVector3 m_dstAngle;
111  btQuaternion m_startAngle;
112 };
113 
114 class CScaleTo : public CActionInterval {
115 public:
116  CScaleTo() { RE_ASSERT(false); /*Default constructor not supported*/ }
117  CScaleTo(float duration, float sx, float sy, float sz);
118  CScaleTo(float duration, btVector3& scale);
119 
120  virtual void initWithDuration(float duration, float sx, float sy, float sz);
121  virtual void startWithTarget(CGameObject* target);
122  virtual void update(float);
123 
124 protected:
125  btVector3 m_startScale;
126  btVector3 m_endScale;
127  btVector3 m_deltaScale;
128 };
129 
130 class CScaleBy : public CScaleTo {
131 public:
132  CScaleBy(float duration, float sx, float sy, float sz);
133  CScaleBy(float duration, btVector3& scale);
134 
135  virtual void startWithTarget(CGameObject* target);
136  virtual CActionInterval* reverse();
137 };
138 
139 class CSequence : public CActionInterval {
140  Q_OBJECT
141 public:
142  CSequence();
143  ~CSequence();
144 
145  static CFiniteTimeAction* actions(CFiniteTimeAction* action, ...);
146 
147  CSequence* initHavingActions(CFiniteTimeAction* firstAction, CFiniteTimeAction* secondAction);
148  virtual void startWithTarget(CGameObject* target);
149  virtual void update(float t);
150  virtual void stop();
151  virtual CActionInterval* reverse();
152 
153 private:
154  CFiniteTimeAction *m_actions[2];
155  float m_split;
156  unsigned int m_last;
157 };
158 
160 #define MAKE_CALLBACK_METHOD(x) fastdelegate::MakeDelegate(this, x)
161 
162 class CCallFuncN : public CActionInterval {
163 public:
164  CCallFuncN() { LOG("Default constructor not supported"); }
165  explicit CCallFuncN(CallbackMethod);
166 
167  virtual void startWithTarget(CGameObject * target);
168  virtual void update(float);
169 
170 private:
171  CallbackMethod m_callbackMethod;
172 };
173 
174 #endif // RIOENGINE_CENGINE_CACTIONINTERVAL_H_
virtual void startWithTarget(CGameObject *target)
btVector3 m_delta
#define LOG
Definition: macro.h:43
virtual void startWithTarget(CGameObject *target)
virtual void initWithDuration(float duration, btVector3 &angle)
virtual CActionInterval * reverse()
btVector3 m_startPosition
virtual void startWithTarget(CGameObject *target)
virtual void initWithDuration(float duration, float sx, float sy, float sz)
virtual void startWithTarget(CGameObject *target)
virtual void update(float t)
btVector3 m_endPosition
virtual void update(float t)
virtual void update(float)
CScaleBy(float duration, float sx, float sy, float sz)
CSequence * initHavingActions(CFiniteTimeAction *firstAction, CFiniteTimeAction *secondAction)
virtual void initWithDuration(float duration)
virtual void update(float)
virtual void startWithTarget(CGameObject *target)
virtual CActionInterval * reverse()
btVector3 m_endScale
virtual void startWithTarget(CGameObject *target)
virtual void startWithTarget(CGameObject *target)
virtual void update(float t)
virtual void startWithTarget(CGameObject *target)
btVector3 m_deltaScale
#define RE_ASSERT
Definition: macro.h:57
virtual void initWithDuration(float duration, btVector3 &angle)
virtual bool isDone()
virtual CActionInterval * reverse()
virtual void stop()
static CFiniteTimeAction * actions(CFiniteTimeAction *action,...)
virtual CActionInterval * reverse()
virtual void step(float dt)
virtual void update(float t)
btVector3 m_startScale
virtual void startWithTarget(CGameObject *target)
fastdelegate::FastDelegate0 CallbackMethod