コード例 #1
0
        private static Match CheckForInterpolation(InterpolationData interpolation, string bufferContents)
        {
            if (interpolation == null)
            {
                return(null);
            }

            if (!bufferContents.EndsWith(interpolation.End))
            {
                return(null);
            }

            var startPosition = bufferContents.IndexOf(interpolation.Start);

            if (startPosition < 0)
            {
                return(null);
            }

            var index = startPosition + interpolation.Start.Length;

            var length = bufferContents.IndexOf(interpolation.End);

            var input = bufferContents.Substring(index, length - index);

            var match = Regex.Match(input, interpolation.ArgumentPattern);

            return(match);
        }
コード例 #2
0
        /// <summary>
        ///   Try to interpolate the three most recent messages. Interpolation only works if the
        ///   first and the third message do not interpolate.
        /// </summary>
        /// <param name="newMessage">
        ///   The message to be stored. Storage is in charge of the decorated instance.
        /// </param>
        public void Store(MessaggioPosizione newMessage)
        {
            this.decorated.Store(newMessage);

            var lastThreeMessages = this.messaggiPosizioneCollection.Find(m => m.CodiceMezzo == newMessage.CodiceMezzo)
                .SortByDescending(m => m.IstanteAcquisizione)
                .ThenByDescending(m => m.Id)
                .Limit(3)
                .ToList();

            if ((lastThreeMessages.Count == 3) &&
                firstAndThirdMessagesDoNotInterpolate(lastThreeMessages) &&
                this.AllInTheSamePosition(lastThreeMessages))
            {
                var interpolatingMessage = lastThreeMessages[0];
                var msgToInterpolate = lastThreeMessages[1];
                var lastInterpolationData = msgToInterpolate.InterpolationData ?? new InterpolationData(0, 0, null);

                var interpolationData = new InterpolationData(
                    (int)(lastInterpolationData.Length_sec +
                        newMessage.IstanteAcquisizione.Subtract(msgToInterpolate.IstanteAcquisizione).TotalSeconds),
                    lastInterpolationData.Messages + 1,
                    msgToInterpolate.IstanteAcquisizione);

                var deleteTask = this.messaggiPosizioneCollection.DeleteOneAsync(m => m.Id == msgToInterpolate.Id);
                var updateTask = this.messaggiPosizioneCollection.UpdateOneAsync(
                    m => m.Id == interpolatingMessage.Id,
                    Builders<MessaggioPosizione>.Update.Set(m => m.InterpolationData, interpolationData));

                Task.WaitAll(deleteTask, updateTask);
            }
        }
コード例 #3
0
    private void Update()
    {
        PlayAnimation();
        InterpolationData interpolationData = GetInterpolationData(curAnimation, animationTime);

        UpdateMaterials(interpolationData);
    }
コード例 #4
0
 public AnimationKeyRemovedEvent(ulong propertyAnimationId, ulong keyId, int frame, float undoValue, InterpolationData undoInterpolation)
 {
     PropertyAnimationId = propertyAnimationId;
     KeyId             = keyId;
     Frame             = frame;
     UndoValue         = undoValue;
     UndoInterpolation = undoInterpolation;
 }
コード例 #5
0
 public AnimationKeyAddedEvent(ulong propertyAnimationId, ulong keyId, int frame, float value, InterpolationData interpolation)
 {
     PropertyAnimationId = propertyAnimationId;
     KeyId         = keyId;
     Frame         = frame;
     Value         = value;
     Interpolation = interpolation;
 }
コード例 #6
0
ファイル: GalleryAnimator.cs プロジェクト: dave95b/Puzzles
    private void AnimateSlide()
    {
        Vector3 destination = gallery.GetSlidePosition();

        collider.enabled = false;
        var data = new InterpolationData <Vector3>(slide, scroll.localPosition, destination, slideDuration, slideCurve, enableCollider);

        interpolator.Interpolate(data);
    }
