view.c, cl_parse.c, cl_main.c, gl_rmain.c - trying to remove all uses of origin,...
authorhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Fri, 7 Mar 2003 09:24:59 +0000 (09:24 +0000)
committerhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Fri, 7 Mar 2003 09:24:59 +0000 (09:24 +0000)
view.c, gl_rmain.c - viewmodel entities are now processed in view.c instead of gl_rmain.c
view.c now uses matrix and inversematrix for view damage kicks

what this means:
the QC feature viewmodelforclient now works

git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@2805 d7cf8633-e32d-0410-b094-e92efae38249

cl_main.c
cl_parse.c
gl_rmain.c
view.c

index ec48129..9488601 100644 (file)
--- a/cl_main.c
+++ b/cl_main.c
@@ -264,34 +264,60 @@ static void CL_PrintEntities_f (void)
        }
 }
 
-static const vec3_t nomodelmins = {-16, -16, -16};
-static const vec3_t nomodelmaxs = {16, 16, 16};
+//static const vec3_t nomodelmins = {-16, -16, -16};
+//static const vec3_t nomodelmaxs = {16, 16, 16};
 void CL_BoundingBoxForEntity(entity_render_t *ent)
 {
        if (ent->model)
        {
-               if (ent->angles[0] || ent->angles[2])
+               //if (ent->angles[0] || ent->angles[2])
+               if (ent->matrix.m[2][0] != 0 || ent->matrix.m[2][1] != 0)
                {
                        // pitch or roll
-                       VectorAdd(ent->origin, ent->model->rotatedmins, ent->mins);
-                       VectorAdd(ent->origin, ent->model->rotatedmaxs, ent->maxs);
+                       ent->mins[0] = ent->matrix.m[0][3] + ent->model->rotatedmins[0];
+                       ent->mins[1] = ent->matrix.m[1][3] + ent->model->rotatedmins[1];
+                       ent->mins[2] = ent->matrix.m[2][3] + ent->model->rotatedmins[2];
+                       ent->maxs[0] = ent->matrix.m[0][3] + ent->model->rotatedmaxs[0];
+                       ent->maxs[1] = ent->matrix.m[1][3] + ent->model->rotatedmaxs[1];
+                       ent->maxs[2] = ent->matrix.m[2][3] + ent->model->rotatedmaxs[2];
+                       //VectorAdd(ent->origin, ent->model->rotatedmins, ent->mins);
+                       //VectorAdd(ent->origin, ent->model->rotatedmaxs, ent->maxs);
                }
-               else if (ent->angles[1])
+               //else if (ent->angles[1])
+               else if (ent->matrix.m[0][1] != 0 || ent->matrix.m[1][0] != 0)
                {
                        // yaw
-                       VectorAdd(ent->origin, ent->model->yawmins, ent->mins);
-                       VectorAdd(ent->origin, ent->model->yawmaxs, ent->maxs);
+                       ent->mins[0] = ent->matrix.m[0][3] + ent->model->yawmins[0];
+                       ent->mins[1] = ent->matrix.m[1][3] + ent->model->yawmins[1];
+                       ent->mins[2] = ent->matrix.m[2][3] + ent->model->yawmins[2];
+                       ent->maxs[0] = ent->matrix.m[0][3] + ent->model->yawmaxs[0];
+                       ent->maxs[1] = ent->matrix.m[1][3] + ent->model->yawmaxs[1];
+                       ent->maxs[2] = ent->matrix.m[2][3] + ent->model->yawmaxs[2];
+                       //VectorAdd(ent->origin, ent->model->yawmins, ent->mins);
+                       //VectorAdd(ent->origin, ent->model->yawmaxs, ent->maxs);
                }
                else
                {
-                       VectorAdd(ent->origin, ent->model->normalmins, ent->mins);
-                       VectorAdd(ent->origin, ent->model->normalmaxs, ent->maxs);
+                       ent->mins[0] = ent->matrix.m[0][3] + ent->model->normalmins[0];
+                       ent->mins[1] = ent->matrix.m[1][3] + ent->model->normalmins[1];
+                       ent->mins[2] = ent->matrix.m[2][3] + ent->model->normalmins[2];
+                       ent->maxs[0] = ent->matrix.m[0][3] + ent->model->normalmaxs[0];
+                       ent->maxs[1] = ent->matrix.m[1][3] + ent->model->normalmaxs[1];
+                       ent->maxs[2] = ent->matrix.m[2][3] + ent->model->normalmaxs[2];
+                       //VectorAdd(ent->origin, ent->model->normalmins, ent->mins);
+                       //VectorAdd(ent->origin, ent->model->normalmaxs, ent->maxs);
                }
        }
        else
        {
-               VectorAdd(ent->origin, nomodelmins, ent->mins);
-               VectorAdd(ent->origin, nomodelmaxs, ent->maxs);
+               ent->mins[0] = ent->matrix.m[0][3] - 16;
+               ent->mins[1] = ent->matrix.m[1][3] - 16;
+               ent->mins[2] = ent->matrix.m[2][3] - 16;
+               ent->maxs[0] = ent->matrix.m[0][3] + 16;
+               ent->maxs[1] = ent->matrix.m[1][3] + 16;
+               ent->maxs[2] = ent->matrix.m[2][3] + 16;
+               //VectorAdd(ent->origin, nomodelmins, ent->mins);
+               //VectorAdd(ent->origin, nomodelmaxs, ent->maxs);
        }
 }
 
