summaryrefslogtreecommitdiff
path: root/src/lib/evas/include/evas_3d_utils.h
diff options
context:
space:
mode:
authorse.osadchy <se.osadchy@samsung.com>2015-11-09 14:37:42 -0800
committerCedric BAIL <cedric@osg.samsung.com>2015-11-09 15:27:26 -0800
commit3d77f55f910a844b45019238ed458bf62e6c1c20 (patch)
tree8522846623ac432ec79a79100c56a0321f2efdb6 /src/lib/evas/include/evas_3d_utils.h
parent3031a4a5c6e7c57c3d40e1a65b3641961c30002a (diff)
evas: refactor duplicated data structure with eina_matrix.
Summary: Move data structure and functionality to eina_matrix from evas_mat. Reviewers: raster, Hermet, cedric Subscribers: Oleksander, cedric Differential Revision: https://phab.enlightenment.org/D3020 Signed-off-by: Cedric BAIL <cedric@osg.samsung.com>
Diffstat (limited to 'src/lib/evas/include/evas_3d_utils.h')
-rw-r--r--src/lib/evas/include/evas_3d_utils.h929
1 files changed, 145 insertions, 784 deletions
diff --git a/src/lib/evas/include/evas_3d_utils.h b/src/lib/evas/include/evas_3d_utils.h
index dfa0b3946b..23d338d448 100644
--- a/src/lib/evas/include/evas_3d_utils.h
+++ b/src/lib/evas/include/evas_3d_utils.h
@@ -16,9 +16,6 @@ typedef struct _Evas_Color Evas_Color;
16typedef struct _Evas_Vec2 Evas_Vec2; 16typedef struct _Evas_Vec2 Evas_Vec2;
17typedef struct _Evas_Vec3 Evas_Vec3; 17typedef struct _Evas_Vec3 Evas_Vec3;
18typedef struct _Evas_Vec4 Evas_Vec4; 18typedef struct _Evas_Vec4 Evas_Vec4;
19typedef struct _Evas_Mat2 Evas_Mat2;
20typedef struct _Evas_Mat3 Evas_Mat3;
21typedef struct _Evas_Mat4 Evas_Mat4;
22typedef struct _Evas_Box2 Evas_Box2; 19typedef struct _Evas_Box2 Evas_Box2;
23typedef struct _Evas_Box3 Evas_Box3; 20typedef struct _Evas_Box3 Evas_Box3;
24typedef struct _Evas_Line3 Evas_Line3; 21typedef struct _Evas_Line3 Evas_Line3;
@@ -55,24 +52,6 @@ struct _Evas_Vec4
55 Evas_Real w; 52 Evas_Real w;
56}; 53};
57 54
58struct _Evas_Mat2
59{
60 Evas_Real m[4];
61 int flags;
62};
63
64struct _Evas_Mat3
65{
66 Evas_Real m[9];
67 int flags;
68};
69
70struct _Evas_Mat4
71{
72 Evas_Real m[16];
73 int flags;
74};
75
76struct _Evas_Box2 55struct _Evas_Box2
77{ 56{
78 Evas_Vec2 p0; 57 Evas_Vec2 p0;
@@ -204,34 +183,34 @@ evas_vec2_normalize(Evas_Vec2 *out, const Evas_Vec2 *v)
204} 183}
205 184
206static inline void 185static inline void
207evas_vec2_transform(Evas_Vec2 *out, const Evas_Mat2 *m, const Evas_Vec2 *v) 186evas_vec2_transform(Evas_Vec2 *out, const Eina_Matrix2 *m, const Evas_Vec2 *v)
208{ 187{
209 Evas_Vec2 tmp; 188 Evas_Vec2 tmp;
210 189
211 tmp.x = (m->m[0] * v->x) + (m->m[2] * v->y); 190 tmp.x = (m->xx * v->x) + (m->yx * v->y);
212 tmp.y = (m->m[1] * v->x) + (m->m[3] * v->y); 191 tmp.y = (m->xy * v->x) + (m->yy * v->y);
213 192
214 evas_vec2_copy(out, &tmp); 193 evas_vec2_copy(out, &tmp);
215} 194}
216 195
217static inline void 196static inline void
218evas_vec2_homogeneous_position_transform(Evas_Vec2 *out, const Evas_Mat3 *m, const Evas_Vec2 *v) 197evas_vec2_homogeneous_position_transform(Evas_Vec2 *out, const Eina_Matrix3 *m, const Evas_Vec2 *v)
219{ 198{
220 Evas_Vec2 tmp; 199 Evas_Vec2 tmp;
221 200
222 tmp.x = (m->m[0] * v->x) + (m->m[3] * v->y) + m->m[6]; 201 tmp.x = (m->xx * v->x) + (m->yx * v->y) + m->zx;
223 tmp.y = (m->m[1] * v->x) + (m->m[4] * v->y) + m->m[7]; 202 tmp.y = (m->xy * v->x) + (m->yy * v->y) + m->zy;
224 203
225 evas_vec2_scale(out, &tmp, 1.0 / ((m->m[2] * v->x) + (m->m[5] * v->y) + m->m[8])); 204 evas_vec2_scale(out, &tmp, 1.0 / ((m->xz * v->x) + (m->yz * v->y) + m->zz));
226} 205}
227 206
228static inline void 207static inline void
229evas_vec2_homogeneous_direction_transform(Evas_Vec2 *out, const Evas_Mat3 *m, const Evas_Vec2 *v) 208evas_vec2_homogeneous_direction_transform(Evas_Vec2 *out, const Eina_Matrix3 *m, const Evas_Vec2 *v)
230{ 209{
231 Evas_Vec2 tmp; 210 Evas_Vec2 tmp;
232 211
233 tmp.x = (m->m[0] * v->x) + (m->m[3] * v->y); 212 tmp.x = (m->xx * v->x) + (m->yx * v->y);
234 tmp.y = (m->m[1] * v->x) + (m->m[4] * v->y); 213 tmp.y = (m->xy * v->x) + (m->yy * v->y);
235 214
236 evas_vec2_copy(out, &tmp); 215 evas_vec2_copy(out, &tmp);
237} 216}
@@ -366,56 +345,56 @@ evas_vec3_normalize(Evas_Vec3 *out, const Evas_Vec3 *v)
366} 345}
367 346
368static inline void 347static inline void
369evas_vec3_transform(Evas_Vec3 *out, const Evas_Vec3 *v, const Evas_Mat3 *m) 348evas_vec3_transform(Evas_Vec3 *out, const Evas_Vec3 *v, const Eina_Matrix3 *m)
370{ 349{
371 Evas_Vec3 tmp; 350 Evas_Vec3 tmp;
372 351
373 if (m->flags & EVAS_MATRIX_IS_IDENTITY) 352 if (eina_matrix3_type_get(m) & EINA_MATRIX_TYPE_IDENTITY)
374 { 353 {
375 evas_vec3_copy(out, v); 354 evas_vec3_copy(out, v);
376 return; 355 return;
377 } 356 }
378 357
379 tmp.x = (m->m[0] * v->x) + (m->m[3] * v->y) + (m->m[6] * v->z); 358 tmp.x = (m->xx * v->x) + (m->yx * v->y) + (m->zx * v->z);
380 tmp.y = (m->m[1] * v->x) + (m->m[4] * v->y) + (m->m[7] * v->z); 359 tmp.y = (m->xy * v->x) + (m->yy * v->y) + (m->zy * v->z);
381 tmp.z = (m->m[2] * v->x) + (m->m[5] * v->y) + (m->m[8] * v->z); 360 tmp.z = (m->xz * v->x) + (m->yz * v->y) + (m->zz * v->z);
382 361
383 evas_vec3_copy(out, &tmp); 362 evas_vec3_copy(out, &tmp);
384} 363}
385 364
386static inline void 365static inline void
387evas_vec3_homogeneous_position_transform(Evas_Vec3 *out, const Evas_Vec3 *v, const Evas_Mat4 *m) 366evas_vec3_homogeneous_position_transform(Evas_Vec3 *out, const Evas_Vec3 *v, const Eina_Matrix4 *m)
388{ 367{
389 Evas_Vec3 tmp; 368 Evas_Vec3 tmp;
390 369
391 if (m->flags & EVAS_MATRIX_IS_IDENTITY) 370 if (eina_matrix4_type_get(m) & EINA_MATRIX_TYPE_IDENTITY)
392 { 371 {
393 evas_vec3_copy(out, v); 372 evas_vec3_copy(out, v);
394 return; 373 return;
395 } 374 }
396 375
397 tmp.x = (m->m[0] * v->x) + (m->m[4] * v->y) + (m->m[8] * v->z) + m->m[12]; 376 tmp.x = (m->xx * v->x) + (m->zw * v->y) + (m->zx * v->z) + m->wx;
398 tmp.y = (m->m[1] * v->x) + (m->m[5] * v->y) + (m->m[9] * v->z) + m->m[13]; 377 tmp.y = (m->xy * v->x) + (m->yx * v->y) + (m->zy * v->z) + m->wy;
399 tmp.z = (m->m[2] * v->x) + (m->m[6] * v->y) + (m->m[10] * v->z) + m->m[14]; 378 tmp.z = (m->xz * v->x) + (m->yz * v->y) + (m->zz * v->z) + m->wz;
400 379
401 evas_vec3_scale(out, &tmp, 380 evas_vec3_scale(out, &tmp,
402 1.0 / ((m->m[3] * v->x) + (m->m[7] * v->y) + (m->m[11] * v->z) + m->m[15])); 381 1.0 / ((m->xw * v->x) + (m->yw * v->y) + (m->zw * v->z) + m->ww));
403} 382}
404 383
405static inline void 384static inline void
406evas_vec3_homogeneous_direction_transform(Evas_Vec3 *out, const Evas_Vec3 *v, const Evas_Mat4 *m) 385evas_vec3_homogeneous_direction_transform(Evas_Vec3 *out, const Evas_Vec3 *v, const Eina_Matrix4 *m)
407{ 386{
408 Evas_Vec3 tmp; 387 Evas_Vec3 tmp;
409 388
410 if (m->flags & EVAS_MATRIX_IS_IDENTITY) 389 if (eina_matrix4_type_get(m) & EINA_MATRIX_TYPE_IDENTITY)
411 { 390 {
412 evas_vec3_copy(out, v); 391 evas_vec3_copy(out, v);
413 return; 392 return;
414 } 393 }
415 394
416 tmp.x = (m->m[0] * v->x) + (m->m[4] * v->y) + (m->m[8] * v->z); 395 tmp.x = (m->xx * v->x) + (m->zw * v->y) + (m->zx * v->z);
417 tmp.y = (m->m[1] * v->x) + (m->m[5] * v->y) + (m->m[9] * v->z); 396 tmp.y = (m->xy * v->x) + (m->yx * v->y) + (m->zy * v->z);
418 tmp.z = (m->m[2] * v->x) + (m->m[6] * v->y) + (m->m[10] * v->z); 397 tmp.z = (m->xz * v->x) + (m->yz * v->y) + (m->zz * v->z);
419 398
420 evas_vec3_copy(out, &tmp); 399 evas_vec3_copy(out, &tmp);
421} 400}
@@ -581,20 +560,20 @@ evas_vec4_normalize(Evas_Vec4 *out, const Evas_Vec4 *v)
581} 560}
582 561
583static inline void 562static inline void
584evas_vec4_transform(Evas_Vec4 *out, const Evas_Vec4 *v, const Evas_Mat4 *m) 563evas_vec4_transform(Evas_Vec4 *out, const Evas_Vec4 *v, const Eina_Matrix4 *m)
585{ 564{
586 Evas_Vec4 tmp; 565 Evas_Vec4 tmp;
587 566
588 if (m->flags & EVAS_MATRIX_IS_IDENTITY) 567 if (eina_matrix4_type_get(m) & EINA_MATRIX_TYPE_IDENTITY)
589 { 568 {
590 evas_vec4_copy(out, v); 569 evas_vec4_copy(out, v);
591 return; 570 return;
592 } 571 }
593 572
594 tmp.x = (m->m[0] * v->x) + (m->m[4] * v->y) + (m->m[ 8] * v->z) + (m->m[12] * v->w); 573 tmp.x = (m->xx * v->x) + (m->yx * v->y) + (m->zx * v->z) + (m->wx * v->w);
595 tmp.y = (m->m[1] * v->x) + (m->m[5] * v->y) + (m->m[ 9] * v->z) + (m->m[13] * v->w); 574 tmp.y = (m->xy * v->x) + (m->yy * v->y) + (m->zy * v->z) + (m->wy * v->w);
596 tmp.z = (m->m[2] * v->x) + (m->m[6] * v->y) + (m->m[10] * v->z) + (m->m[14] * v->w); 575 tmp.z = (m->xz * v->x) + (m->yz * v->y) + (m->zz * v->z) + (m->wz * v->w);
597 tmp.w = (m->m[3] * v->x) + (m->m[7] * v->y) + (m->m[11] * v->z) + (m->m[15] * v->w); 576 tmp.w = (m->xw * v->x) + (m->yw * v->y) + (m->zw * v->z) + (m->ww * v->w);
598 577
599 evas_vec4_copy(out, &tmp); 578 evas_vec4_copy(out, &tmp);
600} 579}
@@ -745,108 +724,8 @@ evas_vec4_homogeneous_direction_set(Evas_Vec4 *out, const Evas_Vec3 *v)
745 out->w = 0.0; 724 out->w = 0.0;
746} 725}
747 726
748/* 4x4 matrix */
749static inline void 727static inline void
750evas_mat4_identity_set(Evas_Mat4 *m) 728evas_mat4_look_at_set(Eina_Matrix4 *m,
751{
752 m->m[0] = 1.0;
753 m->m[1] = 0.0;
754 m->m[2] = 0.0;
755 m->m[3] = 0.0;
756
757 m->m[4] = 0.0;
758 m->m[5] = 1.0;
759 m->m[6] = 0.0;
760 m->m[7] = 0.0;
761
762 m->m[8] = 0.0;
763 m->m[9] = 0.0;
764 m->m[10] = 1.0;
765 m->m[11] = 0.0;
766
767 m->m[12] = 0.0;
768 m->m[13] = 0.0;
769 m->m[14] = 0.0;
770 m->m[15] = 1.0;
771
772 m->flags = EVAS_MATRIX_IS_IDENTITY;
773}
774
775static inline void
776evas_mat4_array_set(Evas_Mat4 *m, const Evas_Real *v)
777{
778 memcpy(&m->m[0], v, sizeof(Evas_Real) * 16);
779 m->flags = 0;
780}
781
782static inline void
783evas_mat4_copy(Evas_Mat4 *dst, const Evas_Mat4 *src)
784{
785 memcpy(dst, src, sizeof(Evas_Mat4));
786}
787
788static inline void
789evas_mat4_nocheck_multiply(Evas_Mat4 *out, const Evas_Mat4 *mat_a,
790 const Evas_Mat4 *mat_b)
791{
792 Evas_Real *d = out->m;
793 const Evas_Real *a = mat_a->m;
794 const Evas_Real *b = mat_b->m;
795
796 if (mat_a->flags & EVAS_MATRIX_IS_IDENTITY)
797 {
798 evas_mat4_copy(out, mat_b);
799 return;
800 }
801
802 if (mat_b->flags & EVAS_MATRIX_IS_IDENTITY)
803 {
804 evas_mat4_copy(out, mat_a);
805 return;
806 }
807
808 d[ 0] = a[ 0] * b[ 0] + a[ 4] * b[ 1] + a[ 8] * b[ 2] + a[12] * b [3];
809 d[ 4] = a[ 0] * b[ 4] + a[ 4] * b[ 5] + a[ 8] * b[ 6] + a[12] * b [7];
810 d[ 8] = a[ 0] * b[ 8] + a[ 4] * b[ 9] + a[ 8] * b[10] + a[12] * b[11];
811 d[12] = a[ 0] * b[12] + a[ 4] * b[13] + a[ 8] * b[14] + a[12] * b[15];
812
813 d[ 1] = a[ 1] * b[ 0] + a[ 5] * b[ 1] + a[ 9] * b[ 2] + a[13] * b [3];
814 d[ 5] = a[ 1] * b[ 4] + a[ 5] * b[ 5] + a[ 9] * b[ 6] + a[13] * b [7];
815 d[ 9] = a[ 1] * b[ 8] + a[ 5] * b[ 9] + a[ 9] * b[10] + a[13] * b[11];
816 d[13] = a[ 1] * b[12] + a[ 5] * b[13] + a[ 9] * b[14] + a[13] * b[15];
817
818 d[ 2] = a[ 2] * b[ 0] + a[ 6] * b[ 1] + a[10] * b[ 2] + a[14] * b [3];
819 d[ 6] = a[ 2] * b[ 4] + a[ 6] * b[ 5] + a[10] * b[ 6] + a[14] * b [7];
820 d[10] = a[ 2] * b[ 8] + a[ 6] * b[ 9] + a[10] * b[10] + a[14] * b[11];
821 d[14] = a[ 2] * b[12] + a[ 6] * b[13] + a[10] * b[14] + a[14] * b[15];
822
823 d[ 3] = a[ 3] * b[ 0] + a[ 7] * b[ 1] + a[11] * b[ 2] + a[15] * b [3];
824 d[ 7] = a[ 3] * b[ 4] + a[ 7] * b[ 5] + a[11] * b[ 6] + a[15] * b [7];
825 d[11] = a[ 3] * b[ 8] + a[ 7] * b[ 9] + a[11] * b[10] + a[15] * b[11];
826 d[15] = a[ 3] * b[12] + a[ 7] * b[13] + a[11] * b[14] + a[15] * b[15];
827
828 out->flags = 0;
829}
830
831static inline void
832evas_mat4_multiply(Evas_Mat4 *out, const Evas_Mat4 *mat_a,
833 const Evas_Mat4 *mat_b)
834{
835 if (out != mat_a && out != mat_b)
836 {
837 evas_mat4_nocheck_multiply(out, mat_a, mat_b);
838 }
839 else
840 {
841 Evas_Mat4 result;
842
843 evas_mat4_nocheck_multiply(&result, mat_a, mat_b);
844 evas_mat4_copy(out, &result);
845 }
846}
847
848static inline void
849evas_mat4_look_at_set(Evas_Mat4 *m,
850 const Evas_Vec3 *pos, const Evas_Vec3 *center, const Evas_Vec3 *up) 729 const Evas_Vec3 *pos, const Evas_Vec3 *center, const Evas_Vec3 *up)
851{ 730{
852 Evas_Vec3 x, y, z; 731 Evas_Vec3 x, y, z;
@@ -860,31 +739,29 @@ evas_mat4_look_at_set(Evas_Mat4 *m,
860 evas_vec3_cross_product(&y, &z, &x); 739 evas_vec3_cross_product(&y, &z, &x);
861 evas_vec3_normalize(&y, &y); 740 evas_vec3_normalize(&y, &y);
862 741
863 m->m[ 0] = x.x; 742 m->xx = x.x;
864 m->m[ 1] = y.x; 743 m->xy = y.x;
865 m->m[ 2] = z.x; 744 m->xz = z.x;
866 m->m[ 3] = 0.0; 745 m->xw = 0.0;
867 746
868 m->m[ 4] = x.y; 747 m->yx = x.y;
869 m->m[ 5] = y.y; 748 m->yy = y.y;
870 m->m[ 6] = z.y; 749 m->yz = z.y;
871 m->m[ 7] = 0.0; 750 m->yw = 0.0;
872 751
873 m->m[ 8] = x.z; 752 m->zx = x.z;
874 m->m[ 9] = y.z; 753 m->zy = y.z;
875 m->m[10] = z.z; 754 m->zz = z.z;
876 m->m[11] = 0.0; 755 m->zw = 0.0;
877 756
878 m->m[12] = -evas_vec3_dot_product(&x, pos); 757 m->wx = -evas_vec3_dot_product(&x, pos);
879 m->m[13] = -evas_vec3_dot_product(&y, pos); 758 m->wy = -evas_vec3_dot_product(&y, pos);
880 m->m[14] = -evas_vec3_dot_product(&z, pos); 759 m->wz = -evas_vec3_dot_product(&z, pos);
881 m->m[15] = 1.0; 760 m->ww = 1.0;
882
883 m->flags = 0;
884} 761}
885 762
886static inline void 763static inline void
887evas_mat4_frustum_set(Evas_Mat4 *m, 764evas_mat4_frustum_set(Eina_Matrix4 *m,
888 Evas_Real left, Evas_Real right, Evas_Real bottom, Evas_Real top, 765 Evas_Real left, Evas_Real right, Evas_Real bottom, Evas_Real top,
889 Evas_Real dnear, Evas_Real dfar) 766 Evas_Real dnear, Evas_Real dfar)
890{ 767{
@@ -893,534 +770,25 @@ evas_mat4_frustum_set(Evas_Mat4 *m,
893 Evas_Real depth = dnear - dfar; 770 Evas_Real depth = dnear - dfar;
894 Evas_Real near_2 = 2.0f * dnear; 771 Evas_Real near_2 = 2.0f * dnear;
895 772
896 m->m[ 0] = near_2 / w; 773 m->xx = near_2 / w;
897 m->m[ 1] = 0.0f; 774 m->xy = 0.0f;
898 m->m[ 2] = 0.0f; 775 m->xz = 0.0f;
899 m->m[ 3] = 0.0f; 776 m->xw = 0.0f;
900
901 m->m[ 4] = 0.0f;
902 m->m[ 5] = near_2 / h;
903 m->m[ 6] = 0.0f;
904 m->m[ 7] = 0.0f;
905 777
906 m->m[ 8] = (right + left) / w; 778 m->yx = 0.0f;
907 m->m[ 9] = (top + bottom) / h; 779 m->yy = near_2 / h;
908 m->m[10] = (dfar + dnear) / depth; 780 m->yz = 0.0f;
909 m->m[11] = -1.0f; 781 m->yw = 0.0f;
910 782
911 m->m[12] = 0.0f; 783 m->zx = (right + left) / w;
912 m->m[13] = 0.0f; 784 m->zy = (top + bottom) / h;
913 m->m[14] = near_2 * dfar / depth; 785 m->zz = (dfar + dnear) / depth;
914 m->m[15] = 0.0f; 786 m->zw = -1.0f;
915 787
916 m->flags = 0; 788 m->wx = 0.0f;
917} 789 m->wy = 0.0f;
918 790 m->wz = near_2 * dfar / depth;
919static inline void 791 m->ww = 0.0f;
920evas_mat4_ortho_set(Evas_Mat4 *m,
921 Evas_Real left, Evas_Real right, Evas_Real bottom, Evas_Real top,
922 Evas_Real dnear, Evas_Real dfar)
923{
924 Evas_Real w = right - left;
925 Evas_Real h = top - bottom;
926 Evas_Real depth = dnear - dfar;
927
928 m->m[ 0] = 2.0f / w;
929 m->m[ 1] = 0.0f;
930 m->m[ 2] = 0.0f;
931 m->m[ 3] = 0.0f;
932
933 m->m[ 4] = 0.0f;
934 m->m[ 5] = 2.0f / h;
935 m->m[ 6] = 0.0f;
936 m->m[ 7] = 0.0f;
937
938 m->m[ 8] = 0.0f;
939 m->m[ 9] = 0.0f;
940 m->m[10] = 2.0f / depth;
941 m->m[11] = 0.0f;
942
943 m->m[12] = -(right + left) / w;
944 m->m[13] = -(top + bottom) / h;
945 m->m[14] = (dfar + dnear) / depth;
946 m->m[15] = 1.0f;
947
948 m->flags = 0;
949}
950
951static inline void
952evas_mat4_nocheck_inverse(Evas_Mat4 *out, const Evas_Mat4 *mat)
953{
954 Evas_Real *d = out->m;
955 const Evas_Real *m = mat->m;
956 Evas_Real det;
957
958 if (mat->flags & EVAS_MATRIX_IS_IDENTITY)
959 {
960 evas_mat4_copy(out, mat);
961 return;
962 }
963
964 d[ 0] = m[ 5] * m[10] * m[15] -
965 m[ 5] * m[11] * m[14] -
966 m[ 9] * m[ 6] * m[15] +
967 m[ 9] * m[ 7] * m[14] +
968 m[13] * m[ 6] * m[11] -
969 m[13] * m[ 7] * m[10];
970
971 d[ 4] = -m[ 4] * m[10] * m[15] +
972 m[ 4] * m[11] * m[14] +
973 m[ 8] * m[ 6] * m[15] -
974 m[ 8] * m[ 7] * m[14] -
975 m[12] * m[ 6] * m[11] +
976 m[12] * m[ 7] * m[10];
977
978 d[ 8] = m[ 4] * m[ 9] * m[15] -
979 m[ 4] * m[11] * m[13] -
980 m[ 8] * m[ 5] * m[15] +
981 m[ 8] * m[ 7] * m[13] +
982 m[12] * m[ 5] * m[11] -
983 m[12] * m[ 7] * m[ 9];
984
985 d[12] = -m[ 4] * m[ 9] * m[14] +
986 m[ 4] * m[10] * m[13] +
987 m[ 8] * m[ 5] * m[14] -
988 m[ 8] * m[ 6] * m[13] -
989 m[12] * m[ 5] * m[10] +
990 m[12] * m[ 6] * m[ 9];
991
992 d[ 1] = -m[ 1] * m[10] * m[15] +
993 m[ 1] * m[11] * m[14] +
994 m[ 9] * m[ 2] * m[15] -
995 m[ 9] * m[ 3] * m[14] -
996 m[13] * m[ 2] * m[11] +
997 m[13] * m[ 3] * m[10];
998
999 d[ 5] = m[ 0] * m[10] * m[15] -
1000 m[ 0] * m[11] * m[14] -
1001 m[ 8] * m[ 2] * m[15] +
1002 m[ 8] * m[ 3] * m[14] +
1003 m[12] * m[ 2] * m[11] -
1004 m[12] * m[ 3] * m[10];
1005
1006 d[ 9] = -m[ 0] * m[ 9] * m[15] +
1007 m[ 0] * m[11] * m[13] +
1008 m[ 8] * m[ 1] * m[15] -
1009 m[ 8] * m[ 3] * m[13] -
1010 m[12] * m[ 1] * m[11] +
1011 m[12] * m[ 3] * m[ 9];
1012
1013 d[13] = m[ 0] * m[ 9] * m[14] -
1014 m[ 0] * m[10] * m[13] -
1015 m[ 8] * m[ 1] * m[14] +
1016 m[ 8] * m[ 2] * m[13] +
1017 m[12] * m[ 1] * m[10] -
1018 m[12] * m[ 2] * m[ 9];
1019
1020 d[ 2] = m[ 1] * m[ 6] * m[15] -
1021 m[ 1] * m[ 7] * m[14] -
1022 m[ 5] * m[ 2] * m[15] +
1023 m[ 5] * m[ 3] * m[14] +
1024 m[13] * m[ 2] * m[ 7] -
1025 m[13] * m[ 3] * m[ 6];
1026
1027 d[ 6] = -m[ 0] * m[ 6] * m[15] +
1028 m[ 0] * m[ 7] * m[14] +
1029 m[ 4] * m[ 2] * m[15] -
1030 m[ 4] * m[ 3] * m[14] -
1031 m[12] * m[ 2] * m[ 7] +
1032 m[12] * m[ 3] * m[ 6];
1033
1034 d[10] = m[ 0] * m[ 5] * m[15] -
1035 m[ 0] * m[ 7] * m[13] -
1036 m[ 4] * m[ 1] * m[15] +
1037 m[ 4] * m[ 3] * m[13] +
1038 m[12] * m[ 1] * m[ 7] -
1039 m[12] * m[ 3] * m[ 5];
1040
1041 d[14] = -m[ 0] * m[ 5] * m[14] +
1042 m[ 0] * m[ 6] * m[13] +
1043 m[ 4] * m[ 1] * m[14] -
1044 m[ 4] * m[ 2] * m[13] -
1045 m[12] * m[ 1] * m[ 6] +
1046 m[12] * m[ 2] * m[ 5];
1047
1048 d[ 3] = -m[ 1] * m[ 6] * m[11] +
1049 m[ 1] * m[ 7] * m[10] +
1050 m[ 5] * m[ 2] * m[11] -
1051 m[ 5] * m[ 3] * m[10] -
1052 m[ 9] * m[ 2] * m[ 7] +
1053 m[ 9] * m[ 3] * m[ 6];
1054
1055 d[ 7] = m[ 0] * m[ 6] * m[11] -
1056 m[ 0] * m[ 7] * m[10] -
1057 m[ 4] * m[ 2] * m[11] +
1058 m[ 4] * m[ 3] * m[10] +
1059 m[ 8] * m[ 2] * m[ 7] -
1060 m[ 8] * m[ 3] * m[ 6];
1061
1062 d[11] = -m[ 0] * m[ 5] * m[11] +
1063 m[ 0] * m[ 7] * m[ 9] +
1064 m[ 4] * m[ 1] * m[11] -
1065 m[ 4] * m[ 3] * m[ 9] -
1066 m[ 8] * m[ 1] * m[ 7] +
1067 m[ 8] * m[ 3] * m[ 5];
1068
1069 d[15] = m[ 0] * m[ 5] * m[10] -
1070 m[ 0] * m[ 6] * m[ 9] -
1071 m[ 4] * m[ 1] * m[10] +
1072 m[ 4] * m[ 2] * m[ 9] +
1073 m[ 8] * m[ 1] * m[ 6] -
1074 m[ 8] * m[ 2] * m[ 5];
1075
1076 det = m[0] * d[0] + m[1] * d[4] + m[2] * d[8] + m[3] * d[12];
1077
1078 if (det == 0.0) return;
1079
1080 det = 1.0 / det;
1081
1082 d[ 0] *= det;
1083 d[ 1] *= det;
1084 d[ 2] *= det;
1085 d[ 3] *= det;
1086 d[ 4] *= det;
1087 d[ 5] *= det;
1088 d[ 6] *= det;
1089 d[ 7] *= det;
1090 d[ 8] *= det;
1091 d[ 9] *= det;
1092 d[10] *= det;
1093 d[11] *= det;
1094 d[12] *= det;
1095 d[13] *= det;
1096 d[14] *= det;
1097 d[15] *= det;
1098
1099 out->flags = 0;
1100}
1101
1102static inline void
1103evas_mat4_inverse(Evas_Mat4 *out, const Evas_Mat4 *mat)
1104{
1105 if (out != mat)
1106 {
1107 evas_mat4_nocheck_inverse(out, mat);
1108 }
1109 else
1110 {
1111 Evas_Mat4 tmp;
1112
1113 evas_mat4_nocheck_inverse(&tmp, mat);
1114 evas_mat4_copy(out, &tmp);
1115 }
1116}
1117
1118static inline void
1119evas_normal_matrix_get(Evas_Mat3 *out, const Evas_Mat4 *m)
1120{
1121 /* Normal matrix is a transposed matirx of inversed modelview.
1122 * And we need only upper-left 3x3 terms to work with. */
1123
1124 Evas_Real det;
1125 Evas_Real a = m->m[0];
1126 Evas_Real b = m->m[4];
1127 Evas_Real c = m->m[8];
1128 Evas_Real d = m->m[1];
1129 Evas_Real e = m->m[5];
1130 Evas_Real f = m->m[9];
1131 Evas_Real g = m->m[2];
1132 Evas_Real h = m->m[6];
1133 Evas_Real i = m->m[10];
1134
1135 det = a * e * i + b * f * g + c * d * h - g * e * c - h * f * a - i * d * b;
1136 det = 1.0 / det;
1137
1138 out->m[0] = (e * i - f * h) * det;
1139 out->m[1] = (h * c - i * b) * det;
1140 out->m[2] = (b * f - c * e) * det;
1141 out->m[3] = (g * f - d * i) * det;
1142 out->m[4] = (a * i - g * c) * det;
1143 out->m[5] = (d * c - a * f) * det;
1144 out->m[6] = (d * h - g * e) * det;
1145 out->m[7] = (g * b - a * h) * det;
1146 out->m[8] = (a * e - d * b) * det;
1147
1148 out->flags = 0;
1149}
1150
1151/* 3x3 matrix */
1152static inline void
1153evas_mat3_identity_set(Evas_Mat3 *m)
1154{
1155 m->m[0] = 1.0;
1156 m->m[1] = 0.0;
1157 m->m[2] = 0.0;
1158 m->m[3] = 0.0;
1159 m->m[4] = 1.0;
1160 m->m[5] = 0.0;
1161 m->m[6] = 0.0;
1162 m->m[7] = 0.0;
1163 m->m[8] = 1.0;
1164
1165 m->flags = EVAS_MATRIX_IS_IDENTITY;
1166}
1167
1168static inline void
1169evas_mat3_array_set(Evas_Mat3 *m, const Evas_Real *v)
1170{
1171 memcpy(&m->m[0], v, sizeof(Evas_Real) * 9);
1172 m->flags = 0;
1173}
1174
1175static inline void
1176evas_mat3_copy(Evas_Mat3 *dst, const Evas_Mat3 *src)
1177{
1178 memcpy(dst, src, sizeof(Evas_Mat3));
1179}
1180
1181static inline void
1182evas_mat3_nocheck_multiply(Evas_Mat3 *out, const Evas_Mat3 *mat_a, const Evas_Mat3 *mat_b)
1183{
1184 Evas_Real *d = out->m;
1185 const Evas_Real *a = mat_a->m;
1186 const Evas_Real *b = mat_b->m;
1187
1188 if (mat_a->flags & EVAS_MATRIX_IS_IDENTITY)
1189 {
1190 evas_mat3_copy(out, mat_b);
1191 return;
1192 }
1193
1194 if (mat_b->flags & EVAS_MATRIX_IS_IDENTITY)
1195 {
1196 evas_mat3_copy(out, mat_a);
1197 return;
1198 }
1199
1200 d[0] = a[0] * b[0] + a[3] * b[1] + a[6] * b[2];
1201 d[3] = a[0] * b[3] + a[3] * b[4] + a[6] * b[5];
1202 d[6] = a[0] * b[6] + a[3] * b[7] + a[6] * b[8];
1203
1204 d[1] = a[1] * b[0] + a[4] * b[1] + a[7] * b[2];
1205 d[4] = a[1] * b[3] + a[4] * b[4] + a[7] * b[5];
1206 d[7] = a[1] * b[6] + a[4] * b[7] + a[7] * b[8];
1207
1208 d[2] = a[2] * b[0] + a[5] * b[1] + a[8] * b[2];
1209 d[5] = a[2] * b[3] + a[5] * b[4] + a[8] * b[5];
1210 d[8] = a[2] * b[6] + a[5] * b[7] + a[8] * b[8];
1211
1212 out->flags = 0;
1213}
1214
1215static inline void
1216evas_mat3_multiply(Evas_Mat3 *out, const Evas_Mat3 *mat_a, const Evas_Mat3 *mat_b)
1217{
1218 if (out != mat_a && out != mat_b)
1219 {
1220 evas_mat3_nocheck_multiply(out, mat_a, mat_b);
1221 }
1222 else
1223 {
1224 Evas_Mat3 tmp;
1225
1226 evas_mat3_nocheck_multiply(&tmp, mat_a, mat_b);
1227 evas_mat3_copy(out, &tmp);
1228 }
1229}
1230
1231static inline void
1232evas_mat3_nocheck_inverse(Evas_Mat3 *out, const Evas_Mat3 *mat)
1233{
1234 Evas_Real *d = &out->m[0];
1235 const Evas_Real *m = &mat->m[0];
1236 Evas_Real det;
1237
1238 if (mat->flags & EVAS_MATRIX_IS_IDENTITY)
1239 {
1240 evas_mat3_copy(out, mat);
1241 return;
1242 }
1243
1244 d[0] = m[4] * m[8] - m[7] * m[5];
1245 d[1] = m[7] * m[2] - m[1] * m[8];
1246 d[2] = m[1] * m[5] - m[4] * m[2];
1247 d[3] = m[6] * m[5] - m[3] * m[8];
1248 d[4] = m[0] * m[8] - m[6] * m[2];
1249 d[5] = m[3] * m[2] - m[0] * m[5];
1250 d[6] = m[3] * m[7] - m[6] * m[4];
1251 d[7] = m[6] * m[1] - m[0] * m[7];
1252 d[8] = m[0] * m[4] - m[3] * m[1];
1253
1254 det = m[0] * d[0] + m[1] * d[3] + m[2] * d[6];
1255
1256 if (det == 0.0)
1257 return;
1258
1259 det = 1.0 / det;
1260
1261 d[0] *= det;
1262 d[1] *= det;
1263 d[2] *= det;
1264 d[3] *= det;
1265 d[4] *= det;
1266 d[5] *= det;
1267 d[6] *= det;
1268 d[7] *= det;
1269 d[8] *= det;
1270
1271 out->flags = 0;
1272}
1273
1274static inline void
1275evas_mat3_invserse(Evas_Mat3 *out, const Evas_Mat3 *mat)
1276{
1277 if (out != mat)
1278 {
1279 evas_mat3_nocheck_inverse(out, mat);
1280 }
1281 else
1282 {
1283 Evas_Mat3 tmp;
1284
1285 evas_mat3_nocheck_inverse(&tmp, mat);
1286 evas_mat3_copy(out, &tmp);
1287 }
1288}
1289
1290static inline void
1291evas_mat3_set_position_transform(Evas_Mat3 *out, const Evas_Real p_x,
1292 const Evas_Real p_y)
1293{
1294 evas_mat3_identity_set(out);
1295 out->m[2] = p_x;
1296 out->m[5] = p_y;
1297 if ((fabs(p_x) > FLT_EPSILON) ||
1298 (fabs(p_y) > FLT_EPSILON))
1299 out->flags = 0;
1300}
1301
1302static inline void
1303evas_mat3_set_scale_transform(Evas_Mat3 *out, Evas_Real s_x, Evas_Real s_y)
1304{
1305 evas_mat3_identity_set(out);
1306 out->m[0] = s_x;
1307 out->m[4] = s_y;
1308 if ((fabs(s_x - 1.0) > FLT_EPSILON) ||
1309 (fabs(s_y - 1.0) > FLT_EPSILON))
1310 out->flags = 0;
1311}
1312
1313/* 2x2 matrix */
1314static inline void
1315evas_mat2_identity_set(Evas_Mat2 *m)
1316{
1317 m->m[0] = 1.0;
1318 m->m[1] = 0.0;
1319 m->m[2] = 0.0;
1320 m->m[3] = 1.0;
1321
1322 m->flags = EVAS_MATRIX_IS_IDENTITY;
1323}
1324
1325static inline void
1326evas_mat2_array_set(Evas_Mat2 *m, const Evas_Real *v)
1327{
1328 memcpy(&m->m[0], v, sizeof(Evas_Real) * 4);
1329 m->flags = 0;
1330}
1331
1332static inline void
1333evas_mat2_copy(Evas_Mat2 *dst, const Evas_Mat2 *src)
1334{
1335 memcpy(dst, src, sizeof(Evas_Mat2));
1336}
1337
1338static inline void
1339evas_mat2_nocheck_multiply(Evas_Mat2 *out, const Evas_Mat2 *mat_a, const Evas_Mat2 *mat_b)
1340{
1341 Evas_Real *d = &out->m[0];
1342 const Evas_Real *a = &mat_a->m[0];
1343 const Evas_Real *b = &mat_b->m[0];
1344
1345 if (mat_a->flags & EVAS_MATRIX_IS_IDENTITY)
1346 {
1347 evas_mat2_copy(out, mat_b);
1348 return;
1349 }
1350
1351 if (mat_b->flags & EVAS_MATRIX_IS_IDENTITY)
1352 {
1353 evas_mat2_copy(out, mat_a);
1354 return;
1355 }
1356
1357 d[0] = a[0] * b[0] + a[2] * b[1];
1358 d[2] = a[0] * b[2] + a[2] * b[3];
1359
1360 d[1] = a[1] * b[0] + a[3] * b[1];
1361 d[3] = a[1] * b[2] + a[3] * b[3];
1362
1363 out->flags = 0;
1364}
1365
1366static inline void
1367evas_mat2_multiply(Evas_Mat2 *out, const Evas_Mat2 *mat_a, const Evas_Mat2 *mat_b)
1368{
1369 if (out != mat_a && out != mat_b)
1370 {
1371 evas_mat2_nocheck_multiply(out, mat_a, mat_b);
1372 }
1373 else
1374 {
1375 Evas_Mat2 tmp;
1376
1377 evas_mat2_nocheck_multiply(&tmp, mat_a, mat_b);
1378 evas_mat2_copy(out, &tmp);
1379 }
1380}
1381
1382static inline void
1383evas_mat2_nocheck_inverse(Evas_Mat2 *out, const Evas_Mat2 *mat)
1384{
1385 Evas_Real *d = &out->m[0];
1386 const Evas_Real *m = &mat->m[0];
1387 Evas_Real det;
1388
1389 if (mat->flags & EVAS_MATRIX_IS_IDENTITY)
1390 {
1391 evas_mat2_copy(out, mat);
1392 return;
1393 }
1394
1395 det = m[0] * m[3] - m[2] * m[1];
1396
1397 if (det == 0.0)
1398 return;
1399
1400 det = 1.0 / det;
1401
1402 d[0] = m[3] * det;
1403 d[1] = -m[1] * det;
1404 d[2] = -m[2] * det;
1405 d[3] = m[0] * det;
1406
1407 out->flags = 0;
1408}
1409
1410static inline void
1411evas_mat2_invserse(Evas_Mat2 *out, const Evas_Mat2 *mat)
1412{
1413 if (out != mat)
1414 {
1415 evas_mat2_nocheck_inverse(out, mat);
1416 }
1417 else
1418 {
1419 Evas_Mat2 tmp;
1420
1421 evas_mat2_nocheck_inverse(&tmp, mat);
1422 evas_mat2_copy(out, &tmp);
1423 }
1424} 792}
1425 793
1426static inline void 794static inline void
@@ -1467,13 +835,13 @@ evas_box3_union(Evas_Box3 *out, const Evas_Box3 *a, const Evas_Box3 *b)
1467} 835}
1468 836
1469static inline void 837static inline void
1470evas_box3_transform(Evas_Box3 *out EINA_UNUSED, const Evas_Box3 *box EINA_UNUSED, const Evas_Mat4 *mat EINA_UNUSED) 838evas_box3_transform(Evas_Box3 *out EINA_UNUSED, const Evas_Box3 *box EINA_UNUSED, const Eina_Matrix4 *mat EINA_UNUSED)
1471{ 839{
1472 /* TODO: */ 840 /* TODO: */
1473} 841}
1474 842
1475static inline void 843static inline void
1476evas_mat4_position_get(const Evas_Mat4 *matrix, Evas_Vec4 *position) 844evas_mat4_position_get(const Eina_Matrix4 *matrix, Evas_Vec4 *position)
1477{ 845{
1478 Evas_Vec4 pos; 846 Evas_Vec4 pos;
1479 847
@@ -1486,7 +854,7 @@ evas_mat4_position_get(const Evas_Mat4 *matrix, Evas_Vec4 *position)
1486} 854}
1487 855
1488static inline void 856static inline void
1489evas_mat4_direction_get(const Evas_Mat4 *matrix, Evas_Vec3 *direction) 857evas_mat4_direction_get(const Eina_Matrix4 *matrix, Evas_Vec3 *direction)
1490{ 858{
1491 /* TODO: Check correctness. */ 859 /* TODO: Check correctness. */
1492 860
@@ -1540,7 +908,7 @@ evas_vec4_quaternion_inverse(Evas_Vec4 *out, const Evas_Vec4 *q)
1540} 908}
1541 909
1542static inline void 910static inline void
1543evas_vec4_quaternion_rotation_matrix_get(const Evas_Vec4 *q, Evas_Mat3 *mat) 911evas_vec4_quaternion_rotation_matrix_get(const Evas_Vec4 *q, Eina_Matrix3 *mat)
1544{ 912{
1545 Evas_Real x, y, z; 913 Evas_Real x, y, z;
1546 Evas_Real xx, xy, xz; 914 Evas_Real xx, xy, xz;
@@ -1565,57 +933,55 @@ evas_vec4_quaternion_rotation_matrix_get(const Evas_Vec4 *q, Evas_Mat3 *mat)
1565 wy = q->w * y; 933 wy = q->w * y;
1566 wz = q->w * z; 934 wz = q->w * z;
1567 935
1568 mat->m[0] = 1.0 - yy - zz; 936 mat->xx = 1.0 - yy - zz;
1569 mat->m[1] = xy + wz; 937 mat->xy = xy + wz;
1570 mat->m[2] = xz - wy; 938 mat->xz = xz - wy;
1571 mat->m[3] = xy - wz; 939 mat->yx = xy - wz;
1572 mat->m[4] = 1.0 - xx - zz; 940 mat->yy = 1.0 - xx - zz;
1573 mat->m[5] = yz + wx; 941 mat->yz = yz + wx;
1574 mat->m[6] = xz + wy; 942 mat->zx = xz + wy;
1575 mat->m[7] = yz - wx; 943 mat->zy = yz - wx;
1576 mat->m[8] = 1.0 - xx - yy; 944 mat->zz = 1.0 - xx - yy;
1577} 945}
1578 946
1579static inline void 947static inline void
1580evas_mat4_build(Evas_Mat4 *out, 948evas_mat4_build(Eina_Matrix4 *out,
1581 const Evas_Vec3 *position, const Evas_Vec4 *orientation, const Evas_Vec3 *scale) 949 const Evas_Vec3 *position, const Evas_Vec4 *orientation, const Evas_Vec3 *scale)
1582{ 950{
1583 Evas_Mat3 rot; 951 Eina_Matrix3 rot;
1584 952
1585 evas_vec4_quaternion_rotation_matrix_get(orientation, &rot); 953 evas_vec4_quaternion_rotation_matrix_get(orientation, &rot);
1586 954
1587 out->m[ 0] = scale->x * rot.m[0]; 955 out->xx = scale->x * rot.xx;
1588 out->m[ 1] = scale->x * rot.m[1]; 956 out->xy = scale->y * rot.xy;
1589 out->m[ 2] = scale->x * rot.m[2]; 957 out->xz = scale->z * rot.xz;
1590 out->m[ 3] = 0.0; 958 out->xw = 0.0;
1591
1592 out->m[ 4] = scale->y * rot.m[3];
1593 out->m[ 5] = scale->y * rot.m[4];
1594 out->m[ 6] = scale->y * rot.m[5];
1595 out->m[ 7] = 0.0;
1596 959
1597 out->m[ 8] = scale->z * rot.m[6]; 960 out->yx = scale->x * rot.yx;
1598 out->m[ 9] = scale->z * rot.m[7]; 961 out->yy = scale->y * rot.yy;
1599 out->m[10] = scale->z * rot.m[8]; 962 out->yz = scale->z * rot.yz;
1600 out->m[11] = 0.0; 963 out->yw = 0.0;
1601 964
1602 out->m[12] = position->x; 965 out->zx = scale->x * rot.zx;
1603 out->m[13] = position->y; 966 out->zy = scale->y * rot.zy;
1604 out->m[14] = position->z; 967 out->zz = scale->z * rot.zz;
1605 out->m[15] = 1.0; 968 out->zw = 0.0;
1606 969
1607 out->flags = 0; 970 out->wx = position->x;
971 out->wy = position->y;
972 out->wz = position->z;
973 out->ww = 1.0;
1608} 974}
1609 975
1610static inline void 976static inline void
1611evas_mat4_inverse_build(Evas_Mat4 *out, const Evas_Vec3 *position, 977evas_mat4_inverse_build(Eina_Matrix4 *out, const Evas_Vec3 *position,
1612 const Evas_Vec4 *orientation, const Evas_Vec3 *scale) 978 const Evas_Vec4 *orientation, const Evas_Vec3 *scale)
1613{ 979{
1614 Evas_Vec4 inv_rotation; 980 Evas_Vec4 inv_rotation;
1615 Evas_Vec3 inv_scale; 981 Evas_Vec3 inv_scale;
1616 Evas_Vec3 inv_translate; 982 Evas_Vec3 inv_translate;
1617 983
1618 Evas_Mat3 rot; 984 Eina_Matrix3 rot;
1619 985
1620 /* Inverse scale. */ 986 /* Inverse scale. */
1621 evas_vec3_set(&inv_scale, 1.0 / scale->x, 1.0 / scale->y, 1.0 / scale->z); 987 evas_vec3_set(&inv_scale, 1.0 / scale->x, 1.0 / scale->y, 1.0 / scale->z);
@@ -1631,27 +997,25 @@ evas_mat4_inverse_build(Evas_Mat4 *out, const Evas_Vec3 *position,
1631 /* Get 3x3 rotation matrix. */ 997 /* Get 3x3 rotation matrix. */
1632 evas_vec4_quaternion_rotation_matrix_get(&inv_rotation, &rot); 998 evas_vec4_quaternion_rotation_matrix_get(&inv_rotation, &rot);
1633 999
1634 out->m[ 0] = inv_scale.x * rot.m[0]; 1000 out->xx = inv_scale.x * rot.xx;
1635 out->m[ 1] = inv_scale.y * rot.m[1]; 1001 out->xy = inv_scale.y * rot.xy;
1636 out->m[ 2] = inv_scale.z * rot.m[2]; 1002 out->xz = inv_scale.z * rot.xz;
1637 out->m[ 3] = 0.0; 1003 out->xw = 0.0;
1638 1004
1639 out->m[ 4] = inv_scale.x * rot.m[3]; 1005 out->yx = inv_scale.x * rot.yx;
1640 out->m[ 5] = inv_scale.y * rot.m[4]; 1006 out->yy = inv_scale.y * rot.yy;
1641 out->m[ 6] = inv_scale.z * rot.m[5]; 1007 out->yz = inv_scale.z * rot.yz;
1642 out->m[ 7] = 0.0; 1008 out->yw = 0.0;
1643 1009
1644 out->m[ 8] = inv_scale.x * rot.m[6]; 1010 out->zx = inv_scale.x * rot.zx;
1645 out->m[ 9] = inv_scale.y * rot.m[7]; 1011 out->zy = inv_scale.y * rot.zy;
1646 out->m[10] = inv_scale.z * rot.m[8]; 1012 out->zz = inv_scale.z * rot.zz;
1647 out->m[11] = 0.0; 1013 out->zw = 0.0;
1648 1014
1649 out->m[12] = inv_translate.x; 1015 out->wx = inv_translate.x;
1650 out->m[13] = inv_translate.y; 1016 out->wy = inv_translate.y;
1651 out->m[14] = inv_translate.z; 1017 out->wz = inv_translate.z;
1652 out->m[15] = 1.0; 1018 out->ww = 1.0;
1653
1654 out->flags = 0;
1655} 1019}
1656 1020
1657static inline void 1021static inline void
@@ -1673,16 +1037,16 @@ evas_color_blend(Evas_Color *dst, const Evas_Color *c0, const Evas_Color *c1, Ev
1673} 1037}
1674 1038
1675static inline void 1039static inline void
1676evas_ray3_init(Evas_Ray3 *ray, Evas_Real x, Evas_Real y, const Evas_Mat4 *mvp) 1040evas_ray3_init(Evas_Ray3 *ray, Evas_Real x, Evas_Real y, const Eina_Matrix4 *mvp)
1677{ 1041{
1678 Evas_Mat4 mat; 1042 Eina_Matrix4 mat;
1679 Evas_Vec4 dnear, dfar; 1043 Evas_Vec4 dnear, dfar;
1680 1044
1681 memset(&mat, 0, sizeof (mat)); 1045 memset(&mat, 0, sizeof (mat));
1682 1046
1683 /* Get the matrix which transforms from normalized device coordinate to 1047 /* Get the matrix which transforms from normalized device coordinate to
1684 modeling coodrinate. */ 1048 modeling coodrinate. */
1685 evas_mat4_inverse(&mat, mvp); 1049 eina_matrix4_inverse(&mat, mvp);
1686 1050
1687 /* Transform near point. */ 1051 /* Transform near point. */
1688 dnear.x = x; 1052 dnear.x = x;
@@ -2123,38 +1487,35 @@ evas_is_box_in_frustum(Evas_Box3 *box, Evas_Vec4 *planes)
2123} 1487}
2124 1488
2125static inline void 1489static inline void
2126evas_frustum_calculate(Evas_Vec4 *planes, Evas_Mat4 *matrix_vp) 1490evas_frustum_calculate(Evas_Vec4 *planes, Eina_Matrix4 *matrix_vp)
2127{ 1491{
2128 int i; 1492 int i;
2129 evas_vec4_set(&planes[0], matrix_vp->m[3] - matrix_vp->m[0], 1493
2130 matrix_vp->m[7] - matrix_vp->m[4], 1494 evas_vec4_set(&planes[0], matrix_vp->xw - matrix_vp->xx,
2131 matrix_vp->m[11] - matrix_vp->m[8], 1495 matrix_vp->yw - matrix_vp->yx,
2132 matrix_vp->m[15] - matrix_vp->m[12]); 1496 matrix_vp->zw - matrix_vp->zx,
2133 1497 matrix_vp->ww - matrix_vp->wx);
2134 evas_vec4_set(&planes[1], matrix_vp->m[3] + matrix_vp->m[0], 1498 evas_vec4_set(&planes[1], matrix_vp->xw - matrix_vp->xx,
2135 matrix_vp->m[7] + matrix_vp->m[4], 1499 matrix_vp->yw - matrix_vp->yx,
2136 matrix_vp->m[11] + matrix_vp->m[8], 1500 matrix_vp->zw - matrix_vp->zx,
2137 matrix_vp->m[15] + matrix_vp->m[12]); 1501 matrix_vp->ww - matrix_vp->wx);
2138 1502 evas_vec4_set(&planes[2], matrix_vp->xw - matrix_vp->xx,
2139 evas_vec4_set(&planes[2], matrix_vp->m[3] + matrix_vp->m[1], 1503 matrix_vp->yw - matrix_vp->yx,
2140 matrix_vp->m[7] + matrix_vp->m[5], 1504 matrix_vp->zw - matrix_vp->zx,
2141 matrix_vp->m[11] + matrix_vp->m[9], 1505 matrix_vp->ww - matrix_vp->wx);
2142 matrix_vp->m[15] + matrix_vp->m[13]); 1506 evas_vec4_set(&planes[3], matrix_vp->xw - matrix_vp->xx,
2143 1507 matrix_vp->yw - matrix_vp->yx,
2144 evas_vec4_set(&planes[3], matrix_vp->m[3] - matrix_vp->m[1], 1508 matrix_vp->zw - matrix_vp->zx,
2145 matrix_vp->m[7] - matrix_vp->m[5], 1509 matrix_vp->ww - matrix_vp->wx);
2146 matrix_vp->m[11] - matrix_vp->m[9], 1510 evas_vec4_set(&planes[4], matrix_vp->xw - matrix_vp->xx,
2147 matrix_vp->m[15] - matrix_vp->m[13]); 1511 matrix_vp->yw - matrix_vp->yx,
2148 1512 matrix_vp->zw - matrix_vp->zx,
2149 evas_vec4_set(&planes[4], matrix_vp->m[3] - matrix_vp->m[2], 1513 matrix_vp->ww - matrix_vp->wx);
2150 matrix_vp->m[7] - matrix_vp->m[6], 1514 evas_vec4_set(&planes[5], matrix_vp->xw - matrix_vp->xx,
2151 matrix_vp->m[11] - matrix_vp->m[10], 1515 matrix_vp->yw - matrix_vp->yx,
2152 matrix_vp->m[15] - matrix_vp->m[14]); 1516 matrix_vp->zw - matrix_vp->zx,
2153 1517 matrix_vp->ww - matrix_vp->wx);
2154 evas_vec4_set(&planes[5], matrix_vp->m[3] + matrix_vp->m[2], 1518
2155 matrix_vp->m[7] + matrix_vp->m[6],
2156 matrix_vp->m[11] + matrix_vp->m[10],
2157 matrix_vp->m[15] + matrix_vp->m[14]);
2158 for (i = 0; i < 6; i++) 1519 for (i = 0; i < 6; i++)
2159 { 1520 {
2160 evas_plane_normalize(&planes[i]); 1521 evas_plane_normalize(&planes[i]);