コード例 #7
0
 private void SaveInterpolationUpdate <T>(ref InterpolationData <T> interpolationRoot, ref Queue <InterpolationData <T> > updateQueue, ref float timeDifferentialToSender, InterpolationData <T> newInterpolationData)
 {
     timeDifferentialToSender = Time.time - newInterpolationData.timestamp;
     if (interpolationRoot == null)
     {
         interpolationRoot = newInterpolationData;
         return;
     }
     updateQueue.Enqueue(newInterpolationData);
 }
コード例 #8
0
 private bool ReadyToInterpolate <T>(ref InterpolationData <T> interpolationRoot,
                                     ref Queue <InterpolationData <T> > updateQueue, float currentInterpolationTime)
 {
     TrimOldUpdates(ref interpolationRoot, ref updateQueue, currentInterpolationTime);
     if (ShouldWaitForMoreUpdates <T>(interpolationRoot, updateQueue, currentInterpolationTime))
     {
         return(false);
     }
     return(true);
 }
コード例 #9
0
        /// <summary>
        /// Performs a scaled linear re-projection into the specified target block.
        /// <br/>
        /// Uses the given mapping function only to determine the corresponding corner points in the source image,
        /// uses a linear interpolation to determine intermediate points.
        /// </summary>
        /// <param name="source">The image to be re-projected.</param>
        /// <param name="target">The resulting image to be filled.</param>
        /// <param name="block">The block being targeted.</param>
        /// <param name="transformTargetToSource">Mapping function that maps target to source pixels.</param>
        /// <param name="scale">A factor to apply when re-projecting the block. See code comments in Reproject method above, where this parameter is set up.</param>
        private static void ScaledReprojection(ArgbImage source, ArgbImage target, ReprojectionBlock block, Func <PointD, PointD> transformTargetToSource, Size scale)
        {
            // determine the number of sections of the scaled block
            var nx = (block.X1 - block.X0 + 1) * scale.Width - 1;
            var ny = (block.Y1 - block.Y0 + 1) * scale.Height - 1;

            // Interpolators for upper and lower line of block
            var upper = InterpolationData.Create(transformTargetToSource(block.LeftTop), transformTargetToSource(block.RightTop), nx);
            var lower = InterpolationData.Create(transformTargetToSource(block.LeftBottom), transformTargetToSource(block.RightBottom), nx);

            // total number of color components collected in a color block due to scaling
            var colorBlockSize = (uint)(scale.Width * scale.Height);

            for (var x = block.X0; x <= block.X1; ++x)
            {
                // setup scale.Width interpolators for interpolating points on the line
                // defined through upper+n and lower+n, with n=0..(scale.Width-1)

                var sourcePoint = new InterpolationData[scale.Width];

                for (var xsub = 0; xsub < scale.Width; ++xsub)
                {
                    sourcePoint[xsub] = InterpolationData.Create(upper++, lower++, ny);
                }

                for (var y = block.Y0; y <= block.Y1; ++y)
                {
                    // storage for color components
                    uint a, r, g, b;
                    a = r = g = b = colorBlockSize >> 2;

                    // collect color components of subpixels.
                    // In the inner loop, we'll step our sourcePoint interpolators.
                    for (var ysub = 0; ysub < scale.Height; ++ysub)
                    {
                        for (var xsub = 0; xsub < scale.Width; ++sourcePoint[xsub], ++xsub)
                        {
                            var color = source[sourcePoint[xsub].x, sourcePoint[xsub].y];

                            a += (color >> 24) & 0xff;
                            r += (color >> 16) & 0xff;
                            g += (color >> 8) & 0xff;
                            b += color & 0xff;
                        }
                    }

                    // average the collected color components and set the target pixel
                    target[x, y] =
                        ((a / colorBlockSize) << 24) |
                        ((r / colorBlockSize) << 16) |
                        ((g / colorBlockSize) << 8) |
                        (b / colorBlockSize);
                }
            }
        }
コード例 #10
0
ファイル: UIWindow_CraftTime.cs プロジェクト: Hengle/Clicker
        public void Init(int craftTime)
        {
            Init();

            m_LerpData      = new InterpolationData <float>(craftTime);
            m_LerpData.From = 0;
            m_LerpData.To   = 1;
            m_LerpData.Start();

            UpdateLeftTime(craftTime);
        }
