- ent = viewmodels[i];
- r_refdef.entities[r_refdef.numentities++] = &ent->render;
- matrix2 = ent->render.matrix;
- Matrix4x4_Concat(&ent->render.matrix, &matrix, &matrix2);
- Matrix4x4_Invert_Simple(&ent->render.inversematrix, &ent->render.matrix);
- CL_BoundingBoxForEntity(&ent->render);
+ // calculate for swinging gun model
+ // the gun bobs when running on the ground, but doesn't bob when you're in the air.
+ // Sajt: I tried to smooth out the transitions between bob and no bob, which works
+ // for the most part, but for some reason when you go through a message trigger or
+ // pick up an item or anything like that it will momentarily jolt the gun.
+ vec3_t forward, right, up;
+ float bspeed;
+ float s;
+ float t;
+
+ s = cl.time * cl_bobmodel_speed.value;
+ if (cl.onground)
+ {
+ if (cl.time - cl.hitgroundtime < 0.2)
+ {
+ // just hit the ground, speed the bob back up over the next 0.2 seconds
+ t = cl.time - cl.hitgroundtime;
+ t = bound(0, t, 0.2);
+ t *= 5;
+ }
+ else
+ t = 1;
+ }
+ else
+ {
+ // recently left the ground, slow the bob down over the next 0.2 seconds
+ t = cl.time - cl.lastongroundtime;
+ t = 0.2 - bound(0, t, 0.2);
+ t *= 5;
+ }
+
+ bspeed = bound (0, xyspeed, 400) * 0.01f;
+ AngleVectors (viewangles, forward, right, up);
+ bob = bspeed * cl_bobmodel_side.value * sin (s) * t;
+ VectorMA (gunorg, bob, right, gunorg);
+ bob = bspeed * cl_bobmodel_up.value * cos (s * 2) * t;
+ VectorMA (gunorg, bob, up, gunorg);