Example #1
0
        public void ApplyBrush(IBrushShape brushshape, int brushsize, double brushcentre_x, double brushcentre_y, bool israising, double milliseconds)
        {
            Terrain terrain = Terrain.GetInstance();

            double[,] mesh = terrain.Map;

            int x = (int)(brushcentre_x / Terrain.SquareSize);
            int y = (int)(brushcentre_y / Terrain.SquareSize);

            double timemultiplier = milliseconds * speed;
            int    meshsize       = mesh.GetUpperBound(0) + 1;

            for (int i = -brushsize; i <= brushsize; i++)
            {
                for (int j = -brushsize; j <= brushsize; j++)
                {
                    int thisx = x + i;
                    int thisy = y + j;
                    if (thisx >= 0 && thisy >= 0 && thisx < meshsize &&
                        thisy < meshsize)
                    {
                        double brushshapecontribution = brushshape.GetStrength((double)i / brushsize, (double)j / brushsize);
                        if (brushshapecontribution > 0)
                        {
                            mesh[thisx, thisy] = mesh[thisx, thisy] + (mesh[x, y] - mesh[thisx, thisy]) * brushshapecontribution * timemultiplier / 50;
                        }
                    }
                }
            }
            terrain.OnHeightMapInPlaceEdited(x - brushsize, y - brushsize, x + brushsize, y + brushsize);
        }