@@ -457,10 +483,13 @@ void CL_DecayLights (void)
 
 void CL_RelinkWorld (void)
 {
+       entity_t *ent = &cl_entities[0];
        if (cl_num_entities < 1)
                cl_num_entities = 1;
-       cl_brushmodel_entities[cl_num_brushmodel_entities++] = &cl_entities[0].render;
-       CL_BoundingBoxForEntity(&cl_entities[0].render);
+       cl_brushmodel_entities[cl_num_brushmodel_entities++] = &ent->render;
+       Matrix4x4_CreateFromQuakeEntity(&ent->render.matrix, ent->render.origin[0], ent->render.origin[1], ent->render.origin[2], ent->render.angles[0], ent->render.angles[1], ent->render.angles[2], ent->render.scale);
+       Matrix4x4_Invert_Simple(&ent->render.inversematrix, &ent->render.matrix);
+       CL_BoundingBoxForEntity(&ent->render);
 }
 
 static void CL_RelinkStaticEntities(void)
@@ -479,6 +508,9 @@ CL_RelinkEntities
 ===============
 */
 extern qboolean Nehahrademcompatibility;
+#define MAXVIEWMODELS 32
+entity_t *viewmodels[MAXVIEWMODELS];
+int numviewmodels;
 static void CL_RelinkNetworkEntities(void)
 {
        entity_t *ent;
@@ -486,6 +518,8 @@ static void CL_RelinkNetworkEntities(void)
        float d, bobjrotate, bobjoffset, lerp;
        vec3_t oldorg, neworg, delta, dlightcolor, v, v2, mins, maxs;
 
+       numviewmodels = 0;
+
        bobjrotate = ANGLEMOD(100*cl.time);
        if (cl_itembobheight.value)
                bobjoffset = (cos(cl.time * cl_itembobspeed.value * (2.0 * M_PI)) + 1.0) * 0.5 * cl_itembobheight.value;
@@ -545,6 +579,9 @@ static void CL_RelinkNetworkEntities(void)
                        }
                }
 
+               if (!ent->render.model || ent->render.model->type != mod_brush)
+                       ent->render.angles[0] = -ent->render.angles[0];
+
                VectorCopy (neworg, ent->persistent.trail_origin);
                // persistent.modelindex will be updated by CL_LerpUpdate
                if (ent->state_current.modelindex != ent->persistent.modelindex || !ent->state_previous.active)
@@ -565,6 +602,14 @@ static void CL_RelinkNetworkEntities(void)
                ent->render.alpha = ent->state_current.alpha * (1.0f / 255.0f); // FIXME: interpolate?
                ent->render.scale = ent->state_current.scale * (1.0f / 16.0f); // FIXME: interpolate?
 
