コード例 #1
0
ファイル: graphene-vectors.c プロジェクト: pmdias/graphene
/**
 * graphene_vec3_normalize:
 * @v: a #graphene_vec3_t
 * @res: (out caller-allocates): return location for the normalized vector
 *
 * Normalizes the given #graphene_vec3_t.
 *
 * Since: 1.0
 */
void
graphene_vec3_normalize (const graphene_vec3_t *v,
                         graphene_vec3_t       *res)
{
  if (graphene_vec3_length (v) != 0.f)
    res->value = graphene_simd4f_normalize3 (v->value);
  else
    res->value = graphene_simd4f_init_zero ();
}
コード例 #2
0
/**
 * graphene_quaternion_init_from_angle_vec3:
 * @q: a #graphene_quaternion_t
 * @angle: the rotation on a given axis, in degrees
 * @axis: the axis of rotation, expressed as a vector
 *
 * Initializes a #graphene_quaternion_t using an @angle on a
 * specific @axis.
 *
 * Returns: (transfer none): the initialized quaternion
 *
 * Since: 1.0
 */
graphene_quaternion_t *
graphene_quaternion_init_from_angle_vec3 (graphene_quaternion_t *q,
                                          float                  angle,
                                          const graphene_vec3_t *axis)
{
  float rad, sin_a, cos_a;
  graphene_simd4f_t axis_n;

  rad = GRAPHENE_DEG_TO_RAD (angle);

  sin_a = sinf (rad / 2.f);
  cos_a = cosf (rad / 2.f);
  axis_n = graphene_simd4f_mul (graphene_simd4f_normalize3 (axis->value),
                                graphene_simd4f_splat (sin_a));

  q->x = graphene_simd4f_get_x (axis_n);
  q->y = graphene_simd4f_get_y (axis_n);
  q->z = graphene_simd4f_get_z (axis_n);
  q->w = cos_a;

  return q;
}