コード例 #11
0
        public void Init(float actionPeriod, bool loop, float multiplayer = 1)
        {
            SetMultiplyer(multiplayer);

            m_LerpPeriod      = new InterpolationData <float>();
            m_LerpPeriod.From = 0;
            m_LerpPeriod.To   = 1;

            m_Loop = loop;

            SetPeriod(actionPeriod);
        }
コード例 #12
0
ファイル: TokenBuilder.cs プロジェクト: johncoder/mimeo
        /// <summary>
        /// Defines a child interpolation token.
        /// </summary>
        /// <param name="interpolationData"></param>
        /// <returns></returns>
        public ISimpleToken Interpolate(InterpolationData interpolationData)
        {
            Ensure.ArgumentNotNull(interpolationData, "interpolationData");

            _currentToken = new InterpolationToken <TModel>
            {
                Interpolation = interpolationData,
                Identifier    = interpolationData.GetIdentifier()
            };
            Token.AddChild(_currentToken);

            return(this);
        }
コード例 #13
0
ファイル: PuzzleAnimator.cs プロジェクト: dave95b/Puzzles
    public void Rotate()
    {
        SetInteractable(false);
        puzzle.Rotation = (++puzzle.Rotation) % 4;

        Vector3 currentRotation = puzzle.transform.rotation.eulerAngles;
        Vector3 targetRotation  = currentRotation - new Vector3(0f, 0f, 90f);

        var data = new InterpolationData <Vector3>(ChangeRotation, currentRotation, targetRotation, rotateDuration, AnimationHelper.LinearCurve, MakeInteractable);

        Interpolator.Interpolate(data);

        OrderController.MoveToTop(puzzle);
    }
コード例 #14
0
    // This is something like what the hybrid renderer does with the VA_AnimationDataComponent.
    private void UpdateMaterials(InterpolationData interpolationData)
    {
        MaterialPropertyBlock materialPropertyBlock = new MaterialPropertyBlock();

        materialPropertyBlock.SetVector("_AnimationData", new Vector4(animationTime, curAnimation.Data.animationMapIndex, interpolationData.animationTime, interpolationData.animationMapIndex));

        foreach (var mr in meshRenderers)
        {
            if (mr.enabled && mr.gameObject.activeSelf)
            {
                mr.SetPropertyBlock(materialPropertyBlock);
            }
        }
    }
コード例 #15
0
    public static void SpriteFade(Interpolator interpolator, SpriteRenderer sprite, float startAplha, float endAlpha, float duration, AnimationCurve curve, Action onEnded = null)
    {
        void fade(float alpha)
        {
            var color = sprite.color;

            color.a      = alpha;
            sprite.color = color;
        }

        var interpolationData = new InterpolationData <float>(fade, startAplha, endAlpha, duration, curve, onEnded);

        interpolator.Interpolate(interpolationData);
    }
コード例 #16
0
ファイル: PuzzleAnimator.cs プロジェクト: dave95b/Puzzles
    private IEnumerator AnimateMove(Vector3 destination, float duration, float initialDelay, bool enableCollider)
    {
        Vector3 origin = transform.position;

        yield return(Yielder.WaitForSeconds(initialDelay));

        InterpolationData <Vector3> interpolationData = new InterpolationData <Vector3>(ChangePosition, origin, destination, duration, moveCurve);

        if (enableCollider)
        {
            interpolationData.OnEnded = MakeInteractable;
        }

        Interpolator.Interpolate(interpolationData);
    }
コード例 #17
0
 private void TrimOldUpdates <T>(ref InterpolationData <T> interpolationRoot,
                                 ref Queue <InterpolationData <T> > updateQueue, float currentInterpolationTime)
 {
     while (updateQueue.Count > 0)
     {
         for (var updateNum = 0; updateNum < updateQueue.Count; updateNum++)
         {
             if (updateQueue.Peek().timestamp < currentInterpolationTime)
             {
                 interpolationRoot = updateQueue.Dequeue();
                 continue;
             }
             return;
         }
     }
 }
