00001 #ifndef ENVIRONMENT_H 00002 #define ENVIRONMENT_H 00003 00004 #ifdef DARWIN 00005 #include <Python/Python.h> 00006 #else 00007 #include <Python.h> 00008 #endif 00009 00010 00011 #include <ngl/Camera.h> 00012 #include <ngl/Vec3.h> 00013 #include <ngl/Colour.h> 00014 #include <list> 00015 #include <ngl/Obj.h> 00016 #include <ngl/TransformStack.h> 00017 #include <ngl/VAOPrimitives.h> 00018 #include "GridNodes.h" 00019 #include "Agent.h" 00020 #include "Map.h" 00021 #include "Models.h" 00022 #include "Parser.h" 00023 #include "GraphEdge.h" 00024 #include "Graph.h" 00025 #include <pthread.h> 00026 #include <unistd.h> 00027 #include "AIagent.h" 00028 #include "UserAgent.h" 00029 #include "GameEntity.h" 00030 00031 00032 00033 00042 00043 class GridNodes; 00044 class Agent; 00045 class AgentOctree; 00046 class Graph; 00047 class UserControls; 00048 class GameEntity; 00049 class Ammo; 00050 00051 //The faces for the Bounding Box 00052 00053 typedef struct face{ 00054 ngl::Vec3 normal; 00055 float minX; 00056 float maxX; 00057 float minY; 00058 float maxY; 00059 float minZ; 00060 float maxZ; 00061 float a; 00062 float b; 00063 float c; 00064 float d; 00065 ngl::Vec3 centre; 00066 }face; 00067 00068 class Environment 00069 { 00070 public : 00071 //---------------------------------------------------------------------------------------------------------------------- 00075 //---------------------------------------------------------------------------------------------------------------------- 00076 Environment(ngl::TransformStack *_t,ngl::Camera *_cam); 00077 //---------------------------------------------------------------------------------------------------------------------- 00079 //---------------------------------------------------------------------------------------------------------------------- 00080 ~Environment(); 00081 //---------------------------------------------------------------------------------------------------------------------- 00083 //---------------------------------------------------------------------------------------------------------------------- 00084 void update(); 00085 //---------------------------------------------------------------------------------------------------------------------- 00087 //---------------------------------------------------------------------------------------------------------------------- 00088 void draw(); 00089 //---------------------------------------------------------------------------------------------------------------------- 00096 //---------------------------------------------------------------------------------------------------------------------- 00097 void addParticle(); 00098 //---------------------------------------------------------------------------------------------------------------------- 00101 //---------------------------------------------------------------------------------------------------------------------- 00102 unsigned int getNumParticles()const; 00103 //---------------------------------------------------------------------------------------------------------------------- 00105 //---------------------------------------------------------------------------------------------------------------------- 00106 inline const ngl::Camera *getCamera() {return m_cam;} 00107 //---------------------------------------------------------------------------------------------------------------------- 00109 //---------------------------------------------------------------------------------------------------------------------- 00110 inline ngl::TransformStack *getTransformStack() const {return m_transform;} 00111 //---------------------------------------------------------------------------------------------------------------------- 00113 //---------------------------------------------------------------------------------------------------------------------- 00114 void clearParticles(); 00115 //---------------------------------------------------------------------------------------------------------------------- 00117 //---------------------------------------------------------------------------------------------------------------------- 00118 void resetObject(); 00119 //---------------------------------------------------------------------------------------------------------------------- 00124 //---------------------------------------------------------------------------------------------------------------------- 00125 void addNewFace(ngl::Vec3 _point, ngl::Vec3 _normal, face *_face); 00126 //---------------------------------------------------------------------------------------------------------------------- 00128 //---------------------------------------------------------------------------------------------------------------------- 00129 void drawBox(); 00130 //---------------------------------------------------------------------------------------------------------------------- 00132 //---------------------------------------------------------------------------------------------------------------------- 00133 int getPrecision(){return m_precision;} 00134 //---------------------------------------------------------------------------------------------------------------------- 00136 //---------------------------------------------------------------------------------------------------------------------- 00137 void createAgents(); 00138 //---------------------------------------------------------------------------------------------------------------------- 00141 //---------------------------------------------------------------------------------------------------------------------- 00142 void agentsQueryUpdate(AIagent *_agent); 00143 //---------------------------------------------------------------------------------------------------------------------- 00146 //---------------------------------------------------------------------------------------------------------------------- 00147 void agentWallCollision(AIagent *_agent); 00148 //---------------------------------------------------------------------------------------------------------------------- 00151 //---------------------------------------------------------------------------------------------------------------------- 00152 void agentObstacleCollision(AIagent *_agent); 00153 //---------------------------------------------------------------------------------------------------------------------- 00156 //---------------------------------------------------------------------------------------------------------------------- 00157 void agentAgentCollision(); 00158 //---------------------------------------------------------------------------------------------------------------------- 00161 //---------------------------------------------------------------------------------------------------------------------- 00162 void approachingAgent(AIagent *_agent); 00163 //---------------------------------------------------------------------------------------------------------------------- 00165 //---------------------------------------------------------------------------------------------------------------------- 00166 void drawGrid(); 00167 //---------------------------------------------------------------------------------------------------------------------- 00170 //---------------------------------------------------------------------------------------------------------------------- 00171 void calculateBBox(std::string _name); 00172 //---------------------------------------------------------------------------------------------------------------------- 00176 //---------------------------------------------------------------------------------------------------------------------- 00177 void addArmy(PyObject *_main,PyObject *_dict); 00178 //---------------------------------------------------------------------------------------------------------------------- 00189 //---------------------------------------------------------------------------------------------------------------------- 00190 void addAgent(std::string _file,PyObject *_main,PyObject *_dict,int _index, std::string _meshName, float _radius,std::string _type,int _id); 00191 //---------------------------------------------------------------------------------------------------------------------- 00196 //---------------------------------------------------------------------------------------------------------------------- 00197 void addAgent(int _index,std::string _meshName, std::string _name); 00198 //---------------------------------------------------------------------------------------------------------------------- 00201 //---------------------------------------------------------------------------------------------------------------------- 00202 AIagent *getAgent(int _id); 00203 //---------------------------------------------------------------------------------------------------------------------- 00205 //---------------------------------------------------------------------------------------------------------------------- 00206 void startPong(); 00207 //---------------------------------------------------------------------------------------------------------------------- 00209 //---------------------------------------------------------------------------------------------------------------------- 00210 void assignPositions(); 00211 //---------------------------------------------------------------------------------------------------------------------- 00213 //---------------------------------------------------------------------------------------------------------------------- 00214 void InitMap(); 00215 //---------------------------------------------------------------------------------------------------------------------- 00217 //---------------------------------------------------------------------------------------------------------------------- 00218 void calculateEdges(); 00219 //---------------------------------------------------------------------------------------------------------------------- 00221 //---------------------------------------------------------------------------------------------------------------------- 00222 void setMessage(const std::string _message); 00223 //---------------------------------------------------------------------------------------------------------------------- 00225 //---------------------------------------------------------------------------------------------------------------------- 00226 void setGameEntityPositions(); 00227 //---------------------------------------------------------------------------------------------------------------------- 00229 //---------------------------------------------------------------------------------------------------------------------- 00230 void checkUserEntityCollection(); 00231 //---------------------------------------------------------------------------------------------------------------------- 00233 //---------------------------------------------------------------------------------------------------------------------- 00234 int getScoreToPrint(); 00235 //---------------------------------------------------------------------------------------------------------------------- 00237 //---------------------------------------------------------------------------------------------------------------------- 00238 int getNoOfBulletsLeftToPrint(); 00239 //---------------------------------------------------------------------------------------------------------------------- 00242 //---------------------------------------------------------------------------------------------------------------------- 00243 void checkBulletCollisions(std::list <Ammo *> _bullets); 00244 //---------------------------------------------------------------------------------------------------------------------- 00248 //---------------------------------------------------------------------------------------------------------------------- 00249 void processKeyDown( 00250 QKeyEvent *_event 00251 ); 00252 //---------------------------------------------------------------------------------------------------------------------- 00256 //---------------------------------------------------------------------------------------------------------------------- 00257 void processKeyUp( 00258 QKeyEvent *_event 00259 ); 00260 00261 00262 float m_redScore; 00263 float m_blueScore; 00264 //---------------------------------------------------------------------------------------------------------------------- 00266 //---------------------------------------------------------------------------------------------------------------------- 00267 bool m_drawBox; 00268 00269 00270 private : 00271 //---------------------------------------------------------------------------------------------------------------------- 00273 //---------------------------------------------------------------------------------------------------------------------- 00274 float m_precision; 00275 //---------------------------------------------------------------------------------------------------------------------- 00277 //---------------------------------------------------------------------------------------------------------------------- 00278 std::list <Agent *> m_agents; 00279 //---------------------------------------------------------------------------------------------------------------------- 00282 //---------------------------------------------------------------------------------------------------------------------- 00283 ngl::TransformStack *m_transform; 00284 //---------------------------------------------------------------------------------------------------------------------- 00287 //---------------------------------------------------------------------------------------------------------------------- 00288 ngl::Camera *m_cam; 00290 //---------------------------------------------------------------------------------------------------------------------- 00291 std::list<face *> m_faces; 00292 //---------------------------------------------------------------------------------------------------------------------- 00294 //---------------------------------------------------------------------------------------------------------------------- 00295 float m_width; 00296 //---------------------------------------------------------------------------------------------------------------------- 00298 //---------------------------------------------------------------------------------------------------------------------- 00299 float m_height; 00300 //---------------------------------------------------------------------------------------------------------------------- 00302 //---------------------------------------------------------------------------------------------------------------------- 00303 bool m_add; 00304 //---------------------------------------------------------------------------------------------------------------------- 00306 //---------------------------------------------------------------------------------------------------------------------- 00307 bool m_initAgent; 00308 //---------------------------------------------------------------------------------------------------------------------- 00310 //---------------------------------------------------------------------------------------------------------------------- 00311 bool m_pong; 00312 //---------------------------------------------------------------------------------------------------------------------- 00314 //---------------------------------------------------------------------------------------------------------------------- 00315 bool m_mazeGame; 00316 //---------------------------------------------------------------------------------------------------------------------- 00318 //---------------------------------------------------------------------------------------------------------------------- 00319 ngl::BBox *table; 00320 //---------------------------------------------------------------------------------------------------------------------- 00322 //---------------------------------------------------------------------------------------------------------------------- 00323 ngl::BBox m_court; 00324 //---------------------------------------------------------------------------------------------------------------------- 00326 //---------------------------------------------------------------------------------------------------------------------- 00327 ngl::Vec3 m_normals[6]; 00328 //---------------------------------------------------------------------------------------------------------------------- 00330 //---------------------------------------------------------------------------------------------------------------------- 00331 ngl::Vec3 m_verts[8]; 00332 //---------------------------------------------------------------------------------------------------------------------- 00334 //---------------------------------------------------------------------------------------------------------------------- 00335 Map *m_map; 00336 //---------------------------------------------------------------------------------------------------------------------- 00338 //---------------------------------------------------------------------------------------------------------------------- 00339 Models *m_model; 00340 //---------------------------------------------------------------------------------------------------------------------- 00342 //---------------------------------------------------------------------------------------------------------------------- 00343 Parser *m_parser; 00344 //---------------------------------------------------------------------------------------------------------------------- 00346 //---------------------------------------------------------------------------------------------------------------------- 00347 std::vector <int> m_obstaclePositions; 00348 //---------------------------------------------------------------------------------------------------------------------- 00350 //---------------------------------------------------------------------------------------------------------------------- 00351 std::map <std::string, std::list<face*> >m_objFaces; 00352 //---------------------------------------------------------------------------------------------------------------------- 00354 //---------------------------------------------------------------------------------------------------------------------- 00355 std::vector <ngl::Vec3> m_obstacles; 00356 //---------------------------------------------------------------------------------------------------------------------- 00358 //---------------------------------------------------------------------------------------------------------------------- 00359 std::list <GameEntity *> m_gameEntities; 00360 //---------------------------------------------------------------------------------------------------------------------- 00362 //---------------------------------------------------------------------------------------------------------------------- 00363 AgentOctree *collisionTree; 00364 //---------------------------------------------------------------------------------------------------------------------- 00366 //---------------------------------------------------------------------------------------------------------------------- 00367 Graph *m_graph; 00368 //---------------------------------------------------------------------------------------------------------------------- 00370 //---------------------------------------------------------------------------------------------------------------------- 00371 bool m_find; 00372 //---------------------------------------------------------------------------------------------------------------------- 00374 //---------------------------------------------------------------------------------------------------------------------- 00375 Agent* m_agent; 00376 //---------------------------------------------------------------------------------------------------------------------- 00378 //---------------------------------------------------------------------------------------------------------------------- 00379 std::vector<ngl::Transformation> m_levelTransform; 00380 00381 }; 00382 00383 00384 00385 00386 00387 #endif // ENVIRONMENT_H