Lerp() public static method

public static Lerp ( double a, double b, double f ) : double
a double
b double
f double
return double
Exemplo n.º 1
0
        /// <summary>
        /// 高度计算
        /// </summary>
        /// <param name="x"></param>
        /// <param name="z"></param>
        /// <returns></returns>
        public float CalculateHeight(float x, float z)
        {
            float num   = this.TGOceanSlope + this.TGOceanSlopeVariation * MathUtils.PowSign(2f * SimplexNoise.OctavedNoise(x + this.mountainsOffset.X, z + this.mountainsOffset.Y, 0.01f, 1, 2f, 0.5f) - 1f, 0.5f);
            float num2  = this.CalculateOceanShoreDistance(x, z);
            float num3  = MathUtils.Saturate(1f - 0.05f * MathUtils.Abs(num2));
            float num4  = MathUtils.Saturate(MathUtils.Sin(this.TGIslandsFrequency * num2));
            float num5  = MathUtils.Saturate(MathUtils.Saturate(-num * num2) - 0.85f * num4);
            float num6  = MathUtils.Saturate(MathUtils.Saturate(0.05f * (-num2 - 10f)) - num4);
            float num7  = this.CalculateMountainRangeFactor(x, z);
            float f     = (1f - num3) * SimplexNoise.OctavedNoise(x, z, 0.001f / this.TGBiomeScaling, 2, 1.97f, 0.8f);
            float f2    = (1f - num3) * SimplexNoise.OctavedNoise(x, z, 0.0017f / this.TGBiomeScaling, 2, 1.93f, 0.7f);
            float num8  = (1f - num6) * (1f - num3) * MathUtils.Saturate((num7 - 0.6f) / 0.4f);
            float num9  = (1f - num6) * MathUtils.Saturate((num7 - (1f - this.TGMountainsPercentage)) / this.TGMountainsPercentage);
            float num10 = 2f * SimplexNoise.OctavedNoise(x, z, 0.02f, 3, 1.93f, 0.8f) - 1f;
            float num11 = 1.5f * SimplexNoise.OctavedNoise(x, z, 0.004f, 4, 1.98f, 0.9f) - 0.5f;
            float num12 = MathUtils.Lerp(60f, 30f, MathUtils.Saturate(1f * num9 + 0.5f * num8 + MathUtils.Saturate(1f - num2 / 30f)));
            float x2    = MathUtils.Lerp(-2f, -4f, MathUtils.Saturate(num9 + 0.5f * num8));
            float num13 = MathUtils.Saturate(2.0f - num12 * MathUtils.Abs(2f * SimplexNoise.OctavedNoise(x + this.riversOffset.X, z + this.riversOffset.Y, 0.001f, 4, 2f, 0.5f) - 1f));
            float num14 = -50f * num5 + this.TGHeightBias;
            float num15 = MathUtils.Lerp(0f, 8f, f);
            float num16 = MathUtils.Lerp(0f, -6f, f2);
            float num17 = this.TGHillsStrength * num8 * num10;
            float num18 = this.TGMountainsStrength * num9 * num11;
            float f3    = this.TGRiversStrength * num13;
            float num19 = num14 + num15 + num16 + num18 + num17;
            float num20 = MathUtils.Min(MathUtils.Lerp(num19, x2, f3), num19);

            return(MathUtils.Clamp(64f + num20, 10f, 123f));
        }
Exemplo n.º 2
0
        private void Update(EvaluationContext context)
        {
            var countX = Count.GetValue(context).Clamp(1, 10000);

            var count = countX;

            if (_points.Length != count)
            {
                _points = new T3.Core.DataTypes.Point[count];
                _pointList.SetLength(count);
            }

            var startP = Start.GetValue(context);
            var endP   = Offset.GetValue(context);
            var startW = StartW.GetValue(context);
            var scaleW = OffsetW.GetValue(context);

            var startPoint = new Vector3(startP.X, startP.Y, startP.Z);
            var offset     = new Vector3(endP.X, endP.Y, endP.Z);
            var index      = 0;

            for (var x = 0; x < countX; x++)
            {
                var fX = x / (float)countX;
                _points[index].Position    = Vector3.Lerp(startPoint, startPoint + offset, fX);
                _points[index].Orientation = Quaternion.Identity;
                _points[index].W           = MathUtils.Lerp(startW, startW + scaleW, fX);
                _pointList[index]          = _points[index];
                index++;
            }

            Result.Value    = _points;
            PointList.Value = _pointList;
        }
