Beispiel #1
0
/*
* GClip_Init_AreaGrid
*/
static void GClip_Init_AreaGrid( areagrid_t *areagrid, const vec3_t world_mins, const vec3_t world_maxs )
{
	int i;

	// the areagrid_marknumber is not allowed to be 0
	if( areagrid->marknumber < 1 ) {
		areagrid->marknumber = 1;
	}

	// choose either the world box size, or a larger box to ensure the grid isn't too fine
	areagrid->size[0] = max( world_maxs[0] - world_mins[0], AREA_GRID * AREA_GRIDMINSIZE );
	areagrid->size[1] = max( world_maxs[1] - world_mins[1], AREA_GRID * AREA_GRIDMINSIZE );
	areagrid->size[2] = max( world_maxs[2] - world_mins[2], AREA_GRID * AREA_GRIDMINSIZE );

	// figure out the corners of such a box, centered at the center of the world box
	areagrid->mins[0] = ( world_mins[0] + world_maxs[0] - areagrid->size[0] ) * 0.5f;
	areagrid->mins[1] = ( world_mins[1] + world_maxs[1] - areagrid->size[1] ) * 0.5f;
	areagrid->mins[2] = ( world_mins[2] + world_maxs[2] - areagrid->size[2] ) * 0.5f;
	areagrid->maxs[0] = ( world_mins[0] + world_maxs[0] + areagrid->size[0] ) * 0.5f;
	areagrid->maxs[1] = ( world_mins[1] + world_maxs[1] + areagrid->size[1] ) * 0.5f;
	areagrid->maxs[2] = ( world_mins[2] + world_maxs[2] + areagrid->size[2] ) * 0.5f;

	// now calculate the actual useful info from that
	VectorNegate( areagrid->mins, areagrid->bias );
	areagrid->scale[0] = AREA_GRID / areagrid->size[0];
	areagrid->scale[1] = AREA_GRID / areagrid->size[1];
	areagrid->scale[2] = AREA_GRID / areagrid->size[2];

	GClip_ClearLink( &areagrid->outside );
	for( i = 0; i < AREA_GRIDNODES; i++ ) {
		GClip_ClearLink( &areagrid->grid[i] );
	}

	memset( areagrid->entmarknumber, 0, sizeof( areagrid->entmarknumber ) );

	if( developer->integer ) {
		Com_Printf( "areagrid settings: divisions %ix%ix1 : box %f %f %f "
			": %f %f %f size %f %f %f grid %f %f %f (mingrid %f)\n", 
			AREA_GRID, AREA_GRID, 
			areagrid->mins[0], areagrid->mins[1], areagrid->mins[2],
			areagrid->maxs[0], areagrid->maxs[1], areagrid->maxs[2], 
			areagrid->size[0], areagrid->size[1], areagrid->size[2], 
			1.0f / areagrid->scale[0], 1.0f / areagrid->scale[1], 1.0f / areagrid->scale[2], 
			AREA_GRIDMINSIZE );
	}
}
Beispiel #2
0
/*
* GClip_CreateAreaNode
* Builds a uniformly subdivided tree for the given world size
*/
static areanode_t *GClip_CreateAreaNode( int depth, vec3_t mins, vec3_t maxs )
{
	areanode_t *anode;
	vec3_t size;
	vec3_t mins1, maxs1, mins2, maxs2;

	anode = &sv_areanodes[sv_numareanodes++];
	GClip_ClearLink( &anode->trigger_edicts );
	GClip_ClearLink( &anode->solid_edicts );

	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] = GClip_CreateAreaNode( depth+1, mins2, maxs2 );
	anode->children[1] = GClip_CreateAreaNode( depth+1, mins1, maxs1 );

	return anode;
}