Пример #1
0
        // Called when the game should load its content
        protected override void LoadContent()
        {
            spriteBatch = new SpriteBatch(GraphicsDevice);

            models.Add(new CModel(Content.Load <Model>("Content/teapot__cv1"),
                                  Vector3.Zero, Vector3.Zero, Vector3.One * 50, GraphicsDevice));

            Effect cubeMapEffect           = Content.Load <Effect>("Content/CubeMapReflect");
            CubeMapReflectMaterial cubeMat = new CubeMapReflectMaterial(
                Content.Load <TextureCube>("Content/clouds"));

            models[0].SetModelEffect(cubeMapEffect, false);
            models[0].Material = cubeMat;

            Plane clip = new Plane(Vector3.Up, 0);

            sky = new SkySphere(Content, GraphicsDevice,
                                Content.Load <TextureCube>("Content/clouds"));

            water = new Water(Content, GraphicsDevice, Vector3.Zero, new Vector2(8000, 8000));

            water.Objects.Add(sky);
            water.Objects.Add(models[0]);
            //water.Objects.Add(models[1]);

            camera = new FreeCamera(new Vector3(0, 400, 1400),
                                    MathHelper.ToRadians(0),
                                    MathHelper.ToRadians(0),
                                    GraphicsDevice);

            lastMouseState = Mouse.GetState();
        }
Пример #2
0
        // Called when the game should load its content
        protected override void LoadContent()
        {
            spriteBatch = new SpriteBatch(GraphicsDevice);

            camera = new FreeCamera(new Vector3(1000, 650, 1000),
                                    MathHelper.ToRadians(45),
                                    MathHelper.ToRadians(-30),
                                    GraphicsDevice);

            camera = new ChaseCamera(new Vector3(0, 250, 700), new Vector3(0, 250, 0),
                                     new Vector3(0, MathHelper.Pi, 0), GraphicsDevice);

            lastMouseState = Mouse.GetState();

            List <Vector2> trackPositions = new List <Vector2>()
            {
                new Vector2(-4000, 0),
                new Vector2(-4000, -4000),
                new Vector2(0, -4000),
                new Vector2(4000, -4000),
                new Vector2(4000, -2000),
                new Vector2(0, -2000),
                new Vector2(-1000, 0),
                new Vector2(0, 2000),
                new Vector2(4000, 2000),
                new Vector2(4000, 4000),
                new Vector2(0, 4000),
                new Vector2(-4000, 4000),
                new Vector2(-4000, 0)
            };

            track = new RaceTrack(trackPositions, 25, 300, 30, GraphicsDevice, Content);

            models.Add(new CModel(Content.Load <Model>("Ground"), new Vector3(0, -10f, 0), Vector3.Zero, Vector3.One * 2, GraphicsDevice));
            models.Add(new CModel(Content.Load <Model>("car"), Vector3.Zero,
                                  Vector3.Zero, Vector3.One, GraphicsDevice));

            foreach (CModel model in models)
            {
                foreach (ModelMesh mesh in model.Model.Meshes)
                {
                    foreach (BasicEffect effect in mesh.Effects)
                    {
                        effect.LightingEnabled                = true;
                        effect.PreferPerPixelLighting         = true;
                        effect.AmbientLightColor              = new Vector3(.4f);
                        effect.DirectionalLight0.Enabled      = true;
                        effect.DirectionalLight0.DiffuseColor = new Vector3(.6f);
                        effect.DirectionalLight0.Direction    = new Vector3(1, -1, -1);
                        effect.DirectionalLight0.Direction.Normalize();
                        effect.DirectionalLight0.SpecularColor = Color.Black.ToVector3();
                    }
                }
            }

            sky = new SkySphere(Content, GraphicsDevice, Content.Load <TextureCube>("clouds"));
        }
