Skip to content

Commit

Permalink
Added zoom fov and related commands from Ironwail
Browse files Browse the repository at this point in the history
Per user request (Konkonfaux)
  • Loading branch information
j0zzz committed Dec 18, 2024
1 parent 6e39e76 commit a96c591
Show file tree
Hide file tree
Showing 9 changed files with 110 additions and 14 deletions.
2 changes: 2 additions & 0 deletions trunk/cl_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -772,6 +772,8 @@ void CL_RelinkEntities (void)
for (i = 0 ; i < 3 ; i++)
cl.velocity[i] = cl.mvelocity[1][i] + frac * (cl.mvelocity[0][i] - cl.mvelocity[1][i]);

SCR_UpdateZoom ();

if (cls.demoplayback)
{
// interpolate the angles
Expand Down
3 changes: 3 additions & 0 deletions trunk/client.h
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,9 @@ typedef struct
double freefly_last_time;
vec3_t freefly_origin;
vec3_t freefly_angles;

float zoom;
float zoomdir;
} client_state_t;

extern client_state_t cl;
Expand Down
2 changes: 2 additions & 0 deletions trunk/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ typedef enum {false, true} qboolean;

#define bound(a, b, c) ((a) >= (c) ? (a) : (b) < (a) ? (a) : (b) > (c) ? (c) : (b))

#define LERP(a, b, t) ((a) + ((b)-(a))*(t))

#define countof(x) (sizeof(x) / sizeof((x)[0]))

//============================================================================
Expand Down
4 changes: 2 additions & 2 deletions trunk/gl_rmain.c
Original file line number Diff line number Diff line change
Expand Up @@ -1903,9 +1903,9 @@ void R_DrawAliasModel (entity_t *ent)
float fovscale = 1.0f;
int hand_offset = cl_hand.value == 1 ? -3 : cl_hand.value == 2 ? 3 : 0;

if (scr_fov.value > 90.f && cl_gun_fovscale.value)
if (r_refdef.basefov > 90.f && cl_gun_fovscale.value)
{
fovscale = tan(scr_fov.value * (0.5f * M_PI / 180.f));
fovscale = tan(r_refdef.basefov * (0.5f * M_PI / 180.f));
fovscale = 1.f + (fovscale - 1.f) * cl_gun_fovscale.value;
}

Expand Down
78 changes: 75 additions & 3 deletions trunk/gl_screen.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ float scr_conlines; // lines of console to display
float oldscreensize, oldfov, oldsbar, oldwidescreenfov, oldsbarscale;
cvar_t scr_viewsize = {"viewsize", "100", CVAR_ARCHIVE};
cvar_t scr_fov = {"fov", "100"}; // 10 - 170
cvar_t scr_zoomfov = {"zoom_fov", "30"}; // 10 - 170
cvar_t scr_zoomspeed = {"zoom_speed", "8"};
cvar_t scr_consize = {"scr_consize", "0.5"};
cvar_t scr_conspeed = {"scr_conspeed", "1000"};
cvar_t scr_centertime = {"scr_centertime", "2"};
Expand Down Expand Up @@ -271,6 +273,64 @@ float InvCalcFov (float fov_y, float width, float height)
return fov_x;
}

/*
====================
SCR_ToggleZoom_f
====================
*/
static void SCR_ToggleZoom_f (void)
{
if (cl.zoomdir)
cl.zoomdir = -cl.zoomdir;
else
cl.zoomdir = cl.zoom > 0.5f ? -1.f : 1.f;
}

/*
====================
SCR_ZoomDown_f
====================
*/
static void SCR_ZoomDown_f (void)
{
cl.zoomdir = 1.f;
}

/*
====================
SCR_ZoomUp_f
====================
*/
static void SCR_ZoomUp_f (void)
{
cl.zoomdir = -1.f;
}

/*
====================
SCR_UpdateZoom
====================
*/
void SCR_UpdateZoom (void)
{
float delta = cl.zoomdir * scr_zoomspeed.value * (cl.time - cl.oldtime);
if (!delta)
return;

cl.zoom += delta;
if (cl.zoom >= 1.f)
{
cl.zoom = 1.f;
cl.zoomdir = 0.f;
}
else if (cl.zoom <= 0.f)
{
cl.zoom = 0.f;
cl.zoomdir = 0.f;
}
vid.recalc_refdef = 1;
}

