summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCedric BAIL <cedric@osg.samsung.com>2015-06-30 18:39:39 +0200
committerCedric BAIL <cedric@osg.samsung.com>2015-08-21 16:40:31 +0200
commitabfe65e05d6ef483432def7a4554f401e33657ca (patch)
tree117e95cad46a77bc5d0097ab2f874527d661e408
parent26f33dc6bd848160577eb9308e3bc77c09dc0aed (diff)
eina: add eina_matrix4_multiply and eina_matrix4_identity function.
-rw-r--r--src/lib/eina/eina_matrix.c113
-rw-r--r--src/lib/eina/eina_matrix.h22
2 files changed, 135 insertions, 0 deletions
diff --git a/src/lib/eina/eina_matrix.c b/src/lib/eina/eina_matrix.c
index 96a0971f11..4263322ae1 100644
--- a/src/lib/eina/eina_matrix.c
+++ b/src/lib/eina/eina_matrix.c
@@ -24,6 +24,7 @@
24 24
25#include <math.h> 25#include <math.h>
26#include <float.h> 26#include <float.h>
27#include <string.h>
27 28
28#include "eina_fp.h" 29#include "eina_fp.h"
29#include "eina_rectangle.h" 30#include "eina_rectangle.h"
@@ -936,3 +937,115 @@ eina_matrix4_transpose(Eina_Matrix4 *out, const Eina_Matrix4 *in)
936 MATRIX_WZ(out) = MATRIX_ZW(in); 937 MATRIX_WZ(out) = MATRIX_ZW(in);
937 MATRIX_WW(out) = MATRIX_WW(in); 938 MATRIX_WW(out) = MATRIX_WW(in);
938} 939}
940
941EAPI void
942eina_matrix4_multiply(Eina_Matrix4 *out,
943 const Eina_Matrix4 *a, const Eina_Matrix4 *b)
944{
945 // FIXME: start implementing SSE multiplication here
946 MATRIX_XX(out) =
947 MATRIX_XX(a) * MATRIX_XX(b)
948 + MATRIX_XY(a) * MATRIX_YX(b)
949 + MATRIX_XZ(a) * MATRIX_ZX(b)
950 + MATRIX_XW(a) * MATRIX_WX(b);
951
952 MATRIX_XY(out) =
953 MATRIX_XX(a) * MATRIX_XY(b)
954 + MATRIX_XY(a) * MATRIX_YY(b)
955 + MATRIX_XZ(a) * MATRIX_ZY(b)
956 + MATRIX_XW(a) * MATRIX_WY(b);
957
958 MATRIX_XZ(out) =
959 MATRIX_XX(a) * MATRIX_XZ(b)
960 + MATRIX_XY(a) * MATRIX_YZ(b)
961 + MATRIX_XZ(a) * MATRIX_ZZ(b)
962 + MATRIX_XW(a) * MATRIX_WZ(b);
963
964 MATRIX_XW(out) =
965 MATRIX_XX(a) * MATRIX_XW(b)
966 + MATRIX_XY(a) * MATRIX_YW(b)
967 + MATRIX_XZ(a) * MATRIX_ZW(b)
968 + MATRIX_XW(a) * MATRIX_WW(b);
969
970 MATRIX_YX(out) =
971 MATRIX_YX(a) * MATRIX_XX(b)
972 + MATRIX_YY(a) * MATRIX_YX(b)
973 + MATRIX_YZ(a) * MATRIX_ZX(b)
974 + MATRIX_YW(a) * MATRIX_WX(b);
975
976 MATRIX_YY(out) =
977 MATRIX_YX(a) * MATRIX_XY(b)
978 + MATRIX_YY(a) * MATRIX_YY(b)
979 + MATRIX_YZ(a) * MATRIX_ZY(b)
980 + MATRIX_YW(a) * MATRIX_WY(b);
981
982 MATRIX_YZ(out) =
983 MATRIX_YX(a) * MATRIX_XZ(b)
984 + MATRIX_YY(a) * MATRIX_YZ(b)
985 + MATRIX_YZ(a) * MATRIX_ZZ(b)
986 + MATRIX_YW(a) * MATRIX_WZ(b);
987
988 MATRIX_YW(out) =
989 MATRIX_YX(a) * MATRIX_XW(b)
990 + MATRIX_YY(a) * MATRIX_YW(b)
991 + MATRIX_YZ(a) * MATRIX_ZW(b)
992 + MATRIX_YW(a) * MATRIX_WW(b);
993
994 MATRIX_ZX(out) =
995 MATRIX_ZX(a) * MATRIX_XX(b)
996 + MATRIX_ZY(a) * MATRIX_YX(b)
997 + MATRIX_ZZ(a) * MATRIX_ZX(b)
998 + MATRIX_ZW(a) * MATRIX_WX(b);
999
1000 MATRIX_ZY(out) =
1001 MATRIX_ZX(a) * MATRIX_XY(b)
1002 + MATRIX_ZY(a) * MATRIX_YY(b)
1003 + MATRIX_ZZ(a) * MATRIX_ZY(b)
1004 + MATRIX_ZW(a) * MATRIX_WY(b);
1005
1006 MATRIX_ZZ(out) =
1007 MATRIX_ZX(a) * MATRIX_XZ(b)
1008 + MATRIX_ZY(a) * MATRIX_YZ(b)
1009 + MATRIX_ZZ(a) * MATRIX_ZZ(b)
1010 + MATRIX_ZW(a) * MATRIX_WZ(b);
1011
1012 MATRIX_ZW(out) =
1013 MATRIX_ZX(a) * MATRIX_XW(b)
1014 + MATRIX_ZY(a) * MATRIX_YW(b)
1015 + MATRIX_ZZ(a) * MATRIX_ZW(b)
1016 + MATRIX_ZW(a) * MATRIX_WW(b);
1017
1018 MATRIX_WX(out) =
1019 MATRIX_WX(a) * MATRIX_XX(b)
1020 + MATRIX_WY(a) * MATRIX_YX(b)
1021 + MATRIX_WZ(a) * MATRIX_ZX(b)
1022 + MATRIX_WW(a) * MATRIX_WX(b);
1023
1024 MATRIX_WY(out) =
1025 MATRIX_WX(a) * MATRIX_XY(b)
1026 + MATRIX_WY(a) * MATRIX_YY(b)
1027 + MATRIX_WZ(a) * MATRIX_ZY(b)
1028 + MATRIX_WW(a) * MATRIX_WY(b);
1029
1030 MATRIX_WZ(out) =
1031 MATRIX_WX(a) * MATRIX_XZ(b)
1032 + MATRIX_WY(a) * MATRIX_YZ(b)
1033 + MATRIX_WZ(a) * MATRIX_ZZ(b)
1034 + MATRIX_WW(a) * MATRIX_WZ(b);
1035
1036 MATRIX_WW(out) =
1037 MATRIX_WX(a) * MATRIX_XW(b)
1038 + MATRIX_WY(a) * MATRIX_YW(b)
1039 + MATRIX_WZ(a) * MATRIX_ZW(b)
1040 + MATRIX_WW(a) * MATRIX_WW(b);
1041}
1042
1043EAPI void
1044eina_matrix4_identity(Eina_Matrix4 *out)
1045{
1046 memset(out, 0, sizeof (Eina_Matrix4));
1047 MATRIX_XX(out) = 1;
1048 MATRIX_YY(out) = 1;
1049 MATRIX_ZZ(out) = 1;
1050 MATRIX_WW(out) = 1;
1051}
diff --git a/src/lib/eina/eina_matrix.h b/src/lib/eina/eina_matrix.h
index ab6be4cf79..17af8d344a 100644
--- a/src/lib/eina/eina_matrix.h
+++ b/src/lib/eina/eina_matrix.h
@@ -582,6 +582,28 @@ EAPI void eina_matrix4_matrix3_to(Eina_Matrix3 *m3, const Eina_Matrix4 *m4);
582EAPI void eina_matrix3_matrix4_to(Eina_Matrix4 *m4, const Eina_Matrix3 *m3); 582EAPI void eina_matrix3_matrix4_to(Eina_Matrix4 *m4, const Eina_Matrix3 *m3);
583 583
584/** 584/**
585 * @brief Set an identity matrix
586 *
587 * @param out The matrix to set
588 *
589 * @since 1.15
590 */
591EAPI void eina_matrix4_identity(Eina_Matrix4 *out);
592
593/**
594 * @brief Multiply two matrix
595 *
596 * @param out The resulting matrix
597 * @param a The first member of the multiplication
598 * @param b The second member of the multiplication
599 *
600 * @since 1.15
601 */
602EAPI void eina_matrix4_multiply(Eina_Matrix4 *out,
603 const Eina_Matrix4 *a, const Eina_Matrix4 *b);
604
605
606/**
585 * @} 607 * @}
586 */ 608 */
587#endif /*EINA_MATRIX3_H_*/ 609#endif /*EINA_MATRIX3_H_*/