[vlc-devel] [PATCH 1/2] viewpoint: remove vlc_viewpoint_reverse

Alexandre Janniaux ajanni at videolabs.io
Sat Jan 9 14:10:46 UTC 2021


The function was doing the wrong operation. The underlying rotation,
which is R = Rz(roll) Rx(pitch) Ry(yaw), was transformed into the
product Rz(-roll) Rx(-pitch) Ry(-yaw), whereas the correct transformation
would have been Ry(-yaw) Rx(-pitch) Rz(-roll), which leads to a reversed
rotation order. In simpler term, this was a good idea to help understand
what was happening but it was wrongly executed.

Removing the function and using the correct input for writing the matrix
simplifies the code and makes the future quaternion code more logical.
The correct version of this process can be done later if still needed.
---
 include/vlc_viewpoint.h                 | 21 ---------------------
 modules/video_output/opengl/renderer.c  |  4 ++--
 modules/video_output/win32/d3d11_quad.c |  4 +---
 modules/video_output/win32/direct3d11.c |  1 -
 src/misc/viewpoint.c                    |  6 +++---
 5 files changed, 6 insertions(+), 30 deletions(-)

diff --git a/include/vlc_viewpoint.h b/include/vlc_viewpoint.h
index 5b218bf050..86528f4ef8 100644
--- a/include/vlc_viewpoint.h
+++ b/include/vlc_viewpoint.h
@@ -59,32 +59,11 @@ static inline void vlc_viewpoint_clip( vlc_viewpoint_t *p_vp )
                           FIELD_OF_VIEW_DEGREES_MAX );
 }
 
-/**
- * Reverse the viewpoint rotation.
- *
- * It can be used to convert a camera view into a world transformation.
- * It will also copy non-rotation related data from \p src to \p dst.
- *
- * \param dst the viewpoint with the final reversed rotation
- * \param src the viewpoint for which the rotation need to be reversed
- */
-static inline void vlc_viewpoint_reverse( vlc_viewpoint_t *dst,
-                                          const vlc_viewpoint_t *src )
-{
-    dst->yaw   = -src->yaw;
-    dst->pitch = -src->pitch;
-    dst->roll  = -src->roll;
-
-    dst->fov   = src->fov;
-}
-
 /**
  * Generate the 4x4 transform matrix corresponding to a viewpoint
  *
  * Convert a vlc_viewpoint_t into a 4x4 transform matrix with a column-major
  * layout.
- * The transformation is applied as-is. you have to reverse the viewpoint with
- * \ref vlc_viewpoint_reverse first if you want to transform the world.
  *
  * \param vp a valid viewpoint object
  * \param matrix a 4x4-sized array which will contain the matrix data
diff --git a/modules/video_output/opengl/renderer.c b/modules/video_output/opengl/renderer.c
index be93214917..795754f900 100644
--- a/modules/video_output/opengl/renderer.c
+++ b/modules/video_output/opengl/renderer.c
@@ -431,8 +431,8 @@ vlc_gl_renderer_SetViewpoint(struct vlc_gl_renderer *renderer,
     // Convert degree into radian
     float f_fovx = p_vp->fov * (float)M_PI / 180.f;
 
-    /* vgl->vp needs to be converted into world transform */
-    vlc_viewpoint_reverse(&renderer->vp, p_vp);
+    /* Copy the viewpoint for future pictures. */
+    renderer->vp = *p_vp;
 
     if (fabsf(f_fovx - renderer->f_fovx) >= 0.001f)
     {
diff --git a/modules/video_output/win32/d3d11_quad.c b/modules/video_output/win32/d3d11_quad.c
index b90ecacad8..1caf64635f 100644
--- a/modules/video_output/win32/d3d11_quad.c
+++ b/modules/video_output/win32/d3d11_quad.c
@@ -739,12 +739,10 @@ void (D3D11_UpdateViewpoint)(vlc_object_t *o, d3d11_device_t *d3d_dev, d3d_quad_
 
     float f_fovy = UpdateFOVy(f_fovx, f_sar);
     float f_z = UpdateZ(f_fovx, f_fovy);
-    vlc_viewpoint_t vp;
-    vlc_viewpoint_reverse(&vp, viewpoint);
 
     getZoomMatrix(SPHERE_RADIUS * f_z, quad->vertexConstants.Zoom);
     getProjectionMatrix(f_sar, f_fovy, quad->vertexConstants.Projection);
-    vlc_viewpoint_to_4x4(&vp, quad->vertexConstants.View);
+    vlc_viewpoint_to_4x4(viewpoint, quad->vertexConstants.View);
 
     ShaderUpdateConstants(o, d3d_dev, quad, VS_CONST_VIEWPOINT, &quad->vertexConstants);
 }
diff --git a/modules/video_output/win32/direct3d11.c b/modules/video_output/win32/direct3d11.c
index 2f10951e4c..3e3fae77ed 100644
--- a/modules/video_output/win32/direct3d11.c
+++ b/modules/video_output/win32/direct3d11.c
@@ -1340,4 +1340,3 @@ static int Direct3D11MapSubpicture(vout_display_t *vd, int *subpicture_region_co
     }
     return VLC_SUCCESS;
 }
-
diff --git a/src/misc/viewpoint.c b/src/misc/viewpoint.c
index b4fb5484af..c4b6aa4f04 100644
--- a/src/misc/viewpoint.c
+++ b/src/misc/viewpoint.c
@@ -28,9 +28,9 @@
 
 void vlc_viewpoint_to_4x4( const vlc_viewpoint_t *vp, float *m )
 {
-    float yaw   = vp->yaw   * (float)M_PI / 180.f + (float)M_PI_2;
-    float pitch = vp->pitch * (float)M_PI / 180.f;
-    float roll  = vp->roll  * (float)M_PI / 180.f;
+    float yaw   = -vp->yaw   * (float)M_PI / 180.f + (float)M_PI_2;
+    float pitch = -vp->pitch * (float)M_PI / 180.f;
+    float roll  = -vp->roll  * (float)M_PI / 180.f;
 
     float s, c;
 
-- 
2.30.0



More information about the vlc-devel mailing list