- vec_t d;
-
- // gun model leaning code
- vec_t lean_speed_up = cl_leanmodel_up_speed.value * cl.realframetime * cl.movevars_timescale;
- if(cl_leanmodel_up.value && lean_speed_up >= 0 && lean_speed_up < 1) // bad things happen if this goes out of range, so prevent the effect
- {
- // prevent the gun from doing a 360* rotation when going around the 0 <-> 360 border
- if(cl.viewangles[PITCH] - gunangles[PITCH] >= 180)
- gunangles[PITCH] += 360;
- if(gunangles[PITCH] - cl.viewangles[PITCH] >= 180)
- gunangles[PITCH] -= 360;
-
- d = cl.viewangles[PITCH] - gunangles[PITCH];
- gunangles[PITCH] = bound(cl.viewangles[PITCH] - cl_leanmodel_up_limit.value, gunangles[PITCH] * (1 - lean_speed_up) + cl.viewangles[PITCH] * lean_speed_up, cl.viewangles[PITCH] + cl_leanmodel_up_limit.value);
- }
- else
- gunangles[PITCH] = cl.viewangles[PITCH];
-
- vec_t lean_speed_side = cl_leanmodel_side_speed.value * cl.realframetime * cl.movevars_timescale;
- if(cl_leanmodel_side.value && lean_speed_side >= 0 && lean_speed_side < 1) // bad things happen if this goes out of range, so prevent the effect
+ vec_t f;
+
+ // lowpass the view angles to the gun angles
+ if(cl.viewangles[PITCH] - cl.gunangles_lowpass[PITCH] >= 180)
+ cl.gunangles_lowpass[PITCH] += 360;
+ if(cl.gunangles_lowpass[PITCH] - cl.viewangles[PITCH] >= 180)
+ cl.gunangles_lowpass[PITCH] -= 360;
+ gunangles[PITCH] = bound(cl.viewangles[PITCH] - cl_leanmodel_up_limit.value, lowpass(cl.viewangles[PITCH], cl_leanmodel_up_speed.value * cl.realframetime * cl.movevars_timescale, &cl.gunangles_lowpass[PITCH]), cl.viewangles[PITCH] + cl_leanmodel_up_limit.value);
+
+ if(cl.viewangles[YAW] - cl.gunangles_lowpass[YAW] >= 180)
+ cl.gunangles_lowpass[YAW] += 360;
+ if(cl.gunangles_lowpass[YAW] - cl.viewangles[YAW] >= 180)
+ cl.gunangles_lowpass[YAW] -= 360;
+ gunangles[YAW] = bound(cl.viewangles[YAW] - cl_leanmodel_side_limit.value, lowpass(cl.viewangles[YAW], cl_leanmodel_side_speed.value * cl.realframetime * cl.movevars_timescale, &cl.gunangles_lowpass[YAW]), cl.viewangles[YAW] + cl_leanmodel_side_limit.value);
+
+ // no need to adjust these
+ gunangles[ROLL] = cl.viewangles[ROLL];
+
+ // the gun origin be the current origin minus highpass of the velocity
+ gunorg[0] = highpass(cl.movement_velocity[0] * cl_followmodel_side_speed.value, cl.realframetime * cl.movevars_timescale * cl_followmodel_side_highpass.value, &cl.gunorg_minus_vieworg_diff_highpass[0]);
+ gunorg[1] = highpass(cl.movement_velocity[1] * cl_followmodel_side_speed.value, cl.realframetime * cl.movevars_timescale * cl_followmodel_side_highpass.value, &cl.gunorg_minus_vieworg_diff_highpass[1]);
+ gunorg[2] = highpass(cl.movement_velocity[2] * cl_followmodel_up_speed.value, cl.realframetime * cl.movevars_timescale * cl_followmodel_up_highpass.value, &cl.gunorg_minus_vieworg_diff_highpass[2]);
+
+ // limit the gun origin
+ f = sqrt(gunorg[0]*gunorg[0] + gunorg[1]*gunorg[1]);
+ if(f > cl_followmodel_side_limit.value)