Exemplo n.º 1
0
        public void ApplyBrush(IBrushShape brushshape, int brushsize, double brushcentre_x, double brushcentre_y, bool israising, double milliseconds)
        {
            if (currentfeature == null)
            {
                return;
            }

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

            if (israising)
            {
                if (Terrain.GetInstance().FeatureMap[x, y] == null)
                {
                    Terrain.GetInstance().FeatureMap[x, y] = currentfeature;
                    LogFile.GetInstance().WriteLine("feature " + currentfeature.texturename1 + " added to " + x + " " + y);
                    Terrain.GetInstance().OnFeatureAdded(currentfeature, x, y);
                }
            }
            else
            {
                if (Terrain.GetInstance().FeatureMap[x, y] != null)
                {
                    Unit oldunit = Terrain.GetInstance().FeatureMap[x, y];
                    Terrain.GetInstance().FeatureMap[x, y] = null;
                    Terrain.GetInstance().OnFeatureRemoved(oldunit, x, y);
                }
            }
        }
Exemplo n.º 2
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 );
        }
Exemplo n.º 3
0
        public void ApplyBrush( IBrushShape brushshape, int brushsize, double brushcentrex, double brushcentrey, bool israising, double milliseconds )
        {
            if (heightscale == null)
            {
                return;
            }
            double targetheight = heightscale.Value;
            Console.WriteLine( "height scale value: " + targetheight );
            int x = (int)( brushcentrex / Terrain.SquareSize );
            int y = (int)(brushcentrey / Terrain.SquareSize);

            for (int i = -brushsize; i <= brushsize; i++)
            {
                for (int j = -brushsize; j <= brushsize; j++)
                {
                    double brushcontribution = brushshape.GetStrength(
                        (double)i / brushsize, (double)j / brushsize );
                    if (brushcontribution > 0)
                    {
                        int thisx = x + i;
                        int thisy = y + j;
                        if (thisx >= 0 && thisy >= 0 &&
                            thisx < Terrain.GetInstance().HeightMapWidth &&
                            thisy < Terrain.GetInstance().HeightMapHeight)
                        {
                            double oldheight = Terrain.GetInstance().Map[thisx, thisy];
                            double newheight = oldheight + (targetheight - oldheight) *
                                speed * milliseconds / 50 * brushcontribution;
                            Terrain.GetInstance().Map[thisx, thisy] = newheight;
                        }
                    }
                }
            }
            Terrain.GetInstance().OnHeightMapInPlaceEdited( x - brushsize, y - brushsize, x + brushsize, y + brushsize );
        }
Exemplo n.º 4
0
        public void ApplyBrush(IBrushShape brushshape, int brushsize, double brushcentre_x, double brushcentre_y, bool israising, double milliseconds)
        {
            TerrainModel terrain = MetaverseClient.GetInstance().worldstorage.terrainmodel;

            double[,] mesh = terrain.Map;

            int x = (int)(brushcentre_x);
            int y = (int)(brushcentre_y);

            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);
        }
Exemplo n.º 5
0
        public void ApplyBrush( IBrushShape brushshape, int brushsize, double brushcentre_x, double brushcentre_y, bool israising, double milliseconds )
        {
            if (currentfeature == null)
            {
                return;
            }

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

            if (israising)
            {
                if (Terrain.GetInstance().FeatureMap[x, y] == null)
                {
                    Terrain.GetInstance().FeatureMap[x, y] = currentfeature;
                    LogFile.GetInstance().WriteLine( "feature " + currentfeature.texturename1 + " added to " + x + " " + y );
                    Terrain.GetInstance().OnFeatureAdded( currentfeature, x, y );
                }
            }
            else
            {
                if (Terrain.GetInstance().FeatureMap[x, y] != null)
                {
                    Unit oldunit = Terrain.GetInstance().FeatureMap[x, y];
                    Terrain.GetInstance().FeatureMap[x, y] = null;
                    Terrain.GetInstance().OnFeatureRemoved( oldunit, x, y );
                }
            }
        }
 public void Register( IBrushShape brushshape )
 {
     Console.WriteLine(this.GetType() + " registering " + brushshape );
     this.brushshapes.Add( brushshape.GetType(), brushshape );
     if (CurrentEditBrush.GetInstance().BrushShape == null)
     {
         CurrentEditBrush.GetInstance().BrushShape = brushshape;
     }
     MainUI.GetInstance().uiwindow.AddBrushShape( brushshape.Name, brushshape.Description, brushshape );
 }
