コード例 #1
0
 /// <summary>
 /// Initialises a new instance of the TerrainPoint class.
 /// </summary>
 /// <param name="foreground">The density of the foreground.</param>
 /// <param name="background">The density of the background.</param>
 /// <param name="material">The material.</param>
 /// <param name="light">The light value.</param>
 public TerrainPoint(byte foreground, byte background, TerrainMaterial material, Colour light)
 {
     this.Foreground = foreground;
     this.Background = background;
     this.Material = material;
     this.Light = light;
 }
コード例 #2
0
        /// <summary>
        /// Creates a new chunk.
        /// </summary>
        /// <param name="chunk">The chunk.</param>
        /// <param name="surfaceHeights">The surface heights.</param>
        public void GeneratePoints(TerrainChunk chunk, float[] surfaceHeights)
        {
            int originX = chunk.Index.X * Metrics.ChunkWidth;
            int originY = chunk.Index.Y * Metrics.ChunkHeight;

            SurfacePosition? surfacePosition = null;
            for (int x = 0; x < Metrics.ChunkWidth; x++)
            {
                // Determine where the surface lies for this x position
                float surface = surfaceHeights[x];

                // Update the on-going check for the surface position
                surfacePosition = this.CheckSurfacePosition(surfacePosition, surface, originY);

                for (int y = 0; y < Metrics.ChunkHeight; y++)
                {
                    int worldX = originX + x;
                    int worldY = originY + y;

                    // Calculate the background and foreground densities
                    byte background = this.GetBackgroundDensity(worldX, worldY, surface);

                    // Get the cave densities for this point
                    PointDensities densities = this.GetCaveDensitiesForPoint(worldX, worldY);
                    if (densities.Origin < background)
                    {
                        // The density cannot be less than the background (ie. if the background is dug out, the
                        // foreground cannot be filled in)
                        densities.Origin = background;
                    }

                    // Update the densities
                    byte foreground = densities.Origin > background ? densities.Origin : background;
                    this.UpdateForegroundIfGreaterDensity(chunk, x, y, foreground);
                    if (x < Metrics.ChunkWidth - 1)
                    {
                        this.UpdateForegroundIfGreaterDensity(chunk, x + 1, y, densities.Right);
                    }

                    if (y < Metrics.ChunkHeight - 1)
                    {
                        this.UpdateForegroundIfGreaterDensity(chunk, x, y + 1, densities.Up);
                    }

                    // Determine the material
                    TerrainMaterial material = this.GetMaterial(worldX, worldY, surface);

                    // TODO: Remove this
                    int val = 255 - (int)(System.Math.Abs((float)worldY) * 8);
                    byte lightTest = val > 0 ? (byte)val : (byte)0;
                    var light = new Colour(lightTest, lightTest, lightTest);
                    // TODO: Remove this

                    // Update the point
                    TerrainPoint point = chunk.Points[x, y];
                    point.Background = background;
                    point.Material = material;
                    point.Light = light;
                }
            }

            chunk.SurfacePosition = surfacePosition.Value;
        }