+               if (ent->render.model && ent->render.model->flags & EF_ROTATE)
+               {
+                       ent->render.angles[1] = bobjrotate;
+                       ent->render.origin[2] += bobjoffset;
+               }
+
+               Matrix4x4_CreateFromQuakeEntity(&ent->render.matrix, ent->render.origin[0], ent->render.origin[1], ent->render.origin[2], ent->render.angles[0], ent->render.angles[1], ent->render.angles[2], ent->render.scale);
+
                // update interpolation info
                CL_LerpUpdate(ent);
 
@@ -659,11 +704,9 @@ static void CL_RelinkNetworkEntities(void)
 
                if (ent->persistent.muzzleflash > 0)
                {
-                       AngleVectors (ent->render.angles, v, NULL, NULL);
-
-                       v2[0] = v[0] * 18 + neworg[0];
-                       v2[1] = v[1] * 18 + neworg[1];
-                       v2[2] = v[2] * 18 + neworg[2] + 16;
+                       v2[0] = ent->render.matrix.m[0][0] * 18 + neworg[0];
+                       v2[1] = ent->render.matrix.m[0][1] * 18 + neworg[1];
+                       v2[2] = ent->render.matrix.m[0][2] * 18 + neworg[2] + 16;
                        CL_TraceLine(neworg, v2, v, NULL, 0, true, NULL);
 
                        CL_AllocDlight (NULL, v, ent->persistent.muzzleflash, 1, 1, 1, 0, 0);
@@ -673,11 +716,7 @@ static void CL_RelinkNetworkEntities(void)
                // LordHavoc: if the model has no flags, don't check each
                if (ent->render.model && ent->render.model->flags)
                {
-                       if (ent->render.model->flags & EF_ROTATE)
-                       {
-                               ent->render.angles[1] = bobjrotate;
-                               ent->render.origin[2] += bobjoffset;
-                       }
+                       // note: EF_ROTATE handled above, above matrix calculation
                        // only do trails if present in the previous frame as well
                        if (ent->state_previous.active)
                        {
@@ -752,6 +791,16 @@ static void CL_RelinkNetworkEntities(void)
                if (effects & EF_NODRAW)
                        continue;
 
+               // store a list of view-relative entities for later adjustment in view code
+               if (ent->render.flags & RENDER_VIEWMODEL)
+               {
+                       if (numviewmodels < MAXVIEWMODELS)
+                               viewmodels[numviewmodels++] = ent;
+                       continue;
+               }
+
+               Matrix4x4_Invert_Simple(&ent->render.inversematrix, &ent->render.matrix);
+
                CL_BoundingBoxForEntity(&ent->render);
                if (ent->render.model && ent->render.model->name[0] == '*' && ent->render.model->type == mod_brush)
                        cl_brushmodel_entities[cl_num_brushmodel_entities++] = &ent->render;
@@ -840,13 +889,15 @@ static void CL_RelinkEffects(void)
                                ent->render.frame2time = e->frame2time;
 
                                // normal stuff
-                               VectorCopy(e->origin, ent->render.origin);
+                               //VectorCopy(e->origin, ent->render.origin);
                                ent->render.model = cl.model_precache[e->modelindex];
                                ent->render.frame = ent->render.frame2;
                                ent->render.colormap = -1; // no special coloring
-                               ent->render.scale = 1;
+                               //ent->render.scale = 1;
                                ent->render.alpha = 1;
 
+                               Matrix4x4_CreateFromQuakeEntity(&ent->render.matrix, e->origin[0], e->origin[1], e->origin[2], 0, 0, 0, 1);
+                               Matrix4x4_Invert_Simple(&ent->render.inversematrix, &ent->render.matrix);
                                CL_BoundingBoxForEntity(&ent->render);
                        }
                }
@@ -940,12 +991,14 @@ void CL_RelinkBeams (void)
                        ent = CL_NewTempEntity ();
                        if (!ent)
                                return;
-                       VectorCopy (org, ent->render.origin);
+                       //VectorCopy (org, ent->render.origin);
                        ent->render.model = b->model;
                        ent->render.effects = EF_FULLBRIGHT;
-                       ent->render.angles[0] = pitch;
-                       ent->render.angles[1] = yaw;
-                       ent->render.angles[2] = rand()%360;
+                       //ent->render.angles[0] = pitch;
+                       //ent->render.angles[1] = yaw;
+                       //ent->render.angles[2] = rand()%360;
+                       Matrix4x4_CreateFromQuakeEntity(&ent->render.matrix, org[0], org[1], org[2], pitch, yaw, lhrandom(0, 360), 1);
+                       Matrix4x4_Invert_Simple(&ent->render.inversematrix, &ent->render.matrix);
                        CL_BoundingBoxForEntity(&ent->render);
                        VectorMA(org, 30, dist, org);
                        d -= 30;
index bbc18f7..fcf885c 100644 (file)
@@ -449,8 +449,10 @@ void CL_ParseServerInfo (void)
        // entire entity array was cleared, so just fill in a few fields
        ent->state_current.active = true;
        ent->render.model = cl.worldmodel = cl.model_precache[1];
-       ent->render.scale = 1;
+       //ent->render.scale = 1;
        ent->render.alpha = 1;
+       Matrix4x4_CreateFromQuakeEntity(&ent->render.matrix, 0, 0, 0, 0, 0, 0, 1);
+       Matrix4x4_Invert_Simple(&ent->render.inversematrix, &ent->render.matrix);
        CL_BoundingBoxForEntity(&ent->render);
        // clear entlife array
        memset(entlife, 0, MAX_EDICTS);
@@ -846,12 +848,13 @@ void CL_ParseStatic (int large)
        ent->render.skinnum = ent->state_baseline.skin;
        ent->render.effects = ent->state_baseline.effects;
        ent->render.alpha = 1;
-       ent->render.scale = 1;
-       ent->render.alpha = 1;
+       //ent->render.scale = 1;
 
-       VectorCopy (ent->state_baseline.origin, ent->render.origin);
-       VectorCopy (ent->state_baseline.angles, ent->render.angles);
+       //VectorCopy (ent->state_baseline.origin, ent->render.origin);
+       //VectorCopy (ent->state_baseline.angles, ent->render.angles);
 
+       Matrix4x4_CreateFromQuakeEntity(&ent->render.matrix, ent->state_baseline.origin[0], ent->state_baseline.origin[1], ent->state_baseline.origin[2], ent->state_baseline.angles[0], ent->state_baseline.angles[1], ent->state_baseline.angles[2], 1);
+       Matrix4x4_Invert_Simple(&ent->render.inversematrix, &ent->render.matrix);
        CL_BoundingBoxForEntity(&ent->render);
 
        // This is definitely cheating...
index 1e751c9..6c74320 100644 (file)
@@ -511,7 +511,6 @@ int VIS_CullSphere(const vec3_t origin, vec_t radius)
 static void R_MarkEntities (void)
 {
        int i;
-       vec3_t v;
        entity_render_t *ent;
 
        ent = &cl_entities[0].render;
@@ -528,26 +527,10 @@ static void R_MarkEntities (void)
        {
                ent = r_refdef.entities[i];
                Mod_CheckLoaded(ent->model);
-
-               // move view-relative models to where they should be
-               if (ent->flags & RENDER_VIEWMODEL)
-               {
-                       // remove flag so it will not be repeated incase RelinkEntities is not called again for a while
-                       ent->flags -= RENDER_VIEWMODEL;
-                       // transform origin
-                       VectorCopy(ent->origin, v);
-                       ent->origin[0] = v[0] * vpn[0] + v[1] * vright[0] + v[2] * vup[0] + r_origin[0];
-                       ent->origin[1] = v[0] * vpn[1] + v[1] * vright[1] + v[2] * vup[1] + r_origin[1];
-                       ent->origin[2] = v[0] * vpn[2] + v[1] * vright[2] + v[2] * vup[2] + r_origin[2];
-                       // adjust angles
-                       VectorAdd(ent->angles, r_refdef.viewangles, ent->angles);
-               }
-
-               VectorCopy(ent->angles, v);
-               if (!ent->model || ent->model->type != mod_brush)
-                       v[0] = -v[0];
-               Matrix4x4_CreateFromQuakeEntity(&ent->matrix, ent->origin[0], ent->origin[1], ent->origin[2], v[0], v[1], v[2], ent->scale);
-               Matrix4x4_Invert_Simple(&ent->inversematrix, &ent->matrix);
+               // some of the renderer still relies on origin...
+               Matrix4x4_OriginFromMatrix(&ent->matrix, ent->origin);
+               // some of the renderer still relies on scale...
+               ent->scale = Matrix4x4_ScaleFromMatrix(&ent->matrix);
                R_LerpAnimation(ent);
                R_UpdateEntLights(ent);
                if ((chase_active.integer || !(ent->flags & RENDER_EXTERIORMODEL))
diff --git a/view.c b/view.c
index 4b46ffc..121b922 100644 (file)
--- a/view.c
+++ b/view.c
@@ -71,7 +71,7 @@ float V_CalcRoll (vec3_t angles, vec3_t velocity)
        float   sign;
        float   side;
        float   value;
-       
+
        AngleVectors (angles, NULL, right, NULL);
        side = DotProduct (velocity, right);
        sign = side < 0 ? -1 : 1;
@@ -224,9 +224,12 @@ V_ParseDamage
 void V_ParseDamage (void)
 {
        int i, armor, blood;
-       vec3_t from, forward, right;
+       vec3_t from;
+       //vec3_t forward, right;
+       vec3_t localfrom;
        entity_t *ent;
-       float side, count;
+       //float side;
+       float count;
 
        armor = MSG_ReadByte ();
        blood = MSG_ReadByte ();
@@ -268,19 +271,24 @@ void V_ParseDamage (void)
 // calculate view angle kicks
 //
        ent = &cl_entities[cl.viewentity];
+       Matrix4x4_Transform(&ent->render.inversematrix, from, localfrom);
+       VectorNormalize(localfrom);
+       v_dmg_pitch = count * localfrom[0] * v_kickpitch.value;
+       v_dmg_roll = count * localfrom[1] * v_kickroll.value;
+       v_dmg_time = v_kicktime.value;
 
-       VectorSubtract (from, ent->render.origin, from);
-       VectorNormalize (from);
+       //VectorSubtract (from, ent->render.origin, from);
+       //VectorNormalize (from);
 
-       AngleVectors (ent->render.angles, forward, right, NULL);
+       //AngleVectors (ent->render.angles, forward, right, NULL);
 
-       side = DotProduct (from, right);
-       v_dmg_roll = count*side*v_kickroll.value;
+       //side = DotProduct (from, right);
+       //v_dmg_roll = count*side*v_kickroll.value;
 
-       side = DotProduct (from, forward);
-       v_dmg_pitch = count*side*v_kickpitch.value;
+       //side = DotProduct (from, forward);
+       //v_dmg_pitch = count*side*v_kickpitch.value;
 
-       v_dmg_time = v_kicktime.value;
+       //v_dmg_time = v_kicktime.value;
 }
 
 static cshift_t v_cshift;
@@ -463,6 +471,44 @@ static void V_AddIdle (float idle)
        r_refdef.viewangles[YAW] += idle * sin(cl.time*v_iyaw_cycle.value) * v_iyaw_level.value;
 }
 
+#define MAXVIEWMODELS 32
+extern int numviewmodels;
+extern entity_t *viewmodels[MAXVIEWMODELS];
+void V_LinkViewEntities(void)
+{
+       int i;
+       //float v[3];
+       entity_t *ent;
+       matrix4x4_t matrix, matrix2;
+
+       if (numviewmodels <= 0)
+               return;
+
+       //Matrix4x4_CreateRotate(&matrix, 1, 0, 0, r_refdef.viewangles[0]);
+       //Matrix4x4_CreateRotate(&matrix, 0, 1, 0, r_refdef.viewangles[0]);
+       //Matrix4x4_CreateRotate(&matrix, 0, 0, 1, r_refdef.viewangles[0]);
+       Matrix4x4_CreateFromQuakeEntity(&matrix, r_refdef.vieworg[0], r_refdef.vieworg[1], r_refdef.vieworg[2], r_refdef.viewangles[0], r_refdef.viewangles[1], r_refdef.viewangles[2], 0.3);
+       for (i = 0;i < numviewmodels && r_refdef.numentities < r_refdef.maxentities;i++)
+       {
+               ent = viewmodels[i];
+               r_refdef.entities[r_refdef.numentities++] = &ent->render;
+
+               //VectorCopy(ent->render.origin, v);
+               //ent->render.origin[0] = v[0] * vpn[0] + v[1] * vright[0] + v[2] * vup[0] + r_refdef.vieworg[0];
+               //ent->render.origin[1] = v[0] * vpn[1] + v[1] * vright[1] + v[2] * vup[1] + r_refdef.vieworg[1];
+               //ent->render.origin[2] = v[0] * vpn[2] + v[1] * vright[2] + v[2] * vup[2] + r_refdef.vieworg[2];
+               //ent->render.angles[0] = ent->render.angles[0] + r_refdef.viewangles[0];
+               //ent->render.angles[1] = ent->render.angles[1] + r_refdef.viewangles[1];
+               //ent->render.angles[2] = ent->render.angles[2] + r_refdef.viewangles[2];
+               //ent->render.scale *= 0.3;
+
+               //Matrix4x4_CreateFromQuakeEntity(&ent->render.matrix, ent->render.origin[0], ent->render.origin[1], ent->render.origin[2], ent->render.angles[0], ent->render.angles[1], ent->render.angles[2], ent->render.scale);
+               matrix2 = ent->render.matrix;
+               Matrix4x4_Concat(&ent->render.matrix, &matrix, &matrix2);
+               Matrix4x4_Invert_Simple(&ent->render.inversematrix, &ent->render.matrix);
+               CL_BoundingBoxForEntity(&ent->render);
+       }
+}
 
 /*
 ==================
@@ -472,11 +518,7 @@ V_CalcRefdef
 */
 void V_CalcRefdef (void)
 {
-       entity_t        *ent, *view;
-       vec3_t          forward;
-       vec3_t          angles;
-       float           bob;
-       float           side;
+       entity_t *ent, *view;
 
        if (cls.state != ca_connected || cls.signon != SIGNONS)
                return;
@@ -500,14 +542,14 @@ void V_CalcRefdef (void)
        }
        else if (chase_active.value)
        {
+               view->render.model = NULL;
                r_refdef.vieworg[2] += cl.viewheight;
                Chase_Update ();
                V_AddIdle (v_idlescale.value);
        }
        else
        {
-               side = V_CalcRoll (cl_entities[cl.viewentity].render.angles, cl.velocity);
-               r_refdef.viewangles[ROLL] += side;
+               r_refdef.viewangles[ROLL] += V_CalcRoll (cl.viewangles, cl.velocity);
 
                if (v_dmg_time > 0)
                {
@@ -521,16 +563,7 @@ void V_CalcRefdef (void)
 
                V_AddIdle (v_idlescale.value);
 
-               // offsets
-               angles[PITCH] = -ent->render.angles[PITCH];     // because entity pitches are actually backward
-               angles[YAW] = ent->render.angles[YAW];
-               angles[ROLL] = ent->render.angles[ROLL];
-
-               AngleVectors (angles, forward, NULL, NULL);
-
-               bob = V_CalcBob ();
-
-               r_refdef.vieworg[2] += cl.viewheight + bob;
+               r_refdef.vieworg[2] += cl.viewheight + V_CalcBob ();
 
                // LordHavoc: origin view kick added
                if (!intimerefresh)
@@ -543,24 +576,28 @@ void V_CalcRefdef (void)
                // (FIXME! this should be in cl_main.c with the other linking code, not view.c!)
                view->state_current.modelindex = cl.stats[STAT_WEAPON];
                view->state_current.frame = cl.stats[STAT_WEAPONFRAME];
-               VectorCopy(r_refdef.vieworg, view->render.origin);
-               //view->render.origin[0] = ent->render.origin[0] + bob * 0.4 * forward[0];
-               //view->render.origin[1] = ent->render.origin[1] + bob * 0.4 * forward[1];
-               //view->render.origin[2] = ent->render.origin[2] + bob * 0.4 * forward[2] + cl.viewheight + bob;
-               view->render.angles[PITCH] = -r_refdef.viewangles[PITCH] - v_idlescale.value * sin(cl.time*v_iyaw_cycle.value) * v_iyaw_level.value;
-               view->render.angles[YAW] = r_refdef.viewangles[YAW] - v_idlescale.value * sin(cl.time*v_ipitch_cycle.value) * v_ipitch_level.value;
-               view->render.angles[ROLL] = r_refdef.viewangles[ROLL] - v_idlescale.value * sin(cl.time*v_iroll_cycle.value) * v_iroll_level.value;
+               //VectorCopy(r_refdef.vieworg, view->render.origin);
+               //view->render.angles[PITCH] = r_refdef.viewangles[PITCH] + v_idlescale.value * sin(cl.time*v_iyaw_cycle.value) * v_iyaw_level.value;
+               //view->render.angles[YAW] = r_refdef.viewangles[YAW] - v_idlescale.value * sin(cl.time*v_ipitch_cycle.value) * v_ipitch_level.value;
+               //view->render.angles[ROLL] = r_refdef.viewangles[ROLL] - v_idlescale.value * sin(cl.time*v_iroll_cycle.value) * v_iroll_level.value;
+               //view->render.scale = 1.0 / 3.0;
+               Matrix4x4_CreateFromQuakeEntity(&view->render.matrix, r_refdef.vieworg[0], r_refdef.vieworg[1], r_refdef.vieworg[2], r_refdef.viewangles[PITCH] + v_idlescale.value * sin(cl.time*v_iyaw_cycle.value) * v_iyaw_level.value, r_refdef.viewangles[YAW] - v_idlescale.value * sin(cl.time*v_ipitch_cycle.value) * v_ipitch_level.value, r_refdef.viewangles[ROLL] - v_idlescale.value * sin(cl.time*v_iroll_cycle.value) * v_iroll_level.value, 0.3);
+               Matrix4x4_Invert_Simple(&view->render.inversematrix, &view->render.matrix);
+               CL_BoundingBoxForEntity(&view->render);
                // FIXME: this setup code is somewhat evil (CL_LerpUpdate should be private?)
                CL_LerpUpdate(view);
-               CL_BoundingBoxForEntity(&view->render);
                view->render.colormap = -1; // no special coloring
                view->render.alpha = ent->render.alpha; // LordHavoc: if the player is transparent, so is the gun
                view->render.effects = ent->render.effects;
-               view->render.scale = 1.0 / 3.0;
+               AngleVectors(r_refdef.viewangles, vpn, vright, vup);
 
                // link into render entities list
-               if (r_refdef.numentities < r_refdef.maxentities && r_drawviewmodel.integer && !chase_active.integer && !envmap && r_drawentities.integer && !(cl.items & IT_INVISIBILITY) && cl.stats[STAT_HEALTH] > 0 && view->render.model != NULL)
-                       r_refdef.entities[r_refdef.numentities++] = &view->render;
+               if (r_drawviewmodel.integer && !chase_active.integer && !envmap && r_drawentities.integer && !(cl.items & IT_INVISIBILITY) && cl.stats[STAT_HEALTH] > 0)
+               {
+                       if (r_refdef.numentities < r_refdef.maxentities && view->render.model != NULL)
+                               r_refdef.entities[r_refdef.numentities++] = &view->render;
+                       V_LinkViewEntities();
+               }
        }
 }