From: divverent Date: Tue, 31 May 2011 20:25:01 +0000 (+0000) Subject: viewmodel matrix fixes: X-Git-Tag: xonotic-v0.6.0~163^2~374 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=3f8dd70cf524fa42fafddb3dbc9aa64591c2d734;p=xonotic%2Fdarkplaces.git viewmodel matrix fixes: - have two separate viewmodel matrices, one that only applies the viewmodel scale (for EF_NOGUNBOB), and one that contains bobbing etc. effects - recalculate both matrices properly when using R_SetView() from CSQC - make sure view parameters are consistent between whether R_SetView() is called or not - fix missing viewmodel scale in intermission git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@11172 d7cf8633-e32d-0410-b094-e92efae38249 --- diff --git a/cl_main.c b/cl_main.c index 06527e4c..00e88da6 100644 --- a/cl_main.c +++ b/cl_main.c @@ -907,7 +907,8 @@ void CL_AddQWCTFFlagModel(entity_t *player, int skin) CL_UpdateRenderEntity(flagrender); } -matrix4x4_t viewmodelmatrix; +matrix4x4_t viewmodelmatrix_withbob; +matrix4x4_t viewmodelmatrix_nobob; static const vec3_t muzzleflashorigin = {18, 0, 0}; @@ -1010,9 +1011,9 @@ void CL_UpdateNetworkEntity(entity_t *e, int recursionlimit, qboolean interpolat { // view-relative entity (guns and such) if (e->render.effects & EF_NOGUNBOB) - matrix = &r_refdef.view.matrix; // really attached to view + matrix = &viewmodelmatrix_nobob; // really attached to view else - matrix = &viewmodelmatrix; // attached to gun bob matrix + matrix = &viewmodelmatrix_withbob; // attached to gun bob matrix } else { diff --git a/client.h b/client.h index 1ea3e64e..72aaa5e0 100644 --- a/client.h +++ b/client.h @@ -1248,6 +1248,7 @@ typedef struct client_state_s vec3_t csqc_viewangles; vec3_t csqc_vieworiginfromengine; vec3_t csqc_viewanglesfromengine; + matrix4x4_t csqc_viewmodelmatrixfromengine; qboolean csqc_usecsqclistener; matrix4x4_t csqc_listenermatrix; char csqc_printtextbuf[MAX_INPUTLINE]; diff --git a/clvm_cmds.c b/clvm_cmds.c index 5210727c..3c153c8f 100644 --- a/clvm_cmds.c +++ b/clvm_cmds.c @@ -683,11 +683,14 @@ static void VM_CL_getlight (void) //[515]: SCENE MANAGER builtins extern qboolean CSQC_AddRenderEdict (prvm_edict_t *ed, int edictnum);//csprogs.c -static void CSQC_R_RecalcView (void) +void CSQC_R_RecalcView (void) { - extern matrix4x4_t viewmodelmatrix; + extern matrix4x4_t viewmodelmatrix_nobob; + extern matrix4x4_t viewmodelmatrix_withbob; Matrix4x4_CreateFromQuakeEntity(&r_refdef.view.matrix, cl.csqc_vieworigin[0], cl.csqc_vieworigin[1], cl.csqc_vieworigin[2], cl.csqc_viewangles[0], cl.csqc_viewangles[1], cl.csqc_viewangles[2], 1); - Matrix4x4_CreateFromQuakeEntity(&viewmodelmatrix, cl.csqc_vieworigin[0], cl.csqc_vieworigin[1], cl.csqc_vieworigin[2], cl.csqc_viewangles[0], cl.csqc_viewangles[1], cl.csqc_viewangles[2], cl_viewmodel_scale.value); + Matrix4x4_Copy(&viewmodelmatrix_nobob, &r_refdef.view.matrix); + Matrix4x4_ConcatScale(&viewmodelmatrix_nobob, cl_viewmodel_scale.value); + Matrix4x4_Concat(&viewmodelmatrix_withbob, &r_refdef.view.matrix, &cl.csqc_viewmodelmatrixfromengine); } void CL_RelinkLightFlashes(void); @@ -720,6 +723,7 @@ void VM_CL_R_ClearScene (void) cl.csqc_vidvars.drawworld = r_drawworld.integer != 0; cl.csqc_vidvars.drawenginesbar = false; cl.csqc_vidvars.drawcrosshair = false; + CSQC_R_RecalcView(); } //#301 void(float mask) addentities (EXT_CSQC) diff --git a/csprogs.c b/csprogs.c index 1a718039..75104721 100644 --- a/csprogs.c +++ b/csprogs.c @@ -240,6 +240,7 @@ void CSQC_UpdateNetworkTimes(double newtime, double oldtime) } //[515]: set globals before calling R_UpdateView, WEIRD CRAP +void CSQC_R_RecalcView (void); static void CSQC_SetGlobals (void) { CSQC_BEGIN @@ -266,6 +267,8 @@ static void CSQC_SetGlobals (void) VectorCopy(cl.punchangle, PRVM_clientglobalvector(view_punchangle)); VectorCopy(cl.punchvector, PRVM_clientglobalvector(view_punchvector)); prog->globals.client->maxclients = cl.maxclients; + + CSQC_R_RecalcView(); CSQC_END } diff --git a/view.c b/view.c index 772c31d1..3e0ccc57 100644 --- a/view.c +++ b/view.c @@ -370,7 +370,8 @@ static void V_BonusFlash_f (void) ============================================================================== */ -extern matrix4x4_t viewmodelmatrix; +extern matrix4x4_t viewmodelmatrix_nobob; +extern matrix4x4_t viewmodelmatrix_withbob; #include "cl_collision.h" #include "csprogs.h" @@ -434,6 +435,7 @@ void V_CalcRefdef (void) entity_t *ent; float vieworg[3], viewangles[3], smoothtime; float gunorg[3], gunangles[3]; + matrix4x4_t tmpmatrix; static float viewheightavg; float viewheight; @@ -445,7 +447,8 @@ void V_CalcRefdef (void) #endif trace_t trace; VectorClear(gunorg); - viewmodelmatrix = identitymatrix; + viewmodelmatrix_nobob = identitymatrix; + viewmodelmatrix_withbob = identitymatrix; r_refdef.view.matrix = identitymatrix; if (cls.state == ca_connected && cls.signon == SIGNONS) { @@ -474,7 +477,9 @@ void V_CalcRefdef (void) r_refdef.view.matrix = ent->render.matrix; Matrix4x4_AdjustOrigin(&r_refdef.view.matrix, 0, 0, cl.stats[STAT_VIEWHEIGHT]); } - viewmodelmatrix = r_refdef.view.matrix; + Matrix4x4_Copy(&viewmodelmatrix_nobob, &r_refdef.view.matrix); + Matrix4x4_ConcatScale(&viewmodelmatrix_nobob, cl_viewmodel_scale.value); + Matrix4x4_Copy(&viewmodelmatrix_withbob, &viewmodelmatrix_nobob); } else { @@ -800,10 +805,17 @@ void V_CalcRefdef (void) viewangles[2] += v_idlescale.value * sin(cl.time*v_iroll_cycle.value) * v_iroll_level.value; } Matrix4x4_CreateFromQuakeEntity(&r_refdef.view.matrix, vieworg[0], vieworg[1], vieworg[2], viewangles[0], viewangles[1], viewangles[2], 1); + // calculate a viewmodel matrix for use in view-attached entities - Matrix4x4_CreateFromQuakeEntity(&viewmodelmatrix, gunorg[0], gunorg[1], gunorg[2], gunangles[0], gunangles[1], gunangles[2], cl_viewmodel_scale.value); + Matrix4x4_Copy(&viewmodelmatrix_nobob, &r_refdef.view.matrix); + Matrix4x4_ConcatScale(&viewmodelmatrix_nobob, cl_viewmodel_scale.value); + + Matrix4x4_CreateFromQuakeEntity(&viewmodelmatrix_withbob, gunorg[0], gunorg[1], gunorg[2], gunangles[0], gunangles[1], gunangles[2], cl_viewmodel_scale.value); VectorCopy(vieworg, cl.csqc_vieworiginfromengine); VectorCopy(viewangles, cl.csqc_viewanglesfromengine); + + Matrix4x4_Invert_Simple(&tmpmatrix, &r_refdef.view.matrix); + Matrix4x4_Concat(&cl.csqc_viewmodelmatrixfromengine, &tmpmatrix, &viewmodelmatrix_withbob); } } }