Пример #1
0
void
_clutter_util_fully_transform_vertices (const CoglMatrix *modelview,
                                        const CoglMatrix *projection,
                                        const float *viewport,
                                        const ClutterVertex *vertices_in,
                                        ClutterVertex *vertices_out,
                                        int n_vertices)
{
  CoglMatrix modelview_projection;
  ClutterVertex4 *vertices_tmp;
  int i;

  vertices_tmp = g_alloca (sizeof (ClutterVertex4) * n_vertices);

  if (n_vertices >= 4)
    {
      /* XXX: we should find a way to cache this per actor */
      cogl_matrix_multiply (&modelview_projection,
                            projection,
                            modelview);
      cogl_matrix_project_points (&modelview_projection,
                                  3,
                                  sizeof (ClutterVertex),
                                  vertices_in,
                                  sizeof (ClutterVertex4),
                                  vertices_tmp,
                                  n_vertices);
    }
  else
    {
      cogl_matrix_transform_points (modelview,
                                    3,
                                    sizeof (ClutterVertex),
                                    vertices_in,
                                    sizeof (ClutterVertex4),
                                    vertices_tmp,
                                    n_vertices);

      cogl_matrix_project_points (projection,
                                  3,
                                  sizeof (ClutterVertex4),
                                  vertices_tmp,
                                  sizeof (ClutterVertex4),
                                  vertices_tmp,
                                  n_vertices);
    }

  for (i = 0; i < n_vertices; i++)
    {
      ClutterVertex4 vertex_tmp = vertices_tmp[i];
      ClutterVertex *vertex_out = &vertices_out[i];
      /* Finally translate from OpenGL coords to window coords */
      vertex_out->x = MTX_GL_SCALE_X (vertex_tmp.x, vertex_tmp.w,
                                      viewport[2], viewport[0]);
      vertex_out->y = MTX_GL_SCALE_Y (vertex_tmp.y, vertex_tmp.w,
                                      viewport[3], viewport[1]);
    }
}
Пример #2
0
RutDiamond *
rut_diamond_new (RutContext *ctx,
                 float size,
                 int tex_width,
                 int tex_height)
{
  RutDiamond *diamond = g_slice_new0 (RutDiamond);
  RutBuffer *buffer = rut_buffer_new (sizeof (CoglVertexP3) * 6);
  RutMesh *pick_mesh = rut_mesh_new_from_buffer_p3 (COGL_VERTICES_MODE_TRIANGLES,
                                                    6,
                                                    buffer);
  CoglVertexP3 *pick_vertices = (CoglVertexP3 *)buffer->data;

  rut_object_init (&diamond->_parent, &rut_diamond_type);

  diamond->ref_count = 1;

  diamond->component.type = RUT_COMPONENT_TYPE_GEOMETRY;

  diamond->ctx = rut_refable_ref (ctx);

  diamond->size = size;

  /* XXX: It could be worth maintaining a cache of diamond slices
   * indexed by the <size, tex_width, tex_height> tuple... */
  diamond->slice = diamond_slice_new (ctx, size, tex_width, tex_height);

  pick_vertices[0].x = 0;
  pick_vertices[0].y = 0;
  pick_vertices[1].x = 0;
  pick_vertices[1].y = size;
  pick_vertices[2].x = size;
  pick_vertices[2].y = size;
  pick_vertices[3] = pick_vertices[0];
  pick_vertices[4] = pick_vertices[2];
  pick_vertices[5].x = size;
  pick_vertices[5].y = 0;

  cogl_matrix_transform_points (&diamond->slice->rotate_matrix,
                                2,
                                sizeof (CoglVertexP3),
                                pick_vertices,
                                sizeof (CoglVertexP3),
                                pick_vertices,
                                6);

  diamond->pick_mesh = pick_mesh;

  return diamond;
}
Пример #3
0
void
_clutter_paint_volume_transform (ClutterPaintVolume *pv,
                                 const CoglMatrix *matrix)
{
  int transform_count;

  if (pv->is_empty)
    {
      gfloat w = 1;
      /* Just transform the origin */
      cogl_matrix_transform_point (matrix,
                                   &pv->vertices[0].x,
                                   &pv->vertices[0].y,
                                   &pv->vertices[0].z,
                                   &w);
      return;
    }

  /* All the vertices must be up to date, since after the transform
   * it wont be trivial to derive the other vertices. */
  _clutter_paint_volume_complete (pv);

  /* Most actors are 2D so we only have to transform the front 4
   * vertices of the paint volume... */
  if (G_LIKELY (pv->is_2d))
    transform_count = 4;
  else
    transform_count = 8;

  cogl_matrix_transform_points (matrix,
                                3,
                                sizeof (ClutterVertex),
                                pv->vertices,
                                sizeof (ClutterVertex),
                                pv->vertices,
                                transform_count);

  pv->is_axis_aligned = FALSE;
}
Пример #4
0
void
_rut_volume_transform (RutVolume *volume,
                       const CoglMatrix *matrix)
{
  int transform_count;

  if (volume->is_empty)
    {
      float w = 1;
      /* Just transform the origin */
      cogl_matrix_transform_point (matrix,
                                   &volume->vertices[0].x,
                                   &volume->vertices[0].y,
                                   &volume->vertices[0].z,
                                   &w);
      return;
    }

  /* All the vertices must be up to date, since after the transform
   * it wont be trivial to derive the other vertices. */
  _rut_volume_complete (volume);

  /* Most actors are 2D so we only have to transform the front 4
   * vertices of the volume... */
  if (G_LIKELY (volume->is_2d))
    transform_count = 4;
  else
    transform_count = 8;

  cogl_matrix_transform_points (matrix,
                                3,
                                sizeof (RutVector3),
                                volume->vertices,
                                sizeof (RutVector3),
                                volume->vertices,
                                transform_count);

  volume->is_axis_aligned = FALSE;
}
Пример #5
0
void
update_control_point_positions (RigSelectionTool *tool,
                                RutCamera *paint_camera) /* 2d ui camera */
{
  RutCamera *camera = tool->camera_component;
  GList *l;

  for (l = tool->selected_entities; l; l = l->next)
    {
      EntityState *entity_state = l->data;
      CoglMatrix transform;
      const CoglMatrix *projection;
      float screen_space[4], x, y;
      const float *viewport;
      GList *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)
        {
          ControlPoint *point = l2->data;

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

          cogl_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];
          cogl_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);
        }
    }
}