Exemple #1
0
        /// <summary>
        /// Rotates a grid vector the specified amount of times. +1 is 60 degrees clockwise.
        /// </summary>
        /// <param name="times">How many times to rotate.</param>
        /// <returns>The new rotated grid vector.</returns>
        public GridVertex Rotate(int times)
        {
            GridVertex old   = this;
            int        index = Array.FindIndex(Directions, vert => vert.Equals(old));

            return(Directions[(index + times + 6) % 6]);
        }
Exemple #2
0
 /// <summary>
 /// Applies a random height distribution to the terrain grid.
 /// </summary>
 public void ApplyHighHeightMap(float h, float scale, float offset, float limit, Vector2 seed)
 {
     for (int j = 0; j <= Size; j++)
     {
         int        x    = j % 2;
         GridVertex vert = new GridVertex(x, j);
         if (HeightMap[vert.U, vert.V] > limit)
         {
             Vector2 pos = vert.ToCartesianCoords2D();
             HeightMap[x, j] += (SimplexNoise.Generate(seed.X + pos.X * scale, seed.Y + pos.Y * scale) - offset) * h;
         }
     }
     for (int i = 1; i <= Size; i++)
     {
         for (int j = 0; j <= Size; j++)
         {
             int        x    = i * 2 + (j % 2);
             GridVertex vert = new GridVertex(x, j);
             if (HeightMap[vert.U, vert.V] > limit)
             {
                 Vector2 pos = vert.ToCartesianCoords2D();
                 HeightMap[x, j]    += (SimplexNoise.Generate(seed.X + pos.X * scale, seed.Y + pos.Y * scale) - offset) * h;
                 HeightMap[x - 1, j] = (HeightMap[x, j] + HeightMap[x - 2, j]) / 2;
             }
         }
     }
 }
Exemple #3
0
        /// <summary>
        /// Adjusts the height of the specified vertex, updating the terrain.
        /// </summary>
        /// <param name="vert">The adjusted vertex.</param>
        /// <param name="h">The height that will be added.</param>
        public void AdjustVertexHeight(GridVertex vert, float h)
        {
            HeightMap[vert.U, vert.V]          += h;
            Body.Shape.Heights[vert.U, vert.V] += h;
            int     index = ((vert.U - 1) * Size + vert.V) * 3;
            int     s3    = Size * 3;
            Vector3 point = vert.ToCartesianCoords3D(HeightMap);

            Builder.Vertices[index - s3 - 1] = point;
            Builder.Vertices[index - 3]      = point;
            Builder.Vertices[index + s3 - 2] = point;
            Builder.Vertices[index - s3 + 1] = point;
            Builder.Vertices[index]          = point;
            Builder.Vertices[index + s3 + 2] = point;
            Rend.GenerateVBO(Builder);
        }
Exemple #4
0
 /// <summary>
 /// Applies a random height distribution to the terrain grid.
 /// </summary>
 public void ApplyClampedHeightMap(float h, float scale, float offset, float clamp, Vector2 seed)
 {
     for (int j = 0; j <= Size; j++)
     {
         int     x   = j % 2;
         Vector2 pos = new GridVertex(x, j).ToCartesianCoords2D();
         HeightMap[x, j] += (Math.Min(SimplexNoise.Generate(seed.X + pos.X * scale, seed.Y + pos.Y * scale), clamp) - offset) * h;
     }
     for (int i = 1; i <= Size; i++)
     {
         for (int j = 0; j <= Size; j++)
         {
             int     x   = i * 2 + (j % 2);
             Vector2 pos = new GridVertex(x, j).ToCartesianCoords2D();
             HeightMap[x, j]    += (Math.Min(SimplexNoise.Generate(seed.X + pos.X * scale, seed.Y + pos.Y * scale), clamp) - offset) * h;
             HeightMap[x - 1, j] = (HeightMap[x, j] + HeightMap[x - 2, j]) / 2;
         }
     }
 }
Exemple #5
0
 /// <summary>
 /// Applies a random height distribution to the terrain grid.
 /// </summary>
 public void GenerateHeightMap(double h)
 {
     HeightMap = new double[Size * 2 + 2, Size + 1];
     for (int j = 0; j <= Size; j++)
     {
         int     x   = j % 2;
         Vector2 pos = new GridVertex(x, j).ToCartesianCoords2D();
         HeightMap[x, j] = h;
     }
     for (int i = 1; i <= Size; i++)
     {
         for (int j = 0; j <= Size; j++)
         {
             int     x   = i * 2 + (j % 2);
             Vector2 pos = new GridVertex(x, j).ToCartesianCoords2D();
             HeightMap[x, j]     = h;
             HeightMap[x - 1, j] = h;
         }
     }
 }
Exemple #6
0
        /// <summary>
        /// Wether this grid vertex equals an object.
        /// </summary>
        /// <param name="obj">The object to compare to.</param>
        /// <returns>Wether they are equal.</returns>
        public override bool Equals(object obj)
        {
            GridVertex vert = (GridVertex)obj;

            return(vert.U == U && vert.V == V);
        }