/*
=================
SCR_CalcRefdef
Expand All @@ -281,8 +341,8 @@ Internal use only
*/
static void SCR_CalcRefdef (void)
{
int h, scaled_sb_lines;
float size;
int h, scaled_sb_lines;
float size, zoom;
qboolean full = false;

scr_fullupdate = 0; // force a background redraw
Expand All @@ -304,6 +364,10 @@ static void SCR_CalcRefdef (void)
Cvar_SetValue (&scr_fov, 10);
if (scr_fov.value > 170)
Cvar_SetValue (&scr_fov, 170);
if (scr_zoomfov.value < 10)
Cvar_SetValue (&scr_zoomfov, 10);
if (scr_zoomfov.value > 170)
Cvar_SetValue (&scr_zoomfov, 170);

// intermission is always full screen
size = cl.intermission ? 120 : scr_viewsize.value;
Expand Down Expand Up @@ -363,7 +427,10 @@ static void SCR_CalcRefdef (void)
else
r_refdef.vrect.y = (h - r_refdef.vrect.height) / 2;

r_refdef.fov_x = scr_fov.value;
zoom = cl.zoom;
zoom *= zoom * (3.f - 2.f * zoom); // smoothstep
r_refdef.basefov = LERP(scr_fov.value, scr_zoomfov.value, zoom);
r_refdef.fov_x = r_refdef.basefov;
if (scr_widescreen_fov.value)
{
float aspectRatio = (float)r_refdef.vrect.width / (float)r_refdef.vrect.height;
Expand Down Expand Up @@ -435,6 +502,8 @@ SCR_Init
void SCR_Init (void)
{
Cvar_Register (&scr_fov);
Cvar_Register (&scr_zoomfov);
Cvar_Register (&scr_zoomspeed);
Cvar_Register (&scr_viewsize);
Cvar_Register (&scr_consize);
Cvar_Register (&scr_conspeed);
Expand All @@ -459,6 +528,9 @@ void SCR_Init (void)
Cmd_AddCommand ("screenshot", SCR_ScreenShot_f);
Cmd_AddCommand ("sizeup", SCR_SizeUp_f);
Cmd_AddCommand ("sizedown", SCR_SizeDown_f);
Cmd_AddCommand ("togglezoom", SCR_ToggleZoom_f);
Cmd_AddCommand ("+zoom", SCR_ZoomDown_f);
Cmd_AddCommand ("-zoom", SCR_ZoomUp_f);

SCR_LoadPics();
SCR_LoadCursorImage();
Expand Down
16 changes: 12 additions & 4 deletions trunk/in_sdl.c
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,8 @@ void IN_Commands (void)

static void IN_MouseMove (usercmd_t *cmd)
{
float sens;

if (m_filter.value)
{
mouse_x = (mx + old_mouse_x) * 0.5;
Expand All @@ -283,8 +285,11 @@ static void IN_MouseMove (usercmd_t *cmd)
}
else
{
mouse_x *= ((mousespeed * m_accel_factor) + sensitivity.value);
mouse_y *= ((mousespeed * m_accel_factor) + sensitivity.value);
sens = tan(DEG2RAD(r_refdef.basefov) * 0.5f) / tan(DEG2RAD(scr_fov.value) * 0.5f);
sens *= ((mousespeed * m_accel_factor) + sensitivity.value);

mouse_x *= sens;
mouse_y *= sens;
}
}
else
Expand All @@ -296,8 +301,11 @@ static void IN_MouseMove (usercmd_t *cmd)
}
else
{
mouse_x *= sensitivity.value;
mouse_y *= sensitivity.value;
sens = tan(DEG2RAD(r_refdef.basefov) * 0.5f) / tan(DEG2RAD(scr_fov.value) * 0.5f);
sens *= sensitivity.value;

mouse_x *= sens;
mouse_y *= sens;
}
}

Expand Down
17 changes: 12 additions & 5 deletions trunk/in_win.c
Original file line number Diff line number Diff line change
Expand Up @@ -999,7 +999,8 @@ IN_MouseMove
*/
void IN_MouseMove (usercmd_t *cmd)
{
int mx, my, i;
int mx, my, i;
float sens;
DIDEVICEOBJECTDATA od;
DWORD dwElements;
HRESULT hr;
Expand Down Expand Up @@ -1118,8 +1119,11 @@ void IN_MouseMove (usercmd_t *cmd)
}
else
{
mouse_x *= ((mousespeed * m_accel_factor) + sensitivity.value);
mouse_y *= ((mousespeed * m_accel_factor) + sensitivity.value);
sens = tan(DEG2RAD(r_refdef.basefov) * 0.5f) / tan(DEG2RAD(scr_fov.value) * 0.5f);
sens *= ((mousespeed * m_accel_factor) + sensitivity.value);

mouse_x *= sens;
mouse_y *= sens;
}
}
else
Expand All @@ -1131,8 +1135,11 @@ void IN_MouseMove (usercmd_t *cmd)
}
else
{
mouse_x *= sensitivity.value;
mouse_y *= sensitivity.value;
sens = tan(DEG2RAD(r_refdef.basefov) * 0.5f) / tan(DEG2RAD(scr_fov.value) * 0.5f);
sens *= sensitivity.value;

mouse_x *= sens;
mouse_y *= sens;
}
}

Expand Down
1 change: 1 addition & 0 deletions trunk/render.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ typedef struct
vec3_t vieworg;
vec3_t viewangles;

float basefov;
float fov_x, fov_y;

int ambientlight;
Expand Down
1 change: 1 addition & 0 deletions trunk/screen.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ void SCR_UpdateScreen (void);

void SCR_SizeUp (void);
void SCR_SizeDown (void);
void SCR_UpdateZoom (void);
void SCR_CenterPrint (char *str);

void ApplyGamma (byte *buffer, int size);
Expand Down

0 comments on commit a96c591

Please sign in to comment.