Original Post
Hi, I'm loading and using bsp version 30 files (same as half-life 1) and have successfully loaded the file into data, but I'm having trouble figuring out how I'm to render this data... Here is how the data is structured:
// BSP Lumps
struct tBSPLump { unsigned int offset, length; };
// BSP header
struct tBSPHeader {
unsigned int version;
tBSPLump dir[NUM_LUMPS];
};
// BSP Entity
typedef unsigned char tBSPEntity;
// BSP Planes
struct tBSPPlane
{
float normal[3];
float dist; // Plane equation is: Normal * X = Dist
enum
{
PLANE_X = 0, // Plane is perpendicular to given axis
PLANE_Y,
PLANE_Z,
PLANE_ANYX, // Dominant axis (axis along which projection of normal has greatest magnitude)
PLANE_ANYY,
PLANE_ANYZ
} type;
};
// BSP Mip-mapped Textures ...header
struct tBSPTextureHeader {
unsigned int numMiptex;
unsigned int offset[4];
};
// ...body
struct tBSPMiptex
{
char name[16];
unsigned int width;
unsigned int height;
unsigned int offset[4];
};
// BSP Vertices
struct tBSPVertices
{
float x, y, z;
};
// BSP Visibility
typedef unsigned __int8 tBSPVisibility;
// BSP Nodes
struct tBSPNodes
{
unsigned short plane_idx;
signed short children[2];
signed short mins[3];
signed short maxs[3];
unsigned short firstface;
unsigned short numfaces;
};
// BSP Texture Info
struct tBSPTexinfo
{
float vecs[2][4]; // [s/t][x/y/z/offset]
int miptex_idx;
int flags;
};
// BSP Faces
struct tBSPFaces
{
unsigned __int16 plane_idx;
unsigned __int16 side;
unsigned __int32 firstedge;
unsigned __int16 numedges;
unsigned __int16 texinfo;
unsigned __int8 styles[4];
unsigned __int32 light_offset;
};
// BSP Lightmaps
struct tBSPLightmap {
signed __int8 imageBits[128][128][3];
};
// BSP Leaves
struct tBSPLeaf
{
signed int contents;
signed int visofs;
signed short mins[3];
signed short maxs[3];
unsigned short firstmarksurface;
unsigned short nummarksurfaces;
unsigned char ambient_level[4];
};
typedef unsigned short tBSPMarkedsurf;
// BSP Clipping nodes
struct tBSPClipnode
{
int plane_idx;
short children[2];
};
// BSP Edges
struct tBSPEdge
{
unsigned short v[2]; // indices numbers of the vertices bounding this edge
};
// BSP Surface Edges
typedef signed int tBSPSurfedge;
// BSP Models
struct tBSPModels
{
float mins[3];
float maxs[3];
float origin[3];
int headnode[4];
int visleafs;
int firstface;
int numfaces;
};
// Header
tBSPHeader head;
// Entity List
tBSPEntity *entity;
//Planes
unsigned int numPlanes;
tBSPPlane *plane;
//Texture
tBSPTextureHeader textureheader;
tBSPMiptex *miptex;
//Vertices
unsigned int numVertices;
tBSPVertices *vertex;
//Visibility
unsigned int numClusters;
tBSPVisibility *pvs;
//Nodes
unsigned int numNodes;
tBSPNodes *node;
//Leaves
unsigned int numLeaves;
tBSPLeaf *leaf;
//Texinfo
unsigned int numTextures;
tBSPTexinfo *texture;
//Faces
unsigned int numFaces;
tBSPFaces *face;
//Lightmaps
unsigned int numLightmaps;
tBSPLightmap *lightmap;
//Clipping nodes
unsigned int numClipNodes;
tBSPClipnode *clipnode;
// Marked Surfaces
unsigned int numMarkedsurfaces;
tBSPMarkedsurf *markedsurf;
//Edges
unsigned int numEdges;
tBSPEdge *edge;
//Surface Edges
unsigned int numSurfEdges;
tBSPSurfedge *surfedge;
//Models
unsigned int numModels;
tBSPModels *model; This is what I have for rendering so far: int BSPLeaf( bspFile info, glVector camera_pos )
{
int index = 0;
bspFile::tBSPNodes node;
bspFile::tBSPPlane;
float distance;
while( index >= 0 ) {
node = info.node[index];
plane = info.plane[node.plane_idx];
distance = dotproduct( glVector( plane.normal[0], plane.normal[1], plane.normal[2] ), camera_pos ) - plane.dist;
if( distance >= 0 ) {
index.node.children[0];
} else {
index.node.children[1];
}
}
return -index - 1;
}
bool BSPClusterCompare( bspFile info, int visCluster, int testCluster )
{
if( info.numClusters == NULL || visCluster < 0 ) return true;
int i = (visCluster * 8) + (testcluster >> 3 );
unsigned __int8 set = info.pvs;
return (set & (1 << (testCluster & 7))) != 0;
}
void BSPRender( glPoint campos, bspFile info )
{
std::set<int> alreadyvis;
std::vector<int> visible;
int camleaf = BSPLeaf( info, campos );
int f;
// Begin leaf iteration :)
for( int l = 0; l < info.numLeaves; l++ ) {
if( BSPClusterCompare( info, camleaf, info.leaf[l].visofs ) ) {
for (int i = 0; i < leaf[l].numFaces; ++i) {
f = i + leaf[L].firstFace;
pair<iterator,bool> data = alreadyvis.insert( f );
if( data.second == true ) {
visible.append( f );
}
}
}
}
for( int v = 0; v < visible.size(); v++ ) {
switch( info.face[ visible[v] ].type ) {
case 1: // Polygon
break;
case 2: // Patch
break;
case 3: // Meshes ???
break;
case 4: // Billboard
break;
}
}
} Basically, I don't know how I would render any of them in any fashion - I'm fairly new to bsp trees and bsp30 files, so i'm not entirely sure. Any help would be appreciated Thanks, Oz~