+ // calculate a view matrix for rendering the scene
+ if (v_idlescale.value)
+ {
+ viewangles[0] += v_idlescale.value * sin(cl.time*v_ipitch_cycle.value) * v_ipitch_level.value;
+ viewangles[1] += v_idlescale.value * sin(cl.time*v_iyaw_cycle.value) * v_iyaw_level.value;
+ 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);
+ if (v_yshearing.value > 0)
+ Matrix4x4_QuakeToDuke3D(&r_refdef.view.matrix, &r_refdef.view.matrix, v_yshearing.value);
+
+ // calculate a viewmodel matrix for use in view-attached entities
+ 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);
+ if (v_yshearing.value > 0)
+ Matrix4x4_QuakeToDuke3D(&viewmodelmatrix_withbob, &viewmodelmatrix_withbob, v_yshearing.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);
+ }
+
+ cl.calcrefdef_prevtime = cl.time;
+}
+
+void V_CalcRefdef (void)
+{
+ entity_t *ent;
+ qboolean cldead;
+
+ if (cls.state == ca_connected && cls.signon == SIGNONS && !cl.csqc_server2csqcentitynumber[cl.viewentity])
+ {
+ // ent is the view entity (visible when out of body)
+ ent = &cl.entities[cl.viewentity];
+
+ cldead = (cl.stats[STAT_HEALTH] <= 0 && cl.stats[STAT_HEALTH] != -666 && cl.stats[STAT_HEALTH] != -2342);
+ V_CalcRefdefUsing(&ent->render.matrix, cl.viewangles, !ent->persistent.trail_allowed, cl.onground, cl.cmd.jump, cl.stats[STAT_VIEWHEIGHT], cldead, cl.intermission != 0, cl.velocity); // FIXME use a better way to detect teleport/warp than trail_allowed
+ }
+ else
+ {
+ viewmodelmatrix_nobob = identitymatrix;
+ viewmodelmatrix_withbob = identitymatrix;
+ cl.csqc_viewmodelmatrixfromengine = identitymatrix;
+ r_refdef.view.matrix = identitymatrix;
+ VectorClear(cl.csqc_vieworiginfromengine);
+ VectorCopy(cl.viewangles, cl.csqc_viewanglesfromengine);