summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCedric BAIL <cedric@osg.samsung.com>2015-06-24 17:23:23 +0200
committerCedric BAIL <cedric@osg.samsung.com>2015-08-21 16:40:31 +0200
commit694149c773af18b5d5a3abb883cf7d521bb4cf56 (patch)
treeee5aba21dbe434aa98e3e14d3e1f08d9c9b9c4d3
parent4f0f81bb30f33b8e5f72008c2cf2ef438d5283e6 (diff)
eina: add eina_matrix4_normalized.
-rw-r--r--src/lib/eina/eina_matrix.c29
-rw-r--r--src/lib/eina/eina_matrix.h15
2 files changed, 44 insertions, 0 deletions
diff --git a/src/lib/eina/eina_matrix.c b/src/lib/eina/eina_matrix.c
index 2e994df758..a43c5b294f 100644
--- a/src/lib/eina/eina_matrix.c
+++ b/src/lib/eina/eina_matrix.c
@@ -23,6 +23,7 @@
23#include "eina_private.h" 23#include "eina_private.h"
24 24
25#include <math.h> 25#include <math.h>
26#include <float.h>
26 27
27#include "eina_fp.h" 28#include "eina_fp.h"
28#include "eina_rectangle.h" 29#include "eina_rectangle.h"
@@ -723,3 +724,31 @@ eina_matrix4_determinant(const Eina_Matrix4 *m)
723 - MATRIX_XY(m) * MATRIX_YX(m) * MATRIX_ZZ(m) * MATRIX_WW(m) 724 - MATRIX_XY(m) * MATRIX_YX(m) * MATRIX_ZZ(m) * MATRIX_WW(m)
724 + MATRIX_XX(m) * MATRIX_YY(m) * MATRIX_ZZ(m) * MATRIX_WW(m); 725 + MATRIX_XX(m) * MATRIX_YY(m) * MATRIX_ZZ(m) * MATRIX_WW(m);
725} 726}
727
728EAPI Eina_Bool
729eina_matrix4_normalized(Eina_Matrix4 *out, const Eina_Matrix4 *in)
730{
731 double det;
732
733 det = eina_matrix4_determinant(in);
734 if (fabs(det) < DBL_EPSILON) return EINA_FALSE;
735
736 MATRIX_XX(out) = MATRIX_XX(in) / det;
737 MATRIX_XY(out) = MATRIX_XY(in) / det;
738 MATRIX_XZ(out) = MATRIX_XZ(in) / det;
739 MATRIX_XW(out) = MATRIX_XW(in) / det;
740 MATRIX_YX(out) = MATRIX_YX(in) / det;
741 MATRIX_YY(out) = MATRIX_YY(in) / det;
742 MATRIX_YZ(out) = MATRIX_YZ(in) / det;
743 MATRIX_YW(out) = MATRIX_YW(in) / det;
744 MATRIX_ZX(out) = MATRIX_ZX(in) / det;
745 MATRIX_ZY(out) = MATRIX_ZY(in) / det;
746 MATRIX_ZZ(out) = MATRIX_ZZ(in) / det;
747 MATRIX_ZW(out) = MATRIX_ZW(in) / det;
748 MATRIX_WX(out) = MATRIX_WX(in) / det;
749 MATRIX_WY(out) = MATRIX_WY(in) / det;
750 MATRIX_WZ(out) = MATRIX_WZ(in) / det;
751 MATRIX_WW(out) = MATRIX_WW(in) / det;
752
753 return EINA_TRUE;
754}
diff --git a/src/lib/eina/eina_matrix.h b/src/lib/eina/eina_matrix.h
index 8dc7014037..bf02f17b5b 100644
--- a/src/lib/eina/eina_matrix.h
+++ b/src/lib/eina/eina_matrix.h
@@ -525,6 +525,21 @@ EAPI void eina_matrix4_values_get(const Eina_Matrix4 *m,
525EAPI double eina_matrix4_determinant(const Eina_Matrix4 *m); 525EAPI double eina_matrix4_determinant(const Eina_Matrix4 *m);
526 526
527/** 527/**
528 * @brief Return the determinant of the given matrix.
529 *
530 * @param m The matrix.
531 * @return The determinant.
532 *
533 * This function returns the determinant of the matrix @p m. No check
534 * is done on @p m.
535 *
536 * @since 1.15
537 */
538EAPI Eina_Bool eina_matrix4_normalized(Eina_Matrix4 *out,
539 const Eina_Matrix4 *in);
540
541
542/**
528 * @brief Convert an Eina_Matrix4 into an Eina_Matrix3. 543 * @brief Convert an Eina_Matrix4 into an Eina_Matrix3.
529 * 544 *
530 * @param m3 The destination Eina_Matrix3. 545 * @param m3 The destination Eina_Matrix3.