private float AnimationCurveCompletionPerc(float origPercentage) { switch (AnimationCurve) { case AnimationCurves.Linear: { return(Mathfx.Lerp(0, 1, origPercentage)); } case AnimationCurves.Elastic: { return(Mathfx.Berp(0, 1, origPercentage)); } case AnimationCurves.Bounce: { return(Mathfx.Bounce(origPercentage)); } case AnimationCurves.EaseInOut: default: { return(Mathfx.Hermite(0, 1, origPercentage)); } } }
/// <summary> /// Return value based on curve from Mathfx class. /// </summary> /// <returns>The value.</returns> /// <param name="animationCurve">Animation curve.</param> /// <param name="start">Start.</param> /// <param name="end">End.</param> /// <param name="t">T.</param> public static float CurvedValue(AnimationCurveEnum animationCurve, float start, float end, float t) { switch (animationCurve) { case AnimationCurveEnum.Hermite: return(Mathfx.Hermite(start, end, t)); case AnimationCurveEnum.Sinerp: return(Mathfx.Sinerp(start, end, t)); case AnimationCurveEnum.Coserp: return(Mathfx.Coserp(start, end, t)); case AnimationCurveEnum.Berp: return(Mathfx.Berp(start, end, t)); case AnimationCurveEnum.Bounce: return(start + ((end - start) * Mathfx.Bounce(t))); case AnimationCurveEnum.Lerp: return(Mathfx.Lerp(start, end, t)); case AnimationCurveEnum.Clerp: return(Mathfx.Clerp(start, end, t)); default: return(0); } }
private float DoLerp() { switch (this._currentLerpType) { case LerpType.Lerp: return(Mathfx.Lerp(this.From, this.To, this.LerpZeroToOne)); case LerpType.Hermite: return(Mathfx.Lerp(this.From, this.To, this.LerpZeroToOne)); case LerpType.Sinerp: return(Mathfx.Sinerp(this.From, this.To, this.LerpZeroToOne)); case LerpType.Coserp: return(Mathfx.Coserp(this.From, this.To, this.LerpZeroToOne)); case LerpType.Berp: return(Mathfx.Berp(this.From, this.To, this.LerpZeroToOne)); case LerpType.Smoothstep: return(Mathfx.SmoothStep(this.From, this.To, this.LerpZeroToOne)); case LerpType.Clerp: return(Mathfx.Clerp(this.From, this.To, this.LerpZeroToOne)); default: throw new ArgumentOutOfRangeException(); } }
public double FromSurfaceTTA(double ApA, double alpha, double gturn_curve, double surface_vel) { var t = 0.0; var v = new Vector3d(0, surface_vel); var h = (double)VSL.Altitude.Absolute; var m = (double)VSL.Physics.M; var eStats = VSL.Engines.NoActiveEngines? VSL.Engines.GetNearestEnginedStageStats() : VSL.Engines.GetEnginesStats(VSL.Engines.Active); var mT = eStats.MaxThrust; var mflow = eStats.MaxMassFlow; var mTm = mT.magnitude * Mathfx.Lerp(0.6, 0.95, Utils.ClampH( VSL.Torque.AngularAcceleration(eStats.TorqueInfo.Torque + VSL.Torque.RCSLimits.Max + VSL.Torque.WheelsLimits.Max).magnitude, 1)); var s = VSL.Geometry.AreaInDirection(mT); var R = Body.Radius; var thrust = true; var throttle = 1.0; // var alpha0 = alpha; //debug while (v.x >= 0) { var atmF = Utils.Clamp(h / Body.atmosphereDepth, 0, 1); if (thrust) { double apaT; var apa = freeclimb_altitude(m, s, h, v.x, v.y, DeltaTime * 4, out apaT); var dapa = (ApA - apa) * gturn_curve; var arc = (alpha - v.y * apaT / (R + (h + apa) / 2)) * (R + apa); var vv = Utils.ClampL(dapa, 0); var hv = Utils.ClampL(arc - dapa, 0) * Utils.Clamp((h - VSL.Altitude.Absolute) / GLB.ORB.GTurnOffset, 0, 1); if (h < Body.atmosphereDepth) { hv *= Math.Sqrt(atmF); } var angle = Math.Atan2(vv, hv); throttle = ThrottleControl.NextThrottle((float)(Math.Sqrt(vv * vv + hv * hv) * Globals.Instance.ORB.Dist2VelF * VSL.Physics.StG / Utils.G0), (float)throttle, (float)m, (float)mTm, 0); var v_throttle = Math.Sin(angle); v.x += (mTm * v_throttle * throttle / m - G(h, v.y)) * DeltaTime; var h_throttle = 0.0; if (arc > 0) { h_throttle = Math.Cos(angle); v.y += (mTm * h_throttle * throttle / m) * DeltaTime; } thrust = ApA - apa > GLB.ORB.Dtol && arc > GLB.ORB.Dtol; if (!CheatOptions.InfinitePropellant) { var dm = mflow * (h_throttle + v_throttle) * throttle * DeltaTime; if (m < dm) { thrust = false; continue; } m -= dm; } // Utils.Log("apaT {}, dapa {}, arc {}, throttle {}, h-thr {}, v-thr {}", apaT, dapa, arc, throttle);//debug } else { v.x -= G(h, v.y) * DeltaTime; } if (h < Body.atmosphereDepth) { var y = v.y - surface_vel * (1 - atmF); var vm = Math.Sqrt(v.x * v.x + y * y); var D = drag(s, h, vm) / m * DeltaTime / vm; v.x -= v.x * D; v.y -= y * D; } alpha -= v.y * DeltaTime / Body.Radius; h += v.x * DeltaTime; t += DeltaTime; // Utils.Log("v.v {}, v.h {}, drag {}, h {}, hmove {}", v.x, v.y, drag(s, h, vm)/m, h, hmove);//debug // DebugUtils.CSV("LambertSolver", t, v.x, v.y, (alpha0-alpha)*(R+h), h, m, mTm*throttle, throttle, Math.Atan2(v.x, v.y)*Mathf.Rad2Deg);//debug } return(t - DeltaTime / 2); }