Exemplo n.º 7
0
        void brushshape_Toggled(object o, EventArgs e)
        {
            IBrushShape targeteffect = brushshapes[o as RadioButton];

            Console.WriteLine("selected shape " + targeteffect);
            CurrentEditBrush.GetInstance().BrushShape = targeteffect;
            ClearVBox(custombrushshapelabels);
            ClearVBox(custombrushshapewidgets);
            targeteffect.ShowControlBox(custombrushshapelabels, custombrushshapewidgets);
        }
Exemplo n.º 8
0
 public void Register(IBrushShape brushshape)
 {
     Console.WriteLine(this.GetType() + " registering " + brushshape);
     this.brushshapes.Add(brushshape.GetType(), brushshape);
     if (CurrentEditBrush.GetInstance().BrushShape == null)
     {
         CurrentEditBrush.GetInstance().BrushShape = brushshape;
     }
     MainUI.GetInstance().uiwindow.AddBrushShape(brushshape.Name, brushshape.Description, brushshape);
 }
Exemplo n.º 9
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);
            }
        }
Exemplo n.º 10
0
        public void ApplyBrush(IBrushShape brushshape, int brushsize, double brushcentre_x, double brushcentre_y, bool israising, double timespanmilliseconds)
        {
            Terrain terrain = Terrain.GetInstance();

            double[,] mesh = terrain.Map;

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

            double timemultiplier = timespanmilliseconds * 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)
                        {
                            double directionmultiplier = 1.0;
                            if (!israising)
                            {
                                directionmultiplier = -1.0;
                            }
                            mesh[thisx, thisy] += (brushshapecontribution * directionmultiplier * timemultiplier);
                            if (mesh[thisx, thisy] >= terrain.MaxHeight)
                            {
                                mesh[thisx, thisy] = terrain.MaxHeight;
                            }
                            else if (mesh[thisx, thisy] < terrain.MinHeight)
                            {
                                mesh[thisx, thisy] = terrain.MinHeight;
                            }
                        }
                    }
                }
            }
            terrain.OnHeightMapInPlaceEdited(x - brushsize, y - brushsize, x + brushsize, y + brushsize);
        }
Exemplo n.º 11
0
        public void ApplyBrush( IBrushShape brushshape, int brushsize, double brushcentre_x, double brushcentre_y, bool israising, double timespanmilliseconds )
        {
            TerrainModel terrain = MetaverseClient.GetInstance().worldstorage.terrainmodel;
            double[,] mesh = terrain.Map;

            int x = (int)(brushcentre_x );
            int y = (int)(brushcentre_y );

            double timemultiplier = timespanmilliseconds * 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)
                        {
                            double directionmultiplier = 1.0;
                            if (!israising)
                            {
                                directionmultiplier = -1.0;
                            }
                            mesh[thisx, thisy] += (brushshapecontribution * directionmultiplier * timemultiplier);
                            if (mesh[thisx, thisy] >= terrain.MaxHeight)
                            {
                                mesh[thisx, thisy] = terrain.MaxHeight;
                            }
                            else if (mesh[thisx, thisy] < terrain.MinHeight)
                            {
                                mesh[thisx, thisy] = terrain.MinHeight;
                            }
                        }
                    }
                }
            }
            terrain.OnHeightMapInPlaceEdited( x - brushsize, y - brushsize, x + brushsize, y + brushsize );
        }
Exemplo n.º 12
0
        public void AddBrushShape(string name, string description, IBrushShape brushshape)
        {
            RadioButton radiobutton = null;

            if (brushshapegroup != null)
            {
                radiobutton = new RadioButton(brushshapegroup, name);
                brushshapevbox.PackEnd(radiobutton);
                brushshapevbox.ShowAll();
            }
            else
            {
                radiobutton = new RadioButton(name);
                brushshapevbox.PackEnd(radiobutton);
                brushshapevbox.ShowAll();
                brushshapegroup = radiobutton;
                brushshape.ShowControlBox(custombrushshapelabels, custombrushshapewidgets);
                // radiobutton.Activate();
            }
            brushshapes.Add(radiobutton, brushshape);
            radiobutton.Toggled += new EventHandler(brushshape_Toggled);
        }
