summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJunsuChoi <jsuya.choi@samsung.com>2020-01-29 14:56:05 +0900
committerJunsuChoi <jsuya.choi@samsung.com>2020-01-29 15:31:07 +0900
commitd1660bdfe5f3a7f259ee38d6daeeb975754e121a (patch)
treeab340272e0a648b01d9b46fa9095c9b62316242d
parentb8f5d12d4e224976d6a01937fcacc73ed5353216 (diff)
eina_matrix: Add eina_matrix4 operator(translate, rotate, scale)
Summary: Add an operator related to the 3D transform in eina_matrix. enum eina_matrix_axis EINA_MATRIX_AXIS_X EINA_MATRIX_AXIS_Y EINA_MATRIX_AXIS_Z eina_matrix4_translate eina_matrix4_scale eina_matrix4_rotate eina_matrix4_transpose Test Plan: src/tests/eina/eina_test_matrix.c Reviewers: Hermet, bu5hm4n, kimcinoo, segfaultxavi Reviewed By: segfaultxavi Subscribers: cedric, #reviewers, #committers Tags: #efl Differential Revision: https://phab.enlightenment.org/D11159
-rw-r--r--src/lib/eina/eina_matrix.c206
-rw-r--r--src/lib/eina/eina_matrix.h64
-rw-r--r--src/tests/eina/eina_test_matrix.c123
3 files changed, 358 insertions, 35 deletions
diff --git a/src/lib/eina/eina_matrix.c b/src/lib/eina/eina_matrix.c
index 7c30d1e767..db3779b8d6 100644
--- a/src/lib/eina/eina_matrix.c
+++ b/src/lib/eina/eina_matrix.c
@@ -1033,41 +1033,7 @@ eina_matrix4_multiply(Eina_Matrix4 *out, const Eina_Matrix4 *mat_a,
1033 return; 1033 return;
1034 } 1034 }
1035 1035
1036 MATRIX_XX(out) = MATRIX_XX(mat_a) * MATRIX_XX(mat_b) + MATRIX_YX(mat_a) * MATRIX_XY(mat_b) + 1036 eina_matrix4_compose(mat_a, mat_b, out);
1037 MATRIX_ZX(mat_a) * MATRIX_XZ(mat_b) + MATRIX_WX(mat_a) * MATRIX_XW(mat_b);
1038 MATRIX_YX(out) = MATRIX_XX(mat_a) * MATRIX_YX(mat_b) + MATRIX_YX(mat_a) * MATRIX_YY(mat_b) +
1039 MATRIX_ZX(mat_a) * MATRIX_YZ(mat_b) + MATRIX_WX(mat_a) * MATRIX_YW(mat_b);
1040 MATRIX_ZX(out) = MATRIX_XX(mat_a) * MATRIX_ZX(mat_b) + MATRIX_YX(mat_a) * MATRIX_ZY(mat_b) +
1041 MATRIX_ZX(mat_a) * MATRIX_ZZ(mat_b) + MATRIX_WX(mat_a) * MATRIX_ZW(mat_b);
1042 MATRIX_WX(out) = MATRIX_XX(mat_a) * MATRIX_WX(mat_b) + MATRIX_YX(mat_a) * MATRIX_WY(mat_b) +
1043 MATRIX_ZX(mat_a) * MATRIX_WZ(mat_b) + MATRIX_WX(mat_a) * MATRIX_WW(mat_b);
1044
1045 MATRIX_XY(out) = MATRIX_XY(mat_a) * MATRIX_XX(mat_b) + MATRIX_YY(mat_a) * MATRIX_XY(mat_b) +
1046 MATRIX_ZY(mat_a) * MATRIX_XZ(mat_b) + MATRIX_WY(mat_a) * MATRIX_XW(mat_b);
1047 MATRIX_YY(out) = MATRIX_XY(mat_a) * MATRIX_YX(mat_b) + MATRIX_YY(mat_a) * MATRIX_YY(mat_b) +
1048 MATRIX_ZY(mat_a) * MATRIX_YZ(mat_b) + MATRIX_WY(mat_a) * MATRIX_YW(mat_b);
1049 MATRIX_ZY(out) = MATRIX_XY(mat_a) * MATRIX_ZX(mat_b) + MATRIX_YY(mat_a) * MATRIX_ZY(mat_b) +
1050 MATRIX_ZY(mat_a) * MATRIX_ZZ(mat_b) + MATRIX_WY(mat_a) * MATRIX_ZW(mat_b);
1051 MATRIX_WY(out) = MATRIX_XY(mat_a) * MATRIX_WX(mat_b) + MATRIX_YY(mat_a) * MATRIX_WY(mat_b) +
1052 MATRIX_ZY(mat_a) * MATRIX_WZ(mat_b) + MATRIX_WY(mat_a) * MATRIX_WW(mat_b);
1053
1054 MATRIX_XZ(out) = MATRIX_XZ(mat_a) * MATRIX_XX(mat_b) + MATRIX_YZ(mat_a) * MATRIX_XY(mat_b) +
1055 MATRIX_ZZ(mat_a) * MATRIX_XZ(mat_b) + MATRIX_WZ(mat_a) * MATRIX_XW(mat_b);
1056 MATRIX_YZ(out) = MATRIX_XZ(mat_a) * MATRIX_YX(mat_b) + MATRIX_YZ(mat_a) * MATRIX_YY(mat_b) +
1057 MATRIX_ZZ(mat_a) * MATRIX_YZ(mat_b) + MATRIX_WZ(mat_a) * MATRIX_YW(mat_b);
1058 MATRIX_ZZ(out) = MATRIX_XZ(mat_a) * MATRIX_ZX(mat_b) + MATRIX_YZ(mat_a) * MATRIX_ZY(mat_b) +
1059 MATRIX_ZZ(mat_a) * MATRIX_ZZ(mat_b) + MATRIX_WZ(mat_a) * MATRIX_ZW(mat_b);
1060 MATRIX_WZ(out) = MATRIX_XZ(mat_a) * MATRIX_WX(mat_b) + MATRIX_YZ(mat_a) * MATRIX_WY(mat_b) +
1061 MATRIX_ZZ(mat_a) * MATRIX_WZ(mat_b) + MATRIX_WZ(mat_a) * MATRIX_WW(mat_b);
1062
1063 MATRIX_XW(out) = MATRIX_XW(mat_a) * MATRIX_XX(mat_b) + MATRIX_YW(mat_a) * MATRIX_XY(mat_b) +
1064 MATRIX_ZW(mat_a) * MATRIX_XZ(mat_b) + MATRIX_WW(mat_a) * MATRIX_XW(mat_b);
1065 MATRIX_YW(out) = MATRIX_XW(mat_a) * MATRIX_YX(mat_b) + MATRIX_YW(mat_a) * MATRIX_YY(mat_b) +
1066 MATRIX_ZW(mat_a) * MATRIX_YZ(mat_b) + MATRIX_WW(mat_a) * MATRIX_YW(mat_b);
1067 MATRIX_ZW(out) = MATRIX_XW(mat_a) * MATRIX_ZX(mat_b) + MATRIX_YW(mat_a) * MATRIX_ZY(mat_b) +
1068 MATRIX_ZW(mat_a) * MATRIX_ZZ(mat_b) + MATRIX_WW(mat_a) * MATRIX_ZW(mat_b);
1069 MATRIX_WW(out) = MATRIX_XW(mat_a) * MATRIX_WX(mat_b) + MATRIX_YW(mat_a) * MATRIX_WY(mat_b) +
1070 MATRIX_ZW(mat_a) * MATRIX_WZ(mat_b) + MATRIX_WW(mat_a) * MATRIX_WW(mat_b);
1071} 1037}
1072 1038
1073EAPI void 1039EAPI void
@@ -1101,6 +1067,176 @@ eina_matrix4_ortho_set(Eina_Matrix4 *m,
1101} 1067}
1102 1068
1103EAPI void 1069EAPI void
1070eina_matrix4_compose(const Eina_Matrix4 *mat_a,
1071 const Eina_Matrix4 *mat_b,
1072 Eina_Matrix4 *out)
1073{
1074 double xx, xy, xz, xw,
1075 yx, yy, yz, yw,
1076 zx, zy, zz, zw,
1077 wx, wy, wz, ww;
1078
1079 xx = MATRIX_XX(mat_a) * MATRIX_XX(mat_b) + MATRIX_XY(mat_a) * MATRIX_YX(mat_b) +
1080 MATRIX_XZ(mat_a) * MATRIX_ZX(mat_b) + MATRIX_XW(mat_a) * MATRIX_WX(mat_b);
1081 xy = MATRIX_XX(mat_a) * MATRIX_XY(mat_b) + MATRIX_XY(mat_a) * MATRIX_YY(mat_b) +
1082 MATRIX_XZ(mat_a) * MATRIX_ZY(mat_b) + MATRIX_XW(mat_a) * MATRIX_WY(mat_b);
1083 xz = MATRIX_XX(mat_a) * MATRIX_XZ(mat_b) + MATRIX_XY(mat_a) * MATRIX_YZ(mat_b) +
1084 MATRIX_XZ(mat_a) * MATRIX_ZZ(mat_b) + MATRIX_XW(mat_a) * MATRIX_WZ(mat_b);
1085 xw = MATRIX_XX(mat_a) * MATRIX_XW(mat_b) + MATRIX_XY(mat_a) * MATRIX_YW(mat_b) +
1086 MATRIX_XZ(mat_a) * MATRIX_ZW(mat_b) + MATRIX_XW(mat_a) * MATRIX_WW(mat_b);
1087
1088 yx = MATRIX_YX(mat_a) * MATRIX_XX(mat_b) + MATRIX_YY(mat_a) * MATRIX_YX(mat_b) +
1089 MATRIX_YZ(mat_a) * MATRIX_ZX(mat_b) + MATRIX_YW(mat_a) * MATRIX_WX(mat_b);
1090 yy = MATRIX_YX(mat_a) * MATRIX_XY(mat_b) + MATRIX_YY(mat_a) * MATRIX_YY(mat_b) +
1091 MATRIX_YZ(mat_a) * MATRIX_ZY(mat_b) + MATRIX_YW(mat_a) * MATRIX_WY(mat_b);
1092 yz = MATRIX_YX(mat_a) * MATRIX_XZ(mat_b) + MATRIX_YY(mat_a) * MATRIX_YZ(mat_b) +
1093 MATRIX_YZ(mat_a) * MATRIX_ZZ(mat_b) + MATRIX_YW(mat_a) * MATRIX_WZ(mat_b);
1094 yw = MATRIX_YX(mat_a) * MATRIX_XW(mat_b) + MATRIX_YY(mat_a) * MATRIX_YW(mat_b) +
1095 MATRIX_YZ(mat_a) * MATRIX_ZW(mat_b) + MATRIX_YW(mat_a) * MATRIX_WW(mat_b);
1096
1097 zx = MATRIX_ZX(mat_a) * MATRIX_XX(mat_b) + MATRIX_ZY(mat_a) * MATRIX_YX(mat_b) +
1098 MATRIX_ZZ(mat_a) * MATRIX_ZX(mat_b) + MATRIX_ZW(mat_a) * MATRIX_WX(mat_b);
1099 zy = MATRIX_ZX(mat_a) * MATRIX_XY(mat_b) + MATRIX_ZY(mat_a) * MATRIX_YY(mat_b) +
1100 MATRIX_ZZ(mat_a) * MATRIX_ZY(mat_b) + MATRIX_ZW(mat_a) * MATRIX_WY(mat_b);
1101 zz = MATRIX_ZX(mat_a) * MATRIX_XZ(mat_b) + MATRIX_ZY(mat_a) * MATRIX_YZ(mat_b) +
1102 MATRIX_ZZ(mat_a) * MATRIX_ZZ(mat_b) + MATRIX_ZW(mat_a) * MATRIX_WZ(mat_b);
1103 zw = MATRIX_ZX(mat_a) * MATRIX_XW(mat_b) + MATRIX_ZY(mat_a) * MATRIX_YW(mat_b) +
1104 MATRIX_ZZ(mat_a) * MATRIX_ZW(mat_b) + MATRIX_ZW(mat_a) * MATRIX_WW(mat_b);
1105
1106 wx = MATRIX_WX(mat_a) * MATRIX_XX(mat_b) + MATRIX_WY(mat_a) * MATRIX_YX(mat_b) +
1107 MATRIX_WZ(mat_a) * MATRIX_ZX(mat_b) + MATRIX_WW(mat_a) * MATRIX_WX(mat_b);
1108 wy = MATRIX_WX(mat_a) * MATRIX_XY(mat_b) + MATRIX_WY(mat_a) * MATRIX_YY(mat_b) +
1109 MATRIX_WZ(mat_a) * MATRIX_ZY(mat_b) + MATRIX_WW(mat_a) * MATRIX_WY(mat_b);
1110 wz = MATRIX_WX(mat_a) * MATRIX_XZ(mat_b) + MATRIX_WY(mat_a) * MATRIX_YZ(mat_b) +
1111 MATRIX_WZ(mat_a) * MATRIX_ZZ(mat_b) + MATRIX_WW(mat_a) * MATRIX_WZ(mat_b);
1112 ww = MATRIX_WX(mat_a) * MATRIX_XW(mat_b) + MATRIX_WY(mat_a) * MATRIX_YW(mat_b) +
1113 MATRIX_WZ(mat_a) * MATRIX_ZW(mat_b) + MATRIX_WW(mat_a) * MATRIX_WW(mat_b);
1114
1115 MATRIX_XX(out) = xx;
1116 MATRIX_XY(out) = xy;
1117 MATRIX_XZ(out) = xz;
1118 MATRIX_XW(out) = xw;
1119
1120 MATRIX_YX(out) = yx;
1121 MATRIX_YY(out) = yy;
1122 MATRIX_YZ(out) = yz;
1123 MATRIX_YW(out) = yw;
1124
1125 MATRIX_ZX(out) = zx;
1126 MATRIX_ZY(out) = zy;
1127 MATRIX_ZZ(out) = zz;
1128 MATRIX_ZW(out) = zw;
1129
1130 MATRIX_WX(out) = wx;
1131 MATRIX_WY(out) = wy;
1132 MATRIX_WZ(out) = wz;
1133 MATRIX_WW(out) = ww;
1134}
1135
1136EAPI void
1137eina_matrix4_translate(Eina_Matrix4 *t, double tx, double ty, double tz)
1138{
1139 Eina_Matrix4 tmp;
1140 MATRIX_XX(&tmp) = 1;
1141 MATRIX_XY(&tmp) = 0;
1142 MATRIX_XZ(&tmp) = 0;
1143 MATRIX_XW(&tmp) = tx;
1144
1145 MATRIX_YX(&tmp) = 0;
1146 MATRIX_YY(&tmp) = 1;
1147 MATRIX_YZ(&tmp) = 0;
1148 MATRIX_YW(&tmp) = ty;
1149
1150 MATRIX_ZX(&tmp) = 0;
1151 MATRIX_ZY(&tmp) = 0;
1152 MATRIX_ZZ(&tmp) = 1;
1153 MATRIX_ZW(&tmp) = tz;
1154
1155 MATRIX_WX(&tmp) = 0;
1156 MATRIX_WY(&tmp) = 0;
1157 MATRIX_WZ(&tmp) = 0;
1158 MATRIX_WW(&tmp) = 1;
1159
1160 eina_matrix4_compose(&tmp, t, t);
1161}
1162
1163EAPI void
1164eina_matrix4_scale(Eina_Matrix4 *t, double sx, double sy, double sz)
1165{
1166 Eina_Matrix4 tmp;
1167 MATRIX_XX(&tmp) = sx;
1168 MATRIX_XY(&tmp) = 0;
1169 MATRIX_XZ(&tmp) = 0;
1170 MATRIX_XW(&tmp) = 0;
1171
1172 MATRIX_YX(&tmp) = 0;
1173 MATRIX_YY(&tmp) = sy;
1174 MATRIX_YZ(&tmp) = 0;
1175 MATRIX_YW(&tmp) = 0;
1176
1177 MATRIX_ZX(&tmp) = 0;
1178 MATRIX_ZY(&tmp) = 0;
1179 MATRIX_ZZ(&tmp) = sz;
1180 MATRIX_ZW(&tmp) = 0;
1181
1182 MATRIX_WX(&tmp) = 0;
1183 MATRIX_WY(&tmp) = 0;
1184 MATRIX_WZ(&tmp) = 0;
1185 MATRIX_WW(&tmp) = 1;
1186
1187 eina_matrix4_compose(&tmp, t, t);
1188}
1189
1190EAPI void
1191eina_matrix4_rotate(Eina_Matrix4 *t, double rad, Eina_Matrix_Axis axis)
1192{
1193 double c, s;
1194
1195 /* Note: Local functions do not guarantee accuracy.
1196 * Errors occur in the calculation of very small or very large numbers.
1197 * Local cos and sin functions differ from the math header cosf and sinf functions
1198 * by result values. The 4th decimal place is different.
1199 * But local functions are certainly faster than functions in math library.
1200 * Later we would want someone to look at this and improve accuracy.
1201 */
1202#if 1
1203 c = cos(rad);
1204 s = sin(rad);
1205#else
1206 /* normalize the angle between -pi,pi */
1207 rad = fmod(rad + M_PI, 2 * M_PI) - M_PI;
1208 c = _cos(rad);
1209 s = _sin(rad);
1210#endif
1211
1212 Eina_Matrix4 tmp;
1213 eina_matrix4_identity(&tmp);
1214
1215 switch (axis)
1216 {
1217 case EINA_MATRIX_AXIS_X:
1218 MATRIX_YY(&tmp) = c;
1219 MATRIX_YZ(&tmp) = -s;
1220 MATRIX_ZY(&tmp) = s;
1221 MATRIX_ZZ(&tmp) = c;
1222 break;
1223 case EINA_MATRIX_AXIS_Y:
1224 MATRIX_XX(&tmp) = c;
1225 MATRIX_XZ(&tmp) = s;
1226 MATRIX_ZX(&tmp) = -s;
1227 MATRIX_ZZ(&tmp) = c;
1228 break;
1229 case EINA_MATRIX_AXIS_Z:
1230 MATRIX_XX(&tmp) = c;
1231 MATRIX_XY(&tmp) = -s;
1232 MATRIX_YX(&tmp) = s;
1233 MATRIX_YY(&tmp) = c;
1234 break;
1235 }
1236 eina_matrix4_compose(&tmp, t, t);
1237}
1238
1239EAPI void
1104eina_matrix3_array_set(Eina_Matrix3 *m, const double *v) 1240eina_matrix3_array_set(Eina_Matrix3 *m, const double *v)
1105{ 1241{
1106 memcpy(&MATRIX_XX(m), v, sizeof(double) * 9); 1242 memcpy(&MATRIX_XX(m), v, sizeof(double) * 9);
diff --git a/src/lib/eina/eina_matrix.h b/src/lib/eina/eina_matrix.h
index ed12f6f0db..201054974b 100644
--- a/src/lib/eina/eina_matrix.h
+++ b/src/lib/eina/eina_matrix.h
@@ -57,6 +57,17 @@ typedef enum _Eina_Matrix_Type
57 } Eina_Matrix_Type; 57 } Eina_Matrix_Type;
58 58
59/** 59/**
60 * @typedef Eina_Matrix_Axis
61 * Matrix Axes
62 */
63typedef enum _Eina_Matrix_Axis
64 {
65 EINA_MATRIX_AXIS_X, /**< X-Axis */
66 EINA_MATRIX_AXIS_Y, /**< Y-Axis */
67 EINA_MATRIX_AXIS_Z, /**< Z-Axis */
68 } Eina_Matrix_Axis;
69
70/**
60 * @defgroup Eina_Matrix3_Group 3x3 floating point matrices 71 * @defgroup Eina_Matrix3_Group 3x3 floating point matrices
61 * 72 *
62 * @brief Definition and operations for 3x3 matrices. 73 * @brief Definition and operations for 3x3 matrices.
@@ -932,6 +943,59 @@ EAPI void eina_matrix4_ortho_set(Eina_Matrix4 *m,
932 double left, double right, double bottom, double top, 943 double left, double right, double bottom, double top,
933 double dnear, double dfar); 944 double dnear, double dfar);
934 945
946
947/**
948 * @brief Sets out as the matrix multiplication (composition) of two matrices.
949 *
950 * @param[in] mat_a The first matrix. Must be non-NULL.
951 * @param[in] mat_b The second matrix. Must be non-NULL.
952 * @param[out] out The results matrix.
953 *
954 * In matrix multiplication, AB, the resultant matrix is created from
955 * the rows of A multiplied against the columns of B and summed. This
956 * is not commutative; i.e. AB != BA, so the ordering of arguments
957 * @p m1 and @p m2 matters.
958 *
959 * @since 1.24
960 */
961EAPI void eina_matrix4_compose(const Eina_Matrix4 *mat_a,
962 const Eina_Matrix4 *mat_b,
963 Eina_Matrix4 *out);
964
965/**
966 * @brief Sets the matrix values for a translation operation.
967 *
968 * @param[out] t Where to store the resulting matrix.
969 * @param[in] tx The X coordinate translation.
970 * @param[in] ty The Y coordinate translation.
971 * @param[in] tz The Z coordinate translation.
972 *
973 * @since 1.24
974 */
975EAPI void eina_matrix4_translate(Eina_Matrix4 *t, double tx, double ty, double tz);
976
977/**
978 * @brief Sets the matrix values for a scaling operation.
979 *
980 * @param[out] t Where to store the resulting matrix.
981 * @param[in] sx The X coordinate scaling factor.
982 * @param[in] sy The Y coordinate scaling factor.
983 * @param[in] sz The Z coordinate scaling factor.
984 *
985 * @since 1.24
986 */
987EAPI void eina_matrix4_scale(Eina_Matrix4 *t, double sx, double sy, double sz);
988
989/**
990 * @brief Sets the matrix values for a rotation operation.
991 * @param[out] t Where to store the resulting matrix.
992 * @param[in] rad The number of radians to rotate.
993 * @param[in] axis The Axis of rotation.
994 *
995 * @since 1.24
996 */
997EAPI void eina_matrix4_rotate(Eina_Matrix4 *t, double rad, Eina_Matrix_Axis axis);
998
935/** 999/**
936 * @} 1000 * @}
937 */ 1001 */
diff --git a/src/tests/eina/eina_test_matrix.c b/src/tests/eina/eina_test_matrix.c
index 2fa860c251..a0812ac12c 100644
--- a/src/tests/eina/eina_test_matrix.c
+++ b/src/tests/eina/eina_test_matrix.c
@@ -192,6 +192,24 @@ EFL_START_TEST(eina_matrix4)
192} 192}
193EFL_END_TEST 193EFL_END_TEST
194 194
195#define MATRIX4_CMP(XX, XY, XZ, XW, YX, YY, YZ, YW, ZX, ZY, ZZ, ZW, WX, WY, WZ, WW, AXX, AXY, AXZ, AXW, AYX, AYY, AYZ, AYW, AZX, AZY, AZZ, AZW, AWX, AWY, AWZ, AWW) \
196 (EINA_DBL_EQ(XX, AXX) && \
197 EINA_DBL_EQ(XY, AXY) && \
198 EINA_DBL_EQ(XZ, AXZ) && \
199 EINA_DBL_EQ(XW, AXW) && \
200 EINA_DBL_EQ(YX, AYX) && \
201 EINA_DBL_EQ(YY, AYY) && \
202 EINA_DBL_EQ(YZ, AYZ) && \
203 EINA_DBL_EQ(YW, AYW) && \
204 EINA_DBL_EQ(ZX, AZX) && \
205 EINA_DBL_EQ(ZY, AZY) && \
206 EINA_DBL_EQ(ZZ, AZZ) && \
207 EINA_DBL_EQ(ZW, AZW) && \
208 EINA_DBL_EQ(WX, AWX) && \
209 EINA_DBL_EQ(WY, AWY) && \
210 EINA_DBL_EQ(WZ, AWZ) && \
211 EINA_DBL_EQ(WW, AWW))
212
195EFL_START_TEST(eina_matrix4_operation) 213EFL_START_TEST(eina_matrix4_operation)
196{ 214{
197 double det; 215 double det;
@@ -202,6 +220,7 @@ EFL_START_TEST(eina_matrix4_operation)
202 zx, zy, zz, zw, 220 zx, zy, zz, zw,
203 wx, wy, wz, ww; 221 wx, wy, wz, ww;
204 const double arr[] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}; 222 const double arr[] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1};
223 double rotate_radian = 45.0 * M_PI / 180.0;
205 224
206 eina_matrix4_values_set(&m, 225 eina_matrix4_values_set(&m,
207 0, 0, 2, 0, 226 0, 0, 2, 0,
@@ -311,6 +330,110 @@ EFL_START_TEST(eina_matrix4_operation)
311 !EINA_DBL_EQ(wy, 7) || 330 !EINA_DBL_EQ(wy, 7) ||
312 !EINA_DBL_EQ(wz, 5) || 331 !EINA_DBL_EQ(wz, 5) ||
313 !EINA_DBL_EQ(ww, 1)); 332 !EINA_DBL_EQ(ww, 1));
333
334
335 eina_matrix4_identity(&m);
336
337 eina_matrix4_scale(&m, 5, 5, 5);
338 eina_matrix4_values_get(&m,
339 &xx, &xy, &xz, &xw,
340 &yx, &yy, &yz, &yw,
341 &zx, &zy, &zz, &zw,
342 &wx, &wy, &wz, &ww);
343
344 fail_if(!MATRIX4_CMP(xx, xy, xz, xw,
345 yx, yy, yz, yw,
346 zx, zy, zz, zw,
347 wx, wy, wz, ww,
348 5, 0, 0, 0,
349 0, 5, 0, 0,
350 0, 0, 5, 0,
351 0, 0, 0, 1));
352
353 eina_matrix4_translate(&m, 5, 5, 5);
354 eina_matrix4_values_get(&m,
355 &xx, &xy, &xz, &xw,
356 &yx, &yy, &yz, &yw,
357 &zx, &zy, &zz, &zw,
358 &wx, &wy, &wz, &ww);
359 fail_if(!MATRIX4_CMP(xx, xy, xz, xw,
360 yx, yy, yz, yw,
361 zx, zy, zz, zw,
362 wx, wy, wz, ww,
363 5, 0, 0, 5,
364 0, 5, 0, 5,
365 0, 0, 5, 5,
366 0, 0, 0, 1));
367
368 eina_matrix4_identity(&m);
369 eina_matrix4_rotate(&m, rotate_radian, EINA_MATRIX_AXIS_X);
370 eina_matrix4_values_get(&m,
371 &xx, &xy, &xz, &xw,
372 &yx, &yy, &yz, &yw,
373 &zx, &zy, &zz, &zw,
374 &wx, &wy, &wz, &ww);
375 fail_if(!MATRIX4_CMP(xx, xy, xz, xw,
376 yx, yy, yz, yw,
377 zx, zy, zz, zw,
378 wx, wy, wz, ww,
379 1, 0, 0, 0,
380 0, cos(rotate_radian), -sin(rotate_radian), 0,
381 0, sin(rotate_radian), cos(rotate_radian), 0,
382 0, 0, 0, 1));
383
384 eina_matrix4_identity(&m);
385 eina_matrix4_rotate(&m, rotate_radian, EINA_MATRIX_AXIS_Y);
386 eina_matrix4_values_get(&m,
387 &xx, &xy, &xz, &xw,
388 &yx, &yy, &yz, &yw,
389 &zx, &zy, &zz, &zw,
390 &wx, &wy, &wz, &ww);
391 fail_if(!MATRIX4_CMP(xx, xy, xz, xw,
392 yx, yy, yz, yw,
393 zx, zy, zz, zw,
394 wx, wy, wz, ww,
395 cos(rotate_radian), 0, sin(rotate_radian), 0,
396 0, 1, 0, 0,
397 -sin(rotate_radian), 0, cos(rotate_radian), 0,
398 0, 0, 0, 1));
399
400 eina_matrix4_identity(&m);
401 eina_matrix4_rotate(&m, rotate_radian, EINA_MATRIX_AXIS_Z);
402 eina_matrix4_values_get(&m,
403 &xx, &xy, &xz, &xw,
404 &yx, &yy, &yz, &yw,
405 &zx, &zy, &zz, &zw,
406 &wx, &wy, &wz, &ww);
407 fail_if(!MATRIX4_CMP(xx, xy, xz, xw,
408 yx, yy, yz, yw,
409 zx, zy, zz, zw,
410 wx, wy, wz, ww,
411 cos(rotate_radian), -sin(rotate_radian), 0, 0,
412 sin(rotate_radian), cos(rotate_radian), 0, 0,
413 0, 0, 1, 0,
414 0, 0, 0, 1));
415
416
417 eina_matrix4_identity(&m1);
418 eina_matrix4_values_set(&m2,
419 1, 2, 3, 4,
420 5, 6, 7, 8,
421 9, 10, 11, 12,
422 13, 14, 15, 16);
423 eina_matrix4_compose(&m1, &m2, &m);
424 eina_matrix4_values_get(&m,
425 &xx, &xy, &xz, &xw,
426 &yx, &yy, &yz, &yw,
427 &zx, &zy, &zz, &zw,
428 &wx, &wy, &wz, &ww);
429 fail_if(!MATRIX4_CMP(xx, xy, xz, xw,
430 yx, yy, yz, yw,
431 zx, zy, zz, zw,
432 wx, wy, wz, ww,
433 1, 2, 3, 4,
434 5, 6, 7, 8,
435 9, 10, 11, 12,
436 13, 14, 15, 16));
314} 437}
315EFL_END_TEST 438EFL_END_TEST
316 439