fCraft.Forester.ProceduralTree.Prepare C# (CSharp) Method

Prepare() public method

public Prepare ( ) : void
return void
            public override void Prepare()
            {
                base.Prepare();
                TrunkRadius = ( float )Math.Sqrt( Height * Args.TrunkThickness );
                if ( TrunkRadius < 1 )
                    TrunkRadius = 1;

                TrunkHeight = Height * .618f;
                BranchDensity = ( Args.BranchDensity / Args.FoliageDensity );

                int ystart = Pos[1];
                int yend = ( Pos[1] + Height );
                int numOfClustersPerY = ( int )( 1.5 + Sqr( Args.FoliageDensity * Height / 19f ) );
                if ( numOfClustersPerY < 1 )
                    numOfClustersPerY = 1;

                List<Vector3I> foliageCoords = new List<Vector3I>();
                for ( int y = yend - 1; y >= ystart; y-- ) {
                    for ( int i = 0; i < numOfClustersPerY; i++ ) {
                        float shapefac = ShapeFunc( y - ystart );
                        if ( shapefac < 0 )
                            continue;
                        float r = ( float )( ( Math.Sqrt( Args.Rand.NextDouble() ) + .328 ) * shapefac );
                        float theta = ( float )( Args.Rand.NextDouble() * 2 * Math.PI );
                        int x = ( int )( r * Math.Sin( theta ) ) + Pos[0];
                        int z = ( int )( r * Math.Cos( theta ) ) + Pos[2];
                        foliageCoords.Add( new Vector3I( x, y, z ) );
                    }
                }
                FoliageCoords = foliageCoords.ToArray();
            }