コード例 #18
0
ファイル: TokenBuilder.cs プロジェクト: johncoder/mimeo
        /// <summary>
        /// Defines a child interpolation token.
        /// </summary>
        /// <param name="start"></param>
        /// <param name="argumentPattern"></param>
        /// <param name="end"></param>
        /// <param name="inject"></param>
        /// <returns></returns>
        public ISimpleToken Interpolate(string start, string argumentPattern, string end, Func <dynamic, string> inject)
        {
            Ensure.ArgumentNotNullOrEmpty(start, "start");
            Ensure.ArgumentNotNullOrEmpty(end, "end");
            Ensure.ArgumentNotNull(inject, "inject");

            var interpolationData = new InterpolationData
            {
                Start           = start,
                ArgumentPattern = argumentPattern,
                End             = end,
                Injection       = inject
            };

            return(Interpolate(interpolationData));
        }
コード例 #19
0
        /// <summary>
        /// Performs a scaled linear re-projection into the specified target block.
        /// <br/>
        /// Uses the given mapping function only to determine the corresponding corner points in the source image,
        /// uses a linear interpolation to determine intermediate points.
        /// </summary>
        /// <param name="source">The image to be re-projected.</param>
        /// <param name="target">The resulting image to be filled.</param>
        /// <param name="block">The block being targeted.</param>
        /// <param name="transformTargetToSource">Mapping function that maps target to source pixels.</param>
        /// <param name="scaleY">A factor to apply when re-projecting the block. See code comments in Reproject method above, where this parameter is set up.</param>
        private static void VerticallyScaledReprojection(ArgbImage source, ArgbImage target, ReprojectionBlock block, Func <PointD, PointD> transformTargetToSource, int scaleY)
        {
            // determine the number of sections of the scaled block
            var nx = block.X1 - block.X0;
            var ny = (block.Y1 - block.Y0 + 1) * scaleY - 1;

            // Interpolators for upper and lower line of block
            var upper = InterpolationData.Create(transformTargetToSource(block.LeftTop), transformTargetToSource(block.RightTop), nx);
            var lower = InterpolationData.Create(transformTargetToSource(block.LeftBottom), transformTargetToSource(block.RightBottom), nx);

            // total number of color components collected in a color block due to scaling
            var colorBlockSize = (uint)scaleY;

            for (var x = block.X0; x <= block.X1; ++x, ++upper, ++lower)
            {
                // setup interpolator for interpolating points on the line defined through upper and lower

                var sourcePoint = InterpolationData.Create(upper, lower, ny);

                for (var y = block.Y0; y <= block.Y1; ++y)
                {
                    // storage for color components
                    uint a, r, g, b;
                    a = r = g = b = colorBlockSize >> 2;

                    // collect color components of sub pixels.
                    // In the inner loop, we'll step our sourcePoint interpolators.
                    for (var ysub = 0; ysub < scaleY; ++ysub, ++sourcePoint)
                    {
                        var color = source[sourcePoint.x, sourcePoint.y];

                        a += (color >> 24) & 0xff;
                        r += (color >> 16) & 0xff;
                        g += (color >> 8) & 0xff;
                        b += color & 0xff;
                    }

                    // average the collected color components and set the target pixel
                    target[x, y] =
                        ((a / colorBlockSize) << 24) |
                        ((r / colorBlockSize) << 16) |
                        ((g / colorBlockSize) << 8) |
                        (b / colorBlockSize);
                }
            }
        }
