cogl/matrix: Frustum with graphene

This commit is contained in:
Georges Basile Stavracas Neto 2019-02-27 19:00:02 -03:00
parent 08015ce784
commit 10f1d3118c
No known key found for this signature in database
GPG Key ID: 886C17EE170D1385

View File

@ -392,41 +392,6 @@ cogl_matrix_rotate_euler (CoglMatrix *matrix,
cogl_matrix_multiply (matrix, matrix, &rotation_transform);
}
/*
* Apply a perspective projection matrix.
*
* Creates the projection matrix and multiplies it with matrix, marking the
* MAT_FLAG_PERSPECTIVE flag.
*/
static void
_cogl_matrix_frustum (CoglMatrix *matrix,
float left,
float right,
float bottom,
float top,
float nearval,
float farval)
{
float x, y, a, b, c, d;
float m[16];
x = (2.0f * nearval) / (right - left);
y = (2.0f * nearval) / (top - bottom);
a = (right + left) / (right - left);
b = (top + bottom) / (top - bottom);
c = -(farval + nearval) / ( farval - nearval);
d = -(2.0f * farval * nearval) / (farval - nearval); /* error? */
#define M(row,col) m[col*4+row]
M (0,0) = x; M (0,1) = 0.0f; M (0,2) = a; M (0,3) = 0.0f;
M (1,0) = 0.0f; M (1,1) = y; M (1,2) = b; M (1,3) = 0.0f;
M (2,0) = 0.0f; M (2,1) = 0.0f; M (2,2) = c; M (2,3) = d;
M (3,0) = 0.0f; M (3,1) = 0.0f; M (3,2) = -1.0f; M (3,3) = 0.0f;
#undef M
matrix_multiply_array_with_flags (matrix, m);
}
void
cogl_matrix_frustum (CoglMatrix *matrix,
float left,
@ -436,7 +401,16 @@ cogl_matrix_frustum (CoglMatrix *matrix,
float z_near,
float z_far)
{
_cogl_matrix_frustum (matrix, left, right, bottom, top, z_near, z_far);
graphene_matrix_t frustum, m;
graphene_matrix_init_frustum (&frustum, left, right, bottom, top, z_near, z_far);
cogl_matrix_to_graphene_matrix (matrix, &m);
graphene_matrix_transpose (&m, &m);
graphene_matrix_multiply (&m, &frustum, &m);
graphene_matrix_to_cogl_matrix (&m, matrix);
_COGL_MATRIX_DEBUG_PRINT (matrix);
}