From cb64ea30f925642b8ae66790b820d0ad83b3d141 Mon Sep 17 00:00:00 2001 From: Spoike Date: Tue, 8 Mar 2022 05:32:03 +0000 Subject: [PATCH] Move playerview weaponmodel matrix into r_refdef instead, to fix viewmodel positions in q3. git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@6211 fc73d0e0-1445-4013-8a0c-d673dee63da5 --- engine/client/cl_plugin.inc | 11 ++++++++ engine/client/cl_ui.c | 2 +- engine/client/client.h | 2 -- engine/client/clq2_ents.c | 7 +++--- engine/client/render.h | 5 +++- engine/client/view.c | 43 ++++++++++++++++--------------- engine/gl/gl_alias.c | 38 ++++++++++++++++++++-------- engine/gl/gl_rmain.c | 50 ++++++++++++++++++------------------- engine/server/svq3_game.c | 1 + engine/vk/vk_backend.c | 48 +++++++++++++++++------------------ 10 files changed, 120 insertions(+), 87 deletions(-) diff --git a/engine/client/cl_plugin.inc b/engine/client/cl_plugin.inc index d9a63643e..d0a7c3108 100644 --- a/engine/client/cl_plugin.inc +++ b/engine/client/cl_plugin.inc @@ -449,6 +449,17 @@ static void Plug_Scene_RenderScene(plugrefdef_t *in, size_t areabytes, const qby VectorCopy(in->viewaxisorg[1], r_refdef.viewaxis[1]); VectorCopy(in->viewaxisorg[2], r_refdef.viewaxis[2]); VectorCopy(in->viewaxisorg[3], r_refdef.vieworg); + + VectorSet(r_refdef.weaponmatrix[0], 1,0,0); + VectorSet(r_refdef.weaponmatrix[1], 0,1,0); + VectorSet(r_refdef.weaponmatrix[2], 0,0,1); + VectorSet(r_refdef.weaponmatrix[3], 0,0,0); + + VectorSet(r_refdef.weaponmatrix_bob[0], 1,0,0); + VectorSet(r_refdef.weaponmatrix_bob[1], 0,1,0); + VectorSet(r_refdef.weaponmatrix_bob[2], 0,0,1); + VectorSet(r_refdef.weaponmatrix_bob[3], 0,0,0); + VectorAngles(r_refdef.viewaxis[0], r_refdef.viewaxis[2], r_refdef.viewangles, false); //do we actually still need this? r_refdef.flags = in->flags; r_refdef.fov_x = in->fov[0]; diff --git a/engine/client/cl_ui.c b/engine/client/cl_ui.c index 0133446e1..d0748e6d5 100644 --- a/engine/client/cl_ui.c +++ b/engine/client/cl_ui.c @@ -604,7 +604,7 @@ void VQ3_RenderView(const q3refdef_t *ref) VectorCopy(ref->vieworg, scene.viewaxisorg[3]); scene.time = ref->time/1000.0f; - if (ref->rdflags & 1/*RDF_NOWORLDMODEL*/) + if (ref->rdflags & 1/*Q3RDF_NOWORLDMODEL*/) scene.flags |= RDF_NOWORLDMODEL; scenefuncs->RenderScene(&scene, sizeof(ref->areamask), ref->areamask); diff --git a/engine/client/client.h b/engine/client/client.h index 574757eb2..648e9183b 100644 --- a/engine/client/client.h +++ b/engine/client/client.h @@ -758,8 +758,6 @@ struct playerview_s vec4_t screentint; vec4_t bordertint; //won't contain v_cshift values, only powerup+contents+damage+bf flashes - vec3_t vw_axis[3]; //weapons should be positioned relative to this - vec3_t vw_origin; //weapons should be positioned relative to this // entity_t viewent; // is this not utterly redundant yet? struct { diff --git a/engine/client/clq2_ents.c b/engine/client/clq2_ents.c index b77281600..762263a8c 100644 --- a/engine/client/clq2_ents.c +++ b/engine/client/clq2_ents.c @@ -2395,9 +2395,10 @@ static void CLQ2_AddViewWeapon (int seat, q2player_state_t *ps, q2player_state_t return; //generate root matrix.. - VectorCopy(pv->simorg, pv->vw_origin); - AngleVectors(pv->simangles, pv->vw_axis[0], pv->vw_axis[1], pv->vw_axis[2]); - VectorInverse(pv->vw_axis[1]); + VectorCopy(pv->simorg, r_refdef.weaponmatrix[3]); + AngleVectors(pv->simangles, r_refdef.weaponmatrix[0], r_refdef.weaponmatrix[1], r_refdef.weaponmatrix[2]); + VectorInverse(r_refdef.weaponmatrix[1]); + memcpy(r_refdef.weaponmatrix_bob, r_refdef.weaponmatrix, sizeof(r_refdef.weaponmatrix_bob)); pv->vm.oldmodel = cl.model_precache[ps->gunindex]; if (!pv->vm.oldmodel) diff --git a/engine/client/render.h b/engine/client/render.h index 7d8a94e82..cffe4943d 100644 --- a/engine/client/render.h +++ b/engine/client/render.h @@ -35,7 +35,7 @@ struct texture_s; static const texid_t r_nulltex = NULL; -//GLES2 requires GL_UNSIGNED_SHORT +//GLES2 requires GL_UNSIGNED_SHORT (gles3 or GL_OES_element_index_uint relax this requirement) //geforce4 only does shorts. gffx can do ints, but with a performance hit (like most things on that gpu) //ati is generally more capable, but generally also has a smaller market share //desktop-gl will generally cope with ints, but expect a performance hit from that with old gpus (so we don't bother) @@ -266,6 +266,9 @@ typedef struct refdef_s qboolean base_known; /*otherwise we do some fallback behaviour (ie: viewangles.0y0 and forcing input_angles)*/ vec3_t base_angles, base_origin; /*for vr output, overrides per-eye viewangles according to that eye's matrix.*/ + vec3_t weaponmatrix[4]; /*forward/left/up/origin*/ + vec3_t weaponmatrix_bob[4]; /*forward/left/up/origin*/ + float fov_x, fov_y, afov; float fovv_x, fovv_y; //viewmodel fovs float mindist, maxdist; //maxdist may be 0, for 'infinite', in which case mindist probably isn't valid either. diff --git a/engine/client/view.c b/engine/client/view.c index 263cda9ee..6c51e9025 100644 --- a/engine/client/view.c +++ b/engine/client/view.c @@ -1063,16 +1063,17 @@ void V_CalcGunPositionAngle (playerview_t *pv, float bob) vw_angles[PITCH] = r_refdef.viewangles[PITCH]; vw_angles[ROLL] = r_refdef.viewangles[ROLL]; - AngleVectors(vw_angles, pv->vw_axis[0], pv->vw_axis[1], pv->vw_axis[2]); - VectorInverse(pv->vw_axis[1]); + + AngleVectors(vw_angles, r_refdef.weaponmatrix[0], r_refdef.weaponmatrix[1], r_refdef.weaponmatrix[2]); + VectorInverse(r_refdef.weaponmatrix[1]); - VectorCopy (r_refdef.vieworg, pv->vw_origin); + VectorCopy (r_refdef.vieworg, r_refdef.weaponmatrix[3]); for (i=0 ; i<3 ; i++) { - pv->vw_origin[i] += pv->vw_axis[0][i]*bob*0.4; -// pv->vw_origin[i] += pv->vw_axis[1][i]*sin(cl.time*5.5342452354235)*0.1; -// pv->vw_origin[i] += pv->vw_axis[2][i]*bob*0.8; + r_refdef.weaponmatrix[3][i] += r_refdef.weaponmatrix[0][i]*bob*0.4; +// r_refdef.weaponmatrix[3][i] += r_refdef.weaponmatrix[1][i]*sin(cl.time*5.5342452354235)*0.1; +// r_refdef.weaponmatrix[3][i] += r_refdef.weaponmatrix[2][i]*bob*0.8; } VectorMA(pv->simvel, -DotProduct(pv->simvel, pv->gravitydir), pv->gravitydir, xyvel); @@ -1082,29 +1083,31 @@ void V_CalcGunPositionAngle (playerview_t *pv, float bob) //FIXME: cl_followmodel should lag the viewmodel's position relative to the view //FIXME: cl_leanmodel should lag the viewmodel's angles relative to the view - if (cl_bobmodel.value) - { //bobmodel causes the viewmodel to bob relative to the view. - float s = pv->bobtime * cl_bobmodel_speed.value, v; - v = xyspeed * 0.01 * cl_bobmodel_side.value * /*cl_viewmodel_scale.value * */sin(s); - VectorMA(pv->vw_origin, v, pv->vw_axis[1], pv->vw_origin); - v = xyspeed * 0.01 * cl_bobmodel_up.value * /*cl_viewmodel_scale.value * */cos(2*s); - VectorMA(pv->vw_origin, v, pv->vw_axis[2], pv->vw_origin); - } - - // fudge position around to keep amount of weapon visible // roughly equal with different FOV //FIXME: should use y fov, not viewsize. if (r_refdef.drawsbar && v_viewmodel_quake.ival) //no sbar = no viewsize cvar. { if (scr_viewsize.value == 110) - pv->vw_origin[2] += 1; + r_refdef.weaponmatrix[3][2] += 1; else if (scr_viewsize.value == 100) - pv->vw_origin[2] += 2; + r_refdef.weaponmatrix[3][2] += 2; else if (scr_viewsize.value == 90) - pv->vw_origin[2] += 1; + r_refdef.weaponmatrix[3][2] += 1; else if (scr_viewsize.value == 80) - pv->vw_origin[2] += 0.5; + r_refdef.weaponmatrix[3][2] += 0.5; + } + + + + memcpy(r_refdef.weaponmatrix_bob, r_refdef.weaponmatrix, sizeof(r_refdef.weaponmatrix_bob)); + if (cl_bobmodel.value) + { //bobmodel causes the viewmodel to bob relative to the view. + float s = pv->bobtime * cl_bobmodel_speed.value, v; + v = xyspeed * 0.01 * cl_bobmodel_side.value * /*cl_viewmodel_scale.value * */sin(s); + VectorMA(r_refdef.weaponmatrix_bob[3], v, r_refdef.weaponmatrix[1], r_refdef.weaponmatrix_bob[3]); + v = xyspeed * 0.01 * cl_bobmodel_up.value * /*cl_viewmodel_scale.value * */cos(2*s); + VectorMA(r_refdef.weaponmatrix_bob[3], v, r_refdef.weaponmatrix[2], r_refdef.weaponmatrix_bob[3]); } } diff --git a/engine/gl/gl_alias.c b/engine/gl/gl_alias.c index a607f41c5..845297780 100644 --- a/engine/gl/gl_alias.c +++ b/engine/gl/gl_alias.c @@ -2590,14 +2590,26 @@ static void R_Sprite_GenerateTrisoup(entity_t *e, int bemode) lightmap = 1; } - if ((e->flags & RF_WEAPONMODEL) && r_refdef.playerview->viewentity > 0) + if (e->flags & RF_WEAPONMODELNOBOB) { - sprorigin[0] = r_refdef.playerview->vw_origin[0]; - sprorigin[1] = r_refdef.playerview->vw_origin[1]; - sprorigin[2] = r_refdef.playerview->vw_origin[2]; - VectorMA(sprorigin, e->origin[0], r_refdef.playerview->vw_axis[0], sprorigin); - VectorMA(sprorigin, e->origin[1], r_refdef.playerview->vw_axis[1], sprorigin); - VectorMA(sprorigin, e->origin[2], r_refdef.playerview->vw_axis[2], sprorigin); + sprorigin[0] = r_refdef.weaponmatrix[3][0]; + sprorigin[1] = r_refdef.weaponmatrix[3][1]; + sprorigin[2] = r_refdef.weaponmatrix[3][2]; + VectorMA(sprorigin, e->origin[0], r_refdef.weaponmatrix[0], sprorigin); + VectorMA(sprorigin, e->origin[1], r_refdef.weaponmatrix[1], sprorigin); + VectorMA(sprorigin, e->origin[2], r_refdef.weaponmatrix[2], sprorigin); +// VectorMA(sprorigin, 12, vpn, sprorigin); + +// batchflags |= BEF_FORCENODEPTH; + } + else if (e->flags & RF_WEAPONMODEL) + { + sprorigin[0] = r_refdef.weaponmatrix_bob[3][0]; + sprorigin[1] = r_refdef.weaponmatrix_bob[3][1]; + sprorigin[2] = r_refdef.weaponmatrix_bob[3][2]; + VectorMA(sprorigin, e->origin[0], r_refdef.weaponmatrix_bob[0], sprorigin); + VectorMA(sprorigin, e->origin[1], r_refdef.weaponmatrix_bob[1], sprorigin); + VectorMA(sprorigin, e->origin[2], r_refdef.weaponmatrix_bob[2], sprorigin); // VectorMA(sprorigin, 12, vpn, sprorigin); // batchflags |= BEF_FORCENODEPTH; @@ -2667,15 +2679,19 @@ static void R_Sprite_GenerateTrisoup(entity_t *e, int bemode) { case SPR_ORIENTED: // bullet marks on walls - if ((e->flags & RF_WEAPONMODEL) && r_refdef.playerview->viewentity > 0) - Matrix3_Multiply(e->axis, r_refdef.playerview->vw_axis, spraxis); + if (e->flags & RF_WEAPONMODELNOBOB) + Matrix3_Multiply(e->axis, r_refdef.weaponmatrix, spraxis); + else if (e->flags & RF_WEAPONMODEL) + Matrix3_Multiply(e->axis, r_refdef.weaponmatrix_bob, spraxis); else memcpy(spraxis, e->axis, sizeof(spraxis)); break; case SPR_ORIENTED_BACKFACE: // bullet marks on walls, invisible to anyone in the direction that its facing... - if ((e->flags & RF_WEAPONMODEL) && r_refdef.playerview->viewentity > 0) - Matrix3_Multiply(e->axis, r_refdef.playerview->vw_axis, spraxis); + if (e->flags & RF_WEAPONMODELNOBOB) + Matrix3_Multiply(e->axis, r_refdef.weaponmatrix, spraxis); + else if ((e->flags & RF_WEAPONMODEL) && r_refdef.playerview->viewentity > 0) + Matrix3_Multiply(e->axis, r_refdef.weaponmatrix_bob, spraxis); else memcpy(spraxis, e->axis, sizeof(spraxis)); VectorNegate(spraxis[1], spraxis[1]); diff --git a/engine/gl/gl_rmain.c b/engine/gl/gl_rmain.c index edc24a30b..c445392ae 100644 --- a/engine/gl/gl_rmain.c +++ b/engine/gl/gl_rmain.c @@ -272,48 +272,48 @@ void R_RotateForEntity (float *m, float *modelview, const entity_t *e, const mod float em[16]; float vm[16]; - if ((e->flags & RF_WEAPONMODELNOBOB) || r_refdef.playerview->viewentity <= 0) + if (e->flags & RF_WEAPONMODELNOBOB) { - vm[0] = vpn[0]; - vm[1] = vpn[1]; - vm[2] = vpn[2]; + vm[0] = r_refdef.weaponmatrix[0][0]; + vm[1] = r_refdef.weaponmatrix[0][1]; + vm[2] = r_refdef.weaponmatrix[0][2]; vm[3] = 0; - vm[4] = -vright[0]; - vm[5] = -vright[1]; - vm[6] = -vright[2]; + vm[4] = r_refdef.weaponmatrix[1][0]; + vm[5] = r_refdef.weaponmatrix[1][1]; + vm[6] = r_refdef.weaponmatrix[1][2]; vm[7] = 0; - vm[8] = vup[0]; - vm[9] = vup[1]; - vm[10] = vup[2]; + vm[8] = r_refdef.weaponmatrix[2][0]; + vm[9] = r_refdef.weaponmatrix[2][1]; + vm[10] = r_refdef.weaponmatrix[2][2]; vm[11] = 0; - vm[12] = r_refdef.vieworg[0]; - vm[13] = r_refdef.vieworg[1]; - vm[14] = r_refdef.vieworg[2]; + vm[12] = r_refdef.weaponmatrix[3][0]; + vm[13] = r_refdef.weaponmatrix[3][1]; + vm[14] = r_refdef.weaponmatrix[3][2]; vm[15] = 1; } else { - vm[0] = r_refdef.playerview->vw_axis[0][0]; - vm[1] = r_refdef.playerview->vw_axis[0][1]; - vm[2] = r_refdef.playerview->vw_axis[0][2]; + vm[0] = r_refdef.weaponmatrix_bob[0][0]; + vm[1] = r_refdef.weaponmatrix_bob[0][1]; + vm[2] = r_refdef.weaponmatrix_bob[0][2]; vm[3] = 0; - vm[4] = r_refdef.playerview->vw_axis[1][0]; - vm[5] = r_refdef.playerview->vw_axis[1][1]; - vm[6] = r_refdef.playerview->vw_axis[1][2]; + vm[4] = r_refdef.weaponmatrix_bob[1][0]; + vm[5] = r_refdef.weaponmatrix_bob[1][1]; + vm[6] = r_refdef.weaponmatrix_bob[1][2]; vm[7] = 0; - vm[8] = r_refdef.playerview->vw_axis[2][0]; - vm[9] = r_refdef.playerview->vw_axis[2][1]; - vm[10] = r_refdef.playerview->vw_axis[2][2]; + vm[8] = r_refdef.weaponmatrix_bob[2][0]; + vm[9] = r_refdef.weaponmatrix_bob[2][1]; + vm[10] = r_refdef.weaponmatrix_bob[2][2]; vm[11] = 0; - vm[12] = r_refdef.playerview->vw_origin[0]; - vm[13] = r_refdef.playerview->vw_origin[1]; - vm[14] = r_refdef.playerview->vw_origin[2]; + vm[12] = r_refdef.weaponmatrix_bob[3][0]; + vm[13] = r_refdef.weaponmatrix_bob[3][1]; + vm[14] = r_refdef.weaponmatrix_bob[3][2]; vm[15] = 1; } diff --git a/engine/server/svq3_game.c b/engine/server/svq3_game.c index adc1f7ef4..9238b2579 100644 --- a/engine/server/svq3_game.c +++ b/engine/server/svq3_game.c @@ -1893,6 +1893,7 @@ qboolean SVQ3_InitGame(server_static_t *server_state_static, server_t *server_st int i; char ssqcprogs[MAX_QPATH]; + memset(sv3.models, 0, sizeof(sv3.models)); sv3.server_state_static = server_state_static; sv3.server_state = server_state; sv3.world = &server_state->world; diff --git a/engine/vk/vk_backend.c b/engine/vk/vk_backend.c index 42202c2e1..8d4da0cab 100644 --- a/engine/vk/vk_backend.c +++ b/engine/vk/vk_backend.c @@ -3817,46 +3817,46 @@ static void BE_RotateForEntity (const entity_t *fte_restrict e, const model_t *f if (e->flags & RF_WEAPONMODELNOBOB) { - vm[0] = vpn[0]; - vm[1] = vpn[1]; - vm[2] = vpn[2]; + vm[0] = r_refdef.weaponmatrix[0][0]; + vm[1] = r_refdef.weaponmatrix[0][1]; + vm[2] = r_refdef.weaponmatrix[0][2]; vm[3] = 0; - vm[4] = -vright[0]; - vm[5] = -vright[1]; - vm[6] = -vright[2]; + vm[4] = r_refdef.weaponmatrix[1][0]; + vm[5] = r_refdef.weaponmatrix[1][1]; + vm[6] = r_refdef.weaponmatrix[1][2]; vm[7] = 0; - vm[8] = vup[0]; - vm[9] = vup[1]; - vm[10] = vup[2]; + vm[8] = r_refdef.weaponmatrix[2][0]; + vm[9] = r_refdef.weaponmatrix[2][1]; + vm[10] = r_refdef.weaponmatrix[2][2]; vm[11] = 0; - vm[12] = r_refdef.vieworg[0]; - vm[13] = r_refdef.vieworg[1]; - vm[14] = r_refdef.vieworg[2]; + vm[12] = r_refdef.weaponmatrix[3][0]; + vm[13] = r_refdef.weaponmatrix[3][1]; + vm[14] = r_refdef.weaponmatrix[3][2]; vm[15] = 1; } else { - vm[0] = r_refdef.playerview->vw_axis[0][0]; - vm[1] = r_refdef.playerview->vw_axis[0][1]; - vm[2] = r_refdef.playerview->vw_axis[0][2]; + vm[0] = r_refdef.weaponmatrix_bob[0][0]; + vm[1] = r_refdef.weaponmatrix_bob[0][1]; + vm[2] = r_refdef.weaponmatrix_bob[0][2]; vm[3] = 0; - vm[4] = r_refdef.playerview->vw_axis[1][0]; - vm[5] = r_refdef.playerview->vw_axis[1][1]; - vm[6] = r_refdef.playerview->vw_axis[1][2]; + vm[4] = r_refdef.weaponmatrix_bob[1][0]; + vm[5] = r_refdef.weaponmatrix_bob[1][1]; + vm[6] = r_refdef.weaponmatrix_bob[1][2]; vm[7] = 0; - vm[8] = r_refdef.playerview->vw_axis[2][0]; - vm[9] = r_refdef.playerview->vw_axis[2][1]; - vm[10] = r_refdef.playerview->vw_axis[2][2]; + vm[8] = r_refdef.weaponmatrix_bob[2][0]; + vm[9] = r_refdef.weaponmatrix_bob[2][1]; + vm[10] = r_refdef.weaponmatrix_bob[2][2]; vm[11] = 0; - vm[12] = r_refdef.playerview->vw_origin[0]; - vm[13] = r_refdef.playerview->vw_origin[1]; - vm[14] = r_refdef.playerview->vw_origin[2]; + vm[12] = r_refdef.weaponmatrix_bob[3][0]; + vm[13] = r_refdef.weaponmatrix_bob[3][1]; + vm[14] = r_refdef.weaponmatrix_bob[3][2]; vm[15] = 1; }