From 48176233bdc264cd4e5bce1f8df83f2f4bc59f7c Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Wed, 26 Apr 2023 05:22:34 +0300 Subject: [PATCH] public: move FOV calculating functions out of libpublic, as they are very specific to engine view --- engine/client/cl_view.c | 47 +++++++++++++++++++++++++++++++++++++++++ public/xash3d_mathlib.c | 47 ----------------------------------------- public/xash3d_mathlib.h | 3 --- 3 files changed, 47 insertions(+), 50 deletions(-) diff --git a/engine/client/cl_view.c b/engine/client/cl_view.c index cac27075..fca79f63 100644 --- a/engine/client/cl_view.c +++ b/engine/client/cl_view.c @@ -229,6 +229,53 @@ void V_RefApplyOverview( ref_viewpass_t *rvp ) ref.dllFuncs.GL_OrthoBounds( mins, maxs ); } +/* +==================== +V_CalcFov +==================== +*/ +static float V_CalcFov( float *fov_x, float width, float height ) +{ + float x, half_fov_y; + + if( *fov_x < 1.0f || *fov_x > 179.0f ) + *fov_x = 90.0f; // default value + + x = width / tan( DEG2RAD( *fov_x ) * 0.5f ); + half_fov_y = atan( height / x ); + + return RAD2DEG( half_fov_y ) * 2; +} + +/* +==================== +V_AdjustFov +==================== +*/ +static void V_AdjustFov( float *fov_x, float *fov_y, float width, float height, qboolean lock_x ) +{ + float x, y; + + if( width * 3 == 4 * height || width * 4 == height * 5 ) + { + // 4:3 or 5:4 ratio + return; + } + + if( lock_x ) + { + *fov_y = 2 * atan((width * 3) / (height * 4) * tan( *fov_y * M_PI_F / 360.0f * 0.5f )) * 360 / M_PI_F; + return; + } + + y = V_CalcFov( fov_x, 640, 480 ); + x = *fov_x; + + *fov_x = V_CalcFov( &y, height, width ); + if( *fov_x < x ) *fov_x = x; + else *fov_y = y; +} + /* ============= V_GetRefParams diff --git a/public/xash3d_mathlib.c b/public/xash3d_mathlib.c index a588ca08..fb066c22 100644 --- a/public/xash3d_mathlib.c +++ b/public/xash3d_mathlib.c @@ -703,53 +703,6 @@ void QuaternionSlerp( const vec4_t p, const vec4_t q, float t, vec4_t qt ) QuaternionSlerpNoAlign( p, q2, t, qt ); } -/* -==================== -V_CalcFov -==================== -*/ -float V_CalcFov( float *fov_x, float width, float height ) -{ - float x, half_fov_y; - - if( *fov_x < 1.0f || *fov_x > 179.0f ) - *fov_x = 90.0f; // default value - - x = width / tan( DEG2RAD( *fov_x ) * 0.5f ); - half_fov_y = atan( height / x ); - - return RAD2DEG( half_fov_y ) * 2; -} - -/* -==================== -V_AdjustFov -==================== -*/ -void V_AdjustFov( float *fov_x, float *fov_y, float width, float height, qboolean lock_x ) -{ - float x, y; - - if( width * 3 == 4 * height || width * 4 == height * 5 ) - { - // 4:3 or 5:4 ratio - return; - } - - if( lock_x ) - { - *fov_y = 2 * atan((width * 3) / (height * 4) * tan( *fov_y * M_PI_F / 360.0f * 0.5f )) * 360 / M_PI_F; - return; - } - - y = V_CalcFov( fov_x, 640, 480 ); - x = *fov_x; - - *fov_x = V_CalcFov( &y, height, width ); - if( *fov_x < x ) *fov_x = x; - else *fov_y = y; -} - /* ================== BoxOnPlaneSide diff --git a/public/xash3d_mathlib.h b/public/xash3d_mathlib.h index 70fb0129..fa7e354a 100644 --- a/public/xash3d_mathlib.h +++ b/public/xash3d_mathlib.h @@ -236,9 +236,6 @@ void Matrix4x4_ConvertToEntity( const matrix4x4 in, vec3_t angles, vec3_t origin void Matrix4x4_Invert_Simple( matrix4x4 out, const matrix4x4 in1 ); qboolean Matrix4x4_Invert_Full( matrix4x4 out, const matrix4x4 in1 ); -float V_CalcFov( float *fov_x, float width, float height ); -void V_AdjustFov( float *fov_x, float *fov_y, float width, float height, qboolean lock_x ); - void R_StudioSlerpBones( int numbones, vec4_t q1[], float pos1[][3], const vec4_t q2[], const float pos2[][3], float s ); void R_StudioCalcBoneQuaternion( int frame, float s, const mstudiobone_t *pbone, const mstudioanim_t *panim, const float *adj, vec4_t q ); void R_StudioCalcBonePosition( int frame, float s, const mstudiobone_t *pbone, const mstudioanim_t *panim, const vec3_t adj, vec3_t pos );