private TreeGenerator ReadGenerator(ContentReader input)
        {
            String source = input.ReadString();
            var    xml    = new XmlDocument();

            xml.LoadXml(source);
            return(TreeGenerator.CreateFromXml(xml));
        }
        public override void Initialise(GraphicsDevice device, ContentManager content)
        {
            m_content         = content;
            m_camera_position = new Vector3(600, 2, -500);
            m_camera_target   = new Vector3(0, 2, 0);
            m_rand            = new Random();
            m_trunk           = content.Load <Effect>("Trunk");
            m_leaves          = content.Load <Effect>("Leaves");
            m_trunk_texture   = content.Load <Texture2D>(@"Trees\PineBark");
            m_leaves_texture  = content.Load <Texture2D>(@"Trees\PineLeaf");

            m_generator = TreeGenerator.CreateFromXml(@"Data\Trees\Pine.xml");
            m_profile   = new TreeProfile(device, m_generator, m_trunk_texture, m_leaves_texture, m_trunk, m_leaves);
            m_tree      = m_profile.GenerateSimpleTree(m_rand);

            m_projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(60), device.Viewport.AspectRatio, 0.5f, 20000.0f);
            m_world      = Matrix.CreateScale(0.1f); // Matrix.CreateTranslation(Vector3.Zero);
            m_view       = Matrix.CreateLookAt(m_camera_position, m_camera_target, Vector3.Up);
            m_device     = device;
        }
        public override TreeProfileContent Process(XmlDocument input, ContentProcessorContext context)
        {
            // Build a tree generator just to validate the XML format
            try
            {
                TreeGenerator.CreateFromXml(input);
            }
            catch (ArgumentException ex)
            {
                ErrorInvalidFormat(ex.Message);
            }

            TreeProfileContent content = new TreeProfileContent();

            string path = "";

            if (TexturePath != null && TexturePath != "" && !(TexturePath.EndsWith("/") || TexturePath.EndsWith(@"\")))
            {
                path = TexturePath + "/";
            }
            else if (TexturePath == null)
            {
                path = "";
            }
            else
            {
                path = TexturePath;
            }

            XmlNode treeNode = input.SelectSingleNode("Tree");

            content.GeneratorXML = input;
            content.TrunkTexture = path + GetChildContent(treeNode, "TrunkTexture");
            content.LeafTexture  = path + GetChildContent(treeNode, "LeafTexture");
            content.TrunkEffect  = TrunkEffect;
            content.LeafEffect   = LeafEffect;

            return(content);
        }
        public override void Update(float dt)
        {
            angle  += MathHelper.ToRadians(10) * dt;
            m_world = Matrix.CreateScale(0.1f) * Matrix.CreateRotationY(angle);

            if ((Game1.Instance.last_mouse_state.LeftButton == Microsoft.Xna.Framework.Input.ButtonState.Pressed) &&
                (Game1.Instance.current_mouse_state.LeftButton == Microsoft.Xna.Framework.Input.ButtonState.Released))
            {
                for (int i = 0; i < Buttons.Length; i++)
                {
                    if (Buttons[i].Contains(Game1.Instance.current_mouse_state.X, Game1.Instance.current_mouse_state.Y))
                    {
                        switch (i)
                        {
                        case 0:
                        {
                            m_trunk_texture  = m_content.Load <Texture2D>(@"Trees\PineBark");
                            m_leaves_texture = m_content.Load <Texture2D>(@"Trees\PineLeaf");
                            m_generator      = TreeGenerator.CreateFromXml(@"Data\Trees\Pine.xml");
                            m_profile        = new TreeProfile(m_device, m_generator, m_trunk_texture, m_leaves_texture, m_trunk, m_leaves);
                            m_tree           = m_profile.GenerateSimpleTree(m_rand);
                        }
                        break;

                        case 1:
                        {
                            m_trunk_texture  = m_content.Load <Texture2D>(@"Trees\BirchBark");
                            m_leaves_texture = m_content.Load <Texture2D>(@"Trees\BirchLeaf");
                            m_generator      = TreeGenerator.CreateFromXml(@"Data\Trees\Birch.xml");
                            m_profile        = new TreeProfile(m_device, m_generator, m_trunk_texture, m_leaves_texture, m_trunk, m_leaves);
                            m_tree           = m_profile.GenerateSimpleTree(m_rand);
                        }
                        break;

                        case 2:
                        {
                            m_trunk_texture  = m_content.Load <Texture2D>(@"Trees\wood_dark");
                            m_leaves_texture = m_content.Load <Texture2D>(@"Trees\WillowLeaf");
                            m_generator      = TreeGenerator.CreateFromXml(@"Data\Trees\Willow.xml");
                            m_profile        = new TreeProfile(m_device, m_generator, m_trunk_texture, m_leaves_texture, m_trunk, m_leaves);
                            m_tree           = m_profile.GenerateSimpleTree(m_rand);
                        }
                        break;

                        case 3:
                        {
                            m_trunk_texture  = m_content.Load <Texture2D>(@"Trees\GrayBark");
                            m_leaves_texture = m_content.Load <Texture2D>(@"Trees\GraywoodLeaf");
                            m_generator      = TreeGenerator.CreateFromXml(@"Data\Trees\Graywood.xml");
                            m_profile        = new TreeProfile(m_device, m_generator, m_trunk_texture, m_leaves_texture, m_trunk, m_leaves);
                            m_tree           = m_profile.GenerateSimpleTree(m_rand);
                        }
                        break;

                        case 4:
                        {
                            m_trunk_texture  = m_content.Load <Texture2D>(@"Trees\wood_dark");
                            m_leaves_texture = m_content.Load <Texture2D>(@"Trees\OakLeaf");
                            m_generator      = TreeGenerator.CreateFromXml(@"Data\Trees\Gardenwood.xml");
                            m_profile        = new TreeProfile(m_device, m_generator, m_trunk_texture, m_leaves_texture, m_trunk, m_leaves);
                            m_tree           = m_profile.GenerateSimpleTree(m_rand);
                        }
                        break;

                        case 5:
                        {
                            m_trunk_texture  = m_content.Load <Texture2D>(@"Trees\PineBark");
                            m_leaves_texture = m_content.Load <Texture2D>(@"Trees\WillowLeaf");
                            m_generator      = TreeGenerator.CreateFromXml(@"Data\Trees\Rug.xml");
                            m_profile        = new TreeProfile(m_device, m_generator, m_trunk_texture, m_leaves_texture, m_trunk, m_leaves);
                            m_tree           = m_profile.GenerateSimpleTree(m_rand);
                        }
                        break;
                        }
                    }
                }
            }
        }