#pragma warning restore CS1591 // Missing XML comment for publicly visible type or member #pragma warning disable CS1591 // Missing XML comment for publicly visible type or member public InterpolationSettings(Mode mode, Style style, Clamping clamping) #pragma warning restore CS1591 // Missing XML comment for publicly visible type or member { this.mode = mode; this.style = style; this.clamping = clamping; }
private static void ClampingTest() { Console.WriteLine($"Clamping Functions"); Console.WriteLine(); Console.WriteLine($" x default limits SmoothStep3 SmoothStep5 SmoothStep7 SmterStep"); Console.WriteLine($"==================================================================================="); //clamping for (double x = -5.0; x < 5.0; x += 0.1) { double clampDefault = Clamping.Clamp(x); double clampLimited = Clamping.Clamp(x, -2.0, 1.5); double smoothStep = Clamping.SmoothStep(x); //same as SmoothStep3 double smoothStep3 = Clamping.SmoothStep3(x, -2.0, 2.0); double smoothStep5 = Clamping.SmoothStep5(x, -2.0, 2.0); double smoothStep7 = Clamping.SmoothStep7(x, -2.0, 2.0); double smootherStep = Clamping.SmootherStep(x, -2.0, 2.0); Console.WriteLine($"{x,5:N1} {clampDefault,9:N1} {clampLimited,9:N1} {smoothStep3,14:N3} {smoothStep5,14:N3} {smoothStep7,14:N3} {smootherStep,12:N3}"); } Console.WriteLine($"==================================================================================="); Console.CursorVisible = true; for (double x = -0.5; x <= 1.5; x += 0.1) { double clampDefault = Clamping.Clamp(x); double clampLimited = Clamping.Clamp(x, -2.0, 1.5); double smoothStep = Clamping.SmoothStep(x); //same as SmoothStep3 double smoothStep3 = Clamping.SmoothStep3(x); double smoothStep5 = Clamping.SmoothStep5(x); double smoothStep7 = Clamping.SmoothStep7(x); double smootherStep = Clamping.SmootherStep(x); Console.WriteLine(); Console.WriteLine($"Clamping.Clamp({x:N1}) = {clampDefault:N3}"); Console.WriteLine($"Clamping.Clamp({x:N1}, -2.0, 1.5) = {clampLimited:N3}"); Console.WriteLine($"Clamping.SmoothStep({x:N1}) = {smoothStep:N3}"); Console.WriteLine($"Clamping.SmoothStep3({x:N1}) = {smoothStep3:N3}"); Console.WriteLine($"Clamping.SmoothStep5({x:N1}) = {smoothStep5:N3}"); Console.WriteLine($"Clamping.SmoothStep7({x:N1}) = {smoothStep7:N3}"); Console.WriteLine($"Clamping.SmootherStep({x:N1}) = {smootherStep:N3}"); } }
protected void CopyFrom(Color color, Clamping clamping) { _calcLock++; _hue = clamping != Clamping.None ? color._hue.NormalizeLoopingValue(360) : color._hue; _saturation = ClampValue(color._saturation, clamping); _lightness = ClampValue(color._lightness, clamping); _red = ClampValue(color._red, clamping); _green = ClampValue(color._green, clamping); _blue = ClampValue(color._blue, clamping); _hueHsv = clamping != Clamping.None ? color._hueHsv.NormalizeLoopingValue(360) : color._hueHsv; _saturationHsv = ClampValue(color._saturationHsv, clamping); _value = ClampValue(color._value, clamping); _rgbValid = color._rgbValid; _hslValid = color._hslValid; _hsvValid = color._hsvValid; _alpha = color._alpha; _calcLock--; }
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member public static Single Interpolate(Single from, Single to, Single t, Mode mode = Mode.Standard, Style style = Style.Linear, Clamping clamp = Clamping.Unclamped) #pragma warning restore CS1591 // Missing XML comment for publicly visible type or member { switch (mode) { case Mode.Standard: break; case Mode.Squares: from *= from; to *= to; break; case Mode.SquareRoots: from = Mathf.Sqrt(from); to = Mathf.Sqrt(to); break; default: throw new ArgumentOutOfRangeException(nameof(mode)); } Single output; switch (style) { case Style.Nearest: output = t < 0.5f ? from : to; break; case Style.Linear: output = from + ((to - from) * t); break; case Style.Polynomial: throw new NotImplementedException(); case Style.Spline: throw new NotImplementedException(); case Style.Cubic: throw new NotImplementedException(); case Style.Spherical: throw new NotImplementedException(); default: throw new ArgumentOutOfRangeException(nameof(style)); } switch (mode) { case Mode.Standard: break; case Mode.Squares: output = Mathf.Sqrt(output); break; case Mode.SquareRoots: output *= output; break; default: throw new ArgumentOutOfRangeException(nameof(mode)); } switch (clamp) { case Clamping.Unclamped: break; case Clamping.Clamped: output = Mathf.Clamp(output, Mathf.Min(from, to), Mathf.Max(from, to)); break; default: throw new ArgumentOutOfRangeException(nameof(clamp)); } return(output); }
#pragma warning restore CS1591 // Missing XML comment for publicly visible type or member #pragma warning disable CS1591 // Missing XML comment for publicly visible type or member public static Color Interpolate(Color from, Color to, Single t, Mode mode = Mode.Standard, Style style = Style.Linear, Clamping clamp = Clamping.Unclamped) #pragma warning restore CS1591 // Missing XML comment for publicly visible type or member { Single r = Interpolate(from.r, to.r, t, mode, style, clamp); Single g = Interpolate(from.g, to.g, t, mode, style, clamp); Single b = Interpolate(from.b, to.b, t, mode, style, clamp); Single a = Interpolate(from.a, to.a, t, mode, style, clamp); return(new Color(r, g, b, a)); }
static bool Prefix(cCameraControl __instance, KeyDef ____zoomIn, KeyDef ____zoomOut, MViewAndControl ____options, MouseLook ____mouseLookY) { /*if (lastTime != Time.timeScale) * { * lastTime = Time.timeScale; * AdvLogger.LogInfo("Time.timeScale changed to " + lastTime); * }*/ Transform cam = __instance.Cam; FocusCameraSettings fcs = __instance._externalCameraFocusSettings; if (fcs?.PositionOfFocus == null || !fcs.PositionOfFocus.Valid || __instance.CameraState != enumCameraState.detached && __instance.CameraState != enumCameraState.unparented) { __instance.CancelExternalCameraFocus(); } else if (____mouseLookY.axes == enumRotationAxes.MouseXAndY) { // Check if user is doing top-down strategic map and don't rotate if so. Vector3 myPos = fcs.PositionOfFocus.Position; bool topdown = FleetControlGUI.Instance.MenuActive && ____options.TopDownViewLocked; if (!topdown) { // TODO: Integrate Ace Combat style camera into new camera mode. /*MainConstruct target = Main.subject != null ? getTarget(Main.subject) : null; * if (target != null && !target.Destroyed) * { * Vector3 up = Main.subject.SafeUp; * myPos += up * Main.subject.AllBasics.GetActualHeight(); * Vector3 diff = target.SafePosition - myPos; * Quaternion look = Quaternion.LookRotation(diff, up); * // Vector3 ea = look.eulerAngles; * ____mouseLookY.transform.localEulerAngles = look.eulerAngles; // new Vector3(ea.x, ea.y, 0f); * ____mouseLookY.rotationX = ____mouseLookY.transform.localEulerAngles.y; * ____mouseLookY.rotationY = 0f; * } * else * {*/ // Record rotational change if any. // Unity euler angles are Z, X, Y. float xChange = 0f; if (Main.rotation != null && Main.rotation.Valid) { Quaternion rot = Main.rotation.Rotation; xChange = rot.eulerAngles.y - Main.lastRotation.eulerAngles.y; Main.lastRotation = rot; } else { Main.rotation = null; } // TODO: Smoothing speed setting. xRotVel = Mathf.Lerp(xRotVel, MouseLook_Update_Patch.xIntent, 0.02f); yRotVel = Mathf.Lerp(yRotVel, MouseLook_Update_Patch.yIntent, 0.02f); ____mouseLookY.rotationX = ____mouseLookY.transform.localEulerAngles.y + xChange + xRotVel; ____mouseLookY.rotationY += yRotVel; // The numbers -89 and 89 are hard-coded/unmodified values from vanilla. ____mouseLookY.rotationY = Mathf.Clamp(____mouseLookY.rotationY, -89f, 89f); ____mouseLookY.transform.localEulerAngles = new Vector3(-____mouseLookY.rotationY, ____mouseLookY.rotationX, 0f); //} // Since DoingStrategicFocus inhibits zoom in/out, switch to another method. fcs.DistanceMethod = fcs.DistanceMethod == DistanceChangeMethod.DoingStrategicFocus ? DistanceChangeMethod.MaintainCurrentFocusDistance : fcs.DistanceMethod; } else // Disallow focus camera zoom when in strategic view. { fcs.DistanceMethod = DistanceChangeMethod.DoingStrategicFocus; } // Done with mouse input for this frame, so remove it. MouseLook_Update_Patch.xIntent = MouseLook_Update_Patch.yIntent = 0f; // Copied from vanilla function. Vector3 focus = myPos; Vector3 forward = cam.forward; Vector3 b = focus - forward * fcs.Distance; // Don't move the camera's altitude if strategic view is already setting it. if (topdown) { b.y = cam.position.y; } else { // TODO: Clamp altitude of b based on terrain. } __instance.Cam.position = b; // Removed lerp. // Again copied from vanilla function. float axis = Input.GetAxis("Mouse ScrollWheel"); if (____zoomIn.IsKey(KeyInputEventType.Held, ModifierAllows.AllowShift) || axis > 0f) { // TODO: Possibly check keybinding instead? int num = OptionsListener.ShiftHeld ? 4 : 1; ____options.FocusCameraDistance -= 0.1f * (float)num; ____options.FocusCameraDistance *= 1f - 0.02f * (float)num; ____options.FocusCameraDistance = Clamping.Clamp(____options.FocusCameraDistance, 1f, 1000f); } else if (____zoomOut.IsKey(KeyInputEventType.Held, ModifierAllows.AllowShift) || axis < 0f) { int num = OptionsListener.ShiftHeld ? 4 : 1; ____options.FocusCameraDistance += 0.1f * (float)num; ____options.FocusCameraDistance *= 1f + 0.02f * (float)num; ____options.FocusCameraDistance = Clamping.Clamp(____options.FocusCameraDistance, 1f, 1000f); } } return(false); }