[7353] | 1 | /* |
---|
| 2 | orxonox - the future of 3D-vertical-scrollers |
---|
[8490] | 3 | |
---|
[7353] | 4 | Copyright (C) 2006 orx |
---|
[8490] | 5 | |
---|
[7353] | 6 | This program is free software; you can redistribute it and/or modify |
---|
| 7 | it under the terms of the GNU General Public License as published by |
---|
| 8 | the Free Software Foundation; either version 2, or (at your option) |
---|
| 9 | any later version. |
---|
[8490] | 10 | |
---|
[7353] | 11 | ### File Specific: |
---|
| 12 | main-programmer: bottac@ee.ethz.ch |
---|
[8490] | 13 | |
---|
[8081] | 14 | Inspired by: |
---|
| 15 | Rendering Q3 Maps by Morgan McGuire http://graphics.cs.brown.edu/games/quake/quake3.html |
---|
| 16 | Unofficial Quake 3 Map Specs by Kekoa Proudfoot http://graphics.stanford.edu/~kekoa/q3/ |
---|
[8490] | 17 | |
---|
[8081] | 18 | Collision detection adapted from: |
---|
| 19 | Quake 3 Collision Detection by Nathan Ostgard http://www.devmaster.net/articles/quake3collision/ |
---|
[7353] | 20 | */ |
---|
| 21 | |
---|
[8490] | 22 | #ifndef _BSP_MANAGER_H |
---|
| 23 | #define _BSP_MANAGER_H |
---|
| 24 | |
---|
| 25 | |
---|
[7385] | 26 | #include <vector> |
---|
| 27 | #include <deque> |
---|
[7353] | 28 | |
---|
[8490] | 29 | |
---|
[8924] | 30 | #define BSP_X_OFFSET 10.0f |
---|
| 31 | #define BSP_Y_OFFSET 40.0f |
---|
| 32 | #define BSP_Z_OFFSET 10.0f |
---|
[8490] | 33 | |
---|
[8924] | 34 | |
---|
[7563] | 35 | // FORWARD DECLARATIONS |
---|
[7353] | 36 | class BspFile; |
---|
| 37 | class BspTreeLeaf; |
---|
| 38 | class BspTreeNode; |
---|
| 39 | class Vector; |
---|
| 40 | class set; |
---|
| 41 | struct face; |
---|
[7563] | 42 | struct brush; |
---|
[8030] | 43 | struct plane; |
---|
| 44 | |
---|
[7833] | 45 | class WorldEntity; |
---|
[7353] | 46 | |
---|
[8904] | 47 | |
---|
| 48 | // Obsolete |
---|
[8081] | 49 | struct BspCollisionEvent |
---|
| 50 | { |
---|
| 51 | Vector normal; //!< normal Vector, length 1 |
---|
| 52 | Vector place; //!< Absoloute coordinates of collision |
---|
| 53 | }; |
---|
| 54 | |
---|
[7353] | 55 | class BspManager |
---|
| 56 | { |
---|
| 57 | public: |
---|
[7395] | 58 | // Constructors |
---|
[8490] | 59 | BspManager(WorldEntity* parent); |
---|
| 60 | |
---|
[8081] | 61 | BspManager(const char* fileName, float scale = 0.4f); |
---|
[8924] | 62 | |
---|
[8904] | 63 | // Deconstructor |
---|
| 64 | ~BspManager(); |
---|
[7353] | 65 | |
---|
[8924] | 66 | |
---|
| 67 | |
---|
[7395] | 68 | // Functions |
---|
[8904] | 69 | int load(const char* fileName, float scale); |
---|
[8081] | 70 | const void draw(); |
---|
[8490] | 71 | const void tick(float time); |
---|
| 72 | void draw_debug_face(int Face); |
---|
[7395] | 73 | void draw_face(int Face); |
---|
| 74 | void draw_patch(face* Face); |
---|
[7353] | 75 | |
---|
[7395] | 76 | |
---|
[8490] | 77 | void checkCollision(WorldEntity* worldEntity); /*!< WorldEntities use this function to check wheter they collided with the BspEntity. |
---|
| 78 | If a collision has been detected, the collides-function of worldEntity will be called.*/ |
---|
| 79 | |
---|
[7353] | 80 | private: |
---|
[7395] | 81 | // Functions |
---|
| 82 | BspTreeNode* getLeaf(BspTreeNode* node, Vector* cam) ; //!< Traverses the tree |
---|
[8490] | 83 | void checkCollision(BspTreeNode* node, Vector* cam); //!< Obsolete. Use this function for debugging only! |
---|
| 84 | void checkCollisionRay(BspTreeNode * node,float startFraction, float endFraction, Vector* start, Vector* end); |
---|
| 85 | void checkCollisionRayN(BspTreeNode * node,float startFraction, float endFraction, Vector* start, Vector* end); |
---|
[8724] | 86 | void TraceBox( Vector& inputStart, Vector& inputEnd,Vector& inputMins, Vector& inputMaxs ); |
---|
[8490] | 87 | void checkCollisionBox(void); |
---|
[7563] | 88 | void checkBrushRay(brush* curBrush); |
---|
[8081] | 89 | void checkBrushRayN(brush* curBrush); |
---|
[8724] | 90 | void checkBrushRayN(brush* curBrush, Vector& inputStart, Vector& inputEnd); |
---|
| 91 | float checkPatchAltitude(BspTreeNode* node); //! To be implemented... |
---|
[8490] | 92 | |
---|
[7395] | 93 | void drawDebugCube(Vector* cam); |
---|
[7563] | 94 | bool isAlreadyVisible(int Face); |
---|
| 95 | void addFace(int Face); |
---|
[8490] | 96 | |
---|
[7563] | 97 | // Data |
---|
| 98 | BspFile* bspFile; |
---|
| 99 | BspTreeNode* root; |
---|
[7395] | 100 | Vector cam; |
---|
| 101 | Vector ship; |
---|
| 102 | Vector viewDir; |
---|
[8030] | 103 | plane* collPlane; |
---|
[7563] | 104 | int lastTex; |
---|
[8490] | 105 | |
---|
| 106 | //obsolete: global variables for collision detection |
---|
[7563] | 107 | bool outputStartsOut; |
---|
| 108 | bool outputAllSolid; |
---|
| 109 | float outputFraction; |
---|
[8490] | 110 | Vector inputStart; |
---|
| 111 | Vector inputEnd; |
---|
[8924] | 112 | |
---|
[8490] | 113 | Vector traceMins; //!< Mins of current bbox |
---|
| 114 | Vector traceMaxs; //!< Maxs of current bbox |
---|
| 115 | Vector traceExtents; /*!< Stores the maximum of the absolute value of each axis in the box. |
---|
| 116 | For example, if traceMins was (-100,-3,-15) and traceMaxs was (55,22,7), traceExtents */ |
---|
| 117 | |
---|
| 118 | WorldEntity* parent; //!< the parent entity of the bspManager: interface to this |
---|
| 119 | |
---|
[7395] | 120 | bool * alreadyVisible; |
---|
| 121 | // Deques to store the visible faces |
---|
| 122 | ::std::deque<int> trasparent; //!< the ones with transparancy go here |
---|
| 123 | ::std::deque<int> opal; //!< the others here. |
---|
[7385] | 124 | |
---|
[8910] | 125 | Vector out; //!< Stores collision coordinates |
---|
[8490] | 126 | Vector out1; //!< For debugging only |
---|
| 127 | Vector out2; //!< For debugging only |
---|
[8924] | 128 | |
---|
[8490] | 129 | int tgl; |
---|
[7353] | 130 | }; |
---|
| 131 | |
---|
[8490] | 132 | #endif /* _BSP_MANAGER_H */ |
---|