示例#1
0
        /// <summary>
        /// Loads content for this demo.
        /// </summary>
        protected override void LoadContent()
        {
            sky = Game.Content.Load<Sky>("sky");
            dude = Game.Content.Load<Model>("dude");

            // Look up our custom skinning information.
            SkinningData skinningData = dude.Tag as SkinningData;

            if (skinningData == null)
                throw new InvalidOperationException
                    ("This model does not contain a SkinningData tag.");

            // Create an animation player, and start decoding an animation clip.
            animationPlayer = new AnimationPlayer(skinningData);

            AnimationClip clip = skinningData.AnimationClips["Take 001"];

            animationPlayer.StartClip(clip);
        }
 /// <summary>
 /// Load your graphics content.
 /// </summary>
 protected override void LoadContent()
 {
     terrain.Model = Content.Load<Model>("Terrain/terrain");
     untitled.Model = Content.Load<Model>("Models/untitled");
     floor.Model = Content.Load<Model>("Models/floor");
     for (int i = 0; i < 4; i++)
     {
         walls[i].Model = Content.Load<Model>("Models/wall");
     }
     sky = Content.Load<Sky>("sky");
     ship.LoadContent(this.Content);
 }
        /// <summary>
        /// Load your graphics content.
        /// </summary>
        protected override void LoadContent()
        {
            spriteBatch = new SpriteBatch(GraphicsDevice);

            // Calculate the projection matrix.
            Viewport viewport = GraphicsDevice.Viewport;

            float aspectRatio = (float)viewport.Width / (float)viewport.Height;

            projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.PiOver4,
                                                                    aspectRatio,
                                                                    1, 10000);

            terrain = Content.Load<Model>("terrain");
            BasicDirectionalLight terrainDirectionalLight = null;
            directionToSun = Vector3.Normalize(new Vector3(2f, 0.2f, -1.0f));

            foreach (ModelMesh mesh in terrain.Meshes)
            {
                foreach (BasicEffect effect in mesh.Effects)
                {
                    effect.Projection = projection;

                    effect.PreferPerPixelLighting = true;

                    // Set the specular lighting to match the sky color.
                    effect.SpecularColor = new Vector3(0f);

                    // Set the fog to match the distant mountains
                    // that are drawn into the sky texture.
                    effect.FogEnabled = false;
                    effect.FogColor = new Vector3(0.15f);
                    effect.FogStart = 100;
                    effect.FogEnd = 320;

                    effect.EnableDefaultLighting();

                    effect.AmbientLightColor = new Vector3(0.5f, 0.5f, 0.5f);
                    effect.DirectionalLight1.Enabled = false;
                    effect.DirectionalLight2.Enabled = false;
                    effect.DirectionalLight0.Direction = -directionToSun;
                    effect.DiffuseColor = new Vector3(1f, 1f, 1f);
                    terrainDirectionalLight = effect.DirectionalLight0;
                }
            }

            heightmap = Content.Load<Texture2D>("Textures/terrain");
            CalculateHeightValues();

            sky = Content.Load<Sky>("skybox");
            sunTexture = Content.Load<Texture2D>("Textures/Sun");

            backbufferWidth = graphics.PreferredBackBufferWidth;
            backbufferHeight = graphics.PreferredBackBufferHeight;

            lightScatterPostProcess = Content.Load<Effect>("Effects/LightScatterPostProcess");

            //Setup post-process parameters
            lightScatterPostProcess.Parameters["Density"].SetValue(0.95f);
            lightScatterPostProcess.Parameters["Weight"].SetValue(1f / 120f * 1.2f);
            lightScatterPostProcess.Parameters["Decay"].SetValue(0.991f);
            lightScatterPostProcess.Parameters["Exposure"].SetValue(0.5f);

            //Trees
            Random r = new Random(Environment.TickCount);
            treeProfile = Content.Load<TreeProfile>("Trees/Willow");

            wind = new WindStrengthSin(0.1f);
            windAnimator = new TreeWindAnimator(wind);

            trees = new LinkedList<Tree>();

            for (int i = 0; i < 300; i++)
            {
                SimpleTree simpleTree = treeProfile.GenerateSimpleTree();
                simpleTree.LeafEffect.CurrentTechnique = simpleTree.LeafEffect.Techniques["SetNoRenderStates"];

                simpleTree.TrunkEffect.Parameters["DirLight0DiffuseColor"].SetValue(new Vector4(terrainDirectionalLight.DiffuseColor, 1f));
                simpleTree.TrunkEffect.Parameters["DirLight0Direction"].SetValue(terrainDirectionalLight.Direction);
                simpleTree.TrunkEffect.Parameters["DirLight1Enabled"].SetValue(false);

                simpleTree.LeafEffect.Parameters["DirLight0DiffuseColor"].SetValue(new Vector4(terrainDirectionalLight.DiffuseColor, 1f));
                simpleTree.LeafEffect.Parameters["DirLight0Direction"].SetValue(terrainDirectionalLight.Direction);
                simpleTree.LeafEffect.Parameters["DirLight1Enabled"].SetValue(false);

                int x = r.Next((int)(terrainWidth / terrainScale));
                int z = r.Next((int)(terrainHeight / terrainScale));
                float y = heightValues[x, z];

                x *= (int)terrainScale;
                z *= (int)terrainScale;

                Vector3 position = new Vector3(x, y, z) - new Vector3(terrainWidth * 0.5f, 0f, terrainHeight * 0.5f);
                Matrix scale = Matrix.CreateScale(Vector3.Lerp(new Vector3(0.005f), new Vector3(0.015f), (float)r.NextDouble()));

                trees.AddLast(new Tree(simpleTree, scale * Matrix.CreateTranslation(position)));
            }

            //Render targets
            sceneRenderTarget = new RenderTarget2D(GraphicsDevice, backbufferWidth, backbufferHeight,
                1, SurfaceFormat.Color, GraphicsDevice.PresentationParameters.MultiSampleType,
                GraphicsDevice.PresentationParameters.MultiSampleQuality);
            lightScatterRenderTarget = new RenderTarget2D(GraphicsDevice, backbufferWidth, backbufferHeight,
                1, SurfaceFormat.Color, GraphicsDevice.PresentationParameters.MultiSampleType,
                GraphicsDevice.PresentationParameters.MultiSampleQuality);

            //FPS
            fpsFont = Content.Load<SpriteFont>("Fonts/Verdana");
        }
 /// <summary>
 /// Load your graphics content.
 /// </summary>
 protected override void LoadContent()
 {
     terrain.Model = Content.Load <Model>("Terrain/terrain");
     sky           = Content.Load <Sky>("sky");
     ship.LoadContent(this.Content);
 }
示例#5
0
 /// <summary>
 /// Load your graphics content.
 /// </summary>
 protected override void LoadContent()
 {
     terrain = Content.Load <Model>("terrain");
     sky     = Content.Load <Sky>("sky");
 }