]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Demo camera (camera_enable 1): fix jerky mouse movement
authorterencehill <piuntn@gmail.com>
Fri, 31 Mar 2023 22:10:28 +0000 (00:10 +0200)
committerterencehill <piuntn@gmail.com>
Fri, 31 Mar 2023 22:10:28 +0000 (00:10 +0200)
qcsrc/client/view.qc

index a9ad0a76bd7e612d58fdeaafa49a40cc27d8fa66..c9de0d15626ceb79ebf58aadbcf32b523ef5953f 100644 (file)
@@ -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';