コード例 #1
0
        private void PerlinNoiseGenration(Vector3 position, VisFrame[,,] frames, WorldTile[] neighbours,
                                          GraphicsDevice device, SpriteBatch sp)
        {
            //PerlinNoise.CreateStaticMap(WorldTile.WORLD_TILE_WIDTH, device);
            var test = PerlinNoise.GeneratePerlinNoiseGPU(new Vector3(position.X / 1000f, position.Y, position.Z / 1000f),
                                                          device, sp);
            var grid = new Color[test.Width * test.Height];

            test.GetData(grid);

            for (var x = 0; x < frames.GetLength(0); x++)
            {
                for (var z = 0; z < frames.GetLength(2); z++)
                {
                    var highest = grid[x * z].R * .5 < _minHeight
                        ? _minHeight
                        : grid[x * z].R * .5;

                    if (highest > _maxHeight)
                    {
                        highest = _maxHeight;
                    }

                    var currentIndex = 0;
                    var counter      = 0;

                    for (var y = 0; y < highest; y++)
                    {
                        frames[x, y, z] = new VisFrame(FrameManager.Frames[_columnData[currentIndex].Frame])
                        {
                            Visible = true
                        };
                        counter++;

                        if (_columnData[currentIndex].Height != 0)
                        {
                            if (counter >= _columnData[currentIndex].Height)
                            {
                                counter = 0;
                                currentIndex++;
                            }
                        }
                        else
                        {
                            if (highest - UpperFramesHeightTogether - 1 <= y)
                            {
                                counter = 0;
                                currentIndex++;
                            }
                        }
                    }
                }
            }

            FillWithAir(frames);
            //ApplyVis(frames,neighbours);
        }