Page principale | Hiérarchie des classes | Liste alphabétique | Liste des classes | Liste des fichiers | Membres de classe

C:/Projects/ngn/include/bsp.h

00001 /***************************************************************************
00002  *            bsp.h
00003  *
00004  *  Sun Feb  1 12:12:39 2004
00005  *  Copyright  2004  thierry schartz
00006  *  thierry.schartz@bluebottle.com
00007  ****************************************************************************/
00008 /*
00009  *  This program is free software; you can redistribute it and/or modify
00010  *  it under the terms of the GNU General Public License as published by
00011  *  the Free Software Foundation; either version 2 of the License, or
00012  *  (at your option) any later version.
00013  *
00014  *  This program is distributed in the hope that it will be useful,
00015  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017  *  GNU Library General Public License for more details.
00018  *
00019  *  You should have received a copy of the GNU General Public License
00020  *  along with this program; if not, write to the Free Software
00021  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00022  */
00023 
00024 #ifndef _BSP_H
00025 #define _BSP_H
00026 
00027 #ifdef WIN32
00028 #include <windows.h>
00029 #endif
00030 
00031 
00032 #include <vector>
00033 #include <string>
00034 #include "GLee.h"
00035 #include "q3types.h"
00036 #include "q3entities.h"
00037 #include "texture.h"
00038 #include "bitset.h"
00039 #include "world.h"
00040 #include "errors.h"
00041 #include "patch.h"
00042 #include "shader.h"
00043 #include "collision.h"
00044 
00045 
00046 
00047 namespace ngn {
00048 class Skybox;
00049 class Camera;
00050     namespace core {
00051         
00052         
00053         
00054        
00055         class Bsp : public World
00056         {
00057             
00058         public:
00059             Bsp();
00060                 virtual ~Bsp();
00061                 // load bsp
00062                 virtual bool load( const char* filename );
00063                         // render bsp
00064                 virtual void render( const Camera& cam );
00065                         // clear loaded bsp
00066                         void clear();
00067                 // set image gamma factor
00068                 void setGammaFactor( float gamma );
00069                         // get image gamma factor
00070                 float getGammaFactor() const;
00071                         // get a spawn position in the map
00072                         const Vector3df& getEntryPoint( unsigned int index ) const;
00073                         // get a random entry point into the map
00074                         const Vector3df& getRandomEntryPoint() const;
00075                 
00076                 protected:
00077                         // finds & adds .jpg or .tga to texture file name
00078                         bool addTextureExtension( char* filename );
00079                         // create textures
00080                         void createTextures( tBSPTexture *pTex );
00081                         // create lightmap textures
00082                         void createLightmap( unsigned int &texture, unsigned char* pImageBits, int width, int height);
00083                         // set gamma factor
00084                         void setGamma( float gamma );
00085                         // get gamma factor
00086                         float getGamma() const;
00087                         // prepare rendering
00088                         void enableVertexArray() const;
00089                         // post rendering operations
00090                         void disableVertexArray() const;
00091                         // render starting at root node of the bsp tree
00092                         void renderTree( int node, bool frustumcheck, const Camera& cam );
00093                         // render a leaf
00094                         void renderLeaf( int leaf, bool frustumcheck, const Camera& cam )const;
00095                         // render a face knowing its index
00096                         void renderFace( int faceindex );
00097                         // render a patch face
00098                         void renderPatch( int index ) const;
00099                         // render the environment map
00100                         void renderSkybox( const Camera& cam ) const;
00101                         // finds if a cluster is visible from another one
00102                         int isClusterVisible( int current, int test );
00103                         // find the leaf we are in
00104                         int findLeaf( const Vector3df& pos );
00105                         // create bezier patches from face data
00106                         void createPatches();
00107 
00108                         // load vertices data
00109                         void loadVertices();
00110                         // load faces data
00111                         void loadFaces();
00112                         // load textures data
00113                         void loadTextures();
00114                         // load lightmaps
00115                         void loadLightmaps();
00116                         // load nodes
00117                         void loadNodes();
00118                         // load leafs
00119                         void loadLeafs();
00120                         // load leaf faces
00121                         void loadLeafFaces();
00122                         // load planes
00123                         void loadPlanes();
00124                         // load visibility data
00125                         void loadVisData();
00126                         // load entities string
00127                         void loadEntities();
00128                         // load models data
00129                         void loadModels();
00130                         // load meshes data
00131                         void loadMeshVertices();
00132                         // load light volumes
00133                         void loadLights();
00134                         // load the environment map
00135                         void loadSkybox();
00136                         // load brushes data
00137                         void loadBrushes();
00138                         // load brush side data
00139                         void loadBrushSides();
00140                         // load leaf brushes data
00141                         void loadLeafBrushes();
00142                         // load vertex indices
00143                         void loadIndices();
00144 
00145 
00146                 private:
00147 
00148                         // adjust gamma factor for lightmaps
00149                         void adjustGamma( unsigned char *pImage, int size, float factor );
00150                         
00151                         int m_nVerts;           // number of vertices     
00152                         int m_nFaces;           // number of faces                 
00153                         int m_nTextures;        // number of textures 
00154                         int m_nLightmaps;       // number of lightmaps 
00155                         int m_nNodes;           // number of nodes
00156                         int m_nLeafs;           // number of leafs
00157                         int m_nLeafFaces;       // number of leaf faces
00158                         int m_nPlanes;          // number of planes
00159                         int m_nModels;          // number of models
00160                         int m_nMeshVertices;// number of mesh vertices
00161                         int m_nPatchFaces;      // number of bezier patches
00162                         int m_nLights;          // number of lights
00163                         int m_nBrushes;         // number of brushes 
00164                         int m_nBrushSides;      // number of brush sides 
00165                         int m_nLeafBrushes;     // number of leaf brushes
00166                         int m_nIndices;         // number of indices
00167         
00168                         tBSPLump m_lumps[ kMaxLumps ];  // lumps info
00169 
00170                         tBSPVertex *m_pVerts;           // pointer to vertices data
00171                         tBSPFace *m_pFaces;                     // pointer to faces data
00172                         tBSPTexture *m_pTextures;       // pointer to textures data
00173                         tBSPNode *m_pNodes;                     // pointer to nodes data
00174                         tBSPLeaf *m_pLeafs;                     // pointer to leafs data
00175                         tBSPPlane *m_pPlanes;           // pointer to planes data
00176                         int *m_pLeafFaces;                      // pointer to leaf faces data
00177                         tBSPVisData m_clusters;         // visibility clusters
00178                         char *m_entities;                       // pointer to entities description string
00179                         tBSPModel *m_pModels;           // pointer to models data
00180                         int *m_pMeshVertices;           // pointer to mesh vertices data
00181                         bsp::tBSPPatchFace *m_pPatchFaces;      // pointer to bezier patches
00182                         tBSPLights *m_pLights;          // pointer to lights data
00183                         tBSPBrush *m_pBrushes;          // pointer to brushes data
00184                         tBSPBrushSide *m_pBrushSides;   // pointer to brush sides data
00185                         int *m_pLeafBrushes;            // pointer to leaf brushes data
00186                         int *m_pIndices;
00187 
00188 
00189                                                         
00190                         GLuint m_texArray[ MAX_TEXTURES ];              // array of textures id
00191                         GLuint m_lightmapArray[ MAX_TEXTURES ]; // array of lightmaps id
00192                         Texture *m_pTex;                                                // textures
00193                 Bitset m_bitset;                                                // keep track of rendered faces
00194                         FILE *m_file;                                                   // file handler
00195                         float m_gamma;                                                  // lightmap gamma factor
00196                         std::vector<bsp::entry_point> m_entry_points;   // map entry points vector
00197                         Skybox *m_skybox;                                               // environment map renderer
00198                         std::string m_map_file;                                 // holds bsp file path
00199                         gl::ShaderProgram *m_shader;                    // GLSL liquid fx
00200                                                                         
00201                         friend class bsp::BSPCollision;
00202                                                                 
00203         };
00204         
00205                                 
00206         
00207     }//core
00208 }//ngn        
00209 #endif /* _BSP_H */

Généré le Fri Nov 19 14:20:29 2004 pour NGN par  doxygen 1.3.9.1