/// <summary>
        /// Optimized Heightmap, using cells to optimize process of drawing and modifying.
        /// The heightmap is divided into cells which are each surrounded by a bounding box and
        /// hidden if they are outside of the field of view or too far away. The bounding boxes 
        /// are also used to speed up the ray detection test when making modifications to the terrain.
        /// </summary>
        /// <param name="divisions">Size of the map, ex: 256x256</param>
        /// <param name="cellsize">The size of a single quad, ex: 50x50</param>
        /// <param name="cellDivisions">Number of quads in each heightmap cell, ex: 16x16</param>
        public Optimized_Heightmap(GraphicsDevice graphicsDevice, Point divisions, Vector2 cellsize, Point cellDivisions)
        {
            this.size = divisions;
            this.cellSize = cellsize;
            this.cellDivisions = cellDivisions;

            //basicEffect = new BasicEffect(graphicsDevice, null);
            //basicEffect.VertexColorEnabled = true;
            effect = Editor.content.Load<Effect>(@"content\shaders\opt_heightmap");
            effectParams = new EffectParams(ref effect, "TransformWireframe");

            int w = (int)((float)divisions.X / (float)cellDivisions.X);
            int h = (int)((float)divisions.Y / (float)cellDivisions.Y);

            cell = new HeightmapCell[w, h];

            //Build the cells
            for (int y = 0; y < w; y++)
            {
                for (int x = 0; x < h; x++)
                {
                    //get the adjacent cells (max 3) : [0,0],[0,1],[1,0]
                    HeightmapCell[,] adjacent_cell = new HeightmapCell[2, 2];
                    if (x > 0) adjacent_cell[0, 1] = cell[x - 1, y];
                    if (y > 0) adjacent_cell[1, 0] = cell[x, y - 1];
                    if (x > 0 && y > 0) adjacent_cell[0, 0] = cell[x - 1, y - 1];

                    cell[x, y] = new HeightmapCell(graphicsDevice, new Point(x, y), cellDivisions, cellsize, adjacent_cell);
                }
            }

            HeightmapCell.Tri collisionTri = cell[0,0].triangle[0];
            testTri = new Triangle(collisionTri.p1, collisionTri.p2, collisionTri.p3, Color.White);
        }
Beispiel #2
0
        /// <summary>
        /// Optimized Heightmap, using cells to optimize process of drawing and modifying.
        /// The heightmap is divided into cells which are each surrounded by a bounding box and
        /// hidden if they are outside of the field of view or too far away. The bounding boxes
        /// are also used to speed up the ray detection test when making modifications to the terrain.
        /// </summary>
        /// <param name="divisions">Size of the map, ex: 256x256</param>
        /// <param name="cellsize">The size of a single quad, ex: 50x50</param>
        /// <param name="cellDivisions">Number of quads in each heightmap cell, ex: 16x16</param>
        public Optimized_Heightmap(GraphicsDevice graphicsDevice, Point divisions, Vector2 cellsize, Point cellDivisions)
        {
            this.size          = divisions;
            this.cellSize      = cellsize;
            this.cellDivisions = cellDivisions;

            //basicEffect = new BasicEffect(graphicsDevice, null);
            //basicEffect.VertexColorEnabled = true;
            effect       = Editor.content.Load <Effect>(@"content\shaders\opt_heightmap");
            effectParams = new EffectParams(ref effect, "TransformWireframe");

            int w = (int)((float)divisions.X / (float)cellDivisions.X);
            int h = (int)((float)divisions.Y / (float)cellDivisions.Y);

            cell = new HeightmapCell[w, h];

            //Build the cells
            for (int y = 0; y < w; y++)
            {
                for (int x = 0; x < h; x++)
                {
                    //get the adjacent cells (max 3) : [0,0],[0,1],[1,0]
                    HeightmapCell[,] adjacent_cell = new HeightmapCell[2, 2];
                    if (x > 0)
                    {
                        adjacent_cell[0, 1] = cell[x - 1, y];
                    }
                    if (y > 0)
                    {
                        adjacent_cell[1, 0] = cell[x, y - 1];
                    }
                    if (x > 0 && y > 0)
                    {
                        adjacent_cell[0, 0] = cell[x - 1, y - 1];
                    }

                    cell[x, y] = new HeightmapCell(graphicsDevice, new Point(x, y), cellDivisions, cellsize, adjacent_cell);
                }
            }

            HeightmapCell.Tri collisionTri = cell[0, 0].triangle[0];
            testTri = new Triangle(collisionTri.p1, collisionTri.p2, collisionTri.p3, Color.White);
        }
Beispiel #3
0
        public HeightmapCell(GraphicsDevice graphicsDevice, Point coordinates, Point divisions, Vector2 cellsize, HeightmapCell[,] adjacent_cell)
        {
            this.coordinates = coordinates;
            this.divisions = divisions;
            this.cellsize = cellsize;
            this.adjacent_cell = adjacent_cell;

            position = new Vector3();
            position.X = coordinates.X * divisions.X * cellsize.X - cellsize.X * coordinates.X;
            position.Z = coordinates.Y * divisions.Y * cellsize.Y - cellsize.Y * coordinates.Y;

            center.X = position.X + (divisions.X * cellsize.X - cellsize.X) / 2;
            center.Z = position.Z + (divisions.Y * cellsize.Y - cellsize.Y) / 2;

            SetUpVertices(graphicsDevice);
            //SetupTilingRefs();
            UpdateAdjacentCells();
            SetVertexBuffer(graphicsDevice, null);

            SetUpIndices();
            SetIndexBuffer(graphicsDevice);

            Update();
        }