示例#1
0
        private void importMapButton_Click(object sender, EventArgs e)
        {
            // show the file open dialog, and get the path from it
            DialogResult result = importMapDialog.ShowDialog();

            if (result == DialogResult.OK)
            {
                if (importMapDialog.FileName.EndsWith(".tif"))
                {
                    try
                    {
                        terrain = new Terrain(xSize, ySize, xMapSize, yMapSize, maxAlt);
                        terrain.terrainFromTIFF(importMapDialog.FileName);
                    }
                    catch (IOException ex)
                    {
                        MessageBox.Show(ex.Message);
                    }
                }
                else if (importMapDialog.FileName.EndsWith(".bmp"))
                {
                    terrain = new Terrain(xSize, ySize, xMapSize, yMapSize, maxAlt);
                    Bitmap inputBmp = new Bitmap(importMapDialog.FileName);
                    terrain.terrainFromBmp(inputBmp);
                }
                else
                {
                    MessageBox.Show("Could not import selected map");
                    return;
                }

                if (texSamplePicture.Image == null)
                {
                    cb           = new ColorBlend();
                    cb.Positions = new[] { 0, 1 / 3f, 1 / 2f, 3 / 4f, 7 / 8f, 1 };
                    cb.Colors    = new[] { Color.FromArgb(61, 84, 51), Color.FromArgb(35, 50, 32), Color.FromArgb(35, 50, 32), Color.FromArgb(160, 153, 147), Color.FromArgb(247, 247, 251), Color.FromArgb(247, 247, 251) };
                    terrain.setTextureSample(cb);
                    texSamplePicture.Image = terrain.getTextureSample();
                }
                else
                {
                    terrain.setTextureSample((Bitmap)texSamplePicture.Image);
                }

                colorMapPicture.Image  = terrain.getTexture();
                heightMapPicture.Image = terrain.getHeightBitmap();
            }
        }
示例#2
0
        private void generateTerrainButton_Click(object sender, EventArgs e)
        {
            xOffset     = (double)xOffsetNum.Value;
            yOffset     = (double)yOffsetNum.Value;
            xSize       = (int)xSizeNum.Value;
            ySize       = (int)ySizeNum.Value;
            xMapSize    = (float)xMapSizeNum.Value;
            yMapSize    = (float)yMapSizeNum.Value;
            maxAlt      = (float)maxAltNum.Value;
            frequency   = (double)frequencyNum.Value;
            octaves     = (int)octavesNum.Value;
            persistance = (double)persistenceNum.Value;
            lacunarity  = (double)lacunarityNum.Value;
            mu          = (double)muNum.Value;



            terrain = new Terrain(xSize, ySize, xMapSize, yMapSize, maxAlt);
            terrain.generateTerrain(xOffset, yOffset, frequency, octaves, persistance, lacunarity, mu);

            if (texSamplePicture.Image == null)
            {
                cb           = new ColorBlend();
                cb.Positions = new[] { 0, 1 / 3f, 1 / 2f, 3 / 4f, 7 / 8f, 1 };
                cb.Colors    = new[] { Color.FromArgb(61, 84, 51), Color.FromArgb(35, 50, 32), Color.FromArgb(35, 50, 32), Color.FromArgb(160, 153, 147), Color.FromArgb(247, 247, 251), Color.FromArgb(247, 247, 251) };
                terrain.setTextureSample(cb);
                texSamplePicture.Image = terrain.getTextureSample();
            }
            else
            {
                terrain.setTextureSample((Bitmap)texSamplePicture.Image);
            }

            heightMapPicture.Image = terrain.getHeightBitmap();

            colorMapPicture.Image = terrain.getTexture();
        }