Ejemplo n.º 1
0
        public CaveValue GetValue(float x, float y, float z, int height)
        {
            CaveValue result = _cave.GetValue(x, y, z, height);

            //result.highHeight = result.highHeight * _scale + _bias;
            //result.lowHeight = result.lowHeight * _scale + _bias;

            return(result);
        }
Ejemplo n.º 2
0
 public AbstractCave(int seed, float rateInMap)
 {
     _seed      = seed;
     _rateInMap = rateInMap;
     InitCaveGenerator();
     _scale          = 1.0f;
     _caveValue      = new CaveValue();
     _caveValue.type = CaveType;
 }
Ejemplo n.º 3
0
 protected override CaveValue checkValue(CaveValue value, int height)
 {
     value.highHeight = (value.highHeight - value.lowHeight > 7 && value.highHeight - value.lowHeight < 10) ? value.lowHeight + 5 : value.highHeight;
     value.highHeight = (value.highHeight - value.lowHeight > 9) ? value.lowHeight : value.highHeight;
     if (value.highHeight < height && value.highHeight >= value.lowHeight && value.highHeight - value.lowHeight >= 3)
     {
         value.highHeight = value.lowHeight + 5;
     }
     if (value.highHeight > height + 6)
     {
         value.lowHeight  -= 30;
         value.highHeight -= 30;
         return(checkValue(value, height));
     }
     return(value);
 }
Ejemplo n.º 4
0
 protected override CaveValue checkValue(CaveValue value, int height)
 {
     value.highHeight = (value.highHeight - value.lowHeight > 10 && value.highHeight - value.lowHeight < 15) ? value.lowHeight + 5 : value.highHeight;
     value.highHeight = (value.highHeight - value.lowHeight > 14) ? value.lowHeight : value.highHeight;
     if (value.highHeight < height && value.highHeight >= value.lowHeight && value.highHeight - value.lowHeight <= 6 && value.highHeight - value.lowHeight >= 3)
     {
         value.highHeight = value.lowHeight + 8;
     }
     if (value.highHeight - value.lowHeight > 7)
     {
         value.highHeight = value.lowHeight + 7 - (value.highHeight - value.lowHeight - 7);
     }
     if (value.highHeight < height - 30)
     {
         value.lowHeight  += 20;
         value.highHeight += 20;
         return(checkValue(value, height));
     }
     return(value);
 }
Ejemplo n.º 5
0
 protected override CaveValue checkValue(CaveValue value, int height)
 {
     value.highHeight = (value.highHeight - value.lowHeight > 12 && value.highHeight - value.lowHeight < 15) ? (value.lowHeight + 8) : value.highHeight;
     value.highHeight = (value.highHeight - value.lowHeight > 14) ? (value.lowHeight) : value.highHeight;
     if (value.highHeight - value.lowHeight < 2)
     {
         value.highHeight = value.lowHeight;
     }
     if (value.highHeight - value.lowHeight > 9)
     {
         value.highHeight = value.lowHeight + 9 - (value.highHeight - value.lowHeight - 9);
     }
     if (value.highHeight > height + 1)
     {
         value.lowHeight  -= 20;
         value.highHeight -= 20;
         return(checkValue(value, height));
     }
     return(value);
 }
Ejemplo n.º 6
0
        public CaveValue GetValue(float x, float y, float z, int height)
        {
            float cv = _controller.GetValue(x, z);

            if (cv > 1)
            {
                cv = 1;
            }
            if (cv < 0)
            {
                cv = 0;
            }
            float curTotalRate = 0;

            for (int i = 0; i < _caves.Length; i++)
            {
                float curTerrainRate = _caves[i].RateInMap / _totalRate;
                float preRate        = curTotalRate;
                //解决精度问题
                if (_caves.Length - 1 == i)
                {
                    curTotalRate = 1f;
                }
                else
                {
                    curTotalRate += curTerrainRate;
                }
                if (cv <= curTotalRate)
                {
                    CaveValue curTerrainValue = _caves[i].GetValue(x, y, z, height);
                    if (_fallOff[i] > 0)
                    {
                        float     a;
                        CaveValue tempA;
                        CaveValue tempB;
                        float     curFallout = curTerrainRate * _fallOff[i];

                        if (cv < preRate + curFallout && i - 1 >= 0)
                        {
                            int j = i - 1;
                            tempA = curTerrainValue;
                            tempB = _caves[j].GetValue(x, y, z, height);
                            var lc = preRate - _caves[j].RateInMap / _totalRate * _fallOff[j];
                            var uc = preRate + curFallout;
                            a = MapCubicSCurve((cv - lc) / (uc - lc));
                            _caveValue.type = tempA.type;
                            _caveValue      = InterpolateLinear(tempB, tempA, a);
                            return(_caveValue);
                        }
                        if (cv < curTotalRate - curFallout)
                        {
                            return(_caves[i].GetValue(x, y, z, height));
                        }
                        if (cv < curTotalRate && i < _caves.Length - 1)
                        {
                            int j = i + 1;
                            tempA = curTerrainValue;
                            tempB = _caves[j].GetValue(x, y, z, height);
                            var lc = curTotalRate - curFallout;
                            var uc = curTotalRate + _caves[j].RateInMap / _totalRate * _fallOff[j];
                            a = MapCubicSCurve((cv - lc) / (uc - lc));
                            _caveValue.type = tempA.type;
                            _caveValue      = InterpolateLinear(tempA, tempB, a);
                            return(_caveValue);
                        }
                        return(_caves[i].GetValue(x, y, z, height));
                    }
                    else
                    {
                        return(curTerrainValue);
                    }
                }
            }
            throw new Exception("传入的概率不正确!");
        }
Ejemplo n.º 7
0
 private CaveValue InterpolateLinear(CaveValue a, CaveValue b, float position)
 {
     a.highHeight = Convert.ToInt32((1.0f - position) * a.highHeight + (position * b.highHeight));
     a.lowHeight  = Convert.ToInt32((1.0f - position) * a.lowHeight + (position * b.lowHeight));
     return(a);
 }
Ejemplo n.º 8
0
 protected virtual CaveValue checkValue(CaveValue value, int height)
 {
     return(value);
 }