+ // 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);
+ }
+}
+
+void V_MakeViewIsometric(void)
+{
+ // when using isometric view to play normal games we have to rotate the camera to make the Ortho matrix do the right thing (forward as up the screen, etc)
+ matrix4x4_t relative;
+ matrix4x4_t modifiedview;
+ matrix4x4_t modify;
+ vec3_t forward, left, up, org;
+ float t[4][4];
+
+ r_refdef.view.useperspective = false;
+ r_refdef.view.usevieworiginculling = !r_trippy.value && v_isometric_usevieworiginculling.integer;
+ r_refdef.view.frustum_y = v_isometric_verticalfov.value * cl.viewzoom;
+ r_refdef.view.frustum_x = r_refdef.view.frustum_y * (float)r_refdef.view.width / (float)r_refdef.view.height / vid_pixelheight.value;
+ r_refdef.view.frustum_x *= r_refdef.frustumscale_x;
+ r_refdef.view.frustum_y *= r_refdef.frustumscale_y;
+ r_refdef.view.ortho_x = r_refdef.view.frustum_x; // used by VM_CL_R_SetView
+ r_refdef.view.ortho_y = r_refdef.view.frustum_y; // used by VM_CL_R_SetView
+
+ t[0][0] = v_isometric_xx.value;
+ t[0][1] = v_isometric_xy.value;
+ t[0][2] = v_isometric_xz.value;
+ t[0][3] = 0.0f;
+ t[1][0] = v_isometric_yx.value;
+ t[1][1] = v_isometric_yy.value;
+ t[1][2] = v_isometric_yz.value;
+ t[1][3] = 0.0f;
+ t[2][0] = v_isometric_zx.value;
+ t[2][1] = v_isometric_zy.value;
+ t[2][2] = v_isometric_zz.value;
+ t[2][3] = 0.0f;
+ t[3][0] = 0.0f;
+ t[3][1] = 0.0f;
+ t[3][2] = 0.0f;
+ t[3][3] = 1.0f;
+ Matrix4x4_FromArrayFloatGL(&modify, t[0]);
+
+ // if the orientation is locked, extract the origin and create just a translate matrix to start with
+ if (v_isometric_locked_orientation.integer)
+ {
+ vec3_t vx, vy, vz, origin;
+ Matrix4x4_ToVectors(&r_refdef.view.matrix, vx, vy, vz, origin);
+ Matrix4x4_CreateTranslate(&r_refdef.view.matrix, origin[0], origin[1], origin[2]);
+ }
+
+ Matrix4x4_Concat(&modifiedview, &r_refdef.view.matrix, &modify);
+ Matrix4x4_CreateFromQuakeEntity(&relative, v_isometric_tx.value, v_isometric_ty.value, v_isometric_tz.value, v_isometric_rot_pitch.value, v_isometric_rot_yaw.value, v_isometric_rot_roll.value, 1.0f);
+ Matrix4x4_Concat(&r_refdef.view.matrix, &modifiedview, &relative);
+ Matrix4x4_ToVectors(&r_refdef.view.matrix, forward, left, up, org);
+ VectorMAMAMAM(1.0f, org, v_isometric_relx.value, forward, v_isometric_rely.value, left, v_isometric_relz.value, up, org);
+ Matrix4x4_FromVectors(&r_refdef.view.matrix, forward, left, up, org);
+
+ if (v_isometric_flipcullface.integer)
+ {
+ int a = r_refdef.view.cullface_front;
+ r_refdef.view.cullface_front = r_refdef.view.cullface_back;
+ r_refdef.view.cullface_back = a;