コード例 #20
0
        /// <summary>
        /// Performs a unscaled linear re-projection into the specified target block.
        /// <br/>
        /// Uses the given mapping function only to determine the corresponding corner points in the source image,
        /// uses a linear interpolation to determine intermediate points.
        /// </summary>
        /// <param name="source">The image to be re-projected.</param>
        /// <param name="target">The resulting image to be filled.</param>
        /// <param name="block">The block being targeted.</param>
        /// <param name="transformTargetToSource">Mapping function that maps target to source pixels.</param>
        private static void UnscaledReprojection(ArgbImage source, ArgbImage target, ReprojectionBlock block, Func <PointD, PointD> transformTargetToSource)
        {
            // Interpolators for upper and lower line of block
            var upper = InterpolationData.Create(transformTargetToSource(block.LeftTop), transformTargetToSource(block.RightTop), block.X1 - block.X0);
            var lower = InterpolationData.Create(transformTargetToSource(block.LeftBottom), transformTargetToSource(block.RightBottom), block.X1 - block.X0);

            for (var x = block.X0; x <= block.X1; ++x, ++upper, ++lower)
            {
                // interpolator for points on the current line defined through upper and lower
                var sourcePoint = InterpolationData.Create(upper, lower, block.Y1 - block.Y0);

                for (var y = block.Y0; y <= block.Y1; ++y, ++sourcePoint)
                {
                    target[x, y] = source[sourcePoint.x, sourcePoint.y];
                }
            }
        }
コード例 #21
0
    // This is resembles the VA_AnimatorSystem.
    private static InterpolationData GetInterpolationData(VA_Animation animation, float animationTime)
    {
        InterpolationData data = new InterpolationData();

        // Calculate next frame time for lerp.
        float animationTimeNext = animationTime + (1.0f / animation.Data.maxFrames);

        if (animationTimeNext > animation.Data.duration)
        {
            // Set time. Using the difference to smooth out animations when looping.
            animationTimeNext -= animationTime;
        }

        data.animationTime     = animationTimeNext;
        data.animationMapIndex = animation.Data.animationMapIndex;

        return(data);
    }