Exemplo n.º 3
0
        protected override void UpdateInternal(UpdateContext context)
        {
            float value = this._moveSpeedFactor * MathUtils.Lerp(this.values[0], 1f, this._elapsed / this.duration);

            this.owner.property.Equal(Attr.MoveSpeedFactor, value);
            this._deltaf[Attr.MoveSpeedFactor] = value - this._moveSpeedFactor;
        }
Exemplo n.º 4
0
 private void setPosition()
 {
     var viewport = _game.State.Viewport;
     float x = MathUtils.Lerp(0f, 0f, _windowInfo.AppWindowWidth, _resolution.Width, viewport.ScreenArea.X);
     float width = MathUtils.Lerp(0f, 0f, _windowInfo.AppWindowWidth, _resolution.Width, viewport.ScreenArea.Width);
     _toolbar.X = x + width / 2f;
 }
Exemplo n.º 5
0
        private float EvalForTwoKeys(FRichCurveKey key1, FRichCurveKey key2, float inTime)
        {
            var diff = key2.Time - key1.Time;

            if (diff > 0f && key1.InterpMode != RCIM_Constant)
            {
                var alpha = (inTime - key1.Time) / diff;
                var p0    = key1.Value;
                var p3    = key2.Value;

                if (key1.InterpMode == RCIM_Linear)
                {
                    return(MathUtils.Lerp(p0, p3, alpha));
                }

                if (IsItNotWeighted(key1, key2))
                {
                    const float oneThird = 1f / 3f;
                    var         p1       = p0 + key1.LeaveTangent * diff * oneThird;
                    var         p2       = p3 - key2.ArriveTangent * diff * oneThird;

                    return(BezierInterp(p0, p1, p2, p3, alpha));
                }

                // it's weighted
                return(WeightedEvalForTwoKeys(key1, key2, inTime));
            }

            return(key1.Value);
        }
Exemplo n.º 6
0
        private float convertX(float x)
        {
            var viewport     = getViewport();
            var virtualWidth = _virtualWidth / viewport.ScaleX;

            x = MathUtils.Lerp(0f, 0f, _windowSize.GetWidth(_game), virtualWidth, x);
            return(x + viewport.X);
        }
Exemplo n.º 7
0
        private float convertY(float y)
        {
            var viewport      = getViewport();
            var virtualHeight = _virtualHeight / viewport.ScaleY;

            y = MathUtils.Lerp(0f, virtualHeight, _windowSize.GetHeight(_game), 0f, y);
            return(y + viewport.Y);
        }
Exemplo n.º 8
0
        private async Task <float[]> GenerateHeightMap(BiomeBase[] biomes, int chunkX, int chunkZ)
        {
            return(await Task.Run(() =>
            {
                int minX = ((chunkX) * 16);
                int minZ = ((chunkZ) * 16);
                var maxX = ((chunkX + 1) << 4);
                var maxZ = ((chunkZ + 1) << 4);

                int cx = (chunkX * 16);
                int cz = (chunkZ * 16);

                /*float q11 = MathUtils.Lerp(biomes[0].MinHeight, biomes[0].MaxHeight,
                 *  MathUtils.ConvertRange(-1f, 1f, 0f, 1f, NoiseProvider.TerrainNoise.GetValue(minX, minZ)));
                 * float q12 = MathUtils.Lerp(biomes[15].MinHeight, biomes[15].MaxHeight,
                 *  MathUtils.ConvertRange(-1f, 1f, 0f, 1f, NoiseProvider.TerrainNoise.GetValue(minX, maxZ)));
                 *
                 * float q21 = MathUtils.Lerp(biomes[240].MinHeight, biomes[240].MaxHeight,
                 *  MathUtils.ConvertRange(-1f, 1f, 0f, 1f,NoiseProvider.TerrainNoise.GetValue(maxX, minZ)));
                 * float q22 = MathUtils.Lerp(biomes[255].MinHeight, biomes[255].MaxHeight,
                 *  MathUtils.ConvertRange(-1f, 1f, 0f, 1f, NoiseProvider.TerrainNoise.GetValue(maxX, maxZ)));*/


                float q11 = MathUtils.Lerp(biomes[0].MinHeight, biomes[0].MaxHeight,
                                           NoiseProvider.TerrainNoise.GetValue(minX, minZ));
                float q12 = MathUtils.Lerp(biomes[15].MinHeight, biomes[15].MaxHeight,
                                           NoiseProvider.TerrainNoise.GetValue(minX, maxZ));

                float q21 = MathUtils.Lerp(biomes[240].MinHeight, biomes[240].MaxHeight,
                                           NoiseProvider.TerrainNoise.GetValue(maxX, minZ));
                float q22 = MathUtils.Lerp(biomes[255].MinHeight, biomes[255].MaxHeight,
                                           NoiseProvider.TerrainNoise.GetValue(maxX, maxZ));

                float[] heightMap = new float[16 * 16];

                for (int x = 0; x < 16; x++)
                {
                    float rx = cx + x;

                    for (int z = 0; z < 16; z++)
                    {
                        float rz = cz + z;

                        var baseNoise = MathUtils.BilinearCmr(
                            rx, rz,
                            q11,
                            q12,
                            q21,
                            q22,
                            minX, maxX, minZ, maxZ);

                        heightMap[(x << 4) + z] = baseNoise; //WaterLevel + ((128f * baseNoise));
                    }
                }

                return heightMap;
            }));
        }
