public static float EaseInQuintInterpolator(float from, float to, float ratio) { ratio = FMath.Clamp(ratio, 0f, 1f); float num = ratio * ratio; return((to - from) * num * num * ratio + from); }
public static float OvershootInterpolator(float from, float to, float ratio) { float num = 1.70158f; ratio = FMath.Clamp(ratio, 0f, 1f); return((to - from) * ((ratio -= 1f) * ratio * ((num + 1f) * ratio + num) + 1f) + from); }
public static float EaseOutQuartInterpolator(float from, float to, float ratio) { ratio = FMath.Clamp(ratio, 0f, 1f); ratio -= 1f; ratio *= ratio; return((from - to) * ratio * ratio + to); }
private void UpdateView() { if (this.barImage == null || this.baseImage == null) { return; } if (this.Width <= 0f || this.Height <= 0f || this.Length <= 0f) { this.barImage.Visible = false; this.baseImage.Visible = false; return; } this.barImage.Visible = true; this.baseImage.Visible = true; float num = FMath.Clamp(this.barLength, 0f, this.length); this.barPosition = FMath.Clamp(this.barPosition, 0f, this.length - num); switch (this.Orientation) { case ScrollBarOrientation.Horizontal: this.barImage.Width = this.Width * (num / this.length); this.barImage.X = this.Width * (this.barPosition / this.length); return; case ScrollBarOrientation.Vertical: this.barImage.Height = this.Height * (num / this.Length); this.barImage.Y = this.Height * (this.barPosition / this.length); return; default: return; } }
public void adjustPositions() { for (int i = 0; i < MapManager.Instance.predefinedMaps.Count; i++) { float newX = 960.0f / 2.0f + i * (thumbnailSize + thumbnailSpacing) - levelSelection * (thumbnailSize + thumbnailSpacing); MapManager.Instance.predefinedMaps [i].thumbnailSprite.RunAction( new MoveTo( new Vector2( newX, MapManager.Instance.predefinedMaps [i].thumbnailSprite.Position.Y), transitionDuration)); float scaleFactor = FMath.Clamp(thumbnailSize - FMath.Abs((960.0f / 2.0f) - newX) / 4.0f, 0.0f, thumbnailSize); MapManager.Instance.predefinedMaps [i].thumbnailSprite.RunAction( new ScaleTo(new Vector2(scaleFactor, scaleFactor), 0.5f)); //adjust labels float labelScaleFactor = FMath.Clamp(1.0f - FMath.Abs((960.0f / 2.0f) - newX) / 1000.0f, 0.0f, 1.0f); labels [i].RunAction( new MoveTo( new Vector2( newX, MapManager.Instance.predefinedMaps [i].thumbnailSprite.Position.Y - thumbnailSize * 0.65f * labelScaleFactor), transitionDuration)); labels [i].RunAction(new ScaleTo(new Vector2(labelScaleFactor, labelScaleFactor), 0.5f)); } }
private void UpdateView() { if (this.scrollBarH == null || this.scrollBarV == null) { return; } if (this.Width > this.PanelWidth) { this.PanelX = 0f; this.scrollBarH.Length = this.Width; } else { this.panel.X = FMath.Clamp(this.panel.X, this.Width - this.panel.Width, 0f); this.scrollBarH.Length = this.panel.Width; } this.scrollBarH.Y = this.Height - this.scrollBarH.Height; this.scrollBarH.Width = this.Width - this.scrollBarV.Width; this.scrollBarH.BarLength = this.Width; if (this.Height > this.PanelHeight) { this.PanelY = 0f; this.scrollBarV.Length = this.Height; } else { this.panel.Y = FMath.Clamp(this.panel.Y, this.Height - this.panel.Height, 0f); this.scrollBarV.Length = this.panel.Height; } this.scrollBarV.X = this.Width - this.scrollBarV.Width; this.scrollBarV.Height = this.Height - this.scrollBarH.Height; this.scrollBarV.BarLength = this.Height; this.UpdateScrollBarPos(); this.UpdateScrollBarVisible(); }
protected override void OnUpdate(float elapsedTime) { base.OnUpdate(elapsedTime); if (!this.animation) { return; } if (Math.Abs(this.flickDistance.X) < 0.5f && Math.Abs(this.flickDistance.Y) < 0.5f) { this.flickDistance = Vector2.Zero; this.animationState = ScrollPanel.AnimationState.None; this.animation = false; this.UpdateView(); return; } this.animationElapsedTime += elapsedTime; float num = (float)Math.Exp((double)(-(double)this.animationElapsedTime * 0.00539892027f)); this.flickDistance = this.startFlickDistance * num; if (Math.Abs(this.flickDistance.X) > 0.5f) { this.panel.X = this.startPanelPos.X + (this.startFlickDistance.X - this.flickDistance.X) / 0.09f; this.panel.X = FMath.Clamp(this.panel.X, this.Width - this.panel.Width, 0f); } if (Math.Abs(this.flickDistance.Y) > 0.5f) { this.panel.Y = this.startPanelPos.Y + (this.startFlickDistance.Y - this.flickDistance.Y) / 0.09f; this.panel.Y = FMath.Clamp(this.panel.Y, this.Height - this.panel.Height, 0f); } this.UpdateScrollBarPos(); }
public void SetDampingConstant(Widget widget, SpringType type, float dampingConstant) { this.SetValue(widget, type, dampingConstant, delegate(Widget w, SpringType t, float value) { value = FMath.Clamp(value, 0f, 1f); this.widgetInfos[w].dampingConstants[(int)t] = -10f * value; }); }
public static float EaseOutExpoInterpolator(float from, float to, float ratio) { ratio = FMath.Clamp(ratio, 0f, 1f); if (ratio < 1f) { return((to - from) * 1.001f * (1f - (float)Math.Pow(2.0, (double)(-10f * ratio))) + from); } return(to); }
public static float EaseInExpoInterpolator(float from, float to, float ratio) { ratio = FMath.Clamp(ratio, 0f, 1f); if (ratio > 0f) { return((to - from) * (float)(Math.Pow(2.0, (double)(10f * (ratio - 1f))) - 0.0010000000474974513) + from); } return(from); }
public static float ShockWave(float d, float time, float wave_half_width, float wave_speed, float wave_fade, float d_scale) { d *= d_scale; float num = time * wave_speed; float num2 = FMath.Clamp(d - num, -wave_half_width, wave_half_width) / wave_half_width; float num3 = (1f + FMath.Cos(Math.Pi * num2)) * 0.5f; return(num3 * FMath.Exp(-d * wave_fade)); }
public static float EaseOutInCircInterpolator(float from, float to, float ratio) { ratio = FMath.Clamp(ratio, 0f, 1f); if (ratio < 0.5f) { return(AnimationUtility.EaseOutCircInterpolator(from, (to + from) / 2f, ratio * 2f)); } return(AnimationUtility.EaseInCircInterpolator((to + from) / 2f, to, ratio * 2f - 1f)); }
public void SetSpriteSize(float size) { size = FMath.Clamp(size, 4.0f, 512.0f); for (int i = 0; i < spriteCount; i++) { sprites[i].Size.X = sprites[i].Size.Y = size; } spriteSize = size; }
public void SetSpringConstant(Widget widget, SpringType type, float springConstant) { this.SetValue(widget, type, springConstant, delegate(Widget w, SpringType t, float value) { value = FMath.Clamp(value, 0f, 1f); this.widgetInfos[w].springConstants[(int)t] = 4f * value + 1f; this.widgetInfos[w].springLimitations[(int)t] = 1f - FMath.Pow(value, 5f); }); }
public static float FlipBounceInterpolator(float from, float to, float ratio) { ratio = FMath.Clamp(ratio, 0f, 1f); if (ratio < 0.333333343f) { ratio *= 3f; return((to - from) * ratio * ratio + from); } ratio = (ratio - 0.333333343f) * 1.5f; return(to + (from - to) / 15f * ((1f - ratio) * (1f - (float)Math.Cos((double)ratio * 18.849555921538759)))); }
public void initLevelSelect() { this.levelSelection = 0; this.Camera2D.SetViewFromViewport(); //labels labels = new List <Support.CustomLabel> (); //mini background discofloor var tex = new Texture2D("/Application/data/tiles/simple5.png", false); var texture = new TextureInfo(tex, new Vector2i(1, 13)); var menuBackground = new SpriteList(texture); for (int x = 0; x < 30; x++) { for (int y = 0; y < 17; y++) { SpriteTile bgTile = new SpriteTile(texture); bgTile.TileIndex1D = Support.random.Next(4, 13); bgTile.Position = new Vector2((float)x * 32.0f, (float)y * 32.0f); bgTile.Scale = bgTile.TextureInfo.TileSizeInPixelsf * 2.0f; bgTile.ScheduleInterval((dt) => { bgTile.TileIndex1D = Support.random.Next(4, 13); }, 0.2f, -1); menuBackground.AddChild(bgTile); } } Background.AddChild(menuBackground); for (int i = 0; i < MapManager.Instance.predefinedMaps.Count; i++) { //add thumbnail float newX = 960.0f / 2.0f + i * (thumbnailSize + thumbnailSpacing); float scaleFactor = FMath.Clamp(thumbnailSize - FMath.Abs((960.0f / 2.0f) - newX) / 4.0f, 0.0f, thumbnailSize); MapManager.Instance.predefinedMaps [i].thumbnailSprite.Scale = new Vector2(scaleFactor, scaleFactor); MapManager.Instance.predefinedMaps [i].thumbnailSprite.Position = new Vector2(newX, 544.0f / 2.0f); Foreground.AddChild(MapManager.Instance.predefinedMaps [i].thumbnailSprite); //add label: var tempLabel = new Support.CustomLabel(new Vector2(newX, 544.0f / 2.0f - thumbnailSize * 0.6f), "Level " + (i + 1) + "\nHighscore: 0", SceneManager.UIFontMap); labels.Add(tempLabel); Foreground.AddChild(tempLabel); } }
internal static AnimationInterpolator GetDampedWaveInterpolator(int strength) { strength = (int)FMath.Clamp((float)strength, 0f, 100f); return(AnimationUtility.GetAnimationInterpolator(delegate(float ratio) { if (strength == 0) { return ratio; } return -FMath.Cos(ratio * 3.14159274f * (float)strength * 2f) * FMath.Exp(-ratio * (float)strength) / 2f; })); }
internal static AnimationInterpolator GetSineWaveInterpolator(int strength) { strength = (int)FMath.Clamp((float)strength, 0f, 100f); return(AnimationUtility.GetAnimationInterpolator(delegate(float ratio) { if (strength == 0) { return ratio; } return (1f + FMath.Sin(ratio * 3.14159274f * (float)strength - 1.57079637f)) / 2f; })); }
/// <summary> /// Saves float data to 8 bit.. /// </summary> public static void Save8Bit(string filename, float[] data) { int size = data.Length; byte[] bytes = new byte[size]; for (int i = 0; i < size; i++) { bytes[i] = (byte)(FMath.Clamp(data[i], 0.0f, 1.0f) * 255.0f); } File.WriteAllBytes(filename, bytes); }
internal static AnimationInterpolator GetSquareWaveInterpolator(int strength) { strength = (int)FMath.Clamp((float)strength, 2f, 100f); return(AnimationUtility.GetAnimationInterpolator(delegate(float ratio) { float num = FMath.Repeat(ratio * (float)strength, 0f, 2f); if (num <= 1f) { return 0f; } return 1f; })); }
internal static AnimationInterpolator GetSawtoothWaveInterpolator(int strength) { strength = (int)FMath.Clamp((float)strength, 1f, 100f); return(AnimationUtility.GetAnimationInterpolator(delegate(float ratio) { float num = FMath.Repeat(ratio * (float)strength, 0f, 2f); if (1f < num) { return 2f - num; } return num; })); }
/// <summary> /// Convert to HSV color space. /// </summary> public ColorHSV ToHSV() { float delta, min; float h = 0, s, v; float R = FMath.Clamp(r * 255.0f, 0.0f, 255.0f); float G = FMath.Clamp(g * 255.0f, 0.0f, 255.0f); float B = FMath.Clamp(b * 255.0f, 0.0f, 255.0f); min = Math.Min(Math.Min(R, G), B); v = Math.Max(Math.Max(R, G), B); delta = v - min; if (v == 0.0) { s = 0; } else { s = delta / v; } if (s == 0) { h = 0.0f; } else { if (R == v) { h = (G - B) / delta; } else if (G == v) { h = 2 + (B - R) / delta; } else if (B == v) { h = 4 + (R - G) / delta; } h *= 60; if (h < 0.0) { h = h + 360; } } return(new ColorHSV(h / 360.0f, s, v / 255.0f)); }
public override void Update(float dt) { if (base.IsRunning) { float t = FMath.Clamp(this.m_elapsed / this.Duration, 0f, 1f); float alpha = this.Tween(t); this.lerp(alpha); if (this.m_elapsed / this.Duration > 1f) { this.Stop(); } this.m_elapsed += dt; } }
/// <summary> /// Saves float data to 16 bit.. /// </summary> public static void Save16Bit(string filename, float[] data) { int size = data.Length * 2; byte[] bytes = new byte[size]; ushort[] tmp = new ushort[data.Length]; for (int i = 0; i < data.Length; i++) { tmp[i] = (ushort)FMath.Clamp(data[i] * ushort.MaxValue, 0, ushort.MaxValue); } Buffer.BlockCopy(tmp, 0, bytes, 0, size); File.WriteAllBytes(filename, bytes); }
public static float BounceInterpolator(float from, float to, float ratio) { ratio = FMath.Clamp(ratio, 0f, 1f); if ((double)ratio < 0.36363636363636365) { return((to - from) * (7.5625f * ratio * ratio) + from); } if (ratio < 0.727272749f) { return((to - from) * (7.5625f * (ratio -= 0.545454562f) * ratio + 0.75f) + from); } if (ratio < 0.909090936f) { return((to - from) * (7.5625f * (ratio -= 0.8181818f) * ratio + 0.9375f) + from); } return((to - from) * (7.5625f * (ratio -= 0.954545438f) * ratio + 0.984375f) + from); }
public static float ElasticInterpolator(float from, float to, float ratio) { float num = 0.3f; float num2 = num / 4f; float num3 = to - from; ratio = FMath.Clamp(ratio, 0f, 1f); if (ratio == 0f) { return(from); } if (ratio == 1f) { return(to); } return((float)((double)num3 * Math.Pow(2.0, (double)(-10f * ratio)) * Math.Sin((double)(ratio - num2) * 6.2831853071795862 / (double)num) + (double)to)); }
void PlayPinStrikeSounds(AActor _other) { int _settledPins = gamemode.lastSettledCount; float _center = 50f; float _otherYLoc = _other.GetActorLocation().Y; float _offset = _otherYLoc >= 0 ? FMath.Abs(_otherYLoc - _center) : FMath.Abs(_otherYLoc + _center); float _highoffset = 350f; float _offsetAsPercentageDecimal = (_offset / _highoffset); float _highVelX = 2500f; float _lowVelX = 1000f; float _velX = FMath.Clamp(_other.GetVelocity().X, _lowVelX, _highVelX); float _velXAsPercentageDecimal = ((_velX - _lowVelX) / (_highVelX - _lowVelX)); //The Less Pins, The Higher The Percentage float _pinSettledPenaltyAsPercentage = 1 - (_settledPins / 10); float _VelXMinusOffsetYDecimal = _velXAsPercentageDecimal - (_offsetAsPercentageDecimal * offsetAsPercentageMultplier) - _pinSettledPenaltyAsPercentage; if (_offsetAsPercentageDecimal > 0.80f) { _VelXMinusOffsetYDecimal = FMath.Min(-0.5f, _VelXMinusOffsetYDecimal - 0.5f); } //MyOwner.PrintString($"Pin Strike. Vel: {_velX} VelAsPerc: {_velXAsPercentageDecimal} Off: {_offset} OffAsPerc: {_offsetAsPercentageDecimal} VelMinusOffset: {_VelXMinusOffsetYDecimal}", FLinearColor.Green, printToLog: true); Random _ran = new Random(); if (_VelXMinusOffsetYDecimal <= -0.5) { MyAudioSourceComponent.Sound = _ran.Next(0, 2) == 0 ? PinStrikeSoundVolume1 : PinStrikeSoundVolume2; } else if (_VelXMinusOffsetYDecimal <= 0.2) { MyAudioSourceComponent.Sound = _ran.Next(0, 2) == 0 ? PinStrikeSoundVolume3 : PinStrikeSoundVolume4; } else { MyAudioSourceComponent.Sound = PinStrikeSoundVolume5; } MyAudioSourceComponent.Play(); }
private void skeletonFittingCanvasZoom(float delta) { float prev = skeletonFittingCanvasScale; if (prev <= 1e-4) { return; } skeletonFittingCanvasScale += delta; skeletonFittingCanvasScale = FMath.Clamp(skeletonFittingCanvasScale, 0.1f, 15f); float ratio = skeletonFittingCanvasScale / prev; if (Math.Abs(1 - ratio) <= 1e-4) { return; } skeletonFittingCanvasTransform.Scale(ratio, ratio, MatrixOrder.Append); }
public Vec4f GetColor(float p) { if (colors.Count == 0) { return(Vec4f.Zero); } p = FMath.Clamp(p, 0.0f, 1.0f); float p2 = p * (float)(colors.Count - 1); int c = (int)p2; if (c >= colors.Count - 1) { return(colors[colors.Count - 1]); } p2 -= (float)c; Vec4f color1 = colors[c]; Vec4f color2 = colors[c + 1]; return(color1 * (1.0f - p2) + color2 * p2); }
public void Zoom(float delta) { float prev = scale; if (prev <= 1e-4) { return; } scale += delta; scale = FMath.Clamp(scale, 0.1f, 15f); float ratio = scale / prev; if (Math.Abs(1 - ratio) <= 1e-4) { return; } transform.Scale(ratio, ratio, MatrixOrder.Append); }