]> git.rm.cloudns.org Git - xonotic/darkplaces.git/commitdiff
viewmodel matrix fixes:
authordivverent <divverent@d7cf8633-e32d-0410-b094-e92efae38249>
Tue, 31 May 2011 20:25:01 +0000 (20:25 +0000)
committerdivverent <divverent@d7cf8633-e32d-0410-b094-e92efae38249>
Tue, 31 May 2011 20:25:01 +0000 (20:25 +0000)
- 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

cl_main.c
client.h
clvm_cmds.c
csprogs.c
view.c

index 06527e4c868f5c5c29ca3481c860389b5eec3794..00e88da6563910726c3885f12709fb243681b151 100644 (file)
--- 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
        {
index 1ea3e64ec16a4ac93c06c42b32fc19c2ed61acf5..72aaa5e06fcb1ff7c551ac262a54ddc550e4ba3e 100644 (file)
--- 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];
index 5210727cbcf35bfaae467ce32d66d1cceeed67e0..3c153c8f110c716efbae0d0cb0ebcd28dd87aced 100644 (file)
@@ -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)
index 1a71803937636a7735ebc82f9bee6092e0fcb27f..75104721549811e89e7aca7586803fd6dd37244b 100644 (file)
--- 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 772c31d15a9694b304a934bc07ca3beed0a66bfe..3e0ccc57ebbf17154f9e4e8dd536fdc818222de5 100644 (file)
--- 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);
                }
        }
 }