Ejemplo n.º 1
0
/*
===============
idClip::CreateClipSectors_r

Builds a uniformly subdivided tree for the given world size
===============
*/
clipSector_t *idClip::CreateClipSectors_r( const int depth, const idBounds &bounds, idVec3 &maxSector ) {
	int				i;
	clipSector_t	*anode;
	idVec3			size;
	idBounds		front, back;
	anode = &clipSectors[idClip::numClipSectors];
	idClip::numClipSectors++;
	if( depth == MAX_SECTOR_DEPTH ) {
		anode->axis = -1;
		anode->children[0] = anode->children[1] = NULL;
		for( i = 0; i < 3; i++ ) {
			if( bounds[1][i] - bounds[0][i] > maxSector[i] ) {
				maxSector[i] = bounds[1][i] - bounds[0][i];
			}
		}
		return anode;
	}
	size = bounds[1] - bounds[0];
	if( size[0] >= size[1] && size[0] >= size[2] ) {
		anode->axis = 0;
	} else if( size[1] >= size[0] && size[1] >= size[2] ) {
		anode->axis = 1;
	} else {
		anode->axis = 2;
	}
	anode->dist = 0.5f * ( bounds[1][anode->axis] + bounds[0][anode->axis] );
	front = bounds;
	back = bounds;
	front[0][anode->axis] = back[1][anode->axis] = anode->dist;
	anode->children[0] = CreateClipSectors_r( depth + 1, front, maxSector );
	anode->children[1] = CreateClipSectors_r( depth + 1, back, maxSector );
	return anode;
}
Ejemplo n.º 2
0
/*
===============
idClip::Init
===============
*/
void idClip::Init( void ) {
	cmHandle_t h;
	idVec3 size, maxSector = vec3_origin;

	// clear clip sectors
	clipSectors = new clipSector_t[MAX_SECTORS];
	memset( clipSectors, 0, MAX_SECTORS * sizeof( clipSector_t ) );
	numClipSectors = 0;
	touchCount = -1;
	// get world map bounds
	h = collisionModelManager->LoadModel( "worldMap", false );
	collisionModelManager->GetModelBounds( h, worldBounds );
	// create world sectors
	CreateClipSectors_r( 0, worldBounds, maxSector );

	size = worldBounds[1] - worldBounds[0];
	gameLocal.Printf( "map bounds are (%1.1f, %1.1f, %1.1f)\n", size[0], size[1], size[2] );
	gameLocal.Printf( "max clip sector is (%1.1f, %1.1f, %1.1f)\n", maxSector[0], maxSector[1], maxSector[2] );

	// initialize a default clip model
	defaultClipModel.LoadModel( idTraceModel( idBounds( idVec3( 0, 0, 0 ) ).Expand( 8 ) ) );

	// set counters to zero
	numRotations = numTranslations = numMotions = numRenderModelTraces = numContents = numContacts = 0;
}