u->z = CLUTTER_UNITS_FROM_FIXED (f->z);
}
-/*
- * Utility functions for manipulating transformation matrix
- *
- * Matrix: 4x4 of ClutterFixed
- */
-#define M(m,row,col) (m)[(col) * 4 + (row)]
-
/* Transforms a vertex using the passed matrix; vertex is
* an in-out parameter
*/
-static inline void
-mtx_transform (const ClutterFixed m[],
- fixed_vertex_t *vertex)
+static void
+mtx_transform (const CoglMatrix *matrix,
+ fixed_vertex_t *vertex)
{
- float _x, _y, _z, _w;
-
- _x = vertex->x;
- _y = vertex->y;
- _z = vertex->z;
- _w = vertex->w;
-
- /* We care lot about precision here, so have to use MUL instead
- * of FAST_MUL
- */
- vertex->x = CLUTTER_FIXED_MUL (M (m, 0, 0), _x)
- + CLUTTER_FIXED_MUL (M (m, 0, 1), _y)
- + CLUTTER_FIXED_MUL (M (m, 0, 2), _z)
- + CLUTTER_FIXED_MUL (M (m, 0, 3), _w);
-
- vertex->y = CLUTTER_FIXED_MUL (M (m, 1, 0), _x)
- + CLUTTER_FIXED_MUL (M (m, 1, 1), _y)
- + CLUTTER_FIXED_MUL (M (m, 1, 2), _z)
- + CLUTTER_FIXED_MUL (M (m, 1, 3), _w);
-
- vertex->z = CLUTTER_FIXED_MUL (M (m, 2, 0), _x)
- + CLUTTER_FIXED_MUL (M (m, 2, 1), _y)
- + CLUTTER_FIXED_MUL (M (m, 2, 2), _z)
- + CLUTTER_FIXED_MUL (M (m, 2, 3), _w);
-
- vertex->w = CLUTTER_FIXED_MUL (M (m, 3, 0), _x)
- + CLUTTER_FIXED_MUL (M (m, 3, 1), _y)
- + CLUTTER_FIXED_MUL (M (m, 3, 2), _z)
- + CLUTTER_FIXED_MUL (M (m, 3, 3), _w);
-
- /* Specially for Matthew: was going to put a comment here, but could not
- * think of anything at all to say ;)
- */
+ cogl_matrix_transform_point (matrix,
+ &vertex->x,
+ &vertex->y,
+ &vertex->z,
+ &vertex->w);
}
-#undef M
-
/* Help macros to scale from OpenGL <-1,1> coordinates system to our
* X-window based <0,window-size> coordinates
*/
* places the result into a fixed @vertex
*/
static inline void
-fixed_vertex_transform (const ClutterFixed matrix[],
+fixed_vertex_transform (const CoglMatrix *matrix,
ClutterFixed x,
ClutterFixed y,
ClutterFixed z,
* transforms the result into ClutterUnits, filling @vertex_p
*/
static inline void
-fixed_vertex_scale (const ClutterFixed matrix[],
+fixed_vertex_scale (const CoglMatrix *matrix,
const fixed_vertex_t *vertex,
const ClutterFixed viewport[],
ClutterVertex *vertex_p)
ClutterUnit *z,
ClutterUnit *w)
{
- ClutterFixed mtx[16];
+ CoglMatrix matrix;
fixed_vertex_t vertex = { 0, };
vertex.x = (x != NULL) ? CLUTTER_UNITS_TO_FIXED (*x) : 0;
_clutter_actor_apply_modelview_transform_recursive (actor, ancestor);
- cogl_get_modelview_matrix (mtx);
- mtx_transform (mtx, &vertex);
+ cogl_get_modelview_matrix (&matrix);
+ mtx_transform (&matrix, &vertex);
cogl_pop_matrix();
ClutterUnit *z,
ClutterUnit *w)
{
- ClutterFixed mtx[16];
+ CoglMatrix matrix;
fixed_vertex_t vertex = { 0, };
vertex.x = (x != NULL) ? CLUTTER_UNITS_TO_FIXED (*x) : 0;
_clutter_actor_apply_modelview_transform_recursive (actor, NULL);
- cogl_get_modelview_matrix (mtx);
- mtx_transform (mtx, &vertex);
+ cogl_get_modelview_matrix (&matrix);
+ mtx_transform (&matrix, &vertex);
cogl_pop_matrix();
ClutterVertex *vertex)
{
ClutterUnit x, y, z, w;
- ClutterFixed mtx_p[16];
+ CoglMatrix matrix_p;
ClutterFixed v[4];
fixed_vertex_t tmp = { 0, };
tmp.z = CLUTTER_UNITS_TO_FIXED (z);
tmp.w = CLUTTER_UNITS_TO_FIXED (w);
- cogl_get_projection_matrix (mtx_p);
+ cogl_get_projection_matrix (&matrix_p);
cogl_get_viewport (v);
/* Now, transform it again with the projection matrix */
- mtx_transform (mtx_p, &tmp);
+ mtx_transform (&matrix_p, &tmp);
/* Finaly translate from OpenGL coords to window coords */
vertex->x =
fixed_vertex_t vertices[])
{
ClutterActorPrivate *priv = self->priv;
- ClutterFixed mtx[16];
+ CoglMatrix mtx;
ClutterFixed width, height;
width = CLUTTER_UNITS_TO_FIXED (priv->allocation.x2 - priv->allocation.x1);
_clutter_actor_apply_modelview_transform_recursive (self, ancestor);
- cogl_get_modelview_matrix (mtx);
+ cogl_get_modelview_matrix (&mtx);
- fixed_vertex_transform (mtx, 0, 0, 0, 1.0, &vertices[0]);
- fixed_vertex_transform (mtx, width, 0, 0, 1.0, &vertices[1]);
- fixed_vertex_transform (mtx, 0, height, 0, 1.0, &vertices[2]);
- fixed_vertex_transform (mtx, width, height, 0, 1.0, &vertices[3]);
+ fixed_vertex_transform (&mtx, 0, 0, 0, 1.0, &vertices[0]);
+ fixed_vertex_transform (&mtx, width, 0, 0, 1.0, &vertices[1]);
+ fixed_vertex_transform (&mtx, 0, height, 0, 1.0, &vertices[2]);
+ fixed_vertex_transform (&mtx, width, height, 0, 1.0, &vertices[3]);
cogl_pop_matrix();
}
ClutterVertex verts[4])
{
ClutterActor *stage;
- ClutterFixed mtx[16];
- ClutterFixed mtx_p[16];
+ CoglMatrix mtx;
+ CoglMatrix mtx_p;
ClutterFixed v[4];
ClutterFixed width, height;
fixed_vertex_t vertices[4];
_clutter_actor_apply_modelview_transform_recursive (self, NULL);
- cogl_get_modelview_matrix (mtx);
+ cogl_get_modelview_matrix (&mtx);
- fixed_vertex_transform (mtx, 0, 0, 0, 1.0, &vertices[0]);
- fixed_vertex_transform (mtx, width, 0, 0, 1.0, &vertices[1]);
- fixed_vertex_transform (mtx, 0, height, 0, 1.0, &vertices[2]);
- fixed_vertex_transform (mtx, width, height, 0, 1.0, &vertices[3]);
+ fixed_vertex_transform (&mtx, 0, 0, 0, 1.0, &vertices[0]);
+ fixed_vertex_transform (&mtx, width, 0, 0, 1.0, &vertices[1]);
+ fixed_vertex_transform (&mtx, 0, height, 0, 1.0, &vertices[2]);
+ fixed_vertex_transform (&mtx, width, height, 0, 1.0, &vertices[3]);
cogl_pop_matrix();
- cogl_get_projection_matrix (mtx_p);
+ cogl_get_projection_matrix (&mtx_p);
cogl_get_viewport (v);
- fixed_vertex_scale (mtx_p, &vertices[0], v, &verts[0]);
- fixed_vertex_scale (mtx_p, &vertices[1], v, &verts[1]);
- fixed_vertex_scale (mtx_p, &vertices[2], v, &verts[2]);
- fixed_vertex_scale (mtx_p, &vertices[3], v, &verts[3]);
+ fixed_vertex_scale (&mtx_p, &vertices[0], v, &verts[0]);
+ fixed_vertex_scale (&mtx_p, &vertices[1], v, &verts[1]);
+ fixed_vertex_scale (&mtx_p, &vertices[2], v, &verts[2]);
+ fixed_vertex_scale (&mtx_p, &vertices[3], v, &verts[3]);
}
/**
box.x2 = box.x1 + natural_width;
box.y2 = box.y1 + natural_height;
-
+
clutter_actor_transform_and_project_box (self, &box, v);
}
else
ClutterActorBox actor_box;
g_return_if_fail (CLUTTER_IS_ACTOR (self));
-
+
actor_x = clutter_actor_get_xu (self);
actor_y = clutter_actor_get_yu (self);
NULL, NULL,
&natural_width,
&natural_height);
-
+
actor_box.x1 = actor_x;
actor_box.y1 = actor_y;
actor_box.x2 = actor_box.x1 + natural_width;
#include <glib.h>
#include <math.h>
+#include <string.h>
void
cogl_matrix_init_identity (CoglMatrix *matrix)
r.wy = a->wx * b->xy + a->wy * b->yy + a->wz * b->zy + a->ww * b->wy;
r.wz = a->wx * b->xz + a->wy * b->yz + a->wz * b->zz + a->ww * b->wz;
r.ww = a->wx * b->xw + a->wy * b->yw + a->wz * b->zw + a->ww * b->ww;
-
+
/* The idea was that having this unrolled; it might be easier for the
* compiler to vectorize, but that's probably not true. Mesa does it
* using a single for (i=0; i<4; i++) approach, may that's better...
*result = r;
}
-/**
- * cogl_3dmatrix_rotate:
- * @matrix: A 3D Affine transformation matrix
- * @angle: The angle in degrees you want to rotate by
- * @x: The X component of your rotation vector
- * @y: The Y component of your rotation vector
- * @z: The Z component of your rotation vector
- *
- * The matrix is multiplied with a rotation matrix representing a rotation
- * of angle degress around the vector (x,y,z)
- *
- * Since: 1.0
- */
void
cogl_matrix_rotate (CoglMatrix *matrix,
float angle,
angle *= G_PI / 180.0f;
float c = cosf (angle);
float s = sinf (angle);
-
+
rotation.xx = x * x * (1.0f - c) + c;
rotation.yx = y * x * (1.0f - c) + z * s;
rotation.zx = x * z * (1.0f - c) - y * s;
rotation.yw = 0.0f;
rotation.zw = 0.0f;
rotation.ww = 1.0f;
-
+
cogl_matrix_multiply (&result, matrix, &rotation);
*matrix = result;
}
}
#endif
+void
+cogl_matrix_transform_point (const CoglMatrix *matrix,
+ float *x,
+ float *y,
+ float *z,
+ float *w)
+{
+ float _x = *x, _y = *y, _z = *z, _w = *w;
+
+ *x = matrix->xx * _x + matrix->xy * _y + matrix->xz * _z + matrix->xw * _w;
+ *y = matrix->yx * _x + matrix->yy * _y + matrix->yz * _z + matrix->yw * _w;
+ *z = matrix->zx * _x + matrix->zy * _y + matrix->zz * _z + matrix->zw * _w;
+ *w = matrix->wx * _x + matrix->wy * _y + matrix->wz * _z + matrix->ww * _w;
+}
+
+void
+cogl_matrix_init_from_gl_matrix (CoglMatrix *matrix, const float *gl_matrix)
+{
+ memcpy (matrix, gl_matrix, sizeof (float) * 16);
+}
+
+const float *
+cogl_matrix_get_gl_matrix (const CoglMatrix *matrix)
+{
+ return (float *)matrix;
+}