2022-08-05 21:58:10 +02:00
|
|
|
|
using System;
|
2022-08-04 18:13:18 +02:00
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
|
|
namespace UniformAim
|
|
|
|
|
{
|
|
|
|
|
public class Core
|
|
|
|
|
{
|
|
|
|
|
//math stuff
|
|
|
|
|
public static float CalculateHFOV(float FOV)
|
|
|
|
|
{
|
2022-08-05 21:58:10 +02:00
|
|
|
|
//RETURNS RADIANS
|
2022-08-16 13:31:25 +02:00
|
|
|
|
return Camera.VerticalToHorizontalFieldOfView(FOV, Camera.main.aspect);
|
2022-08-04 18:13:18 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//calculate sensitivity based on FOV delta and coefficient
|
|
|
|
|
public static float CalculateSensitivity(float aimedFOV, float hipFOV)
|
|
|
|
|
{
|
|
|
|
|
//calculate horizontal FOV values for inputs
|
2022-08-16 13:31:25 +02:00
|
|
|
|
aimedFOV = CalculateHFOV(aimedFOV) * Mathf.Deg2Rad;
|
|
|
|
|
hipFOV = CalculateHFOV(hipFOV) * Mathf.Deg2Rad;
|
2022-08-04 18:13:18 +02:00
|
|
|
|
|
|
|
|
|
float exponent = (float)(100f / Plugin.configCoeff.Value);
|
|
|
|
|
|
|
|
|
|
float tanRatio = (float)(Math.Tan(aimedFOV / 2) / (Math.Tan(hipFOV / 2)));
|
|
|
|
|
|
|
|
|
|
float sensitivity = Plugin.configSens.Value / 100f;
|
|
|
|
|
|
|
|
|
|
float result = (float)Math.Pow(tanRatio, exponent) * sensitivity;
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//check if BaseOpticCamera is present and active
|
|
|
|
|
public static bool isScopeCameraActive()
|
|
|
|
|
{
|
|
|
|
|
if(Camera.allCamerasCount > 1) { return Camera.allCameras[1].GetComponent<Behaviour>().isActiveAndEnabled; }
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
//figure out current fov based on scope and in-game camera statuses
|
|
|
|
|
public static float DetermineCurrentFOV()
|
|
|
|
|
{
|
|
|
|
|
//dirty fix for the Ultima MP-155 shotgun
|
|
|
|
|
if (Plugin.currentFPSCameraFOV> 35 && isScopeCameraActive() && Plugin.currentScopeCameraFOV == 15) { return Plugin.currentFPSCameraFOV; }
|
|
|
|
|
|
|
|
|
|
if (Plugin.SelectedScope == 0 && isScopeCameraActive()) { return Plugin.currentScopeCameraFOV; } else { return Plugin.currentFPSCameraFOV; }
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|