[vlc-devel] [PATCH 1/2] opengl: document the matrices

Steve Lhomme robux4 at videolabs.io
Wed Nov 9 10:08:31 CET 2016


---
 modules/video_output/opengl.c | 18 ++++++++++++------
 1 file changed, 12 insertions(+), 6 deletions(-)

diff --git a/modules/video_output/opengl.c b/modules/video_output/opengl.c
index 26aaec9..865236e 100644
--- a/modules/video_output/opengl.c
+++ b/modules/video_output/opengl.c
@@ -1039,9 +1039,11 @@ static void getViewMatrix(GLfloat matrix[static 16]) {
      memcpy(matrix, m, sizeof(m));
 }
 
+/* rotation around the Y axis */
 static void getYRotMatrix(float teta, GLfloat matrix[static 16]) {
 
     const GLfloat m[] = {
+        /* x        y       z          w */
         cos(teta), 0.0f, -sin(teta), 0.0f,
         0.0f,      1.0f, 0.0f,       0.0f,
         sin(teta), 0.0f, cos(teta),  0.0f,
@@ -1051,9 +1053,11 @@ static void getYRotMatrix(float teta, GLfloat matrix[static 16]) {
     memcpy(matrix, m, sizeof(m));
 }
 
+/* rotation around the X axis */
 static void getXRotMatrix(float phi, GLfloat matrix[static 16]) {
 
     const GLfloat m[] = {
+        /* x        y       z          w */
         1.0f, 0.0f,      0.0f,     0.0f,
         0.0f, cos(phi),  sin(phi), 0.0f,
         0.0f, -sin(phi), cos(phi), 0.0f,
@@ -1066,6 +1070,7 @@ static void getXRotMatrix(float phi, GLfloat matrix[static 16]) {
 static void getZoomMatrix(float zoom, GLfloat matrix[static 16]) {
 
     const GLfloat m[] = {
+        /* x   y     z     w */
         1.0f, 0.0f, 0.0f, 0.0f,
         0.0f, 1.0f, 0.0f, 0.0f,
         0.0f, 0.0f, 1.0f, 0.0f,
@@ -1075,19 +1080,20 @@ static void getZoomMatrix(float zoom, GLfloat matrix[static 16]) {
     memcpy(matrix, m, sizeof(m));
 }
 
+/* perspective matrix see https://www.opengl.org/sdk/docs/man2/xhtml/gluPerspective.xml */
 static void getProjectionMatrix(float sar, GLfloat matrix[static 16]) {
 
-    float f = 3;
-    float n = 0.1;
+    float zFar  = 10;
+    float zNear = 0.1;
 
     float fovy = (float) M_PI / 3;
     float d = 1 / tan(fovy / 2);
 
     const GLfloat m[] = {
-        d / sar, 0.0, 0.0,                   0.0,
-        0.0,     d,   0.0,                   0.0,
-        0.0,     0.0, (n + f) / (n - f),     -1.0,
-        0.0,     0.0, (2 * n * f) / (n - f), 0.0};
+        f / sar, 0.0,                   0.0,                0.0,
+        0.0,     f,                     0.0,                0.0,
+        0.0,     0.0,     (zNear + zFar) / (zNear - zFar), -1.0,
+        0.0,     0.0, (2 * zNear * zFar) / (zNear - zFar),  0.0};
 
      memcpy(matrix, m, sizeof(m));
 }
-- 
2.10.1



More information about the vlc-devel mailing list