Exemplo n.º 9
0
        public Pair <Genome> Crossover(Genome other, RandomNumberGenerator random)
        {
            var o = (SimpleGenome)other;

            var child1 = new SimpleGenome(MathUtils.Lerp(value, o.value, random.NextDouble()));
            var child2 = new SimpleGenome(MathUtils.Lerp(value, o.value, random.NextDouble()));

            return(new Pair <Genome>(child1, child2));
        }
Exemplo n.º 10
0
 protected void UpdateValues()
 {
     foreach (var axis in DeviceAxis.All)
     {
         var value    = CoerceProviderValue(axis, _valueProvider?.GetValue(axis) ?? float.NaN);
         var settings = AxisSettings[axis];
         Values[axis] = MathUtils.Lerp(settings.Minimum / 100f, settings.Maximum / 100f, value);
     }
 }
Exemplo n.º 11
0
        public static Vector4 Mix(Vector4 c1, Vector4 c2, float t)
        {
            var c1Linear = Degamma(c1);
            var c2Linear = Degamma(c2);

            var labMix = MathUtils.Lerp(RgbAToOkLab(c1Linear), RgbAToOkLab(c2Linear), t);

            return(ToGamma(OkLab.OkLabToRgba(labMix)));
        }
Exemplo n.º 12
0
        public Color4 ColorHSV(float hueMin, float hueMax, float saturationMin, float saturationMax, float valueMin, float valueMax, float alphaMin, float alphaMax)
        {
            float  h      = MathUtils.Lerp(hueMin, hueMax, this.NextFloat());
            float  s      = MathUtils.Lerp(saturationMin, saturationMax, this.NextFloat());
            float  v      = MathUtils.Lerp(valueMin, valueMax, this.NextFloat());
            Color4 result = Color4.HsvtoRgb(h, s, v, true);

            result.a = MathUtils.Lerp(alphaMin, alphaMax, this.NextFloat());
            return(result);
        }
Exemplo n.º 13
0
        private void Update(EvaluationContext context)
        {
            var v       = Value.GetValue(context);
            var damping = Damping.GetValue(context);

            var f = (float)(damping * EvaluationContext.LastFrameDuration).Clamp(0f, 1f);

            _dampedValue = MathUtils.Lerp(v, _dampedValue, f);
            Result.Value = _dampedValue;
        }
