-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDynamicObject.hpp
More file actions
299 lines (214 loc) · 6.69 KB
/
DynamicObject.hpp
File metadata and controls
299 lines (214 loc) · 6.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
//================================================//
#ifndef __DYNAMICOBJECT_HPP__
#define __DYNAMICOBJECT_HPP__
#define USE_KINEMATIC_GROUND 1
//================================================//
#include "stdafx.h"
#include "Base.hpp"
#include "Sparks.hpp"
#include "Camera.hpp"
#include "Sound.hpp"
//================================================//
class Switch;
class Trigger;
//================================================//
/* A class for interactive/moving objects in the world */
class DynamicObject{
public:
// Data structures for dynamic objects
typedef struct{
struct{
Ogre::Real step;
Ogre::Real length;
btScalar friction;
bool spline;
bool loop;
bool active;
std::vector<Ogre::Vector3> vectors;
} animation;
struct{
bool enabled;
unsigned int type;
unsigned int actionCode;
bool loop;
Ogre::Real timeout;
Ogre::String str;
int x;
bool hasNext;
Ogre::String next;
bool invisible;
Ogre::Real range;
} trigger;
Ogre::ColourValue colour;
Ogre::Vector3 offset;
Ogre::Quaternion rotationOffset;
unsigned int buffer;
} DYNAMIC_OBJECT_DATA, *PDYNAMIC_OBJECT_DATA;
typedef struct{
int type;
Ogre::Real range;
Ogre::Real inner, outer;
Ogre::ColourValue colour;
bool shadows;
bool hideNode;
Ogre::Real buffer;
} LIGHT_DATA, *PLIGHT_DATA;
enum{
STATE_IDLE = 0,
STATE_ACTIVATED = 1
};
enum{
ARG_NULL = 0,
ARG_ACTION = 1,
ARG_ACTIVATE,
ARG_DEACTIVATE,
ARG_OVERRIDE
};
enum{
TYPE_MOVING_OBJECT = 0,
TYPE_MOVING_KINEMATIC_OBJECT,
TYPE_ELEVATOR,
TYPE_ROTATING_DOOR,
TYPE_SLIDING_DOOR,
TYPE_SWITCH,
TYPE_NPC,
TYPE_STATIC_LIGHT,
TYPE_PULSE_LIGHT,
TYPE_FLICKER_LIGHT,
TYPE_MAGIC_CUBE,
TYPE_TRIGGER,
END
};
// --- //
DynamicObject(void);
virtual ~DynamicObject(void);
virtual void init(Ogre::SceneNode* node, btCollisionObject* colObj);
virtual void init(Ogre::SceneManager* mgr, Physics* physics, Ogre::SceneNode* node, btCollisionObject* colObj);
virtual void initTrigger(Ogre::SceneManager* mgr, Ogre::SceneNode* node, Sparks::Camera* camera){}
virtual void initLight(Ogre::SceneManager* mgr, Ogre::SceneNode* node){}
virtual void initSound(const char* file, bool loop = false);
virtual unsigned send(unsigned arg); // send a command
virtual unsigned recv(void);
virtual unsigned recv(unsigned arg);
// Data functions
virtual DYNAMIC_OBJECT_DATA* getData(void) const;
virtual void deleteData(void);
void setUserData(int n, void* data);
void freeUserData(void);
// Misc. functions
virtual void retrieve(void);
// Some virtual functions to be used by children
virtual void setupAnimation(void){}
virtual void setTriggerData(DYNAMIC_OBJECT_DATA* data){}
virtual void setLinkedObject(DynamicObject* obj){}
virtual void setLinkedObject(void* obj){}
virtual void setTimeout(Ogre::Real timeout){}
virtual void attachSwitch(Switch* _switch){}
virtual void setNextTrigger(Trigger* next){}
// Getter functions
const bool isActive(void) const;
const unsigned getState(void) const;
Ogre::SceneNode* getSceneNode(void) const;
const bool isRetrievable(void) const;
const bool isRetrieved(void) const;
static int findType(Ogre::SceneNode* node);
static unsigned int getTier(int type);
// Setter functions
void setState(const unsigned state){ m_state = state; }
void activate(void);
bool needsUpdate(void);
virtual void update(double timeSinceLastFrame) = 0;
protected:
#define USERDATA_SIZE 10
// This data is used for misc. values needed for certain dynamic objects
struct{
void* data[USERDATA_SIZE];
bool flags[USERDATA_SIZE];
} m_userData;
Ogre::SceneManager* m_pSceneMgr;
Ogre::SceneNode* m_pSceneNode;
btCollisionObject* m_collisionObject;
bool m_retrievable;
bool m_retrieved;
bool m_needsUpdate;
Ogre::Real m_updateRange;
unsigned m_state;
Sound* m_pSound;
bool m_hasSound;
Physics* m_physics;
};
//================================================//
typedef DynamicObject::DYNAMIC_OBJECT_DATA DynamicObjectData;
typedef DynamicObject::LIGHT_DATA LightData;
//================================================//
inline const bool DynamicObject::isActive(void) const
{ return (m_state > STATE_IDLE) ? true : false; }
inline const unsigned DynamicObject::getState(void) const
{ return m_state; }
inline Ogre::SceneNode* DynamicObject::getSceneNode(void) const
{ return m_pSceneNode; }
inline const bool DynamicObject::isRetrievable(void) const
{ return m_retrievable; }
inline const bool DynamicObject::isRetrieved(void) const
{ return m_retrieved; }
inline void DynamicObject::activate(void)
{ m_state = STATE_ACTIVATED; }
//================================================//
/* Here the inherited classes will be defined, such as door, elevator, lever, etc. */
//================================================//
//================================================//
/* Moving object, moves along a track of points in an infinite loop */
class MovingObject : public DynamicObject{
public:
MovingObject(void);
virtual ~MovingObject(void);
virtual void setupAnimation(void);
virtual void update(double timeSinceLastFrame);
protected:
Ogre::AnimationState* m_pAnimState;
bool m_loop;
};
//================================================//
//================================================//
/* Moving kinematic object, same as MovingObject, but applies friction to rigid bodies, e.g. a moving platform that holds the player */
class MovingKinematicObject : public MovingObject{
public:
MovingKinematicObject(void);
void setupAnimation(void);
void update(double timeSinceLastFrame);
protected:
btRigidBody* m_rigidBody;
};
//================================================//
//================================================//
class Elevator : public MovingObject
{
public:
Elevator(void);
unsigned send(unsigned arg);
void update(double timeSinceLastFrame);
protected:
};
//================================================//
//================================================//
/* Switch that can be turned on or off */
class Switch : public DynamicObject
{
public:
Switch(void);
void init(Ogre::SceneManager* mgr, Physics* physics, Ogre::SceneNode* node, btCollisionObject* colObj);
unsigned send(unsigned arg);
void setLinkedObject(DynamicObject* obj);
void deleteData(void);
void update(double timeSinceLastFrame);
protected:
DynamicObject* m_linkedObject;
bool m_linked;
};
//================================================//
inline void Switch::setLinkedObject(DynamicObject* obj)
{ m_linkedObject = obj; m_linked = true; }
//================================================//
//================================================//
#endif
//================================================//