private void MakeBranches()
{
int topy = Pos[1] + ( int )( TrunkHeight + .5 );
float endrad = TrunkRadius * ( 1 - TrunkHeight / Height );
if ( endrad < 1 )
endrad = 1;
foreach ( Vector3I coord in FoliageCoords ) {
float dist = ( float )Math.Sqrt( Sqr( coord.X - Pos.X ) + Sqr( coord.Z - Pos.Z ) );
float ydist = coord[1] - Pos[1];
float value = ( BranchDensity * 220 * Height ) / Cub( ydist + dist );
if ( value < Args.Rand.NextDouble() )
continue;
int posy = coord[1];
float slope = ( float )( BranchSlope + ( .5 - Args.Rand.NextDouble() ) * .16 );
float branchy, basesize;
if ( coord[1] - dist * slope > topy ) {
float threshold = 1 / ( float )Height;
if ( Args.Rand.NextDouble() < threshold )
continue;
branchy = topy;
basesize = endrad;
} else {
branchy = posy - dist * slope;
basesize = endrad + ( TrunkRadius - endrad ) *
( topy - branchy ) / TrunkHeight;
}
float startsize = ( float )( basesize * ( 1 + Args.Rand.NextDouble() ) *
.618 * Math.Pow( dist / Height, .618 ) );
float rndr = ( float )( Math.Sqrt( Args.Rand.NextDouble() ) * basesize * .618 );
float rndang = ( float )( Args.Rand.NextDouble() * 2 * Math.PI );
int rndx = ( int )( rndr * Math.Sin( rndang ) + .5 );
int rndz = ( int )( rndr * Math.Cos( rndang ) + .5 );
Vector3I startcoord = new Vector3I {
X = Pos[0] + rndx,
Z = Pos[2] + rndz,
Y = ( int )branchy
};
if ( startsize < 1 )
startsize = 1;
const float endsize = 1;
TaperedLimb( startcoord, coord, startsize, endsize );
}
}