Exemplo n.º 14
0
        /// <summary>
        /// Interpolates between two bookmarks. The t argument must be between 0 and 1 (inclusive), and
        /// the two endpoints must have the same mode (ORBIT or MAP).
        /// </summary>
        public static Bookmark Interpolate(Bookmark a, Bookmark b, float time)
        {
            Bookmark result = new Bookmark();

            if (a.Mode == Mode.Map)
            {
                Debug.Assert(b.Mode == Mode.Map);

                float rho = MathF.Sqrt(2.0f);
                float rho2 = 2, rho4 = 4;
                float ux0 = a.Map.Center.X, uy0 = a.Map.Center.Y, w0 = a.Map.Extent;
                float ux1 = b.Map.Center.X, uy1 = b.Map.Center.Y, w1 = b.Map.Extent;
                float dx    = ux1 - ux0;
                float dy    = uy1 - uy0;
                float d2    = dx * dx + dy * dy;
                float d1    = MathF.Sqrt(d2);
                float b0    = (w1 * w1 - w0 * w0 + rho4 * d2) / (2.0f * w0 * rho2 * d1);
                float b1    = (w1 * w1 - w0 * w0 - rho4 * d2) / (2.0f * w1 * rho2 * d1);
                float r0    = MathF.Log(MathF.Sqrt(b0 * b0 + 1.0f) - b0);
                float r1    = MathF.Log(MathF.Sqrt(b1 * b1 + 1f) - b1);
                float dr    = r1 - r0;
                bool  valid = dr != 0;
                float s     = ((valid ? dr : MathF.Log(w1 / w0)) / rho);
                s = time * s;

                // this performs Van Wijk interpolation to animate between two waypoints on a map.
                if (valid)
                {
                    var coshr0 = MathF.Cosh(r0);
                    var u      = w0 / (rho2 * d1) * (coshr0 * MathF.Tanh(rho * s + r0) - MathF.Sinh(r0));

                    result.Map.Center.X = (ux0 + u * dx);
                    result.Map.Center.Y = (uy0 + u * dy);
                    result.Map.Extent   = (w0 * coshr0 / MathF.Cosh(rho * s + r0));

                    return(result);
                }

                // for degenerate cases, fall back to a simplified interpolation method.
                result.Map.Center.X = ux0 + time * dx;
                result.Map.Center.Y = uy0 + time * dy;
                result.Map.Extent   = (w0 * MathF.Exp(rho * s));

                return(result);
            }

            Debug.Assert(b.Mode == Mode.Orbit);

            result.Orbit.Phi      = MathUtils.Lerp(a.Orbit.Phi, b.Orbit.Phi, time);
            result.Orbit.Theta    = MathUtils.Lerp(a.Orbit.Theta, b.Orbit.Theta, time);
            result.Orbit.Distance = MathUtils.Lerp(a.Orbit.Distance, b.Orbit.Distance, time);
            result.Orbit.Pivot    = Vector3.Lerp(a.Orbit.Pivot, b.Orbit.Pivot, time);

            return(result);
        }
 public override void _Process(float delta)
 {
     _timer += delta;
     if (_timer > _visible_duration)
     {
         Hide();
         SetProcess(false);
     }
     Reposition();
     SetValue(MathUtils.Lerp(GetValue(), _target_value, delta * 5));
 }
Exemplo n.º 16
0
        private float BezierInterp(float p0, float p1, float p2, float p3, float alpha)
        {
            var p01   = MathUtils.Lerp(p0, p1, alpha);
            var p12   = MathUtils.Lerp(p1, p2, alpha);
            var p23   = MathUtils.Lerp(p2, p3, alpha);
            var p012  = MathUtils.Lerp(p01, p12, alpha);
            var p123  = MathUtils.Lerp(p12, p23, alpha);
            var p0123 = MathUtils.Lerp(p012, p123, alpha);

            return(p0123);
        }
Exemplo n.º 17
0
        private void DoFirstPerson(Vector2 mousePos)
        {
            Vector3 vel = Vector3.Zero;

            if (Globals.Engine.Keyboard[Key.W])
            {
                vel += new Vector3(0, 0, -1);   // camera looks backwards
            }
            if (Globals.Engine.Keyboard[Key.S])
            {
                vel += new Vector3(0, 0, 1);
            }
            if (Globals.Engine.Keyboard[Key.A])
            {
                vel += new Vector3(-1, 0, 0);
            }
            if (Globals.Engine.Keyboard[Key.D])
            {
                vel += new Vector3(1, 0, 0);
            }
            vel.NormalizeFast();

            if (Globals.Engine.Keyboard[Key.ShiftLeft])
            {
                vel *= 4;
            }

            var mouseDelta = mousePos - oldMousePos;

            // unity screen coordinate system
            mouseDelta = new Vector2(-mouseDelta.Y, -mouseDelta.X) * sensitivity * smoothing;

            _smoothMouse.X = MathUtils.Lerp(_smoothMouse.X, mouseDelta.X, 1f / smoothing);
            _smoothMouse.Y = MathUtils.Lerp(_smoothMouse.Y, mouseDelta.Y, 1f / smoothing);

            // find the absolute mouse movement value from point zero
            _mouseAbsolute += _smoothMouse;

            if (clampX < 360)
            {
                _mouseAbsolute.X = MathUtils.Clamp(_mouseAbsolute.X, -clampX * 0.5f, clampX * 0.5f);
            }

            if (clampY < 360)
            {
                _mouseAbsolute.Y = MathUtils.Clamp(_mouseAbsolute.Y, -clampY * 0.5f, clampY * 0.5f);
            }

            var xRotation = Quaternion.FromAxisAngle(Vector3.UnitX, _mouseAbsolute.X);
            var yRotation = Quaternion.FromAxisAngle(Vector3.UnitY, _mouseAbsolute.Y);

            GameObject.LocalRotation = yRotation * xRotation;
            GameObject.Translate(vel * speed, false);
        }