コード例 #22
0
        public void FindPoints(double t, out InterpolationData p1, out InterpolationData p2)
        {
            if (t < Points[0].T)
            {
                p1 = Points[0];
                p2 = Points[0];
                return;
            }

            for (int i = 0; i < Points.Length - 1; i++)
            {
                p1 = Points[i];
                p2 = Points[i + 1];
                if (p1.T <= t && t <= p2.T)
                {
                    return;
                }
            }

            p1 = Points[^ 1];
コード例 #23
0
        public void Cooldown(float timeMiliseconds)
        {
            float timeSeconds = timeMiliseconds / 1000f;

            UpdateLeftTime(timeSeconds);

            m_LerpData      = new InterpolationData <float>(timeSeconds);
            m_LerpData.From = 1;
            m_LerpData.To   = 0;

            if (m_Timer == null)
            {
                m_Timer = GetComponent <Timer>();

                m_Timer.OnStep             += TimerStep_Handler;
                m_Timer.OnTotalTimeElapsed += TimerElapsed_Handler;
            }

            m_Timer.Init(timeSeconds);
            m_Timer.StartCountdown();

            m_LerpData.Start();
        }
コード例 #24
0
 private static float InterpolateAuxLinear(InterpolationData data, float b)
 {
     if (b < data.Bmin)
     {
         return data.Y[0] * b / data.Bmin;
     }
     else if (b > data.Bmax)
     {
         float d = b - data.Bmax;
         return data.Y[ibetaBResolution] + (1.0f - data.Y[ibetaBResolution]) * d / (1 + d);
     }
     else
     {
         float d = (b - data.Bmin) * ibetaBResolution / (data.Bmax - data.Bmin);
         int j = (int)d;
         // linear interpolation
         float y1 = data.Y[j];
         float y2;
         if (j <= ibetaBResolution - 1)
         {
             y2 = data.Y[j + 1];
         }
         else // j > ibetaBResolution - 1
         {
             y2 = 1f;
         }
         d -= j;
         // linear spline
         return y1 + d * (y2 - y1);
     }
 }
コード例 #25
0
        private static InterpolationData[][] CalculateIbetaCache()
        {
            InterpolationData[][] ibetaCache = new InterpolationData[ibetaCacheSize][];

            for (int a = 0; a < ibetaCacheSize; a++)
            {
                ibetaCache[a] = new InterpolationData[ibetaXResolution + 1];
                for (int i = 1; i < ibetaXResolution; i++)
                {
                    ibetaCache[a][i].Y = new float[ibetaBResolution + 1];

                    double x = i / (double)ibetaXResolution;
                    double bmin = BisectIbeta(a + 1, x, 0.0001, 0.00001);
                    double bmax = BisectIbeta(a + 1, x, 0.9999, 0.00001);

                    ibetaCache[a][i].Bmin = (float)bmin;
                    ibetaCache[a][i].Bmax = (float)bmax;
                    for (int j = 0; j <= ibetaBResolution; j++)
                    {
                        ibetaCache[a][i].Y[j] = (float)Ibeta(a + 1, bmin + (bmax - bmin) * j / (double)ibetaBResolution, x);
                    }
                }
            }
            return ibetaCache;
        }
コード例 #26
0
 private static float InterpolateAux(InterpolationData data, float b)
 {
     if (b < data.Bmin)
     {
         return data.Y[0] * b / data.Bmin;
     }
     else if (b > data.Bmax)
     {
         float d = b - data.Bmax;
         return data.Y[ibetaBResolution] + (1.0f - data.Y[ibetaBResolution]) * d / (1 + d);
     }
     else
     {
         float d = (b - data.Bmin) * ibetaBResolution / (data.Bmax - data.Bmin);
         int j = (int)d;
         // hermite interpolation
         float y0;
         if (j == 0)
         {
             y0 = 0f;
         }
         else
         {
             y0 = data.Y[j - 1];
         }
         float y1 = data.Y[j];
         float y2;
         float y3;
         if (j <= ibetaBResolution - 2)
         {
             y2 = data.Y[j + 1];
             y3 = data.Y[j + 2];
         }
         else if (j == ibetaBResolution - 1)
         {
             y2 = data.Y[j + 1];
             y3 = 1f;
         }
         else // j > ibetaBResolution - 1
         {
             y2 = 1f;
             y3 = 1f;
         }
         d -= j;
         // Catmull–Rom spline
         return 0.5f * (y0 * (d * ((2 - d) * d - 1)) + y1 * (d * d * (3 * d - 5) + 2) + y2 * (d * ((4 - 3 * d) * d + 1)) + y3 * ((d - 1) * d * d));
     }
 }
コード例 #27
0
ファイル: InterpolationData.cs プロジェクト: dave95b/Puzzles
 public bool Equals(InterpolationData <T> other)
 {
     return(Action == other.Action);
 }
コード例 #28
0
    private void SmoothMoveTo(Vector3 destination)
    {
        var data = new InterpolationData <Vector3>(move, transform.position, destination, animDuration, curve);

        interpolator.Interpolate(data);
    }
コード例 #29
0
 public void Init()
 {
     m_LerpData           = new InterpolationData <float>();
     m_LerpData.TotalTime = m_MULTIPLAYER_TRANSITION_TIME;
     CurValue             = m_MULTIPLAYER_INIT_VALUE;
 }
コード例 #30
0
 /// <summary>
 /// Creates and initializes an instance of InterpolationData given a start and end position and
 /// the number of steps to be taken to interpolate coordinates between them.
 /// </summary>
 /// <param name="a">An InterpolationData instance whose current position is used as the start position.</param>
 /// <param name="b">An InterpolationData instance whose current position is used as the end position.</param>
 /// <param name="n">The number of steps.</param>
 /// <returns>InterpolationData instance.</returns>
 public static InterpolationData Create(InterpolationData a, InterpolationData b, int n)
 {
     return(new InterpolationData {
         x = a.x, xi = (b.x - a.x) / n, y = a.y, yi = (b.y - a.y) / n
     });
 }
コード例 #31
0
 public AnimationKeyInterpolationDataChanged(ulong keyId, InterpolationData data)
 {
     KeyId = keyId;
     Data  = data;
 }
コード例 #32
0
 private bool ShouldWaitForMoreUpdates <T>(InterpolationData <T> interpolationRoot, Queue <InterpolationData <T> > updateQueue, float currentInterpolationTime)
 {
     return(updateQueue.Count < 1 || currentInterpolationTime < interpolationRoot.timestamp);
 }
コード例 #33
0
    private void AnimatePanel()
    {
        var data = new InterpolationData <float>(SetPanelPosition, panelStartPosition, 0f, panelSlideDuration, panelCurve);

        interpolator.Interpolate(data);
    }