/// <summary>
        /// Draws the trunk using the specified world, view, and projection matrices.
        /// </summary>
        /// <param name="world">World matrix.</param>
        /// <param name="view">View matrix.</param>
        /// <param name="projection">Projection matrix.</param>
        /// <exception cref="InvalidOperationException">If no trunk effect is set.</exception>
        /// <exception cref="InvalidOperationException">If no Skeleton is set.</exception>
        /// <remarks>
        /// This method sets all the appropriate effect parameters.
        /// </remarks>
        public new void DrawTrunk(Matrix world, Matrix view, Matrix projection)
        {
            if (Skeleton == null)
            {
                throw new InvalidOperationException("A Skeleton must be set before trunk can be rendered.");
            }

            if (TrunkEffect == null)
            {
                throw new InvalidOperationException("TrunkEffect must be set before trunk can be rendered.");
            }

            #region New code

            Effect effect = TrunkEffect;

            effect.Parameters["World"].SetValue(world);
            effect.Parameters["WorldIT"].SetValue(Matrix.Transpose(Matrix.Invert(world)));
            effect.Parameters["WorldViewProj"].SetValue(world * view * projection);
            effect.Parameters["ViewInv"].SetValue(Matrix.Invert(view));

            effect.Parameters["Texture"].SetValue(TrunkTexture);

            effect.Parameters["isSkydome"].SetValue(false);

            effect.Parameters["LightDirection"].SetValue(Lighting.LightDirection);
            effect.Parameters["LightColor"].SetValue(Lighting.LightColor);
            effect.Parameters["LightColorAmbient"].SetValue(Lighting.LightColorAmbient);
            effect.Parameters["FogColor"].SetValue(Lighting.FogColor);
            effect.Parameters["fDensity"].SetValue(Lighting.FogDensity);
            effect.Parameters["SunLightness"].SetValue(Lighting.SunLightness);
            effect.Parameters["sunRadiusAttenuation"].SetValue(Lighting.SunRadiusAttenuation);
            effect.Parameters["largeSunLightness"].SetValue(Lighting.LargeSunLightness);
            effect.Parameters["largeSunRadiusAttenuation"].SetValue(Lighting.LargeSunRadiusAttenuation);
            effect.Parameters["dayToSunsetSharpness"].SetValue(Lighting.DayToSunsetSharpness);
            effect.Parameters["hazeTopAltitude"].SetValue(Lighting.HazeTopAltitude);

            #endregion

            #region Original code

//            TrunkEffect.Parameters["World"].SetValue(world);
//            TrunkEffect.Parameters["View"].SetValue(view);
//            TrunkEffect.Parameters["Projection"].SetValue(projection);
//
            Skeleton.CopyBoneBindingMatricesTo(BindingMatrices, AnimationState.BoneRotations);
            TrunkEffect.Parameters["Bones"].SetValue(BindingMatrices);
//
//            TrunkEffect.Parameters["Texture"].SetValue(trunkTexture);

            #endregion

            Trunk.Draw(effect);
        }
        /// <summary>
        /// Draws the leaves using the specified world, view, and projection matrices.
        /// </summary>
        /// <param name="world">World matrix.</param>
        /// <param name="view">View matrix.</param>
        /// <param name="projection">Projection matrix.</param>
        /// <exception cref="InvalidOperationException">If no leaf effect is set.</exception>
        /// <exception cref="InvalidOperationException">If no Skeleton is set.</exception>
        /// <remarks>
        /// This method sets all the appropriate effect parameters.
        /// </remarks>
        public void DrawLeaves(Matrix world, Matrix view, Matrix projection, Vector3 cameraPos)
        {
            if (Skeleton == null)
            {
                throw new InvalidOperationException("A Skeleton must be set before leaves can be rendered.");
            }

            if (LeafEffect == null)
            {
                throw new InvalidOperationException("LeafEffect must be set before leaves can be rendered.");
            }

            LeafEffect.Parameters["WorldView"].SetValue(world * view);
            //leafEffect.Parameters["View"].SetValue(view);
            LeafEffect.Parameters["Projection"].SetValue(projection);
            LeafEffect.Parameters["LeafScale"].SetValue(world.Right.Length());


            Effect effect = LeafEffect;

            effect.Parameters["World"].SetValue(world);
            effect.Parameters["WorldIT"].SetValue(Matrix.Transpose(Matrix.Invert(world)));
            effect.Parameters["WorldViewProj"].SetValue(world * view * projection);
            effect.Parameters["ViewInv"].SetValue(Matrix.Invert(view));

            effect.Parameters["isSkydome"].SetValue(false);

            effect.Parameters["LightDirection"].SetValue(Lighting.LightDirection);
            effect.Parameters["LightColor"].SetValue(Lighting.LightColor);
            effect.Parameters["LightColorAmbient"].SetValue(Lighting.LightColorAmbient);
            effect.Parameters["FogColor"].SetValue(Lighting.FogColor);
            effect.Parameters["fDensity"].SetValue(Lighting.FogDensity);
            effect.Parameters["SunLightness"].SetValue(Lighting.SunLightness);
            effect.Parameters["sunRadiusAttenuation"].SetValue(Lighting.SunRadiusAttenuation);
            effect.Parameters["largeSunLightness"].SetValue(Lighting.LargeSunLightness);
            effect.Parameters["largeSunRadiusAttenuation"].SetValue(Lighting.LargeSunRadiusAttenuation);
            effect.Parameters["dayToSunsetSharpness"].SetValue(Lighting.DayToSunsetSharpness);
            effect.Parameters["hazeTopAltitude"].SetValue(Lighting.HazeTopAltitude);

            if (Skeleton.LeafAxis == null)
            {
                LeafEffect.Parameters["BillboardRight"].SetValue(Vector3.Right);
                LeafEffect.Parameters["BillboardUp"].SetValue(Vector3.Up);
            }
            else
            {
                Vector3 axis    = Skeleton.LeafAxis.Value;
                var     forward = new Vector3(view.M13, view.M23, view.M33);

                Vector3 right = Vector3.Cross(forward, axis);
                right.Normalize();
                Vector3 up = axis;

                Vector3.TransformNormal(ref right, ref view, out right);
                Vector3.TransformNormal(ref up, ref view, out up);

                LeafEffect.Parameters["BillboardRight"].SetValue(right);
                LeafEffect.Parameters["BillboardUp"].SetValue(up);
            }

            Skeleton.CopyBoneBindingMatricesTo(BindingMatrices, AnimationState.BoneRotations);
            LeafEffect.Parameters["Bones"].SetValue(BindingMatrices);

            // Used for normals of billboard leaves
            Vector3 treePos = Vector3.Transform(Vector3.Zero, BindingMatrices[0] * world);

            effect.Parameters["BillboardNormal"].SetValue(cameraPos - treePos);

            LeafEffect.Parameters["Texture"].SetValue(LeafTexture);

            Leaves.Draw(LeafEffect);
        }