1
0
Fork 0

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 <neil@linux.intel.com>
This commit is contained in:
Robert Bragg 2011-11-18 14:07:17 +00:00
parent ba02f70961
commit a4f3d0d18b
3 changed files with 63 additions and 18 deletions

View file

@ -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);
}

View file

@ -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 <emphasis>distance</emphasis> to the near clipping
* plane (will be <emphasis>negative</emphasis> if the plane is
* behind the viewer)
* @far: The <emphasis>distance</emphasis> to the far clipping
* plane (will be <emphasis>negative</emphasis> 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,

View file

@ -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