/// <summary>
 /// Me guardo la altura del primer vertice.
 /// </summary>
 /// <param name="terrain"></param>
 public override void beginEdition(SmartTerrain terrain)
 {
     base.beginEdition(terrain);
     Vector2 coords;
     if (terrain.xzToHeightmapCoords(Position.X, Position.Z, out coords))
         terrain.interpoledIntensity(coords.X, coords.Y, out level);
 }
Exemple #2
0
        /// <summary>
        ///     Me guardo la altura del primer vertice.
        /// </summary>
        /// <param name="terrain"></param>
        public override void beginEdition(SmartTerrain terrain)
        {
            base.beginEdition(terrain);
            TGCVector2 coords;

            if (terrain.xzToHeightmapCoords(Position.X, Position.Z, out coords))
            {
                terrain.interpoledIntensity(coords.X, coords.Y, out level);
            }
        }
Exemple #3
0
        public virtual bool editTerrain(float elapsedTime)
        {
            var speed = elapsedTime * getSpeedAdjustment();

            if (Invert)
            {
                speed *= -1;
            }

            var radius       = Radius / terrain.ScaleXZ;
            var innerRadius  = radius * (Hardness / 100);
            var radius2      = FastMath.Pow2(radius);
            var innerRadius2 = FastMath.Pow2(innerRadius);

            TGCVector2 coords;
            var        heightmapData = terrain.HeightmapData;
            var        changed       = false;

            if (!terrain.xzToHeightmapCoords(Position.X, Position.Z, out coords))
            {
                return(false);
            }

            //Calculo un cuadrado alrededor del vertice seleccionado
            int[] min = { (int)FastMath.Ceiling(coords.X - radius), (int)FastMath.Ceiling(coords.Y - radius) };

            float[] max = { coords.X + radius, coords.Y + radius };

            for (var i = 0; i < 2; i++)
            {
                if (min[i] < 0)
                {
                    min[i] = 0;
                }
                if (max[i] > heightmapData.GetLength(i))
                {
                    max[i] = heightmapData.GetLength(i);
                }
            }

            for (var i = min[0]; i < max[0]; i++)
            {
                for (var j = min[1]; j < max[1]; j++)
                {
                    var dx = i - coords.X;
                    var dz = j - coords.Y;

                    var d2 = FastMath.Pow2(dx) + FastMath.Pow2(dz);

                    //Si es cuadrado o el vertice esta dentro del circulo
                    if (!Rounded || d2 <= radius2)
                    {
                        var intensity = intensityFor(heightmapData, i, j);

                        if (intensity != 0)
                        {
                            if (Hardness != 100)
                            {
                                //Si esta entre el circulo/cuadrado interno, disminuyo la intensidad.
                                if (Rounded)
                                {
                                    var outterIntensity = intensity * (1 - d2 / radius2);

                                    if (d2 > innerRadius2)
                                    {
                                        intensity = outterIntensity;
                                    }
                                    else
                                    {
                                        var alpha = 1 - d2 / innerRadius2;
                                        intensity = outterIntensity + alpha * (intensity - outterIntensity);
                                    }
                                }
                                else
                                {
                                    var maxD = FastMath.Max(FastMath.Abs(dx), FastMath.Abs(dz));
                                    if (maxD > innerRadius)
                                    {
                                        intensity = intensity * (1 - (maxD - innerRadius) / (radius - innerRadius));
                                    }
                                }
                            }

                            var newHeight = FastMath.Max(0, FastMath.Min(heightmapData[i, j] + intensity * speed, 255));

                            if (heightmapData[i, j] != newHeight)
                            {
                                heightmapData[i, j] = newHeight;
                                changed             = true;
                            }
                        }
                    }
                }
            }

            if (changed)
            {
                terrain.setHeightmapData(heightmapData);

                float y;
                terrain.interpoledHeight(bBrush.Position.X, bBrush.Position.Z, out y);
                bBrush.Position = new TGCVector3(bBrush.Position.X, y + 50, bBrush.Position.Z);
            }
            return(changed);
        }