//Code taken from TerrainAnim class. private void RandomizeTerrain() { // Extract entire heightmap (expensive!) _terrHeights = _myTerrData.GetHeights(0, 0, _xRes, _yRes); ResetTerrainHeights(); _diamondSquareNoiseGen.GenerateValues(ref _terrHeights, _xRes, _yRes); _myTerrData.SetHeights(0, 0, _terrHeights); }
// Set the terrain using noise pattern private void RandomizeTerrain() { // Extract entire heightmap (expensive!) _terrHeights = _myTerrData.GetHeights(0, 0, _xRes, _yRes); // STUDENT'S CODE // // ... float[] scale = new float[numberOfPasses]; for (int k = 0; k < numberOfPasses; k++) { scale[k] = UnityEngine.Random.Range(scaleMin, scaleMax); } ResetTerrainHeights(); _diamondSquareNoiseGen.GenerateValues(ref _terrHeights, _xRes, _yRes); for (int i = 0; i < 5; i++) { Debug.Log(_terrHeights[i, 0]); } for (int i = 0; i < _xRes; i++) { float xCoeff = (float)i / _xRes; for (int j = 0; j < _yRes; j++) { float yCoeff = (float)j / _yRes; float currentHeight = 0.0f; for (int k = 0; k < numberOfPasses; k++) { currentHeight += Mathf.PerlinNoise(xCoeff * scale[k], yCoeff * scale[k]); } currentHeight /= (float)numberOfPasses; currentHeight *= weight; _terrHeights[i, j] += currentHeight; float totalWeight = _diamondSquareNoiseGen.Weight + weight; //_terrHeights[i, j] /= totalWeight; } // Set terrain heights (_terrHeights[coordX, coordY] = heightValue) in a loop // You can sample perlin's noise (Mathf.PerlinNoise (xCoeff, yCoeff)) usingcoefficients // between 0.0f and 1.0f // You can combine 2-3 layers of noise with different resolutions and amplitudes fora better effect // END OF STUDENT'S CODE // // Set entire heightmap (expensive!) } _myTerrData.SetHeights(0, 0, _terrHeights); originalTerrainSectionHeight = _myTerrData.GetHeights(147, 168, radiusOfAnimation * 2, radiusOfAnimation * 2); }