From: terencehill Date: Fri, 31 Mar 2023 22:10:28 +0000 (+0200) Subject: Demo camera (camera_enable 1): fix jerky mouse movement X-Git-Tag: xonotic-v0.8.6~86^2 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=db15d3dcf8f7e71ded3f5ead67181d249dc0ab72;p=xonotic%2Fxonotic-data.pk3dir.git Demo camera (camera_enable 1): fix jerky mouse movement --- diff --git a/qcsrc/client/view.qc b/qcsrc/client/view.qc index a9ad0a76b..c9de0d156 100644 --- a/qcsrc/client/view.qc +++ b/qcsrc/client/view.qc @@ -1742,7 +1742,7 @@ vector camera_offset, current_camera_offset, mouse_angles, current_angles, curre void CSQC_Demo_Camera() { float speed, attenuation, dimensions; - vector tmp, delta; + vector tmp; if( autocvar_camera_reset || !camera_mode ) { @@ -1783,30 +1783,22 @@ void CSQC_Demo_Camera() } } - while (mouse_angles.x < -180) mouse_angles.x = mouse_angles.x + 360; - while (mouse_angles.x > 180) mouse_angles.x = mouse_angles.x - 360; - while (mouse_angles.y < -180) mouse_angles.y = mouse_angles.y + 360; - while (mouse_angles.y > 180) mouse_angles.y = mouse_angles.y - 360; - - // Fix difference when angles don't have the same sign - delta = '0 0 0'; - if(mouse_angles.y < -60 && current_angles.y > 60) - delta = '0 360 0'; - if(mouse_angles.y > 60 && current_angles.y < -60) - delta = '0 -360 0'; - if(autocvar_camera_look_player) attenuation = autocvar_camera_look_attenuation; else attenuation = autocvar_camera_speed_attenuation; attenuation = 1 / max(1, attenuation); - current_angles += (mouse_angles - current_angles + delta) * attenuation; + current_angles += (mouse_angles - current_angles) * attenuation; + + // limit current pitch angle to sane values + if (current_angles.x < -90) current_angles.x = -90; + if (current_angles.x > 90 ) current_angles.x = 90; - while (current_angles.x < -180) current_angles.x = current_angles.x + 360; - while (current_angles.x > 180) current_angles.x = current_angles.x - 360; - while (current_angles.y < -180) current_angles.y = current_angles.y + 360; - while (current_angles.y > 180) current_angles.y = current_angles.y - 360; + // limit mouse and current yaw angles to standard values simultaneously so that the difference + // between these angles is not altered + while (current_angles.y < -180 && mouse_angles.y < -180) {current_angles.y += 360; mouse_angles.y += 360;} + while (current_angles.y > 180 && mouse_angles.y > 180 ) {current_angles.y -= 360; mouse_angles.y -= 360;} // Camera position tmp = '0 0 0';