private void generateButton_Click(object sender, RoutedEventArgs e) { rawtile = new List <double[, ]>(); //pow = Convert.ToInt32(powOf2TextBox.Text); //size = (int)Math.Pow(2, pow) + 1; halfSize = Convert.ToInt32(halfSizeTextBox.Text); size = halfSize * 2 + 1; startOctaveNumber = Convert.ToUInt32(startOctaveNumberTextBox.Text); octaves = Convert.ToUInt32(octavesTextBox.Text); persistance = Convert.ToDouble(persistanceTextBox.Text); for (int i = 0; i < plainCnt; ++i) { rawtile.Add(new double[size, size]); } var watch = System.Diagnostics.Stopwatch.StartNew(); Perlin3D.setSeed(Convert.ToInt32(seedTextBox.Text)); Parallel.For(0, plainCnt, index => { CalculateNoise(index); }); watch.Stop(); var elapsedMs = watch.ElapsedMilliseconds; labelMs.Content = elapsedMs.ToString(); normalizeArray(); DrawAll(); }
private void CalculateNoise(int index) { for (int i = 0; i < size; ++i) { for (int j = 0; j < size; ++j) { // center of cube is moved to the center of coordinates and its coords transformed to sphere coords /* * 5 * 1 2 3 4 * 6 */ switch (index) { case 0: rawtile[0][i, j] = Perlin3D.getMultioctave3DNoiseValue(0 - halfSize, halfSize - j, i - halfSize, startOctaveNumber, octaves, persistance); break; case 1: rawtile[1][i, j] = Perlin3D.getMultioctave3DNoiseValue(j - halfSize, 0 - halfSize, i - halfSize, startOctaveNumber, octaves, persistance); break; case 2: rawtile[2][i, j] = Perlin3D.getMultioctave3DNoiseValue(halfSize, j - halfSize, i - halfSize, startOctaveNumber, octaves, persistance); break; case 3: rawtile[3][i, j] = Perlin3D.getMultioctave3DNoiseValue(halfSize - j, halfSize, i - halfSize, startOctaveNumber, octaves, persistance); break; case 4: rawtile[4][i, j] = Perlin3D.getMultioctave3DNoiseValue(j - halfSize, i - halfSize, halfSize, startOctaveNumber, octaves, persistance); break; case 5: rawtile[5][i, j] = Perlin3D.getMultioctave3DNoiseValue(j - halfSize, halfSize - i, 0 - halfSize, startOctaveNumber, octaves, persistance); break; } } } }