Exemplo n.º 1
0
 private void Minimap_OnZoomChanged(object sender, System.EventArgs e)
 {
     transform.localScale = baseScale * Minimap.GetZoom() / 180f;
 }
Exemplo n.º 2
0
        private void AddUIElements()
        {
            _panel = new FlowLayoutPanel {
                Dock          = DockStyle.Top,
                AutoSize      = true,
                FlowDirection = FlowDirection.LeftToRight
            };

            _generateButton = new Button {
                Text     = "Generate Terrain",
                AutoSize = true
            };
            _generateButton.Click += (sender, args) => {
                Window.Cursor = Cursors.WaitCursor;
                Util.ReleaseCom(ref _terrain);
                _terrain = new Terrain();
                var tii = new InitInfo {
                    HeightMapFilename = null,
                    LayerMapFilename0 = "textures/grass.dds",
                    LayerMapFilename1 = "textures/darkdirt.dds",
                    LayerMapFilename2 = "textures/stone.dds",
                    LayerMapFilename3 = "Textures/lightdirt.dds",
                    LayerMapFilename4 = "textures/snow.dds",
                    BlendMapFilename  = null,
                    HeightScale       = 50.0f,
                    HeightMapWidth    = 2049,
                    HeightMapHeight   = 2049,
                    CellSpacing       = 0.5f,

                    Seed         = (int)_txtSeed.Value,
                    NoiseSize1   = (float)_txtNoise1.Value,
                    Persistence1 = (float)_txtPersistence1.Value,
                    Octaves1     = (int)_txtOctaves1.Value,
                    NoiseSize2   = (float)_txtNoise2.Value,
                    Persistence2 = (float)_txtPersistence2.Value,
                    Octaves2     = (int)_txtOctaves2.Value
                };
                _terrain.Init(Device, ImmediateContext, tii);
                _camera.Height = _terrain.Height;
                _hmImg.Image   = _terrain.HeightMapImg;
                Util.ReleaseCom(ref _minimap);
                _minimap      = new Minimap(Device, ImmediateContext, MinimapSize, MinimapSize, _terrain, _camera);
                Window.Cursor = Cursors.Default;
            };

            var labelPadding = new Padding(0, 6, 0, 0);

            _lblSeed = new Label {
                Text     = "Seed:",
                AutoSize = true,
                Padding  = labelPadding
            };
            _txtSeed = new NumericUpDown {
                Value    = 0,
                AutoSize = true,
                Maximum  = int.MaxValue
            };

            _lblNoise1 = new Label {
                Text     = "Noise:",
                AutoSize = true,
                Padding  = labelPadding,
            };
            _txtNoise1 = new NumericUpDown {
                Value         = 3.0m,
                DecimalPlaces = 2,
                Minimum       = 0m,
                Maximum       = 10m,
                Increment     = 0.1m,
                AutoSize      = true
            };
            _lblPersistence1 = new Label {
                Text     = "Persistence:",
                AutoSize = true,
                Padding  = labelPadding
            };
            _txtPersistence1 = new NumericUpDown {
                Value         = 0.7m,
                DecimalPlaces = 2,
                Minimum       = 0m,
                Maximum       = 10m,
                Increment     = 0.1m,
                AutoSize      = true
            };
            _lblOctaves1 = new Label {
                Text     = "Octaves:",
                AutoSize = true,
                Padding  = labelPadding
            };
            _txtOctaves1 = new NumericUpDown {
                Value    = 7,
                AutoSize = true,
                Minimum  = 1,
                Maximum  = 20,
            };

            _lblNoise2 = new Label {
                Text     = "Noise:",
                AutoSize = true,
                Padding  = labelPadding
            };
            _txtNoise2 = new NumericUpDown {
                Value         = 2.5m,
                DecimalPlaces = 2,
                Minimum       = 0m,
                Maximum       = 10m,
                Increment     = 0.1m,
                AutoSize      = true
            };
            _lblPersistence2 = new Label {
                Text     = "Persistence:",
                AutoSize = true,
                Padding  = labelPadding
            };
            _txtPersistence2 = new NumericUpDown {
                Value         = 0.8m,
                DecimalPlaces = 2,
                Minimum       = 0m,
                Maximum       = 10m,
                Increment     = 0.1m,
                AutoSize      = true
            };
            _lblOctaves2 = new Label {
                Text     = "Octaves:",
                AutoSize = true,
                Padding  = labelPadding
            };
            _txtOctaves2 = new NumericUpDown {
                Value    = 3,
                AutoSize = true,
                Minimum  = 1,
                Maximum  = 20
            };

            _hmImg = new PictureBox {
                Image       = _terrain.HeightMapImg,
                MaximumSize = new Size(64, 64),
                MinimumSize = new Size(64, 64),
                SizeMode    = PictureBoxSizeMode.StretchImage,
                BackColor   = Color.White
            };


            _panel.Controls.Add(_lblNoise1);
            _panel.Controls.Add(_txtNoise1);
            _panel.Controls.Add(_lblPersistence1);
            _panel.Controls.Add(_txtPersistence1);
            _panel.Controls.Add(_lblOctaves1);
            _panel.Controls.Add(_txtOctaves1);


            _panel.Controls.Add(_lblNoise2);
            _panel.Controls.Add(_txtNoise2);
            _panel.Controls.Add(_lblPersistence2);
            _panel.Controls.Add(_txtPersistence2);
            _panel.Controls.Add(_lblOctaves2);
            _panel.Controls.Add(_txtOctaves2);

            _panel.SetFlowBreak(_txtOctaves2, true);

            _panel.Controls.Add(_lblSeed);
            _panel.Controls.Add(_txtSeed);

            _panel.Controls.Add(_generateButton);


            _tblLayout = new TableLayoutPanel {
                Dock     = DockStyle.Top,
                AutoSize = true
            };
            _tblLayout.RowStyles.Add(new RowStyle(SizeType.AutoSize));
            _tblLayout.ColumnStyles.Add(new ColumnStyle(SizeType.AutoSize));
            _tblLayout.ColumnStyles.Add(new ColumnStyle(SizeType.AutoSize));

            _tblLayout.Controls.Add(_panel, 0, 0);
            _tblLayout.Controls.Add(_hmImg, 1, 0);


            Window.Controls.Add(_tblLayout);
        }