示例#1
0
    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);
    }
示例#2
0
    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);
         */
    }
示例#3
0
 void setHmpv(Hmp p, float v)
 {
     _heightMap [p.x, p.y] = v;
     if (v < _minHeight)
     {
         _minHeight         = v;
         _minHeightPosition = p;
     }
     _maxHeight = Mathf.Max(_maxHeight, v);
 }
示例#4
0
    bool isLegelHmp(Hmp p)
    {
        int width = _heightMap.GetLength(0);

        return(p.x >= 0 && p.x < width && p.y >= 0 && p.y < width);
    }
示例#5
0
 float getHmpv(Hmp p)
 {
     return(_heightMap [p.x, p.y]);
 }