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}"); } }
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); }