Ejemplo n.º 1
0
        public void DrawCubes()
        {
            foreach (EffectPass pass in cubeEffect.CurrentTechnique.Passes)
            {
                for (byte chunkx = 0; chunkx < xychunks; chunkx++)
                {
                    for (byte chunkz = 0; chunkz < xychunks; chunkz++)
                    {
                        //FRUSTUM CULL HERE
                        if (InView(thisqube[chunkx, chunkz]) == false)
                        {
                            culled++;
                            continue;
                        }

                        //Checks to see which terrain type to render
                        for (int terraintype = 0; terraintype < 4; terraintype++)
                        {
                            if (terraintype == 0)
                            {
                                currentVBRenderer = this.staticVBRenderer[chunkx, chunkz][0];
                            }
                            if (terraintype == 1)
                            {
                                currentVBRenderer = this.staticVBRenderer[chunkx, chunkz][1];
                            }
                            if (terraintype == 2)
                            {
                                currentVBRenderer = this.staticVBRenderer[chunkx, chunkz][2];
                            }
                            if (terraintype == 3)
                            {
                                currentVBRenderer = this.staticVBRenderer[chunkx, chunkz][3];
                            }
                            if (currentVBRenderer == null)
                            {
                                continue;
                            }

                            //Render that buffer
                            currentVBRenderer.Render(cubeEffect.View, cubeEffect.Projection, Textures[terraintype]);
                            drawn++;
                        }
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public void DrawCubes()
        {
            foreach (EffectPass pass in cubeEffect.CurrentTechnique.Passes)
            {
                for (byte chunkx = 0; chunkx < xychunks; chunkx++)
                {
                    for (byte chunkz = 0; chunkz < xychunks; chunkz++)
                    {
                        for (int terraintype = 0; terraintype < 4; terraintype++)
                        {
                            if (terraintype == 0)
                            {
                                currentVBRenderer = this.staticVBRenderer[chunkx, chunkz][0];
                            }
                            if (terraintype == 1)
                            {
                                currentVBRenderer = this.staticVBRenderer[chunkx, chunkz][1];
                            }
                            if (terraintype == 2)
                            {
                                currentVBRenderer = this.staticVBRenderer[chunkx, chunkz][2];
                            }
                            if (terraintype == 3)
                            {
                                currentVBRenderer = this.staticVBRenderer[chunkx, chunkz][3];
                            }
                            if (currentVBRenderer == null)
                            {
                                continue;
                            }

                            //Render that buffer
                            currentVBRenderer.Render(cubeEffect.View, cubeEffect.Projection, Textures[terraintype]);
                            drawn++;
                        }
                    }
                }
            }
        }
Ejemplo n.º 3
0
        public void GenerateMap()
        {
            //Make seeds
            seedx = r.Next(60000);
            //Lists for cube storage
            Grass = new List <Vector3> [(int)xychunks, (int)xychunks];
            Dirt  = new List <Vector3> [(int)xychunks, (int)xychunks];
            Water = new List <Vector3> [(int)xychunks, (int)xychunks];
            Stone = new List <Vector3> [(int)xychunks, (int)xychunks];
            //Initialize lists, buffer
            for (byte initx = 0; initx < xychunks; initx++)
            {
                for (byte inity = 0; inity < xychunks; inity++)
                {
                    Grass[initx, inity]            = new List <Vector3>();
                    Dirt[initx, inity]             = new List <Vector3>();
                    Water[initx, inity]            = new List <Vector3>();
                    Stone[initx, inity]            = new List <Vector3>();
                    staticVBRenderer[initx, inity] = new StaticVBRenderer[4];
                }
            }
            //Generate map in chunks

            for (byte chunkx = 0; chunkx < xychunks; chunkx++)
            {
                for (byte chunkz = 0; chunkz < xychunks; chunkz++)
                {
                    for (int x = 0 + (16 * (int)chunkx); x < width + (16 * (int)chunkx); x++)
                    {
                        for (int z = 0 + (16 * (int)chunkz); z < length + (16 * (int)chunkz); z++)
                        {
                            //perlin noise
                            float octave1 = PerlinNoise.noise((x + seedx) * 0.0001f, (z + seedx) * 0.0001f) * 0f;
                            float octave2 = PerlinNoise.noise((x + seedx) * 0.0005f, (z + seedx) * 0.0005f) * 0f;
                            float octave3 = PerlinNoise.noise((x + seedx) * 0.005f, (z + seedx) * 0.005f) * 0f;
                            float octave4 = PerlinNoise.noise((x + seedx) * 0.01f, (z + seedx) * 0.01f) * 20f;
                            float octave5 = PerlinNoise.noise((x + seedx) * 0.03f, (z + seedx) * 0.03f) * 5f;
                            //15,10 | 30, 8 <----- Octave 4/5 combos that are good so far
                            float lowerGroundHeight = octave1 + octave2 + octave3 + octave4 + octave5;
                            //Occlusion Culling
                            occlusionCull.Begin();
                            if ((55 + (int)lowerGroundHeight) <= 64)                                       //Check if water
                            {
                                Water[chunkx, chunkz].Add(new Vector3(x, 56 + (int)lowerGroundHeight, z)); //Add to water list
                                if (54 + (int)lowerGroundHeight < 64)
                                {
                                    for (int tosea = (54 + (int)lowerGroundHeight); tosea < 65; tosea++) //Create lakes/oceans depth
                                    {
                                        Water[chunkx, chunkz].Add(new Vector3(x, tosea + 1, z));         //Also add to list
                                    }
                                }
                            }

                            else
                            {
                                Grass[chunkx, chunkz].Add(new Vector3(x, 55 + (int)lowerGroundHeight, z)); //Add grass to list
                            }
                            occlusionCull.End();
                            //Fill in under ground level
                            if (occlusionCull.IsComplete == true && occlusionCull.PixelCount > 0)
                            {
                                for (int tobottom = (54 + (int)lowerGroundHeight); tobottom > (54 + (int)lowerGroundHeight) - 3; tobottom--)
                                {
                                    if (r.Next(100) > 50)
                                    {
                                        Dirt[chunkx, chunkz].Add(new Vector3(x, tobottom, z)); //Add to list
                                    }
                                    else
                                    {
                                        Stone[chunkx, chunkz].Add(new Vector3(x, tobottom, z)); //Add to list
                                    }
                                }
                            }
                            else if (occlusionCull.IsComplete == true && occlusionCull.PixelCount < 1)
                            {
                                for (int tobottom = (54 + (int)lowerGroundHeight); tobottom > (54 + (int)lowerGroundHeight) - 3; tobottom--)
                                {
                                    if (r.Next(100) > 50)
                                    {
                                        Dirt[chunkx, chunkz].Add(new Vector3(x, tobottom, z)); //Add to list
                                    }
                                    else
                                    {
                                        Stone[chunkx, chunkz].Add(new Vector3(x, tobottom, z)); //Add to list
                                    }
                                }
                            }
                        }
                    }
                }
            }
            //load the buffers
            for (byte chunkx = 0; chunkx < xychunks; chunkx++)
            {
                for (byte chunkz = 0; chunkz < xychunks; chunkz++)
                {
                    //Create buffers in chunks for rendering
                    if (Stone[chunkx, chunkz].Count != 0)
                    {
                        this.staticVBRenderer[chunkx, chunkz][0] = new StaticVBRenderer(ScreenManager.Game.GraphicsDevice, Textures[0], Stone[chunkx, chunkz], staticVBEffect);
                    }
                    if (Grass[chunkx, chunkz].Count != 0)
                    {
                        this.staticVBRenderer[chunkx, chunkz][1] = new StaticVBRenderer(ScreenManager.Game.GraphicsDevice, Textures[1], Grass[chunkx, chunkz], staticVBEffect);
                    }
                    if (Dirt[chunkx, chunkz].Count != 0)
                    {
                        this.staticVBRenderer[chunkx, chunkz][2] = new StaticVBRenderer(ScreenManager.Game.GraphicsDevice, Textures[2], Dirt[chunkx, chunkz], staticVBEffect);
                    }
                    if (Water[chunkx, chunkz].Count != 0)
                    {
                        this.staticVBRenderer[chunkx, chunkz][3] = new StaticVBRenderer(ScreenManager.Game.GraphicsDevice, Textures[3], Water[chunkx, chunkz], staticVBEffect);
                    }
                }
            }
            ////Make boudning boxes for the chunk culling. Need working on.
            int minx = 0;
            int minz = 0;

            for (int chunkx = 0; chunkx < xychunks; chunkx++)
            {
                for (int chunkz = 0; chunkz < xychunks; chunkz++)
                {
                    //box around the chunks of cubes
                    minx = chunkx * 16;
                    minz = chunkz * 16;
                    thisqube[chunkx, chunkz] = new BoundingBox(new Vector3(minx, 0, minz), new Vector3(minx + 16, 128, minz + 16));
                }
            }
        }
Ejemplo n.º 4
0
        public void GenerateMap()
        {
            //Make seeds
            seedx = r.Next(60000);
            //Lists for cube storage
            Grass = new List<Vector3>[(int)xychunks, (int)xychunks];
            Dirt = new List<Vector3>[(int)xychunks, (int)xychunks];
            Water = new List<Vector3>[(int)xychunks, (int)xychunks];
            Stone = new List<Vector3>[(int)xychunks, (int)xychunks];
            //Initialize lists, buffer
            for (byte initx = 0; initx < xychunks; initx++)
            {
                for (byte inity = 0; inity < xychunks; inity++)
                {
                    Grass[initx, inity] = new List<Vector3>();
                    Dirt[initx, inity] = new List<Vector3>();
                    Water[initx, inity] = new List<Vector3>();
                    Stone[initx, inity] = new List<Vector3>();
                    staticVBRenderer[initx, inity] = new StaticVBRenderer[4];
                }
            }
            //Generate map in chunks
            for (byte chunkx = 0; chunkx < xychunks; chunkx++)
            {
                for (byte chunkz = 0; chunkz < xychunks; chunkz++)
                {
                    for (int x = 0 + (16 * (int)chunkx); x < width + (16 * (int)chunkx); x++)
                    {
                        for (int z = 0 + (16 * (int)chunkz); z < length + (16 * (int)chunkz); z++)
                        {
                            //perlin noise
                            float octave1 = PerlinNoise.noise((x + seedx) * 0.0001f, (z + seedx) * 0.0001f) * 0f;
                            float octave2 = PerlinNoise.noise((x + seedx) * 0.0005f, (z + seedx) * 0.0005f) * 0f;
                            float octave3 = PerlinNoise.noise((x + seedx) * 0.005f, (z + seedx) * 0.005f) * 0f;
                            float octave4 = PerlinNoise.noise((x + seedx) * 0.01f, (z + seedx) * 0.01f) * 20f;
                            float octave5 = PerlinNoise.noise((x + seedx) * 0.03f, (z + seedx) * 0.03f) * 5f;
                            //15,10 | 30, 8 <----- Octave 4/5 combos that are good so far

                            float lowerGroundHeight = octave1 + octave2 + octave3 + octave4 + octave5;
                            if ((55 + (int)lowerGroundHeight) <= 64) //Check if water
                            {
                                Water[chunkx, chunkz].Add(new Vector3(x, 56 + (int)lowerGroundHeight, z)); //Add to water list
                                if (54 + (int)lowerGroundHeight < 64)
                                {
                                    for (int tosea = (54 + (int)lowerGroundHeight); tosea < 65; tosea++) //Create lakes/oceans depth
                                    {
                                        Water[chunkx, chunkz].Add(new Vector3(x, tosea + 1, z)); //Also add to list
                                    }
                                }
                            }
                            else
                            {
                                Grass[chunkx, chunkz].Add(new Vector3(x, 55 + (int)lowerGroundHeight, z)); //Add grass to list
                            }

                            //Fill in under ground level
                            for (int tobottom = (54 + (int)lowerGroundHeight); tobottom > (54 + (int)lowerGroundHeight) - 3; tobottom--)
                            {
                                if (r.Next(100) > 50)
                                {
                                    Dirt[chunkx, chunkz].Add(new Vector3(x, tobottom, z)); //Add to list
                                }
                                else
                                {
                                    Stone[chunkx, chunkz].Add(new Vector3(x, tobottom, z)); //Add to list
                                }
                            }
                        }
                    }
                }
            }
            //load the buffers
            for (byte chunkx = 0; chunkx < xychunks; chunkx++)
            {
                for (byte chunkz = 0; chunkz < xychunks; chunkz++)
                {
                    //Create buffers in chunks for rendering
                    if (Stone[chunkx, chunkz].Count != 0)
                        this.staticVBRenderer[chunkx, chunkz][0] = new StaticVBRenderer(ScreenManager.Game.GraphicsDevice, Textures[0], Stone[chunkx, chunkz], staticVBEffect);
                    if (Grass[chunkx, chunkz].Count != 0)
                        this.staticVBRenderer[chunkx, chunkz][1] = new StaticVBRenderer(ScreenManager.Game.GraphicsDevice, Textures[1], Grass[chunkx, chunkz], staticVBEffect);
                    if (Dirt[chunkx, chunkz].Count != 0)
                        this.staticVBRenderer[chunkx, chunkz][2] = new StaticVBRenderer(ScreenManager.Game.GraphicsDevice, Textures[2], Dirt[chunkx, chunkz], staticVBEffect);
                    if (Water[chunkx, chunkz].Count != 0)
                        this.staticVBRenderer[chunkx, chunkz][3] = new StaticVBRenderer(ScreenManager.Game.GraphicsDevice, Textures[3], Water[chunkx, chunkz], staticVBEffect);
                }
            }
        }
Ejemplo n.º 5
0
        public void DrawCubes()
        {
            foreach (EffectPass pass in cubeEffect.CurrentTechnique.Passes)
            {
                for (byte chunkx = 0; chunkx < xychunks; chunkx++)
                {
                    for (byte chunkz = 0; chunkz < xychunks; chunkz++)
                    {
                        for (int terraintype = 0; terraintype < 4; terraintype++)
                        {
                            if (terraintype == 0)
                                currentVBRenderer = this.staticVBRenderer[chunkx, chunkz][0];
                            if (terraintype == 1)
                                currentVBRenderer = this.staticVBRenderer[chunkx, chunkz][1];
                            if (terraintype == 2)
                                currentVBRenderer = this.staticVBRenderer[chunkx, chunkz][2];
                            if (terraintype == 3)
                                currentVBRenderer = this.staticVBRenderer[chunkx, chunkz][3];
                            if (currentVBRenderer == null)
                                continue;

                            //Render that buffer
                            currentVBRenderer.Render(cubeEffect.View, cubeEffect.Projection, Textures[terraintype]);
                            drawn++;
                        }
                    }
                }
            }
        }
Ejemplo n.º 6
0
        public void DrawCubes()
        {
            foreach (EffectPass pass in cubeEffect.CurrentTechnique.Passes)
            {
                for (byte chunkx = 0; chunkx < xychunks; chunkx++)
                {
                    for (byte chunkz = 0; chunkz < xychunks; chunkz++)
                    {
                        //FRUSTUM CULL HERE
                        if (InView(thisqube[chunkx, chunkz]) == false)
                        {
                            culled++;
                            continue;
                        }

                        //Checks to see which terrain type to render
                        for (int terraintype = 0; terraintype < 4; terraintype++)
                        {
                            if (terraintype == 0)
                                currentVBRenderer = this.staticVBRenderer[chunkx, chunkz][0];
                            if (terraintype == 1)
                                currentVBRenderer = this.staticVBRenderer[chunkx, chunkz][1];
                            if (terraintype == 2)
                                currentVBRenderer = this.staticVBRenderer[chunkx, chunkz][2];
                            if (terraintype == 3)
                                currentVBRenderer = this.staticVBRenderer[chunkx, chunkz][3];
                            if (currentVBRenderer == null)
                                continue;

                            //Render that buffer
                            currentVBRenderer.Render(cubeEffect.View, cubeEffect.Projection, Textures[terraintype]);
                            drawn++;
                        }
                    }
                }
            }
        }