home *** CD-ROM | disk | FTP | other *** search
/ Enter 2005 March / ENTER.ISO / files / fwp-0.0.6-win32-installer.exe / Q3bspLoader.h < prev    next >
Encoding:
C/C++ Source or Header  |  2004-12-06  |  6.7 KB  |  211 lines

  1. #ifndef __Q3bspLoader_h__
  2. #define __Q3bspLoader_h__
  3.  
  4. //#include "texture.h"
  5. //#include "mesh.h"
  6. #include <stdlib.h>
  7. #include <string.h>
  8. #include "vectormath.h"
  9. #include "Model.h"
  10. #include "SpacePartitioningTree.h"
  11.  
  12. #define Q3BSP_FACE_POLYGON        1
  13. #define Q3BSP_FACE_BEZIER_PATCH    2
  14. #define Q3BSP_FACE_MESH            3
  15. #define Q3BSP_FACE_BILLBOARD    4
  16.  
  17. #define Q3BSP_GAMMA_SHIFT        5.0f
  18. #define Q3BSP_SCALE                0.033f
  19.  
  20. //#define Q3BSP_SWITCH_TO_MESH    4        //!< faces with more vertices than this will be drawn as meshes
  21.  
  22. #define Q3BSP_MAX_TEXTURES        512
  23.  
  24. // This is our integer vector structure
  25. typedef struct vector3i_s{
  26.     int x, y, z;                // The x y and z position of our integer vector
  27. }vector3i_t;
  28.  
  29.  
  30. // This is our BSP header structure
  31. typedef struct Q3BSPHeader_s{
  32.     char strID[4];                // This should always be 'IBSP'
  33.     int version;                // This should be 0x2e for Quake 3 files
  34. }Q3BSPHeader_t;
  35.  
  36.  
  37. // This is our BSP lump structure
  38. typedef struct Q3BSPLump_s{
  39.     int offset;                    // The offset into the file for the start of this lump
  40.     int length;                    // The length in bytes for this lump
  41. }Q3BSPLump_t;
  42.  
  43.  
  44. // This is our BSP vertex structure
  45. typedef struct Q3BSPVertex_s{
  46.     vec3_t position;            // (x, y, z) position.
  47.     vec2_t texCoords;        // (u, v) texture coordinate
  48.     vec2_t lmCoords;    // (u, v) lightmap coordinate
  49.     vec3_t normal;            // (x, y, z) normal vector
  50.     unsigned char color[4];                // RGBA color for the vertex
  51. }Q3BSPVertex_t;
  52.  
  53. typedef struct Q3BSPMeshVertex_s{
  54.     int offset;
  55. }Q3BSPMeshVertex_t;
  56.  
  57. // This is our BSP face structure
  58. typedef struct Q3BSPFace_s{
  59.     int textureID;                // The index into the texture array
  60.     int effect;                    // The index for the effects (or -1 = n/a)
  61.     int type;                    // 1=polygon, 2=patch, 3=mesh, 4=billboard
  62.     int startVertIndex;            // The starting index into this face's first vertex
  63.     int numOfVerts;                // The number of vertices for this face
  64.     int meshVertIndex;            // The index into the first meshvertex
  65.     int numMeshVerts;            // The number of mesh vertices
  66.     int lightmapID;                // The texture index for the lightmap
  67.     int lMapCorner[2];            // The face's lightmap corner in the image
  68.     int lMapSize[2];            // The size of the lightmap section
  69.     vec3_t lMapPos;            // The 3D origin of lightmap.
  70.     vec3_t lMapVecs[2];        // The 3D space for s and t unit vectors.
  71.     vec3_t normal;            // The face normal.
  72.     int size[2];                // The bezier patch dimensions.
  73. }Q3BSPFace_t;
  74.  
  75.  
  76. // This is our BSP texture structure
  77. typedef struct Q3BSPTexture_s{
  78.     char strName[64];            // The name of the texture w/o the extension
  79.     int flags;                    // The surface flags (unknown)
  80.     int contents;                // The content flags (unknown)
  81. }Q3BSPTexture_t;
  82.  
  83. // This is our BSP lightmap structure which stores the 128x128 RGB values
  84. typedef struct Q3BSPLightmap_s{
  85.     unsigned char imageBits[128][128][3];   // The RGB data in a 128x128 image
  86. }Q3BSPLightmap_t;
  87.  
  88.  
  89. // This stores a node in the BSP tree
  90. typedef struct Q3BSPNode_s{
  91.     int plane;                    // The index into the planes array
  92.     int front;                    // The child index for the front node
  93.     int back;                    // The child index for the back node
  94.     vector3i_t min;                // The bounding box min position.
  95.     vector3i_t max;                // The bounding box max position.
  96. }Q3BSPNode_t;
  97.  
  98. // This stores a leaf (end node) in the BSP tree
  99. typedef struct Q3BSPLeaf_s{
  100.     int cluster;                // The visibility cluster
  101.     int area;                    // The area portal
  102.     vector3i_s min;                // The bounding box min position
  103.     vector3i_s max;                // The bounding box max position
  104.     int leafface;                // The first index into the face array
  105.     int numOfLeafFaces;            // The number of faces for this leaf
  106.     int leafBrush;                // The first index for into the brushes
  107.     int numOfLeafBrushes;        // The number of brushes for this leaf
  108. }Q3BSPLeaf_t;
  109.  
  110. // This stores a splitter plane in the BSP tree
  111. typedef struct Q3BSPPlane_s{
  112.     vec3_t normal;            // Plane normal.
  113.     float d;                    // The plane distance from origin
  114. }Q3BSPPlane_t;
  115.  
  116. // This stores the cluster data for the PVS's
  117. typedef struct Q3BSPVisData_s{
  118.     int numOfClusters;            // The number of clusters
  119.     int bytesPerCluster;        // The amount of bytes (8 bits) in the cluster's bitset
  120.     unsigned char* pBitsets;                // The array of bytes that holds the cluster bitsets
  121. }Q3BSPVisData_t;
  122.  
  123.  
  124.  
  125. // This is our lumps enumeration
  126. enum Q3BSPLumps_e{
  127.     kEntities = 0,                // Stores player/object positions, etc...
  128.     kTextures,                    // Stores texture information
  129.     kPlanes,                    // Stores the splitting planes
  130.     kNodes,                        // Stores the BSP nodes
  131.     kLeafs,                        // Stores the leafs of the nodes
  132.     kLeafFaces,                    // Stores the leaf's indices into the faces
  133.     kLeafBrushes,                // Stores the leaf's indices into the brushes
  134.     kModels,                    // Stores the info of world models
  135.     kBrushes,                    // Stores the brushes info (for collision)
  136.     kBrushSides,                // Stores the brush surfaces info
  137.     kVertices,                    // Stores the level vertices
  138.     kMeshVerts,                    // Stores the model vertices offsets
  139.     kShaders,                    // Stores the shader files (blending, anims..)
  140.     kFaces,                        // Stores the faces for the level
  141.     kLightmaps,                    // Stores the lightmaps for the level
  142.     kLightVolumes,                // Stores extra world lighting information
  143.     kVisData,                    // Stores PVS and cluster info (visibility)
  144.     kMaxLumps                    // A constant to store the number of lumps
  145. };
  146.  
  147.  
  148. // This is our Quake3 BSP class
  149. class Q3BSP{
  150. public:
  151.     Q3BSP(const char* filename);
  152.     ~Q3BSP();
  153.  
  154.     void clear();
  155.  
  156.     int getLeafIndex(vec3_t pos);
  157.  
  158.     Q3bspExtension* buildQ3bspExtension();
  159.  
  160. protected:
  161.     // This loads a .bsp file by it's file name (Returns true if successful)
  162.     bool loadBSP(const char* filename);
  163.     bool faceShouldBeConverted(Q3BSPFace_t* face);
  164.     Mesh* convertToMesh();
  165.     PotentialVisibilitySet* buildPVS();
  166.  
  167.     bool clusterIsVisible(int current, int test);
  168.  
  169.     
  170.     int numVerts;            // The number of verts in the model
  171.     int numMeshVerts;
  172.     int numFaces;            // The number of faces in the model
  173.     int numTextures;        // The number of texture maps
  174.     int numLightmaps;        // The number of light maps
  175.  
  176.     int numNodes;
  177.     int numLeafs;
  178.     int numLeafFaces;
  179.     int numPlanes;
  180.  
  181.  
  182.  
  183.     Q3BSPVertex_t  *pVerts;        // The object's vertices
  184.     Q3BSPMeshVertex_t* pMeshVerts;
  185.     Q3BSPFace_t    *pFaces;        // The faces information of the object
  186.  
  187.  
  188.  
  189.     Q3BSPNode_t    *pNodes;
  190.     Q3BSPLeaf_t    *pLeafs;
  191.     Q3BSPPlane_t   *pPlanes;
  192.     int         *pLeafFaces;
  193.     Q3BSPVisData_t  clusters;
  194.  
  195.  
  196.     Texture* textures[Q3BSP_MAX_TEXTURES];
  197.     Texture* lightmaps[Q3BSP_MAX_TEXTURES];    // The lightmap texture array
  198. };
  199.  
  200.  
  201.  
  202.  
  203. class Q3bspLoader{
  204. public:
  205.     static Q3bspExtension* q3bspExtension;
  206.  
  207.     static bool loadBSP(const char* filename, Model* model);
  208. };
  209.  
  210. #endif    /* __Q3bspLoader_h__*/
  211.