void square(Hmp left, Hmp right, Hmp bottom, Hmp top, float randomScope) { int cnt = 0; float amount = 0; if (isLegelHmp(left)) { amount += getHmpv(left); cnt++; } if (isLegelHmp(right)) { amount += getHmpv(right); cnt++; } if (isLegelHmp(bottom)) { amount += getHmpv(bottom); cnt++; } if (isLegelHmp(top)) { amount += getHmpv(top); cnt++; } float centerValue = amount / cnt + (float)((_randomGen.NextDouble() - 0.5) * 2) * randomScope; Hmp center = new Hmp(top.x, left.y); setHmpv(center, centerValue); }
void diamond(Hmp lb, Hmp lt, Hmp rb, Hmp rt, float randomScope) { int centerX = (lb.x + rt.x) / 2; int centerY = (lb.y + rt.y) / 2; Hmp center = new Hmp(centerX, centerY); float centerValue = 0.25f * (getHmpv(lb) + getHmpv(lt) + getHmpv(rb) + getHmpv(rt)) + (_flagCenterDown ? -((float)(_randomGen.NextDouble() + 0.5f) * randomScope) * center_deep_scale : (float)((_randomGen.NextDouble() - 0.5) * 2) * randomScope); _flagCenterDown = false; setHmpv(center, centerValue); /* * float nextRandomScope = randomScope * reduce_rate; * // left square * square (new Hmp (lb.x + lb.x - center.x, center.y), center, lb, lt, nextRandomScope); * * // right square * square (center, new Hmp (rb.x + rb.x - center.x, center.y), rb, rt, nextRandomScope); * * // bottom square * square (lb, rb, new Hmp (center.x, lb.y + lb.y - center.y), center, nextRandomScope); * * // top square * square (lt, rt, center, new Hmp (center.x, lt.y + lt.y - center.y), nextRandomScope); */ }
void setHmpv(Hmp p, float v) { _heightMap [p.x, p.y] = v; if (v < _minHeight) { _minHeight = v; _minHeightPosition = p; } _maxHeight = Mathf.Max(_maxHeight, v); }
bool isLegelHmp(Hmp p) { int width = _heightMap.GetLength(0); return(p.x >= 0 && p.x < width && p.y >= 0 && p.y < width); }
float getHmpv(Hmp p) { return(_heightMap [p.x, p.y]); }