Exemplo n.º 13
0
        public void ApplyBrush(IBrushShape brushshape, int brushsize, double brushcentrex, double brushcentrey, bool israising, double milliseconds)
        {
            if (heightscale == null)
            {
                return;
            }
            double targetheight = heightscale.Value;

            Console.WriteLine("height scale value: " + targetheight);
            int x = (int)(brushcentrex / Terrain.SquareSize);
            int y = (int)(brushcentrey / Terrain.SquareSize);

            for (int i = -brushsize; i <= brushsize; i++)
            {
                for (int j = -brushsize; j <= brushsize; j++)
                {
                    double brushcontribution = brushshape.GetStrength(
                        (double)i / brushsize, (double)j / brushsize);
                    if (brushcontribution > 0)
                    {
                        int thisx = x + i;
                        int thisy = y + j;
                        if (thisx >= 0 && thisy >= 0 &&
                            thisx < Terrain.GetInstance().HeightMapWidth&&
                            thisy < Terrain.GetInstance().HeightMapHeight)
                        {
                            double oldheight = Terrain.GetInstance().Map[thisx, thisy];
                            double newheight = oldheight + (targetheight - oldheight) *
                                               speed * milliseconds / 50 * brushcontribution;
                            Terrain.GetInstance().Map[thisx, thisy] = newheight;
                        }
                    }
                }
            }
            Terrain.GetInstance().OnHeightMapInPlaceEdited(x - brushsize, y - brushsize, x + brushsize, y + brushsize);
        }
Exemplo n.º 14
0
 public void AddBrushShape( string name, string description, IBrushShape brushshape )
 {
     RadioButton radiobutton = null;
     if (brushshapegroup != null )
     {
         radiobutton = new RadioButton( brushshapegroup, name );
         brushshapevbox.PackEnd( radiobutton );
         brushshapevbox.ShowAll();
     }
     else
     {
         radiobutton = new RadioButton( name );
         brushshapevbox.PackEnd( radiobutton );
         brushshapevbox.ShowAll();
         brushshapegroup = radiobutton;
         brushshape.ShowControlBox( custombrushshapelabels, custombrushshapewidgets );
        // radiobutton.Activate();
     }
     brushshapes.Add( radiobutton, brushshape );
     radiobutton.Toggled += new EventHandler( brushshape_Toggled );
 }
Exemplo n.º 15
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 );
                int mapy = (int)(brushcentrey );
                int mapwidth = MetaverseClient.GetInstance().worldstorage.terrainmodel.HeightMapWidth - 1;
                int mapheight = MetaverseClient.GetInstance().worldstorage.terrainmodel.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
                                //LogFile.WriteLine( speed + " " + directionmultiplier + " " + timemultiplier + " " + brushshapecontribution );
                                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.SetPixel( thisx, thisy, (byte)alphadata[thisx, thisy], (byte)alphadata[thisx, thisy], (byte)alphadata[thisx, thisy], 255 );
                                //LogFile.WriteLine( "setting pixel " + thisx + " " + thisy + " to " + (byte)alphadata[thisx, thisy] );
                                //thistexture.AlphaData[thisx, thisy] = (byte)alphadata[thisx, thisy];
                                //  Console.WriteLine(thisx + " " + thisy + " " + (byte)alphadata[thisx, thisy]);
                            }
                        }
                    }
                }

                thistexture.Save( "editedblend.jpg" );

                //thistexture.ReloadAlpha();
                maptexturestage.onChanged();
                //thistexture.Modified = true;
                MetaverseClient.GetInstance().worldstorage.terrainmodel.OnBlendMapInPlaceEdited( maptexturestage, mapx - brushsize, mapy - brushsize, mapx + brushsize, mapy + brushsize );
            }
        }
Exemplo n.º 16
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);
                int mapy               = (int)(brushcentrey);
                int mapwidth           = MetaverseClient.GetInstance().worldstorage.terrainmodel.HeightMapWidth - 1;
                int mapheight          = MetaverseClient.GetInstance().worldstorage.terrainmodel.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
                                //LogFile.WriteLine( speed + " " + directionmultiplier + " " + timemultiplier + " " + brushshapecontribution );
                                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.SetPixel(thisx, thisy, (byte)alphadata[thisx, thisy], (byte)alphadata[thisx, thisy], (byte)alphadata[thisx, thisy], 255);
                                //LogFile.WriteLine( "setting pixel " + thisx + " " + thisy + " to " + (byte)alphadata[thisx, thisy] );
                                //thistexture.AlphaData[thisx, thisy] = (byte)alphadata[thisx, thisy];
                                //  Console.WriteLine(thisx + " " + thisy + " " + (byte)alphadata[thisx, thisy]);
                            }
                        }
                    }
                }

                thistexture.Save("editedblend.jpg");

                //thistexture.ReloadAlpha();
                maptexturestage.onChanged();
                //thistexture.Modified = true;
                MetaverseClient.GetInstance().worldstorage.terrainmodel.OnBlendMapInPlaceEdited(maptexturestage, mapx - brushsize, mapy - brushsize, mapx + brushsize, mapy + brushsize);
            }
        }