const CoglMatrix * rut_camera_get_projection (RutCamera *camera) { if (G_UNLIKELY (camera->projection_cache_age != camera->projection_age)) { cogl_matrix_init_identity (&camera->projection); if (camera->orthographic) { float x1, x2, y1, y2; if (camera->zoom != 1) { float center_x = camera->x1 + (camera->x2 - camera->x1) / 2.0; float center_y = camera->y1 + (camera->y2 - camera->y1) / 2.0; float inverse_scale = 1.0 / camera->zoom; float dx = (camera->x2 - center_x) * inverse_scale; float dy = (camera->y2 - center_y) * inverse_scale; camera->x1 = center_x - dx; camera->x2 = center_x + dx; camera->y1 = center_y - dy; camera->y2 = center_y + dy; } else { x1 = camera->x1; x2 = camera->x2; y1 = camera->y1; y2 = camera->y2; } cogl_matrix_orthographic (&camera->projection, x1, y1, x2, y2, camera->near, camera->far); } else { float aspect_ratio = camera->viewport[2] / camera->viewport[3]; rut_util_matrix_scaled_perspective (&camera->projection, camera->fov, aspect_ratio, camera->near, camera->far, camera->zoom); } camera->projection_cache_age = camera->projection_age; } return &camera->projection; }
void cogl_matrix_stack_orthographic (CoglMatrixStack *stack, float x_1, float y_1, float x_2, float y_2, float near, float far) { CoglMatrixEntryLoad *entry; entry = _cogl_matrix_stack_push_replacement_entry (stack, COGL_MATRIX_OP_LOAD); entry->matrix = _cogl_magazine_chunk_alloc (cogl_matrix_stack_matrices_magazine); cogl_matrix_init_identity (entry->matrix); cogl_matrix_orthographic (entry->matrix, x_1, y_1, x_2, y_2, near, far); }
static void setup_orthographic_modelview (void) { CoglMatrix matrix; int fb_width = cogl_framebuffer_get_width (test_fb); int fb_height = cogl_framebuffer_get_height (test_fb); /* Set up a non-identity modelview matrix. When the journal is * flushed it will usually flush the identity matrix. Using the * non-default matrix ensures that we test that Cogl restores the * matrix we asked for. The matrix sets up an orthographic transform * in the modelview matrix */ cogl_matrix_init_identity (&matrix); cogl_matrix_orthographic (&matrix, 0.0f, 0.0f, /* x_1 y_1 */ fb_width, fb_height, -1.0f, /* nearval */ 1.0f /* farval */); cogl_framebuffer_set_modelview_matrix (test_fb, &matrix); }