interpolateLinear() public static method

public static interpolateLinear ( float v1, float v2, float fraction ) : float
v1 float
v2 float
fraction float
return float
Esempio n. 1
0
        public RiverBuilder GenerateRiver(float waterlevel, int seed, out List <PathFinderNode> RiverPath)
        {
            float oldDelta = chan.getMaxDelta();

            RiverPath = new List <PathFinderNode>();
            //Start = FindStartPoint(DateTime.Now.Millisecond%4);
            //End = FindEndPoint((DateTime.Now.Millisecond+1)%4);
            Random       r           = new Random(seed);
            List <Point> StartPoints = new List <Point>();

            float max = chan.findMax();
            float min = chan.findMin();
            float inv = 1f / (max - min);

            waterlevel = Tools.interpolateLinear(0f, 1f, (20f - 0f) * (1f / (45f - 0f)));
            float maxoffset = Tools.interpolateLinear(0f, 1f, (5f - 0f) * (1f / (45f - 0f)));

            // Source can spawn >5m ASL, but must be >10m
            //  from the highest altitude on the map.
            chan.normalize();             // stretch it the fsck out.

            Start = FindStartPoint(0);
            End   = FindEndPoint(2);

            Console.WriteLine(" * Generating river, s={0}, e={1}.", Start, End);

            List <PathFinderNode> p = FindPath(Start, End);        //,seed,20f);

            if (p == null)
            {
                Console.WriteLine(" ! Unable to retrieve path..");
                return(this);
            }

            CleanPath(p);
            CreateBank(p);
            //CleanupFloodplain();

            Console.WriteLine(" * Maximum terrain delta: {0}", chan.getMaxDelta());
            chan.setMaxDelta(oldDelta / 2f);
            Console.WriteLine(" * Adjusted terrain delta: {0}", chan.getMaxDelta());

            chan.smooth(1);             // CleanupFloodplain is broken, dunno why.
            RiverPath = p;
            return(this);
        }
Esempio n. 2
0
        public Layer normalize(float new_min, float new_max)
        {
            float min_r = r.findMin();
            float min_g = g.findMin();
            float min_b = b.findMin();
            float max_r = r.findMax();
            float max_g = g.findMax();
            float max_b = b.findMax();
            float min   = Math.Min(min_r, Math.Min(min_g, min_b));
            float max   = Math.Max(max_r, Math.Max(max_g, max_b));

            min_r = Tools.interpolateLinear(new_min, new_max, (min_r - min) / (max - min));
            min_g = Tools.interpolateLinear(new_min, new_max, (min_g - min) / (max - min));
            min_b = Tools.interpolateLinear(new_min, new_max, (min_b - min) / (max - min));
            max_r = Tools.interpolateLinear(new_min, new_max, (max_r - min) / (max - min));
            max_g = Tools.interpolateLinear(new_min, new_max, (max_g - min) / (max - min));
            max_b = Tools.interpolateLinear(new_min, new_max, (max_b - min) / (max - min));
            r.normalize(min_r, max_r);
            g.normalize(min_g, max_g);
            b.normalize(min_b, max_b);
            return(this);
        }