[vlc-devel] [PATCH 15/15] core: handle the mouse navigation in VR/360° videos in the core

Steve Lhomme robux4 at videolabs.io
Mon Nov 7 10:52:04 CET 2016


--
* replaces the vrnav module
* dragging the mouse drags the "world" rather than moving in the "world"

replaces https://patches.videolan.org/patch/14922/
* put the new fields in a union
---
 src/video_output/display.c       | 27 ++++++++++++++++++++++++++-
 src/video_output/video_output.c  |  1 +
 src/video_output/vout_internal.h |  7 +++++++
 3 files changed, 34 insertions(+), 1 deletion(-)

diff --git a/src/video_output/display.c b/src/video_output/display.c
index 535b3c3..5346788 100644
--- a/src/video_output/display.c
+++ b/src/video_output/display.c
@@ -1678,7 +1678,17 @@ static inline void vout_SendEventMousePressed(vout_thread_t *vout, int button)
         int x, y;
         var_GetCoords(vout, "mouse-moved", &x, &y);
         var_SetCoords(vout, "mouse-clicked", x, y);
-        var_SetBool(vout->obj.libvlc, "intf-popupmenu", false);
+        if ( vout->p->display.vd &&
+             vout->p->display.vd->projection != VOUT_PROJECTION_FLAT )
+        {
+            vout->p->vr_navigation.b_enabled = true;
+            vout->p->vr_navigation.viewpoint =
+                    vout->p->display.vd->owner.sys->viewpoint;
+            vout->p->vr_navigation.x = x;
+            vout->p->vr_navigation.y = y;
+        }
+        else
+            var_SetBool(vout->obj.libvlc, "intf-popupmenu", false);
         return;
     }
     case MOUSE_BUTTON_CENTER:
@@ -1697,11 +1707,26 @@ static inline void vout_SendEventMousePressed(vout_thread_t *vout, int button)
 static inline void vout_SendEventMouseReleased(vout_thread_t *vout, int button)
 {
     var_NAndInteger(vout, "mouse-button-down", 1 << button);
+    if (button == MOUSE_BUTTON_LEFT && vout->p->vr_navigation.b_enabled)
+        vout->p->vr_navigation.b_enabled = false;
 }
 
 static inline void vout_SendEventMouseMoved(vout_thread_t *vout, int x, int y)
 {
     var_SetCoords(vout, "mouse-moved", x, y);
+
+    vout_thread_sys_t *p_sys = vout->p;
+    if( p_sys->vr_navigation.b_enabled )
+    {
+        vlc_viewpoint_t viewpoint = p_sys->vr_navigation.viewpoint;
+        int i_horizontal = x - p_sys->vr_navigation.x;
+        int i_vertical   = y - p_sys->vr_navigation.y;
+
+        viewpoint.yaw   -= (float)i_horizontal / 300;
+        viewpoint.pitch -= (float)i_vertical   / 400;
+
+        vout_SetDisplayViewpoint( vout->p->display.vd, &viewpoint);
+    }
 }
 
 void vout_SendDisplayEventMouse(vout_thread_t *vout, const vlc_mouse_t *m)
diff --git a/src/video_output/video_output.c b/src/video_output/video_output.c
index f3614d2..fcb3459 100644
--- a/src/video_output/video_output.c
+++ b/src/video_output/video_output.c
@@ -1330,6 +1330,7 @@ static int ThreadStart(vout_thread_t *vout, vout_display_state_t *state)
     vout->p->decoder_pool = NULL;
     vout->p->display_pool = NULL;
     vout->p->private_pool = NULL;
+    vout->p->vr_navigation.b_enabled = false;
 
     vout->p->filter.configuration = NULL;
     video_format_Copy(&vout->p->filter.format, &vout->p->original);
diff --git a/src/video_output/vout_internal.h b/src/video_output/vout_internal.h
index 5ef1435..6884372 100644
--- a/src/video_output/vout_internal.h
+++ b/src/video_output/vout_internal.h
@@ -130,6 +130,13 @@ struct vout_thread_sys_t
     picture_pool_t  *decoder_pool;
     picture_fifo_t  *decoder_fifo;
     vout_chrono_t   render;           /**< picture render time estimator */
+
+    /* VR navigation */
+    union {
+        bool             b_enabled;
+        vlc_viewpoint_t  viewpoint;
+        int              x, y;
+    } vr_navigation;
 };
 
 /* TODO to move them to vlc_vout.h */
-- 
2.10.1



More information about the vlc-devel mailing list