Automatically adjust the FOV depending on the aspect ratio

This commit is contained in:
smallmodel 2025-01-02 15:52:45 +01:00
parent df22895b94
commit 465d462756
No known key found for this signature in database
GPG key ID: A96F163ED4891440

View file

@ -485,9 +485,16 @@ static int CG_CalcFov(void)
int contents;
float fov_x, fov_y;
int inwater;
float fov_ratio;
fov_x = cg.camera_fov;
x = cg.refdef.width / tan(fov_x / 360 * M_PI);
fov_ratio = (float)cg.refdef.width / (float)cg.refdef.height * (3.0 / 4.0);
if (fov_ratio == 1) {
fov_x = cg.camera_fov;
} else {
fov_x = RAD2DEG(atan(tan(DEG2RAD(cg.camera_fov / 2.0)) * fov_ratio)) * 2.0;
}
x = cg.refdef.width / tan(fov_x / 360 * M_PI);
fov_y = atan2(cg.refdef.height, x);
fov_y = fov_y * 360 / M_PI;