Exemplo n.º 18
0
    public static void SmoothlyUpdateBar(TextureProgress bar, float target, float delta)
    {
        if (delta <= 0)
        {
            GD.PrintErr("Tried to run SmoothlyUpdateBar with non-positive delta!");
            return;
        }

        var weight = Math.Min(3.0f * delta + 0.2f, 1.0f);

        bar.Value = MathUtils.Lerp((float)bar.Value, target, weight, 1.0f / (float)bar.MaxValue);
    }
Exemplo n.º 19
0
        private float convertY(float y)
        {
            var   viewport      = getViewport();
            var   virtualHeight = _virtualHeight / viewport.ScaleY;
            float density       = Resources.System.DisplayMetrics.Density;

            y = (y - GLUtils.ScreenViewport.Y) / density;
            float height = _windowSize.GetHeight(null) - ((GLUtils.ScreenViewport.Y * 2) / density);

            y = MathUtils.Lerp(0f, virtualHeight, height, 0f, y);
            return(y + viewport.Y);
        }
Exemplo n.º 20
0
        private float convertX(float x)
        {
            var   viewport     = getViewport();
            var   virtualWidth = _virtualWidth / viewport.ScaleX;
            float density      = Resources.System.DisplayMetrics.Density;

            x = (x - GLUtils.ScreenViewport.X) / density;
            float width = _windowSize.GetWidth(null) - ((GLUtils.ScreenViewport.X * 2) / density);

            x = MathUtils.Lerp(0f, 0f, width, virtualWidth, x);
            return(x + viewport.X);
        }
Exemplo n.º 21
0
        private float convertY(float y)
        {
            var   viewport      = getViewport();
            var   virtualHeight = _virtualHeight / viewport.ScaleY;
            float density       = (float)UIScreen.MainScreen.Scale;

            y = y - (GLUtils.ScreenViewport.Y / density);
            float height = (_gameWindow.Height - (GLUtils.ScreenViewport.Y * 2)) / density;

            y = MathUtils.Lerp(0f, virtualHeight, height, 0f, y);
            return(y + viewport.Y);
        }
Exemplo n.º 22
0
        private float convertX(float x)
        {
            var   viewport     = getViewport();
            var   virtualWidth = _virtualWidth / viewport.ScaleX;
            float density      = (float)UIScreen.MainScreen.Scale;

            x = x - (GLUtils.ScreenViewport.X / density);
            float width = (_gameWindow.Width - (GLUtils.ScreenViewport.X * 2)) / density;

            x = MathUtils.Lerp(0f, 0f, width, virtualWidth, x);
            return(x + viewport.X);
        }
Exemplo n.º 23
0
        private void Update(EvaluationContext context)
        {
            var closeCircle  = CloseCircle.GetValue(context);
            var circleOffset = closeCircle ? 1 : 0;
            var corners      = Count.GetValue(context).Clamp(1, 10000);
            var pointCount   = corners + circleOffset;
            var listCount    = corners + 2 * circleOffset; // Separator

            if (_pointList.NumElements != listCount)
            {
                //_points = new T3.Core.DataTypes.Point[count];
                _pointList.SetLength(listCount);
            }

            var axis            = Axis.GetValue(context);
            var center          = Center.GetValue(context);
            var offset          = Offset.GetValue(context);
            var radius          = Radius.GetValue(context);
            var radiusOffset    = RadiusOffset.GetValue(context);
            var thickness       = W.GetValue(context);
            var thicknessOffset = WOffset.GetValue(context);

            var angelInRads = StartAngel.GetValue(context) * MathUtils.ToRad + (float)Math.PI / 2;
            var deltaAngle  = -Cycles.GetValue(context) * MathUtils.Pi2 / (pointCount - circleOffset);

            for (var index = 0; index < pointCount; index++)
            {
                var f = corners == 1
                            ? 1
                            : (float)index / pointCount;
                var length  = MathUtils.Lerp(radius, radius + radiusOffset, f);
                var v       = Vector3.UnitX * length;
                var rot     = Quaternion.CreateFromAxisAngle(axis, angelInRads);
                var vInAxis = Vector3.Transform(v, rot) + Vector3.Lerp(center, center + offset, f);

                var p = new Point
                {
                    Position    = vInAxis,
                    W           = MathUtils.Lerp(thickness, thickness + thicknessOffset, f),
                    Orientation = rot
                };
                _pointList[index] = p;
                angelInRads      += deltaAngle;
            }

            if (closeCircle)
            {
                _pointList[listCount - 1] = Point.Separator();
            }

            ResultList.Value = _pointList;
        }