Пример #3
0
        // Called when the game should load its content
        protected override void LoadContent()
        {
            spriteBatch = new SpriteBatch(GraphicsDevice);

            models.Add(new CModel(Content.Load <Model>("ground"),
                                  Vector3.Zero, Vector3.Zero, Vector3.One, GraphicsDevice));

            models.Add(new CModel(Content.Load <Model>("brick_wall"),
                                  Vector3.Zero, new Vector3(0, 0, 0), Vector3.One, GraphicsDevice));

            Effect           lightingEffect = Content.Load <Effect>("LightingEffect");
            LightingMaterial lightingMat    = new LightingMaterial();

            Effect            normalMapEffect = Content.Load <Effect>("NormalMapEffect");
            NormalMapMaterial normalMat       = new NormalMapMaterial(
                Content.Load <Texture2D>("brick_normal_map"));

            lightingMat.LightDirection = new Vector3(.5f, .5f, 1);
            lightingMat.LightColor     = Vector3.One;

            normalMat.LightDirection = new Vector3(.5f, .5f, 1);
            normalMat.LightColor     = Vector3.One;

            models[0].SetModelEffect(lightingEffect, true);
            models[1].SetModelEffect(normalMapEffect, true);

            models[0].Material = lightingMat;
            models[1].Material = normalMat;

            camera = new FreeCamera(new Vector3(0, 400, 1400),
                                    MathHelper.ToRadians(0),
                                    MathHelper.ToRadians(0),
                                    GraphicsDevice);

            sky = new SkySphere(Content, GraphicsDevice,
                                Content.Load <TextureCube>("clouds"));

            lastMouseState = Mouse.GetState();
        }
Пример #4
0
        // Called when the game should load its content
        protected override void LoadContent()
        {
            spriteBatch = new SpriteBatch(GraphicsDevice);

            models.Add(new CModel(Content.Load <Model>("teapot"),
                                  Vector3.Zero, Vector3.Zero, Vector3.One * 50, GraphicsDevice));

            Effect cubeMapEffect           = Content.Load <Effect>("CubeMapReflect");
            CubeMapReflectMaterial cubeMat = new CubeMapReflectMaterial(
                Content.Load <TextureCube>("clouds"));

            models[0].SetModelEffect(cubeMapEffect, true);
            models[0].Material = cubeMat;

            sky = new SkySphere(Content, GraphicsDevice,
                                Content.Load <TextureCube>("clouds"));

            camera = new FreeCamera(new Vector3(0, 400, 1400),
                                    MathHelper.ToRadians(0),
                                    MathHelper.ToRadians(0),
                                    GraphicsDevice);

            lastMouseState = Mouse.GetState();
        }
