Beispiel #1
0
        public void ApplyBrush(IBrushShape brushshape, int brushsize, double brushcentrex, double brushcentrey, bool israising, double milliseconds)
        {
            if (thistexture != null && maptexturestage != null)
            {
                double timemultiplier = milliseconds * speed;

                double directionmultiplier = 1.0;
                if (!israising)
                {
                    directionmultiplier = -1.0;
                }

                int mapx               = (int)(brushcentrex / Terrain.SquareSize);
                int mapy               = (int)(brushcentrey / Terrain.SquareSize);
                int mapwidth           = Terrain.GetInstance().HeightMapWidth - 1;
                int mapheight          = Terrain.GetInstance().HeightMapHeight - 1;
                int texturex           = (int)(texturewidth * mapx / mapwidth);
                int texturey           = (int)(textureheight * mapy / mapheight);
                int texturebrushwidth  = (int)(texturewidth * brushsize / mapwidth);
                int texturebrushheight = (int)(textureheight * brushsize / mapheight);
                for (int i = -texturebrushwidth; i <= texturebrushwidth; i++)
                {
                    for (int j = -texturebrushheight; j <= texturebrushheight; j++)
                    {
                        double brushshapecontribution = brushshape.GetStrength((double)i / texturebrushwidth,
                                                                               (double)j / texturebrushheight);
                        if (brushshapecontribution > 0)
                        {
                            int thisx = texturex + i;
                            int thisy = texturey + j;
                            //      Console.WriteLine(thisx + " " + thisy);
                            if (thisx >= 0 && thisy >= 0 && thisx < texturewidth &&
                                thisy < textureheight)
                            {
                                // we update our double array then set the int array iwthin ITexture itself
                                alphadata[thisx, thisy] += speed * directionmultiplier * timemultiplier * brushshapecontribution;
                                if (alphadata[thisx, thisy] >= 255)
                                {
                                    alphadata[thisx, thisy] = 255;
                                }
                                else if (alphadata[thisx, thisy] < 0)
                                {
                                    alphadata[thisx, thisy] = 0;
                                }
                                thistexture.AlphaData[thisx, thisy] = (byte)alphadata[thisx, thisy];
                                //  Console.WriteLine(thisx + " " + thisy + " " + (byte)alphadata[thisx, thisy]);
                            }
                        }
                    }
                }
                thistexture.ReloadAlpha();
                thistexture.Modified = true;
                Terrain.GetInstance().OnBlendMapInPlaceEdited(maptexturestage, mapx - brushsize, mapy - brushsize, mapx + brushsize, mapy + brushsize);
            }
        }