From a4f3d0d18b4f93d9e2731a686759d93b7f4b642c Mon Sep 17 00:00:00 2001 From: Robert Bragg Date: Fri, 18 Nov 2011 14:07:17 +0000 Subject: [PATCH] matrix: Add cogl_matrix_orthographic This adds an experimental cogl_matrix_orthographic() function that is more consistent with other Cogl api by taking x_1, y_1, x_2, y_2 arguments to define the top-left and bottom-right coordinates of the orthographic coordinates instead of OpenGL style left, right, bottom and top values. Reviewed-by: Neil Roberts --- cogl/cogl-matrix.c | 47 ++++++++++++------- cogl/cogl-matrix.h | 32 +++++++++++++ .../cogl-2.0-experimental-sections.txt | 2 +- 3 files changed, 63 insertions(+), 18 deletions(-) diff --git a/cogl/cogl-matrix.c b/cogl/cogl-matrix.c index 396017c5e..92d13b82c 100644 --- a/cogl/cogl-matrix.c +++ b/cogl/cogl-matrix.c @@ -1420,31 +1420,31 @@ cogl_matrix_perspective (CoglMatrix *matrix, * MAT_FLAG_GENERAL_SCALE and MAT_FLAG_TRANSLATION flags. */ static void -_cogl_matrix_ortho (CoglMatrix *matrix, - float left, - float right, - float bottom, - float top, - float nearval, - float farval) +_cogl_matrix_orthographic (CoglMatrix *matrix, + float x_1, + float y_1, + float x_2, + float y_2, + float nearval, + float farval) { float m[16]; -#define M(row,col) m[col*4+row] - M (0,0) = 2.0f / (right-left); +#define M(row, col) m[col * 4 + row] + M (0,0) = 2.0f / (x_2 - x_1); M (0,1) = 0.0f; M (0,2) = 0.0f; - M (0,3) = -(right+left) / (right-left); + M (0,3) = -(x_2 + x_1) / (x_2 - x_1); M (1,0) = 0.0f; - M (1,1) = 2.0f / (top-bottom); + M (1,1) = 2.0f / (y_1 - y_2); M (1,2) = 0.0f; - M (1,3) = -(top+bottom) / (top-bottom); + M (1,3) = -(y_1 + y_2) / (y_1 - y_2); M (2,0) = 0.0f; M (2,1) = 0.0f; - M (2,2) = -2.0f / (farval-nearval); - M (2,3) = -(farval+nearval) / (farval-nearval); + M (2,2) = -2.0f / (farval - nearval); + M (2,3) = -(farval + nearval) / (farval - nearval); M (3,0) = 0.0f; M (3,1) = 0.0f; @@ -1463,10 +1463,23 @@ cogl_matrix_ortho (CoglMatrix *matrix, float right, float bottom, float top, - float near_val, - float far_val) + float near, + float far) { - _cogl_matrix_ortho (matrix, left, right, bottom, top, near_val, far_val); + _cogl_matrix_orthographic (matrix, left, top, right, bottom, near, far); + _COGL_MATRIX_DEBUG_PRINT (matrix); +} + +void +cogl_matrix_orthographic (CoglMatrix *matrix, + float x_1, + float y_1, + float x_2, + float y_2, + float near, + float far) +{ + _cogl_matrix_orthographic (matrix, x_1, y_1, x_2, y_2, near, far); _COGL_MATRIX_DEBUG_PRINT (matrix); } diff --git a/cogl/cogl-matrix.h b/cogl/cogl-matrix.h index 0bb3e75e8..78a653193 100644 --- a/cogl/cogl-matrix.h +++ b/cogl/cogl-matrix.h @@ -294,6 +294,36 @@ cogl_matrix_perspective (CoglMatrix *matrix, float z_near, float z_far); +#ifdef COGL_ENABLE_EXPERIMENTAL_API +#define cogl_matrix_orthographic cogl_matrix_orthographic_EXP +/** + * cogl_matrix_orthographic: + * @matrix: A 4x4 transformation matrix + * @x_1: The x coordinate for the first vertical clipping plane + * @y_1: The y coordinate for the first horizontal clipping plane + * @x_2: The x coordinate for the second vertical clipping plane + * @y_2: The y coordinate for the second horizontal clipping plane + * @near: The distance to the near clipping + * plane (will be negative if the plane is + * behind the viewer) + * @far: The distance to the far clipping + * plane (will be negative if the plane is + * behind the viewer) + * + * Multiplies @matrix by a parallel projection matrix. + * + * Since: 1.10 + */ +void +cogl_matrix_orthographic (CoglMatrix *matrix, + float x_1, + float y_1, + float x_2, + float y_2, + float near, + float far); +#endif + /** * cogl_matrix_ortho: * @matrix: A 4x4 transformation matrix @@ -307,6 +337,8 @@ cogl_matrix_perspective (CoglMatrix *matrix, * the plane is behind the viewer) * * Multiplies @matrix by a parallel projection matrix. + * + * Deprecated: 1.10: Use cogl_matrix_orthographic() */ void cogl_matrix_ortho (CoglMatrix *matrix, diff --git a/doc/reference/cogl-2.0-experimental/cogl-2.0-experimental-sections.txt b/doc/reference/cogl-2.0-experimental/cogl-2.0-experimental-sections.txt index f2dd72c17..842126387 100644 --- a/doc/reference/cogl-2.0-experimental/cogl-2.0-experimental-sections.txt +++ b/doc/reference/cogl-2.0-experimental/cogl-2.0-experimental-sections.txt @@ -479,7 +479,7 @@ cogl_matrix_copy cogl_matrix_equal cogl_matrix_free cogl_matrix_frustum -cogl_matrix_ortho +cogl_matrix_orthographic cogl_matrix_perspective cogl_matrix_look_at cogl_matrix_multiply