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

MakeTrunk() public method

public MakeTrunk ( ) : void
return void
            public override void MakeTrunk()
            {
                int starty = Pos[1];
                int midy = ( int )( Pos[1] + TrunkHeight * .382 );
                int topy = ( int )( Pos[1] + TrunkHeight + .5 );

                int x = Pos[0];
                int z = Pos[2];
                float midrad = TrunkRadius * .8f;
                float endrad = TrunkRadius * ( 1 - TrunkHeight / Height );

                if ( endrad < 1 )
                    endrad = 1;
                if ( midrad < endrad )
                    midrad = endrad;

                float startrad;
                List<RootBase> rootbases = new List<RootBase>();
                if ( Args.RootButtresses || Args.Shape == TreeShape.Mangrove ) {
                    startrad = TrunkRadius * .8f;
                    rootbases.Add( new RootBase {
                        X = x,
                        Z = z,
                        Radius = startrad
                    } );
                    float buttressRadius = TrunkRadius * .382f;
                    float posradius = TrunkRadius;
                    if ( Args.Shape == TreeShape.Mangrove ) {
                        posradius *= 2.618f;
                    }
                    int numOfButtresss = ( int )( Math.Sqrt( TrunkRadius ) + 3.5 );
                    for ( int i = 0; i < numOfButtresss; i++ ) {
                        float rndang = ( float )( Args.Rand.NextDouble() * 2 * Math.PI );
                        float thisposradius = ( float )( posradius * ( .9 + Args.Rand.NextDouble() * .2 ) );
                        int thisx = x + ( int )( thisposradius * Math.Sin( rndang ) );
                        int thisz = z + ( int )( thisposradius * Math.Cos( rndang ) );

                        float thisbuttressradius = ( float )( buttressRadius * ( .618 + Args.Rand.NextDouble() ) );
                        if ( thisbuttressradius < 1 )
                            thisbuttressradius = 1;

                        TaperedLimb( new Vector3I( thisx, starty, thisz ), new Vector3I( x, midy, z ),
                                     thisbuttressradius, thisbuttressradius );
                        rootbases.Add( new RootBase {
                            X = thisx,
                            Z = thisz,
                            Radius = thisbuttressradius
                        } );
                    }
                } else {
                    startrad = TrunkRadius;
                    rootbases.Add( new RootBase {
                        X = x,
                        Z = z,
                        Radius = startrad
                    } );
                }
                TaperedLimb( new Vector3I( x, starty, z ), new Vector3I( x, midy, z ), startrad, midrad );
                TaperedLimb( new Vector3I( x, midy, z ), new Vector3I( x, topy, z ), midrad, endrad );
                MakeBranches();
                if ( Args.Roots != RootMode.None ) {
                    MakeRoots( rootbases.ToArray() );
                }
            }