示例#1
0
/**
 * graphene_matrix_project_point:
 * @m: ...
 * @p: ...
 * @res: (out caller-allocates): ...
 *
 * ...
 *
 * Since: 1.0
 */
void
graphene_matrix_project_point (const graphene_matrix_t *m,
                               const graphene_point_t  *p,
                               graphene_point_t        *res)
{
  graphene_vec3_t pa, qa;
  graphene_vec3_t pback, qback, uback;
  float p_z, u_z, t;

  g_return_if_fail (m != NULL);
  g_return_if_fail (p != NULL);
  g_return_if_fail (res != NULL);

  graphene_vec3_init (&pa, p->x, p->y, 0.0f);
  graphene_vec3_init (&qa, p->x, p->y, 1.0f);

  graphene_matrix_transform_vec3 (m, &pa, &pback);
  graphene_matrix_transform_vec3 (m, &qa, &qback);

  graphene_vec3_subtract (&qback, &pback, &uback);

  p_z = graphene_vec3_get_z (&pback);
  u_z = graphene_vec3_get_z (&uback);
  t = -p_z / u_z;

  graphene_point_init (res,
                       graphene_vec3_get_x (&pback) + t * graphene_vec3_get_x (&uback),
                       graphene_vec3_get_y (&pback) + t * graphene_vec3_get_y (&uback));
}
示例#2
0
/**
 * graphene_rect_get_bottom_left:
 * @r: a #graphene_rect_t
 * @p: (out caller-allocates): return location for a #graphene_point_t
 *
 * Retrieves the coordinates of the bottom-left corner of the given rectangle.
 *
 * Since: 1.0
 */
void
graphene_rect_get_bottom_left (const graphene_rect_t *r,
                               graphene_point_t      *p)
{
  graphene_rect_t rr;

  rr = *r;
  graphene_rect_normalize_in_place (&rr);

  graphene_point_init (p, rr.origin.x, rr.origin.y + rr.size.height);
}
示例#3
0
/**
 * graphene_rect_get_top_right:
 * @r: a #graphene_rect_t
 * @p: (out caller-allocates): return location for a #graphene_point_t
 *
 * Retrieves the coordinates of the top-right corner of the given rectangle.
 *
 * Since: 1.0
 */
void
graphene_rect_get_top_right (const graphene_rect_t *r,
                             graphene_point_t      *p)
{
  graphene_rect_t rr;

  rr = *r;
  graphene_rect_normalize_in_place (&rr);

  graphene_point_init (p, rr.origin.x + rr.size.width, rr.origin.y);
}
示例#4
0
/**
 * graphene_rect_get_center:
 * @r: a #graphene_rect_t
 * @p: (out caller-allocates): return location for a #graphene_point_t
 *
 * Retrieves the coordinates of the center of the given rectangle.
 *
 * Since: 1.0
 */
void
graphene_rect_get_center (const graphene_rect_t  *r,
                          graphene_point_t       *p)
{
  graphene_rect_t rr;

  rr = *r;
  graphene_rect_normalize_in_place (&rr);

  graphene_point_init (p,
                       rr.origin.x + (rr.size.width / 2.f),
                       rr.origin.y + (rr.size.height / 2.f));
}
示例#5
0
/**
 * graphene_rect_init:
 * @r: a #graphene_rect_t
 * @x: the X coordinate of the @graphene_rect_t.origin
 * @y: the Y coordinate of the @graphene_rect_t.origin
 * @width: the width of the @graphene_rect_t.size
 * @height: the height of the @graphene_rect_t.size
 *
 * Initializes the given #graphene_rect_t with the given values.
 *
 * This function will implicitly normalize the #graphene_rect_t
 * before returning.
 *
 * Returns: (transfer none): the initialized rectangle
 *
 * Since: 1.0
 */
graphene_rect_t *
graphene_rect_init (graphene_rect_t *r,
                    float            x,
                    float            y,
                    float            width,
                    float            height)
{
  graphene_point_init (&r->origin, x, y);
  graphene_size_init (&r->size, width, height);

  graphene_rect_normalize_in_place (r);

  return r;
}