Пример #5
0
        // Called when the game should load its content
        protected override void LoadContent()
        {
            spriteBatch = new SpriteBatch(GraphicsDevice);

            camera = new FreeCamera(new Vector3(8000, 6000, 8000),
                                    MathHelper.ToRadians(45),
                                    MathHelper.ToRadians(-30),
                                    GraphicsDevice);

            terrain = new Terrain(Content.Load <Texture2D>("terrain"), 30, 4800,
                                  Content.Load <Texture2D>("grass"), 6, new Vector3(1, -1, 0),
                                  GraphicsDevice, Content);

            terrain.WeightMap     = Content.Load <Texture2D>("weightMap");
            terrain.RTexture      = Content.Load <Texture2D>("sand");
            terrain.GTexture      = Content.Load <Texture2D>("rock");
            terrain.BTexture      = Content.Load <Texture2D>("snow");
            terrain.DetailTexture = Content.Load <Texture2D>("noise_texture");

            // Positions where trees should be drawn
            List <Vector3> treePositions = new List <Vector3>();

            // Continue until we get 500 trees on the terrain
            for (int i = 0; i < 500; i++) // 500
            {
                // Get X and Z coordinates from the random generator, between
                // [-(terrain width) / 2 * (cell size), (terrain width) / 2 * (cell size)]
                float x = r.Next(-256 * 30, 256 * 30);
                float z = r.Next(-256 * 30, 256 * 30);

                // Get the height and steepness of this position on the terrain,
                // taking the height of the billboard into account
                float steepness;
                float y = terrain.GetHeightAtPosition(x, z, out steepness) + 100;

                // Reject this position if it is too low, high, or steep. Otherwise
                // add it to the list
                if (steepness < MathHelper.ToRadians(15) && y > 2300 && y < 3200)
                {
                    treePositions.Add(new Vector3(x, y, z));
                }
                else
                {
                    i--;
                }
            }

            trees = new BillboardSystem(GraphicsDevice, Content,
                                        Content.Load <Texture2D>("tree_billboard"), new Vector2(200),
                                        treePositions.ToArray());

            trees.Mode            = BillboardSystem.BillboardMode.Cylindrical;
            trees.EnsureOcclusion = true;


            // List of positions to place grass billboards
            List <Vector3> grassPositions = new List <Vector3>();

            // Retrieve pixel grid from grass map
            Texture2D grassMap = Content.Load <Texture2D>("grass_map");

            Color[] grassPixels = new Color[grassMap.Width * grassMap.Height];
            grassMap.GetData <Color>(grassPixels);

            // Loop until 1000 billboards have been placed
            for (int i = 0; i < 300; i++)
            {
                // Get X and Z coordinates from the random generator, between
                // [-(terrain width) / 2 * (cell size), (terrain width) / 2 * (cell size)]
                float x = r.Next(-256 * 30, 256 * 30);
                float z = r.Next(-256 * 30, 256 * 30);

                // Get corresponding coordinates in grass map
                int xCoord = (int)(x / 30) + 256;
                int zCoord = (int)(z / 30) + 256;

                // Get value between 0 and 1 from grass map
                float texVal = grassPixels[zCoord * 512 + xCoord].R / 255f;

                // Retrieve height
                float steepness;
                float y = terrain.GetHeightAtPosition(x, z, out steepness) + 50;

                // Randomly place a billboard here based on pixel color in grass
                // map
                if ((int)((float)r.NextDouble() * texVal * 10) == 1)
                {
                    grassPositions.Add(new Vector3(x, y, z));
                }
                else
                {
                    i--;
                }
            }

            // Create grass billboard system
            grass = new BillboardSystem(GraphicsDevice, Content,
                                        Content.Load <Texture2D>("grass_billboard"), new Vector2(100),
                                        grassPositions.ToArray());

            grass.Mode            = BillboardSystem.BillboardMode.Cylindrical;
            grass.EnsureOcclusion = false;


            List <Vector3> cloudPositions = new List <Vector3>();

            // Create 20 "clusters" of clouds
            for (int i = 0; i < 20; i++)
            {
                Vector3 cloudLoc = new Vector3(
                    r.Next(-8000, 8000),
                    r.Next(4000, 6000),
                    r.Next(-8000, 8000));

                // Add 10 cloud billboards around each cluster point
                for (int j = 0; j < 10; j++)
                {
                    cloudPositions.Add(cloudLoc +
                                       new Vector3(
                                           r.Next(-3000, 3000),
                                           r.Next(-300, 900),
                                           r.Next(-1500, 1500)));
                }
            }

            clouds = new BillboardSystem(GraphicsDevice, Content,
                                         Content.Load <Texture2D>("cloud2"), new Vector2(2000),
                                         cloudPositions.ToArray());

            clouds.Mode            = BillboardSystem.BillboardMode.Spherical;
            clouds.EnsureOcclusion = false;

            sky = new SkySphere(Content, GraphicsDevice,
                                Content.Load <TextureCube>("clouds"));

            water = new Water(Content, GraphicsDevice,
                              new Vector3(0, 1600, 0), new Vector2(256 * 30));

            water.Objects.Add(sky);
            water.Objects.Add(terrain);

            lastMouseState = Mouse.GetState();
        }