- VectorSubtract(cl.gunangles_highpass, cl.gunangles_prev, cl.gunangles_highpass);
-
- // 3. calculate the RAW adjustment vectors
- gunorg[0] *= (cl_followmodel.value ? -cl_followmodel_side_speed.value : 0);
- gunorg[1] *= (cl_followmodel.value ? -cl_followmodel_side_speed.value : 0);
- gunorg[2] *= (cl_followmodel.value ? -cl_followmodel_up_speed.value : 0);
-
- gunangles[PITCH] *= (cl_leanmodel.value ? -cl_leanmodel_up_speed.value : 0);
- gunangles[YAW] *= (cl_leanmodel.value ? -cl_leanmodel_side_speed.value : 0);
- gunangles[ROLL] = 0;
-
- // 4. perform highpass/lowpass on the adjustment vectors (turning velocity into acceleration!)
- // trick: we must do the lowpass LAST, so the lowpass vector IS the final vector!
- highpass3(gunorg, frametime*cl_followmodel_side_highpass.value, frametime*cl_followmodel_side_highpass.value, frametime*cl_followmodel_up_highpass.value, cl.gunorg_adjustment_highpass, gunorg);
- lowpass3(gunorg, frametime*cl_followmodel_side_lowpass.value, frametime*cl_followmodel_side_lowpass.value, frametime*cl_followmodel_up_lowpass.value, cl.gunorg_adjustment_lowpass, gunorg);
- // we assume here: PITCH = 0, YAW = 1, ROLL = 2
- highpass3(gunangles, frametime*cl_leanmodel_up_highpass.value, frametime*cl_leanmodel_side_highpass.value, 0, cl.gunangles_adjustment_highpass, gunangles);
- lowpass3(gunangles, frametime*cl_leanmodel_up_lowpass.value, frametime*cl_leanmodel_side_lowpass.value, 0, cl.gunangles_adjustment_lowpass, gunangles);
-
- // 5. use the adjusted vectors
- VectorAdd(vieworg, gunorg, gunorg);
- VectorAdd(viewangles, gunangles, gunangles);
-
- // bounded XY speed, used by several effects below
- xyspeed = bound (0, sqrt(cl.velocity[0]*cl.velocity[0] + cl.velocity[1]*cl.velocity[1]), 400);
-
- // vertical view bobbing code
- if (cl_bob.value && cl_bobcycle.value)
+ VectorCopy(vieworg, cl.gunorg_prev);
+ }
+
+ // 2. for the gun origin, only keep the high frequency (non-DC) parts, which is "somewhat like velocity"
+ VectorAdd(cl.gunorg_highpass, cl.gunorg_prev, cl.gunorg_highpass);
+ highpass3_limited(vieworg, frametime*cl_followmodel_side_highpass1.value, cl_followmodel_side_limit.value, frametime*cl_followmodel_side_highpass1.value, cl_followmodel_side_limit.value, frametime*cl_followmodel_up_highpass1.value, cl_followmodel_up_limit.value, cl.gunorg_highpass, gunorg);
+ VectorCopy(vieworg, cl.gunorg_prev);
+ VectorSubtract(cl.gunorg_highpass, cl.gunorg_prev, cl.gunorg_highpass);
+
+ // in the highpass, we _store_ the DIFFERENCE to the actual view angles...
+ VectorAdd(cl.gunangles_highpass, cl.gunangles_prev, cl.gunangles_highpass);
+ cl.gunangles_highpass[PITCH] += 360 * floor((viewangles[PITCH] - cl.gunangles_highpass[PITCH]) / 360 + 0.5);
+ cl.gunangles_highpass[YAW] += 360 * floor((viewangles[YAW] - cl.gunangles_highpass[YAW]) / 360 + 0.5);
+ cl.gunangles_highpass[ROLL] += 360 * floor((viewangles[ROLL] - cl.gunangles_highpass[ROLL]) / 360 + 0.5);
+ highpass3_limited(viewangles, frametime*cl_leanmodel_up_highpass1.value, cl_leanmodel_up_limit.value, frametime*cl_leanmodel_side_highpass1.value, cl_leanmodel_side_limit.value, 0, 0, cl.gunangles_highpass, gunangles);
+ VectorCopy(viewangles, cl.gunangles_prev);
+ VectorSubtract(cl.gunangles_highpass, cl.gunangles_prev, cl.gunangles_highpass);
+
+ // 3. calculate the RAW adjustment vectors
+ gunorg[0] *= (cl_followmodel.value ? -cl_followmodel_side_speed.value : 0);
+ gunorg[1] *= (cl_followmodel.value ? -cl_followmodel_side_speed.value : 0);
+ gunorg[2] *= (cl_followmodel.value ? -cl_followmodel_up_speed.value : 0);
+
+ gunangles[PITCH] *= (cl_leanmodel.value ? -cl_leanmodel_up_speed.value : 0);
+ gunangles[YAW] *= (cl_leanmodel.value ? -cl_leanmodel_side_speed.value : 0);
+ gunangles[ROLL] = 0;
+
+ // 4. perform highpass/lowpass on the adjustment vectors (turning velocity into acceleration!)
+ // trick: we must do the lowpass LAST, so the lowpass vector IS the final vector!
+ highpass3(gunorg, frametime*cl_followmodel_side_highpass.value, frametime*cl_followmodel_side_highpass.value, frametime*cl_followmodel_up_highpass.value, cl.gunorg_adjustment_highpass, gunorg);
+ lowpass3(gunorg, frametime*cl_followmodel_side_lowpass.value, frametime*cl_followmodel_side_lowpass.value, frametime*cl_followmodel_up_lowpass.value, cl.gunorg_adjustment_lowpass, gunorg);
+ // we assume here: PITCH = 0, YAW = 1, ROLL = 2
+ highpass3(gunangles, frametime*cl_leanmodel_up_highpass.value, frametime*cl_leanmodel_side_highpass.value, 0, cl.gunangles_adjustment_highpass, gunangles);
+ lowpass3(gunangles, frametime*cl_leanmodel_up_lowpass.value, frametime*cl_leanmodel_side_lowpass.value, 0, cl.gunangles_adjustment_lowpass, gunangles);
+
+ // 5. use the adjusted vectors
+ VectorAdd(vieworg, gunorg, gunorg);
+ VectorAdd(viewangles, gunangles, gunangles);
+
+ // bounded XY speed, used by several effects below
+ xyspeed = bound (0, sqrt(clvelocity[0]*clvelocity[0] + clvelocity[1]*clvelocity[1]), 400);
+
+ // vertical view bobbing code
+ if (cl_bob.value && cl_bobcycle.value)
+ {
+ // LordHavoc: this code is *weird*, but not replacable (I think it
+ // should be done in QC on the server, but oh well, quake is quake)
+ // LordHavoc: figured out bobup: the time at which the sin is at 180
+ // degrees (which allows lengthening or squishing the peak or valley)
+ cycle = cl.time / cl_bobcycle.value;
+ cycle -= (int) cycle;
+ if (cycle < cl_bobup.value)
+ cycle = sin(M_PI * cycle / cl_bobup.value);
+ else
+ cycle = sin(M_PI + M_PI * (cycle-cl_bobup.value)/(1.0 - cl_bobup.value));
+ // bob is proportional to velocity in the xy plane
+ // (don't count Z, or jumping messes it up)
+ bob = xyspeed * bound(0, cl_bob.value, 0.05);
+ bob = bob*0.3 + bob*0.7*cycle;
+ vieworg[2] += bob;
+ // we also need to adjust gunorg, or this appears like pushing the gun!
+ // In the old code, this was applied to vieworg BEFORE copying to gunorg,
+ // but this is not viable with the new followmodel code as that would mean
+ // that followmodel would work on the munged-by-bob vieworg and do feedback
+ gunorg[2] += bob;
+ }
+
+ // horizontal view bobbing code
+ if (cl_bob2.value && cl_bob2cycle.value)
+ {
+ vec3_t bob2vel;
+ vec3_t forward, right, up;
+ float side, front;
+
+ cycle = cl.time / cl_bob2cycle.value;
+ cycle -= (int) cycle;
+ if (cycle < 0.5)
+ cycle = cos(M_PI * cycle / 0.5); // cos looks better here with the other view bobbing using sin
+ else
+ cycle = cos(M_PI + M_PI * (cycle-0.5)/0.5);
+ bob = bound(0, cl_bob2.value, 0.05) * cycle;
+
+ // this value slowly decreases from 1 to 0 when we stop touching the ground.
+ // The cycle is later multiplied with it so the view smooths back to normal
+ if (clonground && !clcmdjump) // also block the effect while the jump button is pressed, to avoid twitches when bunny-hopping
+ cl.bob2_smooth = 1;
+ else