static gpointer matrix_setup (void) { MatrixBench *res = g_new0 (MatrixBench, 1); int i; res->a = alloc_n_matrix (N_ROUNDS); res->b = alloc_n_matrix (N_ROUNDS); res->c = alloc_n_matrix (N_ROUNDS); res->pa = alloc_n_vec (N_ROUNDS); res->qa = alloc_n_vec (N_ROUNDS); res->ra = alloc_n_vec (N_ROUNDS); for (i = 0; i < N_ROUNDS; i++) { graphene_simd4f_t p, q; p = graphene_simd4f_init (i, i, i, i); q = graphene_simd4f_init (N_ROUNDS - i, N_ROUNDS - i, N_ROUNDS - i, N_ROUNDS - i); res->a[i] = graphene_simd4x4f_init (p, p, p, p); res->b[i] = graphene_simd4x4f_init (q, q, q, q); res->pa[i] = graphene_simd4f_init (i, i, 0.f, 0.f); res->qa[i] = graphene_simd4f_init (N_ROUNDS - i, N_ROUNDS - 1, 1.f, 0.f); } return res; }
/** * graphene_matrix_init_translate: * @m: a #graphene_matrix_t * @p: the translation coordinates * * Initializes a #graphene_matrix_t with a translation to the * given coordinates. * * Returns: (transfer none): the initialized matrix * * Since: 1.0 */ graphene_matrix_t * graphene_matrix_init_translate (graphene_matrix_t *m, const graphene_point3d_t *p) { m->value = graphene_simd4x4f_init (graphene_simd4f_init (1.0f, 0.0f, 0.0f, 0.0f), graphene_simd4f_init (0.0f, 1.0f, 0.0f, 0.0f), graphene_simd4f_init (0.0f, 0.0f, 1.0f, 0.0f), graphene_simd4f_init (p->x, p->y, p->z, 1.0f)); return m; }
/** * graphene_matrix_init_scale: * @m: a #graphene_matrix_t * @x: the scale factor on the X axis * @y: the scale factor on the Y axis * @z: the scale factor on the Z axis * * Initializes a #graphene_matrix_t with the given scaling factors. * * Returns: (transfer none): the initialized matrix * * Since: 1.0 */ graphene_matrix_t * graphene_matrix_init_scale (graphene_matrix_t *m, float x, float y, float z) { m->value = graphene_simd4x4f_init (graphene_simd4f_init ( x, 0.0f, 0.0f, 0.0f), graphene_simd4f_init (0.0f, y, 0.0f, 0.0f), graphene_simd4f_init (0.0f, 0.0f, z, 0.0f), graphene_simd4f_init (0.0f, 0.0f, 0.0f, 1.0f)); return m; }
/** * graphene_matrix_init_from_vec4: * @m: a #graphene_matrix_t * @v0: the first row vector * @v1: the second row vector * @v2: the third row vector * @v3: the fourth row vector * * Initializes a #graphene_matrix_t with the given four row * vectors. * * Returns: (transfer none): the initialized matrix * * Since: 1.0 */ graphene_matrix_t * graphene_matrix_init_from_vec4 (graphene_matrix_t *m, const graphene_vec4_t *v0, const graphene_vec4_t *v1, const graphene_vec4_t *v2, const graphene_vec4_t *v3) { m->value = graphene_simd4x4f_init (v0->value, v1->value, v2->value, v3->value); return m; }
graphene_matrix_t * graphene_matrix_init_translate (graphene_matrix_t *m, const graphene_point3d_t *p) { g_return_val_if_fail (m != NULL, NULL); g_return_val_if_fail (p != NULL, m); m->value = graphene_simd4x4f_init (graphene_simd4f_init (1.0f, 0.0f, 0.0f, 0.0f), graphene_simd4f_init (0.0f, 1.0f, 0.0f, 0.0f), graphene_simd4f_init (0.0f, 0.0f, 1.0f, 0.0f), graphene_simd4f_init (p->x, p->y, p->z, 1.0f)); return m; }
graphene_matrix_t * graphene_matrix_init_scale (graphene_matrix_t *m, float x, float y, float z) { g_return_val_if_fail (m != NULL, NULL); m->value = graphene_simd4x4f_init (graphene_simd4f_init ( x, 0.0f, 0.0f, 0.0f), graphene_simd4f_init (0.0f, y, 0.0f, 0.0f), graphene_simd4f_init (0.0f, 0.0f, z, 0.0f), graphene_simd4f_init (0.0f, 0.0f, 0.0f, 1.0f)); return m; }
/** * graphene_matrix_init_from_2d: * @m: a #graphene_matrix_t * @xx: the xx member * @yx: the yx member * @xy: the xy member * @yy: the yy member * @x_0: the x0 member * @y_0: the y0 member * * Initializes a #graphene_matrix_t from the values of an affine * transformation matrix. * * The arguments map to the following matrix layout: * * |[ * | xx yx | | a b 0 | * | xy yy | = | c d 0 | * | x0 y0 | | tx ty 1 | * ]| * * This function can be used to convert between a matrix type from * other libraries and a #graphene_matrix_t. * * Returns: (transfer none): the initialized matrix * * Since: 1.0 */ graphene_matrix_t * graphene_matrix_init_from_2d (graphene_matrix_t *m, double xx, double yx, double xy, double yy, double x_0, double y_0) { m->value = graphene_simd4x4f_init (graphene_simd4f_init ( xx, yx, 0.f, 0.f), graphene_simd4f_init ( yx, yy, 0.f, 0.f), graphene_simd4f_init (0.f, 0.f, 1.f, 0.f), graphene_simd4f_init (x_0, y_0, 0.f, 1.f)); return m; }
graphene_matrix_t * graphene_matrix_init_from_vec4 (graphene_matrix_t *m, const graphene_vec4_t *v0, const graphene_vec4_t *v1, const graphene_vec4_t *v2, const graphene_vec4_t *v3) { g_return_val_if_fail (m != NULL, NULL); g_return_val_if_fail (v0 != NULL && v1 != NULL && v2 != NULL && v3 != NULL, m); m->value = graphene_simd4x4f_init (v0->value, v1->value, v2->value, v3->value); return m; }
/** * graphene_matrix_init_skew: * @m: a #graphene_matrix_t * @x_skew: skew factor on the X axis * @y_skew: skew factor on the Y axis * * Initializes a #graphene_matrix_t with a skew transformation * with the given factors. * * Returns: (transfer none): the initialized matrix * * Since: 1.0 */ graphene_matrix_t * graphene_matrix_init_skew (graphene_matrix_t *m, float x_skew, float y_skew) { float t_x, t_y; t_x = tanf (x_skew); t_y = tanf (y_skew); m->value = graphene_simd4x4f_init (graphene_simd4f_init (1.0f, t_y, 0.0f, 0.0f), graphene_simd4f_init ( t_x, 1.0f, 0.0f, 0.0f), graphene_simd4f_init (0.0f, 0.0f, 1.0f, 0.0f), graphene_simd4f_init (0.0f, 0.0f, 0.0f, 1.0f)); return m; }
/** * graphene_quaternion_to_matrix: * @q: a #graphene_quaternion_t * @m: (out caller-allocates): a #graphene_matrix_t * * Converts a quaternion into a transformation matrix expressing * the rotation defined by the #graphene_quaternion_t. * * Since: 1.0 */ void graphene_quaternion_to_matrix (const graphene_quaternion_t *q, graphene_matrix_t *m) { graphene_simd4f_t m_x, m_y, m_z, m_w; m_x = graphene_simd4f_init (1.f - 2.f * (q->y * q->y + q->z * q->z), 2.f * (q->x * q->y + q->w * q->z), 2.f * (q->x * q->z - q->w * q->y), 0.f); m_y = graphene_simd4f_init ( 2.f * (q->x * q->y - q->w * q->z), 1.f - 2.f * (q->x * q->x + q->z * q->z), 2.f * (q->y * q->z + q->w * q->x), 0.f); m_z = graphene_simd4f_init ( 2.f * (q->x * q->z + q->w * q->y), 2.f * (q->y * q->z - q->w * q->x), 1.f - 2.f * (q->x * q->x + q->y * q->y), 0.f); m_w = graphene_simd4f_init (0.f, 0.f, 0.f, 1.f); m->value = graphene_simd4x4f_init (m_x, m_y, m_z, m_w); }