Krig Game Engine
Loading...
Searching...
No Matches
Object.h
Go to the documentation of this file.
1
7#ifndef _OBJECT_H_
8#define _OBJECT_H_
9
10#include <GL/glut.h>
11#include <string>
12#include <map>
13
14#include "ObjectNode.h"
15#include "Sphere.h"
16#include "Quaternion.h"
17#include "ParticleSystem.h"
18#include "constants.h"
19
20extern "C" {
21 #include "luajit-2.1/lua.h"
22 #include "luajit-2.1/lualib.h"
23 #include "luajit-2.1/lauxlib.h"
24}
25
26// States
27#define DEAD 0
28#define NORMAL 1
29
30#define MAX_TEXTURES 32
31
32class Terrain;
33class Camera;
34
35class Object : public ObjectNode {
36 public:
37 Object();
38 virtual ~Object();
39
40 void processCollisions(Object*);
41
42 // virtual functions ///////////////////////
43 virtual void draw(Object*) = 0;
44 virtual void drawOutline(Object*) = 0;
45 virtual void drawShadow(Vector*) {}
46
47 virtual void handleCollision(Object*) = 0;
48
49 virtual void update(Vector*) = 0;
50 virtual void animate(const float&, Object*);
51
52 virtual void orientOnTerrain(Terrain *temp, const Quaternion &baseRotation) {}
53 virtual void setHeightFromTerrain(Terrain *temp, const float &offset){}
54
55 virtual void buildLuaObjectTable(lua_State *L);
56 virtual void transferLuaObjectTable(lua_State *L);
57
58 virtual void printTypeName() = 0;
60
61 void showCollisionBox();
62 void showControlTriangle();
63
64 float calcTriangleCenter(const float& p1, const float& p2, const float& p3);
65
66 void init();
67 void initSettings();
68 void cleanup();
69
70 void loadScript(const std::string&, lua_State* luaState);
71 void animateScript(const float&);
72 void unloadScript();
73
74 void setPosition(const GLfloat&, const GLfloat&, const GLfloat&);
75 void setPosition(const Vector&);
76 void setRotationAxis(const GLfloat&, const GLfloat&, const GLfloat&, const GLfloat&);
77 void setRotationAxis(const Vector&, const GLfloat&);
78 void setRotationEuler(const GLfloat&, const GLfloat&, const GLfloat&);
79 void setRotationEuler(const Vector&);
80 void setRotationQuaternion(const Quaternion&);
81 void setVelocity(const GLfloat&, const GLfloat&, const GLfloat&);
82 void setVelocity(const Vector&);
83 void setRotationVelocity(const GLfloat&, const GLfloat&, const GLfloat&);
84 void setRotationVelocity(const Vector&);
85
86 void setScale(const GLfloat&, const GLfloat&, const GLfloat&);
87 void setScale(const Vector&);
88 void setScaleRate(const GLfloat&, const GLfloat&, const GLfloat&);
89 void setScaleRate(const Vector&);
90
91 void setDrawEnabled(const bool &isDrawEnabled) { isDrawEnabled_ = isDrawEnabled; }
92 bool getDrawEnabled() { return isDrawEnabled_; }
93
94 bool getInView() { return isInView_; }
95 void setParticleSystem(const int&);
96
97 float getScriptValue(const char* s) {
98 float value = 0.0f;
99
100 if (L_ != NULL) {
101 lua_getglobal(L_, s);
102 value = (float)lua_tonumber(L_, -1);
103 lua_pop(L_, 1);
104 }
105
106 return value;
107 }
108
109 void setScriptValue(const char* s, const float &value) {
110 if (L_ != NULL) {
111 lua_pushnumber(L_, value);
112 lua_setglobal(L_, s);
113 }
114 }
115
117 void setState(const unsigned char&);
118 void setScript(const std::string&);
119
120 void setSpeed(const GLfloat&, const GLfloat&, const GLfloat&);
121 void setSpeed(const Vector&);
122
123 void setCollisionDetectionEnabled(const bool &isCollisionDetectionEnabled) {
124 isCollisionDetectionEnabled_ = isCollisionDetectionEnabled;
125 }
126
127 bool getCollisionDetectionEnabled() { return isCollisionDetectionEnabled_; }
128
129 void setActive(const bool &new_active) { active_ = new_active; }
130 bool getActive() { return active_; }
131
132 Vector getPosition() { return position_; }
133 Vector getVelocity() { return velocity_; }
134 Vector getRotationVelocity() { return rotationVelocity_; }
135 Vector getScaleRate() { return scaleRate_; }
136 Vector getSpeed() { return speed_; }
137
138 bool isRotationChanged() { return rotationChanged_; }
139 void setRotationChanged(const bool &rotationChanged_l) { rotationChanged_ = rotationChanged_l; }
140 Quaternion getRotation() { return rotation_; }
141 void setRotation(const Quaternion &rotation) { rotation_ = rotation; rotationChanged_ = true;}
142 Vector getDirection() { return direction_; }
143 Vector getUp() { return up_; }
144 Vector getScale() { return scale_; }
145
146 Quaternion getRInterpStart() { return rInterpStart_; }
147 Quaternion getRInterpEnd() { return rInterpEnd_; }
148 void setRInterpStart(const Quaternion &rInterpStart_l) { rInterpStart_ = rInterpStart_l;}
149 void setRInterpEnd(const Quaternion &rInterpEnd_l) { rInterpEnd_= rInterpEnd_l;}
150
151 bool isInterpolationEnabled() { return isInterpolationEnabled_; }
152 void setIsInterpolationEnabled(const bool &isInterpolationEnabled_l) {
153 isInterpolationEnabled_ = isInterpolationEnabled_l;
154 }
155
156 float getValInterpBegin() { return valInterpBegin_; }
157 float getValInterpCurrent() { return valInterpCurrent_; }
158 float getValInterpEnd() { return valInterpEnd_; }
159
160 void setValInterpBegin(const float &valInterpBegin) { valInterpBegin_ = valInterpBegin; }
161 void setValInterpCurrent(const float &valInterpCurrent) { valInterpCurrent_ = valInterpCurrent; }
162 void setValInterpEnd(const float &valInterpEnd) { valInterpEnd_ = valInterpEnd; }
163
164 void setSuspendTime(const float &time) { suspendTime_ = time; }
165
167 void setState(const int &state_l) {state_ = state_l; }
168 int getState() { return state_; }
169
170 void setScaleChanged(const bool &scaleChanged_l) { scaleChanged_ = scaleChanged_l; }
171
172 void setIsAlwaysLit(const bool &isAlwaysLit) { isAlwaysLit_ = isAlwaysLit; }
173 bool getIsAlwaysLit() { return isAlwaysLit_; }
174
175 void setTypeId (const int &type_id) { typeId_ = type_id; }
176 int getTypeId() { return typeId_; }
177
178 Sphere getBoundingSphere() { return boundingSphere_; }
179
180 std::string getScriptName() { return scriptName_; }
181
182 Vector getOrth() { return orth_; }
183
184 bool getEnableSphereTest() { return enableSphereTest_; }
185
186 bool isDrawable() {
187 return getActive() &&
188 getInView() &&
189 getDrawEnabled() &&
190 getState() != DEAD;
191 }
192
193 void setGameLevelId(const unsigned int& gameLevelId) { gameLevelId_ = gameLevelId; }
194 unsigned int getGameLevelId() { return gameLevelId_; }
195
196 static unsigned int textureIds[MAX_TEXTURES];
197 static std::map <std::string, unsigned int> textureHash;
198
199 protected:
200 // orientation //
201 Vector position_; // x,y,z position of object
202 Quaternion rotation_;
203 Vector scale_; // x,y,z scale values
204
205 Vector baseDirection_; // base direction of object
206 Vector direction_; // direction facing
207 Vector up_;
208 Vector orth_;
209
210 // rate of change //
211 Vector velocity_;
212 Vector speed_;
213 Vector rotationVelocity_;
214 Vector scaleRate_;
215
216 // collision detection //
217 Vector collisionBox_[2]; // 0 = min points, 1 = max points
218 Vector controlPoints_[3]; // used for orienting objects on surfaces
219 Sphere boundingSphere_;
220
221 // state attributes //
222 unsigned char state_; // objects current state
223 bool active_; // is object active?
224 bool isDrawEnabled_;
225
226 bool isInView_; // is the object within the camera's view
227
228 bool isCollisionDetectionEnabled_;
229
230 // used for interpolation between 2 orientations //
231 Quaternion rInterpStart_;
232 Quaternion rInterpEnd_;
233
234 float valInterpBegin_, valInterpCurrent_, valInterpEnd_;
235 bool isInterpolationEnabled_;
236
237 // Necessary for the Lua implementation
238 lua_State* L_;
239 std::string scriptName_;
240 int scriptIndex_;
241
242 float suspendTime_;
243
244 ParticleSystem *particleSystem_;
245
246 int typeId_;
247 unsigned int gameLevelId_;
248
249 Vector lastLight_;
250 bool scaleChanged_;
251 bool rotationChanged_;
252
253 bool isAlwaysLit_;
254
255 bool enableSphereTest_;
256
257 private:
258 void traverseAndCopyLuaTable(lua_State*, lua_State*, const int&);
259 void copyLuaTableKey(lua_State*, lua_State*);
260};
261
262#endif
A game object link in the game list linked list.
Base class from which all concrete particle systems are derived.
Quaternion representation for 3D rotations.
represent and operate on a sphere.
Definition Camera.h:13
void setState(const int &state_l)
Definition Object.h:167
void setState(const unsigned char &)
Definition Object.cpp:441
Definition Quaternion.h:18
Definition Terrain.h:14
Definition Vector.h:15