/*
================
idBrittleFracture::Fracture_r
================
*/
void idBrittleFracture::Fracture_r( idFixedWinding &w ) {
	int i, j, bestPlane;
	float a, c, s, dist, bestDist;
	idVec3 origin;
	idPlane windingPlane, splitPlanes[2];
	idMat3 axis, axistemp;
	idFixedWinding back;
	idTraceModel trm;
	idClipModel *clipModel;
	while( 1 ) {
		origin = w.GetCenter();
		w.GetPlane( windingPlane );
		if( w.GetArea() < maxShardArea ) {
			break;
		}
		// randomly create a split plane
		a = gameLocal.random.RandomFloat() * idMath::TWO_PI;
		c = cos( a );
		s = -sin( a );
		axis[2] = windingPlane.Normal();
		axis[2].NormalVectors( axistemp[0], axistemp[1] );
		axis[0] = axistemp[ 0 ] * c + axistemp[ 1 ] * s;
		axis[1] = axistemp[ 0 ] * s + axistemp[ 1 ] * -c;
		// get the best split plane
		bestDist = 0.0f;
		bestPlane = 0;
		for( i = 0; i < 2; i++ ) {
			splitPlanes[i].SetNormal( axis[i] );
			splitPlanes[i].FitThroughPoint( origin );
			for( j = 0; j < w.GetNumPoints(); j++ ) {
				dist = splitPlanes[i].Distance( w[j].ToVec3() );
				if( dist > bestDist ) {
					bestDist = dist;
					bestPlane = i;
				}
			}
		}
		// split the winding
		if( !w.Split( &back, splitPlanes[bestPlane] ) ) {
			break;
		}
		// recursively create shards for the back winding
		Fracture_r( back );
	}
	// translate the winding to it's center
	origin = w.GetCenter();
	for( j = 0; j < w.GetNumPoints(); j++ ) {
		w[j].ToVec3() -= origin;
	}
	w.RemoveEqualPoints();
	trm.SetupPolygon( w );
	trm.Shrink( CM_CLIP_EPSILON );
	clipModel = new idClipModel( trm );
	physicsObj.SetClipModel( clipModel, 1.0f, shards.Num() );
	physicsObj.SetOrigin( GetPhysics()->GetOrigin() + origin, shards.Num() );
	physicsObj.SetAxis( GetPhysics()->GetAxis(), shards.Num() );
	AddShard( clipModel, w );
}
Ejemplo n.º 2
0
    ShardDefinition::ShardDefinition(std::istream& input)
    {
        CsvTsv::InputColumn<size_t> 
            minPostings("MinPostings",
                        "Minimum number of postings for any document in shard.");
        CsvTsv::InputColumn<double>
            density("Density",
                    "Target density for RowTables in the shard.");

        CsvTsv::CsvTableParser parser(input);
        CsvTsv::TableReader reader(parser);
        reader.DefineColumn(minPostings);
        reader.DefineColumn(density);

        reader.ReadPrologue();
        while (!reader.AtEOF())
        {
            reader.ReadDataRow();

            AddShard(minPostings, density);
        }
        reader.ReadEpilogue();
    }