Exemplo n.º 1
0
        public static HeightMap GenBasicTerrainMap(HeightmapProperties heightProps, int seed)
        {
            HeightMap h = new HeightMap(heightProps.size, seed);
            h.AddPerlinNoise(heightProps.perlinFreq);
            h.Perturb(heightProps.perturb, heightProps.perturb);
            for (int i = 0; i < HeightMapGen.erodePasses; i++ )
                h.Erode(heightProps.erode);
            h.Smoothen();

            return h;
        }
Exemplo n.º 2
0
        public void Blend(HeightMap subMap, string blendMode, int x, int y, float amount)
        {
            int diam = subMap.Size;
            float rad = diam / 2;
            int heightsXLen = Heights.GetLength (0);
            int heightsYLen = Heights.GetLength (1);

            for (int i = 0; i < diam; ++i)
            {
                for (int j = 0; j < diam; ++j)
                {
                    int origX = (int) (x + (i - rad));
                    int origY = (int) (y + (j - rad));
                    //Check if point falls within a circle
                    double diffXSq = Math.Pow((double) (x - origX), 2.0);
                    double diffYSq = Math.Pow((double) (y - origY), 2.0);
                    double radSq = Math.Pow ((double) rad, 2.0);

                    int actualX = GetSeamlessPoint(heightsXLen, origX);
                    int actualY = GetSeamlessPoint(heightsYLen, origY);

                    if (diffXSq + diffYSq <= radSq) {

                        //if (actualX < heightsXLen && actualY < heightsYLen && actualX >= 0 && actualY >= 0) {
                            switch (blendMode) {
                                case "add":
                                Heights[actualX, actualY] += (1f + Math.Abs (subMap.Heights[i, j])) * amount;
                                    break;
                                case "subtract":
                                Heights[actualX, actualY] -= Math.Abs (subMap.Heights[i, j]) * amount;
                                    break;
                            }

                            if (Heights[actualX, actualY] <= 0.0f) {
                                Heights[actualX, actualY] = 0.001f;
                            } else if (Heights[actualX, actualY] > 5.0f) {
                                Heights[actualX, actualY] = 5.0f;
                            }
                        //}
                    }
                }
            }
        }