Пример #1
0
/* Transform a homogeneous vertex position from model space to Cogl
 * window coordinates (with 0,0 being top left) */
static void
transform_point (CoglMatrix *matrix_mv,
                 CoglMatrix *matrix_p,
                 float *viewport,
                 float *x,
                 float *y)
{
  float z = 0;
  float w = 1;

  /* Apply the modelview matrix transform */
  cogl_matrix_transform_point (matrix_mv, x, y, &z, &w);

  /* Apply the projection matrix transform */
  cogl_matrix_transform_point (matrix_p, x, y, &z, &w);

  /* Perform perspective division */
  *x /= w;
  *y /= w;

  /* Apply viewport transform */
  *x = VIEWPORT_TRANSFORM_X (*x, viewport[0], viewport[2]);
  *y = VIEWPORT_TRANSFORM_Y (*y, viewport[1], viewport[3]);
}
Пример #2
0
void
update_control_point_positions(rig_selection_tool_t *tool,
                               rut_object_t *paint_camera) /* 2d ui camera */
{
    rut_object_t *camera = tool->camera_component;
    c_llist_t *l;

    for (l = tool->selected_entities; l; l = l->next) {
        entity_state_t *entity_state = l->data;
        c_matrix_t transform;
        const c_matrix_t *projection;
        float screen_space[4], x, y;
        const float *viewport;
        c_llist_t *l2;

        get_modelview_matrix(tool->camera, entity_state->entity, &transform);

        projection = rut_camera_get_projection(camera);

        viewport = rut_camera_get_viewport(camera);

        for (l2 = entity_state->control_points; l2; l2 = l2->next) {
            control_point_t *point = l2->data;

            point->position[0] = point->x;
            point->position[1] = point->y;
            point->position[2] = point->z;

            c_matrix_transform_points(&transform,
                                       3, /* num components for input */
                                       sizeof(float) * 3, /* input stride */
                                       point->position,
                                       sizeof(float) * 3, /* output stride */
                                       point->position,
                                       1 /* n_points */);

            /* update the input region, need project the transformed point and
             * do
             * the viewport transform */
            screen_space[0] = point->position[0];
            screen_space[1] = point->position[1];
            screen_space[2] = point->position[2];
            c_matrix_project_points(projection,
                                     3, /* num components for input */
                                     sizeof(float) * 3, /* input stride */
                                     screen_space,
                                     sizeof(float) * 4, /* output stride */
                                     screen_space,
                                     1 /* n_points */);

            /* perspective divide */
            screen_space[0] /= screen_space[3];
            screen_space[1] /= screen_space[3];

            /* apply viewport transform */
            x = VIEWPORT_TRANSFORM_X(screen_space[0], viewport[0], viewport[2]);
            y = VIEWPORT_TRANSFORM_Y(screen_space[1], viewport[1], viewport[3]);

            point->screen_pos[0] = x;
            point->screen_pos[1] = y;

            map_window_coords_to_overlay_coord(
                paint_camera, tool->tool_overlay, &x, &y);

            rut_transform_init_identity(point->transform);
            rut_transform_translate(point->transform, x, y, 0);
            rut_input_region_set_circle(point->input_region, x, y, 10);
        }
    }
}