[vlc-devel] [PATCH 11/18] input: use vlc_viewpoint_from/to_euler

Alexandre Janniaux ajanni at videolabs.io
Wed Mar 31 09:25:43 UTC 2021


From: Alexandre Janniaux <alexandre.janniaux at gmail.com>

... and also clip pitch to avoid singularities in locations where a
relative viewpoint update is used. Otherwise, conversions between
viewpoints and euler angles might lead to corrupted values and blinking
pitch angles.
---
 src/input/input.c | 22 ++++++++++++++++++----
 1 file changed, 18 insertions(+), 4 deletions(-)

diff --git a/src/input/input.c b/src/input/input.c
index 69552bc3e5..b134d4f097 100644
--- a/src/input/input.c
+++ b/src/input/input.c
@@ -1758,6 +1758,10 @@ static void ControlNav( input_thread_t *p_input, int i_type )
 
     if( b_viewpoint_ch && viewpoint_updated )
     {
+        /* We need to clip the pitch here to avoid singularity poles, otherwise
+         * the next vlc_viewpoint_to_euler might reverse the pitch. */
+        pitch = VLC_CLIP(pitch, -85.f, 85.f);
+
         priv->viewpoint_changed = true;
         vlc_viewpoint_from_euler( &priv->viewpoint, yaw, pitch, roll );
         ViewpointApply( p_input );
@@ -2148,10 +2152,20 @@ static bool Control( input_thread_t *p_input,
             else
             {
                 priv->viewpoint_changed = true;
-                priv->viewpoint.yaw   += param.viewpoint.yaw;
-                priv->viewpoint.pitch += param.viewpoint.pitch;
-                priv->viewpoint.roll  += param.viewpoint.roll;
-                priv->viewpoint.fov   += param.viewpoint.fov;
+                float previous[3], update[3];
+                vlc_viewpoint_to_euler(&priv->viewpoint, &previous[0],
+                                       &previous[1], &previous[2]);
+                vlc_viewpoint_to_euler(&param.viewpoint, &update[0],
+                                       &update[1], &update[2]);
+
+                /* We need to clip the pitch here to avoid singularity poles,
+                 * otherwise the next vlc_viewpoint_to_euler might reverse
+                 * the pitch. */
+                vlc_viewpoint_from_euler(&priv->viewpoint,
+                        previous[0] + update[0],
+                        VLC_CLIP(previous[1] + update[1], -85.f, 85.f),
+                        previous[2] + update[2]);
+                priv->viewpoint.fov += param.viewpoint.fov;
             }
 
             ViewpointApply( p_input );
-- 
2.31.0



More information about the vlc-devel mailing list