📄 q3bsp.h
字号:
// ==========================================================================================================
//
// BREW v2.0+ OPENGLES MICROENGINE
//
// ----------------------------------------
//
// Written by Vander Nunes
//
// ==========================================================================================================
#ifndef __Q3BSP_H__
#define __Q3BSP_H__
// TORUS ENGINE
#include "../defines.h"
#include "../mobmodel.h"
#include "../math3d.h"
#include "../texture.h"
#include "../camera.h"
#include "../torus.h"
// BREW
#include "AEEAppGen.h"
#include "AEEModGen.h"
#include "AEEStdLib.h"
#include "AEEFile.h"
#include "AEEImage.h"
#define BSPHEADERID "IBSP"
#define BSPVERSION 46
// plane types are used to speed some tests
// 0-2 are axial planes
#define PLANE_X 0
#define PLANE_Y 1
#define PLANE_Z 2
// 3-5 are non-axial planes snapped to the nearest
#define PLANE_ANYX 3
#define PLANE_ANYY 4
#define PLANE_ANYZ 5
#define PLANE_NON_AXIAL 3
/*
direntry lump list and specification
Index Lump Name Description
0 Entities Game-related object descriptions.
1 Textures Surface descriptions.
2 Planes Planes used by map geometry.
3 Nodes BSP tree nodes.
4 Leafs BSP tree leaves.
5 Leaffaces Lists of face indices, one list per leaf.
6 Leafbrushes Lists of brush indices, one list per leaf.
7 Models Descriptions of rigid world geometry in map.
8 Brushes Convex polyhedra used to describe solid space.
9 Brushsides Brush surfaces.
10 Vertexes Vertices used to describe faces.
11 Meshverts Lists of offsets, one list per mesh.
12 Effects List of special map effects.
13 Faces Surface geometry.
14 Lightmaps Packed lightmap data.
15 Lightvols Local illumination data.
16 Visdata Cluster-cluster visibility data.
*/
typedef struct
{
int iOffset; // offset of the lump inside the bsp file
int iLength; // length of the lump
} direntry;
typedef struct
{
char szMagic[4]; // must be IBSP
int iVersion; // must be 46
direntry sEntries[17]; // must fill the 17 lump entries with their offsets and lengths
} header;
typedef struct
{
char szName[64]; // texture name
int iFlags; // texture surface flags
int iContents; // texture content flags
} texture_lump;
typedef struct
{
vec3f_t vNormal; // ### floating-point plane normal
float fDist; // ### floating-point plane distance
} plane_lump;
typedef struct node_s
{
int iPlane; // plane index
int iChildren[2]; // children indices. negavite are leaf indices: -(leaf+1)
vec3_t iMin; // bbox min
vec3_t iMax; // bbox max
} node_lump;
typedef struct
{
int iCluster; // visdata cluster index. if negative, leaf is outside map or is invalid.
int iArea; // areaportal area
vec3_t iMin; // bbox min
vec3_t iMax; // bbox max
int iLeafFace; // first leafface for this leaf
int iLeafFaceCount; // number of leaffaces for this leaf
int iLeafBrush; // first leafbrush for this leaf
int iLeafBrushCount; // number of leafbrushes for this leaf
} leaf_lump;
typedef struct
{
int iFace; // face index
} leafface_lump;
typedef struct
{
int iBrush; // brush index
} leafbrush_lump;
typedef struct
{
vec3f_t fMin; // ### floating-point bbox min
vec3f_t fMax; // ### floating-point bbox max
int iFace; // model's first face index
int iFaceCount; // model's face count
int iBrush; // model's fist brush index
int iBrushCount; // model's brush count
} model_lump;
typedef struct
{
int iBrushSide; // first brushside for this brush
int iBrushSideCount; // brushside count
int iTexture; // texture index
} brush_lump;
typedef struct
{
int iPlane; // plane index
int iTexture; // texture index
} brushside_lump;
typedef struct
{
float fPosition[3]; // ### floating-point position
float fTexCoord[2][2]; // ### floating-point uv
float fNormal[3]; // ### floating-point normal
byte jColor[4]; // color RGBA
} vertex_lump;
typedef struct
{
int iOffset; // vertex index offset, relative to first vertex of corresponding face
} meshvert_lump;
typedef struct
{
char szName[64]; // shader name
int iBrush; // affected brush
int iUnknown; // always 5, except in q3dm8 which has one effect with -1
} effect_lump;
typedef struct
{
int iTexture; // texture index
int iEffect; // effect index or -1 if no effect
int iType; // face type: 1==polygon, 2==patch, 3==mesh, 4==billboard
int iVertex; // index of first vertex
int iVertexCount; // vertex count
int iMeshVert; // index of first meshvert
int iMeshVertCount; // meshvert count
int iLm; // lightmap index
int iLmStart[2]; // corner of this face's lightmap image in lightmap
int iLmSize[2]; // size of this face's lightmap image in lightmap
float fLmOrigin[3]; // ### floating-point world-space origin of lightmap
float fLmVecs[2][3]; // ### floating-point world-space lightmap s and t unit vectors
float fNormal[3]; // ### floating-point surface normal
int iSize[2]; // patch dimensions
} face_lump;
typedef struct
{
byte jLm[128][128][3]; // lightmap RGB color data
} lightmap_lump;
typedef struct
{
byte jAmbient[3]; // RGB ambient color
byte jDirectional[3]; // RGB directional color
byte jDir[2]; // light direction: 0==phi, 1==theta
} lightvol_lump;
typedef struct
{
int iVectorCount; // vector count
int iVectorSize; // vector size
byte* pjVecs; // list of visibility data, allocated at run-time
} visdata_lump;
//
// extra structures to adapt to opengl-es (faster rendering)
//
typedef struct
{
int iType; // face type: 1==polygon, 2==patch, 3==mesh, 4==billboard
int iTextureIndex; // texture index for face
int iLightmapIndex; // lightmap index
word* pTris; // triangle list for the face polygon
word wTriCount; // number of triangles for this face polygon
dword dwFrame; // rendering frame counter
} fast_face;
typedef struct
{
fast_face* pFaces; // polygon list
int* pVertices; // vertice list
dword* pTexCoords; // texture coordinates list per vertex
dword* pLitCoords; // lightmap coordinates list per vertex
dword* pColValues; // RGBA color values per vertex
} fast_bsp;
//-----------------------------------------------------------------------------
class CQ3BSP
{
private:
CEngine* m_pEngine;
CVfs* m_pVfs;
WORD m_wTexCount;
texture_lump* m_pTextures;
CTexture* m_pSurfaces;
DWORD m_dwPlaneCount;
plane_lump* m_pPlanes;
DWORD m_dwNodeCount;
node_lump* m_pNodes;
DWORD m_dwLeafCount;
leaf_lump* m_pLeafs;
DWORD m_dwLeafFaceCount;
leafface_lump* m_pLeafFaces;
DWORD m_dwLeafBrushCount;
leafbrush_lump* m_pLeafBrushes;
DWORD m_dwModelCount;
model_lump* m_pModels;
DWORD m_dwBrushCount;
brush_lump* m_pBrushes;
DWORD m_dwBrushSideCount;
brushside_lump* m_pBrushSides;
DWORD m_dwVertexCount;
vertex_lump* m_pVertices;
DWORD m_dwMeshVertCount;
meshvert_lump* m_pMeshVerts;
DWORD m_dwEffectCount;
effect_lump* m_pEffects;
DWORD m_dwFaceCount;
face_lump* m_pFaces;
DWORD m_dwLightmapCount;
lightmap_lump* m_pLightmaps;
CTexture* m_pLightmapTextures;
DWORD m_dwLightvolCount;
lightvol_lump* m_pLightvols;
DWORD m_dwVisdataCount;
visdata_lump m_Visdata;
fast_bsp m_FastBSP;
dword m_dwFrame;
vec3_t m_Origin;
int m_iAngle;
boolean LoadEntities(direntry* pEntry);
boolean LoadTextures(direntry* pEntry);
boolean LoadPlanes(direntry* pEntry);
boolean LoadNodes(direntry* pEntry);
boolean LoadLeafs(direntry* pEntry);
boolean LoadLeafFaces(direntry* pEntry);
boolean LoadLeafBrushes(direntry* pEntry);
boolean LoadModels(direntry* pEntry);
boolean LoadBrushes(direntry* pEntry);
boolean LoadBrushSides(direntry* pEntry);
boolean LoadVertices(direntry* pEntry);
boolean LoadMeshVerts(direntry* pEntry);
boolean LoadEffects(direntry* pEntry);
boolean LoadFaces(direntry* pEntry);
boolean LoadLightmaps(direntry* pEntry);
boolean LoadLightvols(direntry* pEntry);
boolean LoadVisdata(direntry* pEntry);
void ParseMapInfo(char* szInfo);
int FindLeaf(CCamera* pCam);
void ConvertToFast(void);
boolean IsClusterVisible(int iFromLeaf, int iToLeaf);
void WalkTree(CCamera* pCam, int iNode, int iCamNode);
void RenderLeaf(int iLeaf);
public:
CQ3BSP(CEngine* pEngine);
~CQ3BSP();
// load a bsp tree
boolean Load(char* szFile);
// unload loaded bsp tree
void Unload();
// render loaded bsp tree
void Render(CCamera* pCam);
// return the info_player_start
void GetInfoPlayerStart(vec3_t v);
// return the player initial angle
int InfoPlayerStartAngle();
};
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -