Exemple #1
0
        public void UpdateVertex(int x, int y, Vector3 vector, VertexEquation equation)
        {
            //skip references vertices
            //if ((coordinates.X > 0 || coordinates.Y > 0) && (x == divisions.X - 1 || y == divisions.Y - 1))
            //    return;

            int index = x + y * divisions.X;

            if (index < 0 || index >= vertices.Length)
                return;

            switch (equation)
            {
                case VertexEquation.Substitute:
                    vertices[index].Position = vector;
                    break;
                case VertexEquation.Add:
                    vertices[index].Position += vector;
                    break;
                case VertexEquation.Substract:
                    vertices[index].Position -= vector;
                    break;
                case VertexEquation.Multiply:
                    vertices[index].Position *= vector;
                    break;
                case VertexEquation.Divide:
                    vertices[index].Position /= vector;
                    break;
            }

            if (vertices[index].Position.Y < minHeight)
            {
                minHeight = vertices[index].Position.Y;
                UpdateBoundingBox(minHeight, maxHeight);

                
                //----------------Update adjacent boundingboxes-------------------
                if(coordinates.X == 0 || coordinates.Y == 0)                    

                if (x == 0 || y == 0)
                {
                    if (x == 0 && y == 0 && adjacent_cell[0, 0] != null)
                        adjacent_cell[0,0].UpdateBoundingBox();
                    if (y == 0 && adjacent_cell[1, 0] != null)
                        adjacent_cell[1,0].UpdateBoundingBox();
                    if (x == 0 && adjacent_cell[0, 1] != null)
                        adjacent_cell[0, 1].UpdateBoundingBox();
                }
            }
            else if (vertices[index].Position.Y > maxHeight)
            {
                maxHeight = vertices[index].Position.Y;
                UpdateBoundingBox(minHeight, maxHeight);

                //Update adjacent boundingboxes
                if (x == 0 || y == 0)
                {
                    if (x == 0 && y == 0 && adjacent_cell[0, 0] != null)
                        adjacent_cell[0, 0].UpdateBoundingBox();
                    if (y == 0 && adjacent_cell[1, 0] != null)
                        adjacent_cell[1, 0].UpdateBoundingBox();
                    if (x == 0 && adjacent_cell[0, 1] != null)
                        adjacent_cell[0, 1].UpdateBoundingBox();
                }
            }


            Redraw();

            //SetVertexBuffer(null, null);

            //if (x == divisions.X - 1 || y == divisions.Y - 1)
            //    UpdateAdjacentCells();
            
        }
        public void UpdateVertex(int x, int y, Vector3 vector, VertexEquation equation)
        {
            //skip references vertices
            //if ((coordinates.X > 0 || coordinates.Y > 0) && (x == divisions.X - 1 || y == divisions.Y - 1))
            //    return;

            int index = x + y * divisions.X;

            if (index < 0 || index >= vertices.Length)
            {
                return;
            }

            switch (equation)
            {
            case VertexEquation.Substitute:
                vertices[index].Position = vector;
                break;

            case VertexEquation.Add:
                vertices[index].Position += vector;
                break;

            case VertexEquation.Substract:
                vertices[index].Position -= vector;
                break;

            case VertexEquation.Multiply:
                vertices[index].Position *= vector;
                break;

            case VertexEquation.Divide:
                vertices[index].Position /= vector;
                break;
            }

            if (vertices[index].Position.Y < minHeight)
            {
                minHeight = vertices[index].Position.Y;
                UpdateBoundingBox(minHeight, maxHeight);


                //----------------Update adjacent boundingboxes-------------------
                if (coordinates.X == 0 || coordinates.Y == 0)
                {
                    if (x == 0 || y == 0)
                    {
                        if (x == 0 && y == 0 && adjacent_cell[0, 0] != null)
                        {
                            adjacent_cell[0, 0].UpdateBoundingBox();
                        }
                        if (y == 0 && adjacent_cell[1, 0] != null)
                        {
                            adjacent_cell[1, 0].UpdateBoundingBox();
                        }
                        if (x == 0 && adjacent_cell[0, 1] != null)
                        {
                            adjacent_cell[0, 1].UpdateBoundingBox();
                        }
                    }
                }
            }
            else if (vertices[index].Position.Y > maxHeight)
            {
                maxHeight = vertices[index].Position.Y;
                UpdateBoundingBox(minHeight, maxHeight);

                //Update adjacent boundingboxes
                if (x == 0 || y == 0)
                {
                    if (x == 0 && y == 0 && adjacent_cell[0, 0] != null)
                    {
                        adjacent_cell[0, 0].UpdateBoundingBox();
                    }
                    if (y == 0 && adjacent_cell[1, 0] != null)
                    {
                        adjacent_cell[1, 0].UpdateBoundingBox();
                    }
                    if (x == 0 && adjacent_cell[0, 1] != null)
                    {
                        adjacent_cell[0, 1].UpdateBoundingBox();
                    }
                }
            }


            Redraw();

            //SetVertexBuffer(null, null);

            //if (x == divisions.X - 1 || y == divisions.Y - 1)
            //    UpdateAdjacentCells();
        }