Exemplo n.º 24
0
        private void ProcessFadeIn()
        {
            Last.Volume =
                MathUtils.Lerp(Last.Volume, _originalVolume, Game.LastFrameTime * FadeInMultiplier);

            if (!(Last.Volume >= _originalVolume - 0.05f))
            {
                return;
            }

            Last.Volume   = _originalVolume;
            IsDoingFadeIn = false;
        }
Exemplo n.º 25
0
        public static double Perlin(double x, double y, double z)
        {
            var xi = (int)x & 255; // Calculate the "unit cube" that the point asked will be located in
            var yi = (int)y & 255; // The left bound is ( |_x_|,|_y_|,|_z_| ) and the right bound is that
            var zi = (int)z & 255; // plus 1.  Next we calculate the location (from 0.0 to 1.0) in that cube.
            var xf = x - (int)x;   // We also Fade the location to smooth the result.
            var yf = y - (int)y;
            var zf = z - (int)z;
            var u  = Fade(xf);
            var v  = Fade(yf);
            var w  = Fade(zf);

            var a  = p[xi] + yi;     // This here is Perlin's hash function.  We take our x value (remember,
            var aa = p[a] + zi;      // between 0 and 255) and get a random value (from our p[] array above) between
            var ab = p[a + 1] + zi;  // 0 and 255.  We then add y to it and plug that into p[], and add z to that.
            var b  = p[xi + 1] + yi; // Then, we get another random value by adding 1 to that and putting it into p[]
            var ba = p[b] + zi;      // and add z to it.  We do the whole thing over again starting with x+1.  Later
            var
                bb = p[b + 1] +
                     zi; // we plug aa, ab, ba, and bb back into p[] along with their +1's to get another set.
            // in the end we have 8 values between 0 and 255 - one for each vertex on the unit cube.
            // These are all interpolated together using u, v, and w below.

            double x1, x2, y1, y2;

            x1 = MathUtils.Lerp(
                Grad(p[aa], xf, yf,
                     zf),                                    // This is where the "magic" happens.  We calculate a new set of p[] values and use that to get
                Grad(p[ba], xf - 1, yf,
                     zf),                                    // our final gradient values.  Then, we interpolate between those gradients with the u value to get
                u);                                          // 4 x-values.  Next, we interpolate between the 4 x-values with v to get 2 y-values.  Finally,
            x2 = MathUtils.Lerp(Grad(p[ab], xf, yf - 1, zf), // we interpolate between the y-values to get a z-value.
                                Grad(p[bb], xf - 1, yf - 1, zf),
                                u);                          // When calculating the p[] values, remember that above, p[a+1] expands to p[xi]+yi+1 -- so you are
            y1 = MathUtils.Lerp(x1, x2,
                                v);                          // essentially adding 1 to yi.  Likewise, p[ab+1] expands to p[p[xi]+yi+1]+zi+1] -- so you are adding
            // to zi.  The other 3 parameters are your possible return values (see Grad()), which are actually
            x1 = MathUtils.Lerp(
                Grad(p[aa + 1], xf, yf,
                     zf - 1), // the vectors from the edges of the unit cube to the point in the unit cube itself.
                Grad(p[ba + 1], xf - 1, yf, zf - 1),
                u);
            x2 = MathUtils.Lerp(Grad(p[ab + 1], xf, yf - 1, zf - 1),
                                Grad(p[bb + 1], xf - 1, yf - 1, zf - 1),
                                u);
            y2 = MathUtils.Lerp(x1, x2, v);

            return
                ((MathUtils.Lerp(y1, y2, w) + 1) /
                 2); // For convenience we bound it to 0 - 1 (theoretical min/max before is -1 - 1)
        }
