/* =============== SV_CreateworldSector Builds a uniformly subdivided tree for the given world size =============== */ static worldSector_t *SV_CreateworldSector( int depth, vec3_t mins, vec3_t maxs ) { worldSector_t *anode; vec3_t size; vec3_t mins1, maxs1, mins2, maxs2; anode = &sv_worldSectors[sv_numworldSectors]; sv_numworldSectors++; if (depth == AREA_DEPTH) { anode->axis = -1; anode->children[0] = anode->children[1] = NULL; return anode; } VectorSubtract (maxs, mins, size); if (size[0] > size[1]) { anode->axis = 0; } else { anode->axis = 1; } anode->dist = 0.5 * (maxs[anode->axis] + mins[anode->axis]); VectorCopy (mins, mins1); VectorCopy (mins, mins2); VectorCopy (maxs, maxs1); VectorCopy (maxs, maxs2); maxs1[anode->axis] = mins2[anode->axis] = anode->dist; anode->children[0] = SV_CreateworldSector (depth+1, mins2, maxs2); anode->children[1] = SV_CreateworldSector (depth+1, mins1, maxs1); return anode; }
// Builds a uniformly subdivided tree for the given world size static worldSector_t *SV_CreateworldSector( int depth, vector3 *mins, vector3 *maxs ) { worldSector_t *anode; vector3 size; vector3 mins1, maxs1, mins2, maxs2; anode = &sv_worldSectors[sv_numworldSectors]; sv_numworldSectors++; if (depth == AREA_DEPTH) { anode->axis = -1; anode->children[0] = anode->children[1] = NULL; return anode; } VectorSubtract (maxs, mins, &size); if (size.x > size.y) { anode->axis = 0; } else { anode->axis = 1; } anode->dist = 0.5f * (maxs->data[anode->axis] + mins->data[anode->axis]); VectorCopy (mins, &mins1); VectorCopy (mins, &mins2); VectorCopy (maxs, &maxs1); VectorCopy (maxs, &maxs2); maxs1.data[anode->axis] = mins2.data[anode->axis] = anode->dist; anode->children[0] = SV_CreateworldSector (depth+1, &mins2, &maxs2); anode->children[1] = SV_CreateworldSector (depth+1, &mins1, &maxs1); return anode; }
/* * SV_CreateworldSector * * Builds a uniformly subdivided tree for the given world size */ static worldSector_t * SV_CreateworldSector(int depth, Vec3 mins, Vec3 maxs) { worldSector_t *anode; Vec3 size; Vec3 mins1, maxs1, mins2, maxs2; anode = &sv_worldSectors[sv_numworldSectors]; sv_numworldSectors++; if(depth == AREA_DEPTH){ anode->axis = -1; anode->children[0] = anode->children[1] = NULL; return anode; } subv3 (maxs, mins, size); if(size[0] > size[1]) anode->axis = 0; else anode->axis = 1; anode->dist = 0.5 * (maxs[anode->axis] + mins[anode->axis]); copyv3 (mins, mins1); copyv3 (mins, mins2); copyv3 (maxs, maxs1); copyv3 (maxs, maxs2); maxs1[anode->axis] = mins2[anode->axis] = anode->dist; anode->children[0] = SV_CreateworldSector (depth+1, mins2, maxs2); anode->children[1] = SV_CreateworldSector (depth+1, mins1, maxs1); return anode; }
/* ======================================================================================================================================= SV_ClearWorld ======================================================================================================================================= */ void SV_ClearWorld(void) { clipHandle_t h; vec3_t mins, maxs; memset(sv_worldSectors, 0, sizeof(sv_worldSectors)); sv_numworldSectors = 0; // get world map bounds h = CM_InlineModel(0); CM_ModelBounds(h, mins, maxs); SV_CreateworldSector(0, mins, maxs); }
/* * SV_ClearWorld * */ void SV_ClearWorld(void) { Cliphandle h; Vec3 mins, maxs; Q_Memset(sv_worldSectors, 0, sizeof(sv_worldSectors)); sv_numworldSectors = 0; /* get world map bounds */ h = CM_InlineModel(0); CM_ModelBounds(h, mins, maxs); SV_CreateworldSector(0, mins, maxs); }