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); }
/// <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); } }
private void Update() { PlayAnimation(); InterpolationData interpolationData = GetInterpolationData(curAnimation, animationTime); UpdateMaterials(interpolationData); }
public AnimationKeyRemovedEvent(ulong propertyAnimationId, ulong keyId, int frame, float undoValue, InterpolationData undoInterpolation) { PropertyAnimationId = propertyAnimationId; KeyId = keyId; Frame = frame; UndoValue = undoValue; UndoInterpolation = undoInterpolation; }
public AnimationKeyAddedEvent(ulong propertyAnimationId, ulong keyId, int frame, float value, InterpolationData interpolation) { PropertyAnimationId = propertyAnimationId; KeyId = keyId; Frame = frame; Value = value; Interpolation = interpolation; }
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); }
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); }
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); }
/// <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); } } }
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); }
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); }
/// <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); }
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); }
// 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); } } }
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); }
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); }
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; } } }
/// <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)); }
/// <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); } } }
/// <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]; } } }
// 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); }
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];
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(); }
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); } }
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; }
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)); } }
public bool Equals(InterpolationData <T> other) { return(Action == other.Action); }
private void SmoothMoveTo(Vector3 destination) { var data = new InterpolationData <Vector3>(move, transform.position, destination, animDuration, curve); interpolator.Interpolate(data); }
public void Init() { m_LerpData = new InterpolationData <float>(); m_LerpData.TotalTime = m_MULTIPLAYER_TRANSITION_TIME; CurValue = m_MULTIPLAYER_INIT_VALUE; }
/// <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 }); }
public AnimationKeyInterpolationDataChanged(ulong keyId, InterpolationData data) { KeyId = keyId; Data = data; }
private bool ShouldWaitForMoreUpdates <T>(InterpolationData <T> interpolationRoot, Queue <InterpolationData <T> > updateQueue, float currentInterpolationTime) { return(updateQueue.Count < 1 || currentInterpolationTime < interpolationRoot.timestamp); }
private void AnimatePanel() { var data = new InterpolationData <float>(SetPanelPosition, panelStartPosition, 0f, panelSlideDuration, panelCurve); interpolator.Interpolate(data); }