Exemplo n.º 26
0
        private void ProcessFadeOut()
        {
            Last.Volume =
                MathUtils.Lerp(Last.Volume, 0f, Game.LastFrameTime * FadeOutMultiplier);

            if (!(Last.Volume <= 0.05f))
            {
                return;
            }

            IsDoingFadeOut = false;

            Last.Stop();
        }
Exemplo n.º 27
0
        private void resizeGameWindow()
        {
            int height = _editor.Editor.Settings.WindowSize.Height - 100;

            if (_panel.Visible)
            {
                float panelWidth = MathUtils.Lerp(0f, 0f, _layer.IndependentResolution.Value.Width, _editor.Editor.Settings.WindowSize.Width, _panel.Width);
                AGSEditor.Platform.SetHostedGameWindow(new Rectangle((int)Math.Round(panelWidth), 0, (int)Math.Round(_editor.Editor.Settings.WindowSize.Width - panelWidth), height));
            }
            else
            {
                AGSEditor.Platform.SetHostedGameWindow(new Rectangle(0, 0, _editor.Editor.Settings.WindowSize.Width, height));
            }
        }
Exemplo n.º 28
0
        private float EvalForTwoKeys(FSimpleCurveKey key1, FSimpleCurveKey key2, float inTime)
        {
            var diff = key2.Time - key1.Time;

            if (diff > 0f && InterpMode != RCIM_Constant)
            {
                var alpha = (inTime - key1.Time) / diff;
                var p0    = key1.Value;
                var p3    = key2.Value;

                return(MathUtils.Lerp(p0, p3, alpha));
            }

            return(key1.Value);
        }
Exemplo n.º 29
0
        public void QueueDisc(Vector2 center, Vector2 radius, float depth, Color color, int sides = 32, float startAngle = 0f, float endAngle = (float)Math.PI * 2f)
        {
            Vector2 p = Vector2.Zero;

            for (int i = 0; i <= sides; i++)
            {
                float   x      = MathUtils.Lerp(startAngle, endAngle, (float)i / (float)sides);
                Vector2 vector = center + radius * new Vector2(MathUtils.Sin(x), 0f - MathUtils.Cos(x));
                if (i > 0)
                {
                    QueueTriangle(p, vector, center, depth, color);
                }
                p = vector;
            }
        }
Exemplo n.º 30
0
        private void Update(EvaluationContext context)
        {
            var  deviceContext = _d3dDevice.ImmediateContext;
            bool enabled       = Enabled.GetValue(context);
            bool logToConsole  = LogToConsole.GetValue(context);

            if (enabled && _readyToMeasure)
            {
                _queryTimeStampDisjoint.Begin(deviceContext);
                _queryTimeStampFrameBegin.End(deviceContext);
            }

            Command.GetValue(context);

            if (!enabled)
            {
                return;
            }

            if (_readyToMeasure)
            {
                _queryTimeStampFrameEnd.End(deviceContext);
                _queryTimeStampDisjoint.End(deviceContext);
                _readyToMeasure = false;
            }
            else
            {
                // check if last measurement is ready
                bool dataFetched = true;
                dataFetched &= _queryTimeStampDisjoint.GetData(deviceContext, AsynchronousFlags.None, out QueryDataTimestampDisjoint disjointData);
                dataFetched &= _queryTimeStampFrameBegin.GetData(deviceContext, AsynchronousFlags.None, out long timeStampframeBegin);
                dataFetched &= _queryTimeStampFrameEnd.GetData(deviceContext, AsynchronousFlags.None, out long timeStampframeEnd);

                if (dataFetched && !disjointData.Disjoint)
                {
                    float durationInS = (float)(timeStampframeEnd - timeStampframeBegin) / disjointData.Frequency;
                    int   usDuration  = (int)(durationInS * 1000f * 1000f);
                    if (logToConsole)
                    {
                        Log.Debug($"Subtree took: {usDuration}us on GPU.");
                    }
                    LastMeasureInMicroSeconds = usDuration;
                    _readyToMeasure           = true;
                }

                LastMeasureInMs = MathUtils.Lerp(LastMeasureInMs, (float)(LastMeasureInMicroSeconds / 1000.0), 0.03f);
            }
        }