summaryrefslogtreecommitdiff
path: root/src/lib/eina
diff options
context:
space:
mode:
authorCedric BAIL <cedric@osg.samsung.com>2015-05-28 14:35:55 +0200
committerCedric BAIL <cedric@osg.samsung.com>2015-05-29 17:20:28 +0200
commit9a83100a4ac1b040bde8aa63c868be3ad806758a (patch)
treeadb0ca777db9ac4e5bb6a68f21b76d9f806e4946 /src/lib/eina
parent5cdf202ee4c81afcd5a18749a09eab9724a76402 (diff)
eina: add the beginning of an Eina_Matrix4 API.
Diffstat (limited to 'src/lib/eina')
-rw-r--r--src/lib/eina/eina_matrix.c103
-rw-r--r--src/lib/eina/eina_matrix.h135
2 files changed, 238 insertions, 0 deletions
diff --git a/src/lib/eina/eina_matrix.c b/src/lib/eina/eina_matrix.c
index 468acf58fd..8e2d0beb98 100644
--- a/src/lib/eina/eina_matrix.c
+++ b/src/lib/eina/eina_matrix.c
@@ -32,12 +32,19 @@
32#define MATRIX_XX(m) (m)->xx 32#define MATRIX_XX(m) (m)->xx
33#define MATRIX_XY(m) (m)->xy 33#define MATRIX_XY(m) (m)->xy
34#define MATRIX_XZ(m) (m)->xz 34#define MATRIX_XZ(m) (m)->xz
35#define MATRIX_XW(m) (m)->xw
35#define MATRIX_YX(m) (m)->yx 36#define MATRIX_YX(m) (m)->yx
36#define MATRIX_YY(m) (m)->yy 37#define MATRIX_YY(m) (m)->yy
37#define MATRIX_YZ(m) (m)->yz 38#define MATRIX_YZ(m) (m)->yz
39#define MATRIX_YW(m) (m)->yw
38#define MATRIX_ZX(m) (m)->zx 40#define MATRIX_ZX(m) (m)->zx
39#define MATRIX_ZY(m) (m)->zy 41#define MATRIX_ZY(m) (m)->zy
40#define MATRIX_ZZ(m) (m)->zz 42#define MATRIX_ZZ(m) (m)->zz
43#define MATRIX_ZW(m) (m)->zw
44#define MATRIX_WX(m) (m)->wx
45#define MATRIX_WY(m) (m)->wy
46#define MATRIX_WZ(m) (m)->wz
47#define MATRIX_WW(m) (m)->ww
41#define MATRIX_SIZE 9 48#define MATRIX_SIZE 9
42 49
43#define QUAD_X0(q) q->x0 50#define QUAD_X0(q) q->x0
@@ -109,6 +116,17 @@ eina_matrix3_type_get(const Eina_Matrix3 *m)
109} 116}
110 117
111EAPI Eina_Matrix_Type 118EAPI Eina_Matrix_Type
119eina_matrix4_type_get(const Eina_Matrix4 *m)
120{
121 if ((MATRIX_XX(m) == 1) && (MATRIX_XY(m) == 0) && (MATRIX_XZ(m) == 0) && (MATRIX_XW(m) == 0) &&
122 (MATRIX_YX(m) == 0) && (MATRIX_YY(m) == 1) && (MATRIX_YZ(m) == 0) && (MATRIX_YW(m) == 0) &&
123 (MATRIX_ZX(m) == 0) && (MATRIX_ZY(m) == 0) && (MATRIX_ZZ(m) == 1) && (MATRIX_ZW(m) == 0) &&
124 (MATRIX_WX(m) == 0) && (MATRIX_WY(m) == 0) && (MATRIX_WZ(m) == 0) && (MATRIX_WW(m) == 1))
125 return EINA_MATRIX_TYPE_IDENTITY;
126 return EINA_MATRIX_TYPE_AFFINE;
127}
128
129EAPI Eina_Matrix_Type
112eina_matrix3_f16p16_type_get(const Eina_Matrix3_F16p16 *m) 130eina_matrix3_f16p16_type_get(const Eina_Matrix3_F16p16 *m)
113{ 131{
114 if ((MATRIX_ZX(m) != 0) || (MATRIX_ZY(m) != 0) || (MATRIX_ZZ(m) != 65536)) 132 if ((MATRIX_ZX(m) != 0) || (MATRIX_ZY(m) != 0) || (MATRIX_ZZ(m) != 65536))
@@ -158,6 +176,56 @@ eina_matrix3_values_get(const Eina_Matrix3 *m,
158} 176}
159 177
160EAPI void 178EAPI void
179eina_matrix4_values_set(Eina_Matrix4 *m,
180 double xx, double xy, double xz, double xw,
181 double yx, double yy, double yz, double yw,
182 double zx, double zy, double zz, double zw,
183 double wx, double wy, double wz, double ww)
184{
185 MATRIX_XX(m) = xx;
186 MATRIX_XY(m) = xy;
187 MATRIX_XZ(m) = xz;
188 MATRIX_XW(m) = xw;
189 MATRIX_YX(m) = yx;
190 MATRIX_YY(m) = yy;
191 MATRIX_YZ(m) = yz;
192 MATRIX_YW(m) = yw;
193 MATRIX_ZX(m) = zx;
194 MATRIX_ZY(m) = zy;
195 MATRIX_ZZ(m) = zz;
196 MATRIX_ZW(m) = zw;
197 MATRIX_WX(m) = wx;
198 MATRIX_WY(m) = wy;
199 MATRIX_WZ(m) = wz;
200 MATRIX_WW(m) = ww;
201}
202
203EAPI void
204eina_matrix4_values_get(const Eina_Matrix4 *m,
205 double *xx, double *xy, double *xz, double *xw,
206 double *yx, double *yy, double *yz, double *yw,
207 double *zx, double *zy, double *zz, double *zw,
208 double *wx, double *wy, double *wz, double *ww)
209{
210 if (xx) *xx = MATRIX_XX(m);
211 if (xy) *xy = MATRIX_XY(m);
212 if (xz) *xz = MATRIX_XZ(m);
213 if (xw) *xw = MATRIX_XW(m);
214 if (yx) *yx = MATRIX_YX(m);
215 if (yy) *yy = MATRIX_YY(m);
216 if (yz) *yz = MATRIX_YZ(m);
217 if (yw) *yw = MATRIX_YW(m);
218 if (zx) *zx = MATRIX_ZX(m);
219 if (zy) *zy = MATRIX_ZY(m);
220 if (zz) *zz = MATRIX_ZZ(m);
221 if (zw) *zw = MATRIX_ZW(m);
222 if (wx) *wx = MATRIX_WX(m);
223 if (wy) *wy = MATRIX_WY(m);
224 if (wz) *wz = MATRIX_WZ(m);
225 if (ww) *ww = MATRIX_WW(m);
226}
227
228EAPI void
161eina_matrix3_fixed_values_get(const Eina_Matrix3 *m, 229eina_matrix3_fixed_values_get(const Eina_Matrix3 *m,
162 Eina_F16p16 *xx, Eina_F16p16 *xy, Eina_F16p16 *xz, 230 Eina_F16p16 *xx, Eina_F16p16 *xy, Eina_F16p16 *xz,
163 Eina_F16p16 *yx, Eina_F16p16 *yy, Eina_F16p16 *yz, 231 Eina_F16p16 *yx, Eina_F16p16 *yy, Eina_F16p16 *yz,
@@ -590,3 +658,38 @@ eina_matrix3_quad_quad_map(Eina_Matrix3 *m,
590 658
591 return EINA_TRUE; 659 return EINA_TRUE;
592} 660}
661
662EAPI void
663eina_matrix4_matrix3_to(Eina_Matrix3 *m3, const Eina_Matrix4 *m4)
664{
665 MATRIX_XX(m3) = MATRIX_XX(m4);
666 MATRIX_XY(m3) = MATRIX_XY(m4);
667 MATRIX_XZ(m3) = MATRIX_XZ(m4);
668 MATRIX_YX(m3) = MATRIX_YX(m4);
669 MATRIX_YY(m3) = MATRIX_YY(m4);
670 MATRIX_YZ(m3) = MATRIX_YZ(m4);
671 MATRIX_ZX(m3) = MATRIX_ZX(m4);
672 MATRIX_ZY(m3) = MATRIX_ZY(m4);
673 MATRIX_ZZ(m3) = MATRIX_ZZ(m4);
674}
675
676EAPI void
677eina_matrix3_matrix4_to(Eina_Matrix4 *m4, const Eina_Matrix3 *m3)
678{
679 MATRIX_XX(m4) = MATRIX_XX(m3);
680 MATRIX_XY(m4) = MATRIX_XY(m3);
681 MATRIX_XZ(m4) = MATRIX_XZ(m3);
682 MATRIX_XW(m4) = 0;
683 MATRIX_YX(m4) = MATRIX_YX(m3);
684 MATRIX_YY(m4) = MATRIX_YY(m3);
685 MATRIX_YZ(m4) = MATRIX_YZ(m3);
686 MATRIX_YW(m4) = 0;
687 MATRIX_ZX(m4) = MATRIX_ZX(m3);
688 MATRIX_ZY(m4) = MATRIX_ZY(m3);
689 MATRIX_ZZ(m4) = MATRIX_ZZ(m3);
690 MATRIX_ZW(m4) = 0;
691 MATRIX_WX(m4) = 0;
692 MATRIX_WY(m4) = 0;
693 MATRIX_WZ(m4) = 0;
694 MATRIX_WW(m4) = 1;
695}
diff --git a/src/lib/eina/eina_matrix.h b/src/lib/eina/eina_matrix.h
index 4f6c23e729..83fff16540 100644
--- a/src/lib/eina/eina_matrix.h
+++ b/src/lib/eina/eina_matrix.h
@@ -398,5 +398,140 @@ EAPI Eina_Bool eina_matrix3_quad_square_map(Eina_Matrix3 *m,
398 398
399/** 399/**
400 * @} 400 * @}
401 * @defgroup Eina_Matrix4 Matrices in floating point
402 * @ingroup Eina_Basic
403 * @brief Matrix definition and operations
404 * @{
405 */
406
407typedef struct _Eina_Matrix4 Eina_Matrix4;
408struct _Eina_Matrix4
409{
410 double xx; /**< xx in x' = (x * xx) + (y * xy) + (z * xz) + xw */
411 double xy; /**< xy in x' = (x * xx) + (y * xy) + (z * xz) + xw */
412 double xz; /**< xz in x' = (x * xx) + (y * xy) + (z * xz) + xw */
413 double xw; /**< xw in x' = (x * xx) + (y * xy) + (z * xz) + xw */
414
415 double yx; /**< yx in y' = (x * yx) + (y * yy) + (z * yz) + yw */
416 double yy; /**< yy in y' = (x * yx) + (y * yy) + (z * yz) + yw */
417 double yz; /**< yz in y' = (x * yx) + (y * yy) + (z * yz) + yw */
418 double yw; /**< yw in y' = (x * yx) + (y * yy) + (z * yz) + yw */
419
420 double zx; /**< zx in z' = (x * zx) + (y * zy) + (z * zz) + zw */
421 double zy; /**< zy in z' = (x * zx) + (y * zy) + (z * zz) + zw */
422 double zz; /**< zz in z' = (x * zx) + (y * zy) + (z * zz) + zw */
423 double zw; /**< zw in z' = (x * zx) + (y * zy) + (z * zz) + zw */
424
425 double wx; /**< wx in w' = (x * wx) + (y * wy) + (z * wz) + ww */
426 double wy; /**< wy in w' = (x * wx) + (y * wy) + (z * wz) + ww */
427 double wz; /**< wz in w' = (x * wx) + (y * wy) + (z * wz) + ww */
428 double ww; /**< ww in w' = (x * wx) + (y * wy) + (z * wz) + ww */
429};
430
431/**
432 * @brief Return the type of the given floating point matrix.
433 *
434 * @param m The floating point matrix.
435 * @return The type of the matrix.
436 *
437 * This function returns the type of the matrix @p m. No check is done
438 * on @p m.
439 *
440 * @since 1.15
441 */
442EAPI Eina_Matrix_Type eina_matrix4_type_get(const Eina_Matrix4 *m);
443
444/**
445 * @brief Set the values of the coefficients of the given floating
446 * point matrix.
447 *
448 * @param m The floating point matrix.
449 * @param xx The first coefficient value.
450 * @param xy The second coefficient value.
451 * @param xz The third coefficient value.
452 * @param xw The fourth coefficient value.
453 * @param yx The fifth coefficient value.
454 * @param yy The sixth coefficient value.
455 * @param yz The seventh coefficient value.
456 * @param yw The heighth coefficient value.
457 * @param zx The nineth coefficient value.
458 * @param zy The tenth coefficient value.
459 * @param zz The eleventh coefficient value.
460 * @param zw The twelfth coefficient value.
461 * @param wx The thirteenth coefficient value.
462 * @param wy The fourteenth coefficient value.
463 * @param wz The fifteenth coefficient value.
464 * @param ww The sizteenth coefficient value.
465 *
466 * This function sets the values of the coefficients of the matrix
467 * @p m. No check is done on @p m.
468 *
469 * @see eina_matrix4_values_get()
470 *
471 * @since 1.15
472 */
473EAPI void eina_matrix4_values_set(Eina_Matrix4 *m,
474 double xx, double xy, double xz, double xw,
475 double yx, double yy, double yz, double yw,
476 double zx, double zy, double zz, double zw,
477 double wx, double wy, double wz, double ww);
478
479/**
480 * @brief Get the values of the coefficients of the given floating
481 * point matrix.
482 *
483 * @param m The floating point matrix.
484 * @param xx The first coefficient value.
485 * @param xy The second coefficient value.
486 * @param xz The third coefficient value.
487 * @param xw The fourth coefficient value.
488 * @param yx The fifth coefficient value.
489 * @param yy The sixth coefficient value.
490 * @param yz The seventh coefficient value.
491 * @param yw The heighth coefficient value.
492 * @param zx The nineth coefficient value.
493 * @param zy The tenth coefficient value.
494 * @param zz The eleventh coefficient value.
495 * @param zw The twelfth coefficient value.
496 * @param wx The thirteenth coefficient value.
497 * @param wy The fourteenth coefficient value.
498 * @param wz The fifteenth coefficient value.
499 * @param ww The sizteenth coefficient value.
500 *
501 * This function gets the values of the coefficients of the matrix
502 * @p m. No check is done on @p m.
503 *
504 * @see eina_matrix4_values_set()
505 *
506 * @since 1.15
507 */
508EAPI void eina_matrix4_values_get(const Eina_Matrix4 *m,
509 double *xx, double *xy, double *xz, double *xw,
510 double *yx, double *yy, double *yz, double *yw,
511 double *zx, double *zy, double *zz, double *zw,
512 double *wx, double *wy, double *wz, double *ww);
513
514/**
515 * @brief Convert an Eina_Matrix4 into an Eina_Matrix3.
516 *
517 * @param m3 The destination Eina_Matrix3.
518 * @param m4 The source Eina_Matrix4.
519 *
520 * @since 1.15
521 */
522EAPI void eina_matrix4_matrix3_to(Eina_Matrix3 *m3, const Eina_Matrix4 *m4);
523
524/**
525 * @brief Convert an Eina_Matrix3 into an Eina_Matrix4.
526 *
527 * @param m3 The destination Eina_Matrix3.
528 * @param m4 The source Eina_Matrix4.
529 *
530 * @since 1.15
531 */
532EAPI void eina_matrix3_matrix4_to(Eina_Matrix4 *m4, const Eina_Matrix3 *m3);
533
534/**
535 * @}
401 */ 536 */
402#endif /*EINA_MATRIX3_H_*/ 537#endif /*EINA_MATRIX3_H_*/