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

Steve Lhomme robux4 at videolabs.io
Fri Nov 4 18:08:58 CET 2016


--
* replaces the vrnav module
* dragging the mouse drags the "world" rather than moving in the "world"
---
 src/video_output/display.c       | 26 +++++++++++++++++++++++++-
 src/video_output/video_output.c  |  1 +
 src/video_output/vout_internal.h |  5 +++++
 3 files changed, 31 insertions(+), 1 deletion(-)

diff --git a/src/video_output/display.c b/src/video_output/display.c
index 4ee4a7c..dfd11bc 100644
--- a/src/video_output/display.c
+++ b/src/video_output/display.c
@@ -1678,7 +1678,16 @@ 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->b_projection_nav = true;
+            vout->p->src_viewpoint = vout->p->display.vd->owner.sys->viewpoint;
+            vout->p->i_src_x = x;
+            vout->p->i_src_y = y;
+        }
+        else
+            var_SetBool(vout->obj.libvlc, "intf-popupmenu", false);
         return;
     }
     case MOUSE_BUTTON_CENTER:
@@ -1697,11 +1706,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->b_projection_nav)
+        vout->p->b_projection_nav = 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->b_projection_nav )
+    {
+        vlc_viewpoint_t viewpoint = p_sys->src_viewpoint;
+        int i_horizontal = x - p_sys->i_src_x;
+        int i_vertical   = y - p_sys->i_src_y;
+
+        viewpoint.f_yaw   -= (float)i_horizontal / 300;
+        viewpoint.f_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 e426525..bcd4e86 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->b_projection_nav = 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..f010eaf 100644
--- a/src/video_output/vout_internal.h
+++ b/src/video_output/vout_internal.h
@@ -130,6 +130,11 @@ 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 */
+    bool             b_projection_nav;
+    vlc_viewpoint_t  src_viewpoint;
+    int              i_src_x, i_src_y;
 };
 
 /* TODO to move them to vlc_vout.h */
-- 
2.10.1



More information about the vlc-devel mailing list