summaryrefslogtreecommitdiff
path: root/src/lib/evas/include/evas_3d_utils.h
diff options
context:
space:
mode:
authorse.osadchy <se.osadchy@samsung.com>2015-12-07 16:12:56 -0800
committerCedric BAIL <cedric@osg.samsung.com>2015-12-07 16:36:16 -0800
commit82504d9d77f761f2575f63095459011eba02a594 (patch)
tree45206a1a76def085d5821ce255e06b42e89d57e5 /src/lib/evas/include/evas_3d_utils.h
parent32eb2d32c4c57d46f8a51fc51bc85e0cc296da10 (diff)
evas: recognize duplicated data structure with eina_quternion and ector.
Summary: Move data structure and functionality to eina_quaternion from evas_vec4. Reviewers: raster, Hermet, cedric Subscribers: jpeg, Oleksander Differential Revision: https://phab.enlightenment.org/D3327 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.h355
1 files changed, 52 insertions, 303 deletions
diff --git a/src/lib/evas/include/evas_3d_utils.h b/src/lib/evas/include/evas_3d_utils.h
index f3d4ed07ff..319c599209 100644
--- a/src/lib/evas/include/evas_3d_utils.h
+++ b/src/lib/evas/include/evas_3d_utils.h
@@ -15,7 +15,6 @@
15typedef struct _Evas_Color Evas_Color; 15typedef 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;
19typedef struct _Evas_Box2 Evas_Box2; 18typedef struct _Evas_Box2 Evas_Box2;
20typedef struct _Evas_Box3 Evas_Box3; 19typedef struct _Evas_Box3 Evas_Box3;
21typedef struct _Evas_Line3 Evas_Line3; 20typedef struct _Evas_Line3 Evas_Line3;
@@ -44,14 +43,6 @@ struct _Evas_Vec3
44 Evas_Real z; 43 Evas_Real z;
45}; 44};
46 45
47struct _Evas_Vec4
48{
49 Evas_Real x;
50 Evas_Real y;
51 Evas_Real z;
52 Evas_Real w;
53};
54
55struct _Evas_Box2 46struct _Evas_Box2
56{ 47{
57 Evas_Vec2 p0; 48 Evas_Vec2 p0;
@@ -400,7 +391,7 @@ evas_vec3_homogeneous_direction_transform(Evas_Vec3 *out, const Evas_Vec3 *v, co
400} 391}
401 392
402static inline void 393static inline void
403evas_vec3_quaternion_rotate(Evas_Vec3 *out, const Evas_Vec3 *v, const Evas_Vec4 *q) 394evas_vec3_quaternion_rotate(Evas_Vec3 *out, const Evas_Vec3 *v, const Eina_Quaternion *q)
404{ 395{
405 Evas_Vec3 uv, uuv; 396 Evas_Vec3 uv, uuv;
406 Evas_Vec3 axis; 397 Evas_Vec3 axis;
@@ -434,152 +425,8 @@ evas_vec3_orthogonal_projection_on_plain(Evas_Vec3 *out, const Evas_Vec3 *v, con
434 return; 425 return;
435} 426}
436 427
437/* 4D vector */
438static inline void
439evas_vec4_set(Evas_Vec4 *dst, Evas_Real x, Evas_Real y, Evas_Real z, Evas_Real w)
440{
441 dst->x = x;
442 dst->y = y;
443 dst->z = z;
444 dst->w = w;
445}
446
447static inline void
448evas_vec4_array_set(Evas_Vec4 *dst, const Evas_Real *v)
449{
450 dst->x = v[0];
451 dst->y = v[1];
452 dst->z = v[2];
453 dst->w = v[3];
454}
455
456static inline void
457evas_vec4_copy(Evas_Vec4 *dst, const Evas_Vec4 *src)
458{
459 dst->x = src->x;
460 dst->y = src->y;
461 dst->z = src->z;
462 dst->w = src->w;
463}
464
465static inline void
466evas_vec4_homogeneous_regulate(Evas_Vec4 *out, const Evas_Vec4 *v)
467{
468 if (v->w != 0.0)
469 {
470 Evas_Real scale = 1.0 / v->w;
471
472 out->x = v->x * scale;
473 out->y = v->y * scale;
474 out->z = v->z * scale;
475 out->w = 1.0;
476 }
477}
478
479static inline void
480evas_vec4_negate(Evas_Vec4 *out, const Evas_Vec4 *v)
481{
482 out->x = -v->x;
483 out->y = -v->y;
484 out->z = -v->z;
485 out->w = -v->w;
486}
487
488static inline void 428static inline void
489evas_vec4_add(Evas_Vec4 *out, const Evas_Vec4 *a, const Evas_Vec4 *b) 429evas_vec3_plain_by_points(Eina_Quaternion *out, const Evas_Vec3 *a, const Evas_Vec3 *b, const Evas_Vec3 *c)
490{
491 out->x = a->x + b->x;
492 out->y = a->y + b->y;
493 out->z = a->z + b->z;
494 out->w = a->w + b->w;
495}
496
497static inline void
498evas_vec4_subtract(Evas_Vec4 *out, const Evas_Vec4 *a, const Evas_Vec4 *b)
499{
500 out->x = a->x - b->x;
501 out->y = a->y - b->y;
502 out->z = a->z - b->z;
503 out->w = a->w - b->w;
504}
505
506static inline void
507evas_vec4_scale(Evas_Vec4 *out, const Evas_Vec4 *v, Evas_Real scale)
508{
509 out->x = scale * v->x;
510 out->y = scale * v->y;
511 out->z = scale * v->z;
512 out->w = scale * v->w;
513}
514
515static inline void
516evas_vec4_multiply(Evas_Vec4 *out, const Evas_Vec4 *a, const Evas_Vec4 *b)
517{
518 out->x = a->x * b->x;
519 out->y = a->y * b->y;
520 out->z = a->z * b->z;
521 out->w = a->w * b->w;
522}
523
524static inline Evas_Real
525evas_vec4_length_get(const Evas_Vec4 *v)
526{
527 return (Evas_Real)sqrt((double)((v->x * v->x) + (v->y * v->y) +
528 (v->z * v->z) + (v->w + v->w)));
529}
530
531static inline Evas_Real
532evas_vec4_length_square_get(const Evas_Vec4 *v)
533{
534 return (v->x * v->x) + (v->y * v->y) + (v->z * v->z) + (v->w * v->w);
535}
536
537static inline Evas_Real
538evas_vec4_distance_get(const Evas_Vec4 *a, const Evas_Vec4 *b)
539{
540 Evas_Vec4 v;
541
542 evas_vec4_subtract(&v, a, b);
543 return evas_vec4_length_get(&v);
544}
545
546static inline Evas_Real
547evas_vec4_distance_square_get(const Evas_Vec4 *a, const Evas_Vec4 *b)
548{
549 Evas_Vec4 v;
550
551 evas_vec4_subtract(&v, a, b);
552 return evas_vec4_length_square_get(&v);
553}
554
555static inline void
556evas_vec4_normalize(Evas_Vec4 *out, const Evas_Vec4 *v)
557{
558 /* Assume "v" is not a zero vector */
559 evas_vec4_scale(out, v, 1.0 / evas_vec4_length_get(v));
560}
561
562static inline void
563evas_vec4_transform(Evas_Vec4 *out, const Evas_Vec4 *v, const Eina_Matrix4 *m)
564{
565 Evas_Vec4 tmp;
566
567 if (eina_matrix4_type_get(m) == EINA_MATRIX_TYPE_IDENTITY)
568 {
569 evas_vec4_copy(out, v);
570 return;
571 }
572
573 tmp.x = (m->xx * v->x) + (m->yx * v->y) + (m->zx * v->z) + (m->wx * v->w);
574 tmp.y = (m->xy * v->x) + (m->yy * v->y) + (m->zy * v->z) + (m->wy * v->w);
575 tmp.z = (m->xz * v->x) + (m->yz * v->y) + (m->zz * v->z) + (m->wz * v->w);
576 tmp.w = (m->xw * v->x) + (m->yw * v->y) + (m->zw * v->z) + (m->ww * v->w);
577
578 evas_vec4_copy(out, &tmp);
579}
580
581static inline void
582evas_vec4_plain_by_points(Evas_Vec4 *out, const Evas_Vec3 *a, const Evas_Vec3 *b, const Evas_Vec3 *c)
583{ 430{
584 out->x = (b->y - a->y) * (c->z - a->z) - (b->z - a->z) * (c->y - a->y); 431 out->x = (b->y - a->y) * (c->z - a->z) - (b->z - a->z) * (c->y - a->y);
585 out->y = -(b->x - a->x) * (c->z - a->z) + (b->z - a->z) * (c->x - a->x); 432 out->y = -(b->x - a->x) * (c->z - a->z) + (b->z - a->z) * (c->x - a->x);
@@ -589,16 +436,8 @@ evas_vec4_plain_by_points(Evas_Vec4 *out, const Evas_Vec3 *a, const Evas_Vec3 *b
589 (-a->z) * ((b->x - a->x) * (c->y - a->y) - (b->y - a->y) * (c->x - a->x)); 436 (-a->z) * ((b->x - a->x) * (c->y - a->y) - (b->y - a->y) * (c->x - a->x));
590} 437}
591 438
592static inline Evas_Real
593evas_vec4_angle_plains(Evas_Vec4 *a, Evas_Vec4 *b)
594{
595 return (Evas_Real) ((a->x * b->x) + (a->y * b->y) + (a->z * b->z)) / ((sqrt((a->x * a->x) +
596 (a->y * a->y) + (a->z * a->z))) * (sqrt((b->x * b->x) + (b->y * b->y) +
597 (b->z * b->z))));
598}
599
600static inline void 439static inline void
601evas_vec3_homogeneous_position_set(Evas_Vec3 *out, const Evas_Vec4 *v) 440evas_vec3_homogeneous_position_set(Evas_Vec3 *out, const Eina_Quaternion *v)
602{ 441{
603 /* Assume "v" is a positional vector. (v->w != 0.0) */ 442 /* Assume "v" is a positional vector. (v->w != 0.0) */
604 Evas_Real h = 1.0 / v->w; 443 Evas_Real h = 1.0 / v->w;
@@ -609,7 +448,7 @@ evas_vec3_homogeneous_position_set(Evas_Vec3 *out, const Evas_Vec4 *v)
609} 448}
610 449
611static inline void 450static inline void
612evas_vec3_homogeneous_direction_set(Evas_Vec3 *out, const Evas_Vec4 *v) 451evas_vec3_homogeneous_direction_set(Evas_Vec3 *out, const Eina_Quaternion *v)
613{ 452{
614 /* Assume "v" is a directional vector. (v->w == 0.0) */ 453 /* Assume "v" is a directional vector. (v->w == 0.0) */
615 out->x = v->x; 454 out->x = v->x;
@@ -707,24 +546,6 @@ evas_triangle3_if_equivalent(Evas_Triangle3 *a, Evas_Triangle3 *b)
707} 546}
708 547
709static inline void 548static inline void
710evas_vec4_homogeneous_position_set(Evas_Vec4 *out, const Evas_Vec3 *v)
711{
712 out->x = v->x;
713 out->y = v->y;
714 out->z = v->z;
715 out->w = 1.0;
716}
717
718static inline void
719evas_vec4_homogeneous_direction_set(Evas_Vec4 *out, const Evas_Vec3 *v)
720{
721 out->x = v->x;
722 out->y = v->y;
723 out->z = v->z;
724 out->w = 0.0;
725}
726
727static inline void
728evas_mat4_look_at_set(Eina_Matrix4 *m, 549evas_mat4_look_at_set(Eina_Matrix4 *m,
729 const Evas_Vec3 *pos, const Evas_Vec3 *center, const Evas_Vec3 *up) 550 const Evas_Vec3 *pos, const Evas_Vec3 *center, const Evas_Vec3 *up)
730{ 551{
@@ -841,16 +662,16 @@ evas_box3_transform(Evas_Box3 *out EINA_UNUSED, const Evas_Box3 *box EINA_UNUSED
841} 662}
842 663
843static inline void 664static inline void
844evas_mat4_position_get(const Eina_Matrix4 *matrix, Evas_Vec4 *position) 665evas_mat4_position_get(const Eina_Matrix4 *matrix, Eina_Quaternion *position)
845{ 666{
846 Evas_Vec4 pos; 667 Eina_Quaternion pos;
847 668
848 pos.x = 0.0; 669 pos.x = 0.0;
849 pos.y = 0.0; 670 pos.y = 0.0;
850 pos.z = 0.0; 671 pos.z = 0.0;
851 pos.w = 1.0; 672 pos.w = 1.0;
852 673
853 evas_vec4_transform(position, &pos, matrix); 674 eina_quaternion_transform(position, &pos, matrix);
854} 675}
855 676
856static inline void 677static inline void
@@ -858,14 +679,14 @@ evas_mat4_direction_get(const Eina_Matrix4 *matrix, Evas_Vec3 *direction)
858{ 679{
859 /* TODO: Check correctness. */ 680 /* TODO: Check correctness. */
860 681
861 Evas_Vec4 dir; 682 Eina_Quaternion dir;
862 683
863 dir.x = 0.0; 684 dir.x = 0.0;
864 dir.y = 0.0; 685 dir.y = 0.0;
865 dir.z = 1.0; 686 dir.z = 1.0;
866 dir.w = 1.0; 687 dir.w = 1.0;
867 688
868 evas_vec4_transform(&dir, &dir, matrix); 689 eina_quaternion_transform(&dir, &dir, matrix);
869 690
870 direction->x = dir.x; 691 direction->x = dir.x;
871 direction->y = dir.y; 692 direction->y = dir.y;
@@ -873,84 +694,12 @@ evas_mat4_direction_get(const Eina_Matrix4 *matrix, Evas_Vec3 *direction)
873} 694}
874 695
875static inline void 696static inline void
876evas_vec4_quaternion_multiply(Evas_Vec4 *out, const Evas_Vec4 *a, const Evas_Vec4 *b)
877{
878 Evas_Vec4 r;
879
880 r.x = (a->w * b->x) + (a->x * b->w) + (a->y * b->z) - (a->z * b->y);
881 r.y = (a->w * b->y) - (a->x * b->z) + (a->y * b->w) + (a->z * b->x);
882 r.z = (a->w * b->z) + (a->x * b->y) - (a->y * b->x) + (a->z * b->w);
883 r.w = (a->w * b->w) - (a->x * b->x) - (a->y * b->y) - (a->z * b->z);
884
885 *out = r;
886}
887
888static inline void
889evas_vec4_quaternion_inverse(Evas_Vec4 *out, const Evas_Vec4 *q)
890{
891 Evas_Real norm = (q->x * q->x) + (q->y * q->y) + (q->z * q->z) + (q->w * q->w);
892
893 if (norm > 0.0)
894 {
895 Evas_Real inv_norm = 1.0 / norm;
896 out->x = -q->x * inv_norm;
897 out->y = -q->y * inv_norm;
898 out->z = -q->z * inv_norm;
899 out->w = q->w * inv_norm;
900 }
901 else
902 {
903 out->x = 0.0;
904 out->y = 0.0;
905 out->z = 0.0;
906 out->w = 0.0;
907 }
908}
909
910static inline void
911evas_vec4_quaternion_rotation_matrix_get(const Evas_Vec4 *q, Eina_Matrix3 *mat)
912{
913 Evas_Real x, y, z;
914 Evas_Real xx, xy, xz;
915 Evas_Real yy, yz;
916 Evas_Real zz;
917 Evas_Real wx, wy, wz;
918
919 x = 2.0 * q->x;
920 y = 2.0 * q->y;
921 z = 2.0 * q->z;
922
923 xx = q->x * x;
924 xy = q->x * y;
925 xz = q->x * z;
926
927 yy = q->y * y;
928 yz = q->y * z;
929
930 zz = q->z * z;
931
932 wx = q->w * x;
933 wy = q->w * y;
934 wz = q->w * z;
935
936 mat->xx = 1.0 - yy - zz;
937 mat->xy = xy + wz;
938 mat->xz = xz - wy;
939 mat->yx = xy - wz;
940 mat->yy = 1.0 - xx - zz;
941 mat->yz = yz + wx;
942 mat->zx = xz + wy;
943 mat->zy = yz - wx;
944 mat->zz = 1.0 - xx - yy;
945}
946
947static inline void
948evas_mat4_build(Eina_Matrix4 *out, 697evas_mat4_build(Eina_Matrix4 *out,
949 const Evas_Vec3 *position, const Evas_Vec4 *orientation, const Evas_Vec3 *scale) 698 const Evas_Vec3 *position, const Eina_Quaternion *orientation, const Evas_Vec3 *scale)
950{ 699{
951 Eina_Matrix3 rot; 700 Eina_Matrix3 rot;
952 701
953 evas_vec4_quaternion_rotation_matrix_get(orientation, &rot); 702 eina_quaternion_rotation_matrix3_get(&rot, orientation);
954 703
955 out->xx = scale->x * rot.xx; 704 out->xx = scale->x * rot.xx;
956 out->xy = scale->x * rot.xy; 705 out->xy = scale->x * rot.xy;
@@ -975,9 +724,9 @@ evas_mat4_build(Eina_Matrix4 *out,
975 724
976static inline void 725static inline void
977evas_mat4_inverse_build(Eina_Matrix4 *out, const Evas_Vec3 *position, 726evas_mat4_inverse_build(Eina_Matrix4 *out, const Evas_Vec3 *position,
978 const Evas_Vec4 *orientation, const Evas_Vec3 *scale) 727 const Eina_Quaternion *orientation, const Evas_Vec3 *scale)
979{ 728{
980 Evas_Vec4 inv_rotation; 729 Eina_Quaternion inv_rotation;
981 Evas_Vec3 inv_scale; 730 Evas_Vec3 inv_scale;
982 Evas_Vec3 inv_translate; 731 Evas_Vec3 inv_translate;
983 732
@@ -987,7 +736,7 @@ evas_mat4_inverse_build(Eina_Matrix4 *out, const Evas_Vec3 *position,
987 evas_vec3_set(&inv_scale, 1.0 / scale->x, 1.0 / scale->y, 1.0 / scale->z); 736 evas_vec3_set(&inv_scale, 1.0 / scale->x, 1.0 / scale->y, 1.0 / scale->z);
988 737
989 /* Inverse rotation. */ 738 /* Inverse rotation. */
990 evas_vec4_quaternion_inverse(&inv_rotation, orientation); 739 eina_quaternion_inverse(&inv_rotation, orientation);
991 740
992 /* Inverse translation. */ 741 /* Inverse translation. */
993 evas_vec3_negate(&inv_translate, position); 742 evas_vec3_negate(&inv_translate, position);
@@ -995,7 +744,7 @@ evas_mat4_inverse_build(Eina_Matrix4 *out, const Evas_Vec3 *position,
995 evas_vec3_multiply(&inv_translate, &inv_translate, &inv_scale); 744 evas_vec3_multiply(&inv_translate, &inv_translate, &inv_scale);
996 745
997 /* Get 3x3 rotation matrix. */ 746 /* Get 3x3 rotation matrix. */
998 evas_vec4_quaternion_rotation_matrix_get(&inv_rotation, &rot); 747 eina_quaternion_rotation_matrix3_get(&rot, &inv_rotation);
999 748
1000 out->xx = inv_scale.x * rot.xx; 749 out->xx = inv_scale.x * rot.xx;
1001 out->xy = inv_scale.x * rot.xy; 750 out->xy = inv_scale.x * rot.xy;
@@ -1040,7 +789,7 @@ static inline void
1040evas_ray3_init(Evas_Ray3 *ray, Evas_Real x, Evas_Real y, const Eina_Matrix4 *mvp) 789evas_ray3_init(Evas_Ray3 *ray, Evas_Real x, Evas_Real y, const Eina_Matrix4 *mvp)
1041{ 790{
1042 Eina_Matrix4 mat; 791 Eina_Matrix4 mat;
1043 Evas_Vec4 dnear, dfar; 792 Eina_Quaternion dnear, dfar;
1044 793
1045 memset(&mat, 0, sizeof (mat)); 794 memset(&mat, 0, sizeof (mat));
1046 795
@@ -1054,7 +803,7 @@ evas_ray3_init(Evas_Ray3 *ray, Evas_Real x, Evas_Real y, const Eina_Matrix4 *mvp
1054 dnear.z = -1.0; 803 dnear.z = -1.0;
1055 dnear.w = 1.0; 804 dnear.w = 1.0;
1056 805
1057 evas_vec4_transform(&dnear, &dnear, &mat); 806 eina_quaternion_transform(&dnear, &dnear, &mat);
1058 807
1059 dnear.w = 1.0 / dnear.w; 808 dnear.w = 1.0 / dnear.w;
1060 dnear.x *= dnear.w; 809 dnear.x *= dnear.w;
@@ -1069,7 +818,7 @@ evas_ray3_init(Evas_Ray3 *ray, Evas_Real x, Evas_Real y, const Eina_Matrix4 *mvp
1069 dfar.z = 1.0; 818 dfar.z = 1.0;
1070 dfar.w = 1.0; 819 dfar.w = 1.0;
1071 820
1072 evas_vec4_transform(&dfar, &dfar, &mat); 821 eina_quaternion_transform(&dfar, &dfar, &mat);
1073 822
1074 dfar.w = 1.0 / dfar.w; 823 dfar.w = 1.0 / dfar.w;
1075 dfar.x *= dfar.w; 824 dfar.x *= dfar.w;
@@ -1297,7 +1046,7 @@ evas_sphere_empty_set(Evas_Sphere *dst)
1297} 1046}
1298 1047
1299static inline void 1048static inline void
1300evas_plane_normalize(Evas_Vec4 *plane) 1049evas_plane_normalize(Eina_Quaternion *plane)
1301{ 1050{
1302 Evas_Vec3 tmp; 1051 Evas_Vec3 tmp;
1303 Evas_Real length; 1052 Evas_Real length;
@@ -1310,7 +1059,7 @@ evas_plane_normalize(Evas_Vec4 *plane)
1310} 1059}
1311 1060
1312static inline Eina_Bool 1061static inline Eina_Bool
1313evas_intersection_line_of_two_planes(Evas_Line3 *line, Evas_Vec4 *plane1, Evas_Vec4 *plane2) 1062evas_intersection_line_of_two_planes(Evas_Line3 *line, Eina_Quaternion *plane1, Eina_Quaternion *plane2)
1314{ 1063{
1315 //TODO:parallel case 1064 //TODO:parallel case
1316 Evas_Vec3 planes3D[2]; 1065 Evas_Vec3 planes3D[2];
@@ -1343,13 +1092,13 @@ evas_intersection_line_of_two_planes(Evas_Line3 *line, Evas_Vec4 *plane1, Evas_V
1343} 1092}
1344 1093
1345static inline Eina_Bool 1094static inline Eina_Bool
1346evas_intersection_point_of_three_planes(Evas_Vec3 *point, Evas_Vec4 *plane1, Evas_Vec4 *plane2, Evas_Vec4 *plane3) 1095evas_intersection_point_of_three_planes(Evas_Vec3 *point, Eina_Quaternion *plane1, Eina_Quaternion *plane2, Eina_Quaternion *plane3)
1347{ 1096{
1348 //TODO:parallel case 1097 //TODO:parallel case
1349 int i; 1098 int i;
1350 Evas_Real delta, deltax, deltay, deltaz; 1099 Evas_Real delta, deltax, deltay, deltaz;
1351 Evas_Real matrix_to_det[3][3]; 1100 Evas_Real matrix_to_det[3][3];
1352 Evas_Vec4 planes[3]; 1101 Eina_Quaternion planes[3];
1353 1102
1354 planes[0] = *plane1; 1103 planes[0] = *plane1;
1355 planes[1] = *plane2; 1104 planes[1] = *plane2;
@@ -1387,7 +1136,7 @@ evas_intersection_point_of_three_planes(Evas_Vec3 *point, Evas_Vec4 *plane1, Eva
1387} 1136}
1388 1137
1389static inline Evas_Real 1138static inline Evas_Real
1390evas_point_plane_distance(Evas_Vec3 *point, Evas_Vec4 *plane) 1139evas_point_plane_distance(Evas_Vec3 *point, Eina_Quaternion *plane)
1391{ 1140{
1392 return plane->x * point->x + plane->y * point->y + plane->z * point->z + plane->w; 1141 return plane->x * point->x + plane->y * point->y + plane->z * point->z + plane->w;
1393} 1142}
@@ -1404,7 +1153,7 @@ evas_point_line_distance(Evas_Vec3 *point, Evas_Line3 *line)
1404} 1153}
1405 1154
1406static inline Eina_Bool 1155static inline Eina_Bool
1407evas_is_sphere_in_frustum(Evas_Sphere *bsphere, Evas_Vec4 *planes) 1156evas_is_sphere_in_frustum(Evas_Sphere *bsphere, Eina_Quaternion *planes)
1408{ 1157{
1409 int i; 1158 int i;
1410 Evas_Line3 line; 1159 Evas_Line3 line;
@@ -1450,7 +1199,7 @@ evas_is_sphere_in_frustum(Evas_Sphere *bsphere, Evas_Vec4 *planes)
1450} 1199}
1451 1200
1452static inline Eina_Bool 1201static inline Eina_Bool
1453evas_is_point_in_frustum(Evas_Vec3 *point, Evas_Vec4 *planes) 1202evas_is_point_in_frustum(Evas_Vec3 *point, Eina_Quaternion *planes)
1454{ 1203{
1455 int i; 1204 int i;
1456 for (i = 0; i < 6; i++) 1205 for (i = 0; i < 6; i++)
@@ -1459,7 +1208,7 @@ evas_is_point_in_frustum(Evas_Vec3 *point, Evas_Vec4 *planes)
1459} 1208}
1460 1209
1461static inline Eina_Bool 1210static inline Eina_Bool
1462evas_is_box_in_frustum(Evas_Box3 *box, Evas_Vec4 *planes) 1211evas_is_box_in_frustum(Evas_Box3 *box, Eina_Quaternion *planes)
1463{ 1212{
1464 int i; 1213 int i;
1465 for (i = 0; i < 6; i++) 1214 for (i = 0; i < 6; i++)
@@ -1487,31 +1236,31 @@ evas_is_box_in_frustum(Evas_Box3 *box, Evas_Vec4 *planes)
1487} 1236}
1488 1237
1489static inline void 1238static inline void
1490evas_frustum_calculate(Evas_Vec4 *planes, Eina_Matrix4 *matrix_vp) 1239evas_frustum_calculate(Eina_Quaternion *planes, Eina_Matrix4 *matrix_vp)
1491{ 1240{
1492 int i; 1241 int i;
1493 1242
1494 evas_vec4_set(&planes[0], matrix_vp->xw - matrix_vp->xx, 1243 eina_quaternion_set(&planes[0], matrix_vp->xw - matrix_vp->xx,
1495 matrix_vp->yw - matrix_vp->yx, 1244 matrix_vp->yw - matrix_vp->yx,
1496 matrix_vp->zw - matrix_vp->zx, 1245 matrix_vp->zw - matrix_vp->zx,
1497 matrix_vp->ww - matrix_vp->wx); 1246 matrix_vp->ww - matrix_vp->wx);
1498 evas_vec4_set(&planes[1], matrix_vp->xw - matrix_vp->xx, 1247 eina_quaternion_set(&planes[1], matrix_vp->xw - matrix_vp->xx,
1499 matrix_vp->yw - matrix_vp->yx, 1248 matrix_vp->yw - matrix_vp->yx,
1500 matrix_vp->zw - matrix_vp->zx, 1249 matrix_vp->zw - matrix_vp->zx,
1501 matrix_vp->ww - matrix_vp->wx); 1250 matrix_vp->ww - matrix_vp->wx);
1502 evas_vec4_set(&planes[2], matrix_vp->xw - matrix_vp->xx, 1251 eina_quaternion_set(&planes[2], matrix_vp->xw - matrix_vp->xx,
1503 matrix_vp->yw - matrix_vp->yx, 1252 matrix_vp->yw - matrix_vp->yx,
1504 matrix_vp->zw - matrix_vp->zx, 1253 matrix_vp->zw - matrix_vp->zx,
1505 matrix_vp->ww - matrix_vp->wx); 1254 matrix_vp->ww - matrix_vp->wx);
1506 evas_vec4_set(&planes[3], matrix_vp->xw - matrix_vp->xx, 1255 eina_quaternion_set(&planes[3], matrix_vp->xw - matrix_vp->xx,
1507 matrix_vp->yw - matrix_vp->yx, 1256 matrix_vp->yw - matrix_vp->yx,
1508 matrix_vp->zw - matrix_vp->zx, 1257 matrix_vp->zw - matrix_vp->zx,
1509 matrix_vp->ww - matrix_vp->wx); 1258 matrix_vp->ww - matrix_vp->wx);
1510 evas_vec4_set(&planes[4], matrix_vp->xw - matrix_vp->xx, 1259 eina_quaternion_set(&planes[4], matrix_vp->xw - matrix_vp->xx,
1511 matrix_vp->yw - matrix_vp->yx, 1260 matrix_vp->yw - matrix_vp->yx,
1512 matrix_vp->zw - matrix_vp->zx, 1261 matrix_vp->zw - matrix_vp->zx,
1513 matrix_vp->ww - matrix_vp->wx); 1262 matrix_vp->ww - matrix_vp->wx);
1514 evas_vec4_set(&planes[5], matrix_vp->xw - matrix_vp->xx, 1263 eina_quaternion_set(&planes[5], matrix_vp->xw - matrix_vp->xx,
1515 matrix_vp->yw - matrix_vp->yx, 1264 matrix_vp->yw - matrix_vp->yx,
1516 matrix_vp->zw - matrix_vp->zx, 1265 matrix_vp->zw - matrix_vp->zx,
1517 matrix_vp->ww - matrix_vp->wx); 1266 matrix_vp->ww - matrix_vp->wx);
@@ -1618,7 +1367,7 @@ convex_hull_first_tr_get(float *data, int count, int stride)
1618 Evas_Vec3 triangle2, triangle2_candidate; 1367 Evas_Vec3 triangle2, triangle2_candidate;
1619 Evas_Vec3 triangle3, triangle3_candidate; 1368 Evas_Vec3 triangle3, triangle3_candidate;
1620 Evas_Vec3 first, second, complanar1, complanar2, candidate; 1369 Evas_Vec3 first, second, complanar1, complanar2, candidate;
1621 Evas_Vec4 normal_a, normal_b; 1370 Eina_Quaternion normal_a, normal_b;
1622 1371
1623 Evas_Real cos = 0.0, new_cos = 0.0, tan = 0.0, new_tan = 0.0, cos_2d = 0.0, new_cos_2d = 0.0; 1372 Evas_Real cos = 0.0, new_cos = 0.0, tan = 0.0, new_tan = 0.0, cos_2d = 0.0, new_cos_2d = 0.0;
1624 int first_num = 0, second_num = 0; 1373 int first_num = 0, second_num = 0;
@@ -1715,10 +1464,10 @@ convex_hull_first_tr_get(float *data, int count, int stride)
1715 1464
1716 evas_vec3_set(&complanar1, triangle1.x + 1, triangle1.y, triangle1.z); 1465 evas_vec3_set(&complanar1, triangle1.x + 1, triangle1.y, triangle1.z);
1717 evas_vec3_set(&complanar2, triangle1.x, triangle1.y + 1, triangle1.z); 1466 evas_vec3_set(&complanar2, triangle1.x, triangle1.y + 1, triangle1.z);
1718 evas_vec4_plain_by_points(&normal_a, &triangle1, &complanar1, &complanar2); 1467 evas_vec3_plain_by_points(&normal_a, &triangle1, &complanar1, &complanar2);
1719 1468
1720 if (normal_a.z < 0) 1469 if (normal_a.z < 0)
1721 evas_vec4_scale(&normal_a, &normal_a, -1); 1470 eina_quaternion_scale(&normal_a, &normal_a, -1);
1722 1471
1723 evas_vec3_set(&triangle3, data[0], data[1], data[2]); 1472 evas_vec3_set(&triangle3, data[0], data[1], data[2]);
1724 1473
@@ -1730,12 +1479,12 @@ convex_hull_first_tr_get(float *data, int count, int stride)
1730 if ((i != first_num) && (i != second_num)) 1479 if ((i != first_num) && (i != second_num))
1731 { 1480 {
1732 evas_vec3_set(&candidate, data[j], data[j + 1], data[j + 2]); 1481 evas_vec3_set(&candidate, data[j], data[j + 1], data[j + 2]);
1733 evas_vec4_plain_by_points(&normal_b, &triangle1, &candidate, &triangle2); 1482 evas_vec3_plain_by_points(&normal_b, &triangle1, &candidate, &triangle2);
1734 1483
1735 if (normal_b.z < 0) 1484 if (normal_b.z < 0)
1736 evas_vec4_scale(&normal_b, &normal_b, -1); 1485 eina_quaternion_scale(&normal_b, &normal_b, -1);
1737 1486
1738 new_cos = evas_vec4_angle_plains(&normal_a, &normal_b); 1487 new_cos = eina_quaternion_angle_plains(&normal_a, &normal_b);
1739 1488
1740 if (new_cos > cos + FLT_EPSILON) 1489 if (new_cos > cos + FLT_EPSILON)
1741 { 1490 {
@@ -1772,7 +1521,7 @@ evas_convex_hull_get(float *data, int count, int stride, Eina_Inarray *vertex,
1772 1521
1773 Evas_Vec3 *next = NULL, *best = NULL, *next_2d = NULL, *el_vec3 = NULL; 1522 Evas_Vec3 *next = NULL, *best = NULL, *next_2d = NULL, *el_vec3 = NULL;
1774 Evas_Vec3 tmp1, tmp2; 1523 Evas_Vec3 tmp1, tmp2;
1775 Evas_Vec4 normal_a, normal_b; 1524 Eina_Quaternion normal_a, normal_b;
1776 1525
1777 Eina_Array arr_elems; 1526 Eina_Array arr_elems;
1778 Eina_Array arr_triangles; 1527 Eina_Array arr_triangles;
@@ -1842,8 +1591,8 @@ evas_convex_hull_get(float *data, int count, int stride, Eina_Inarray *vertex,
1842 /* something like the dihedral angle between the triangles 1591 /* something like the dihedral angle between the triangles
1843 is a determining factor in searching the necessary points */ 1592 is a determining factor in searching the necessary points */
1844 1593
1845 evas_vec4_plain_by_points(&normal_a, &elem->p0, &elem->p1, &elem->p2); 1594 evas_vec3_plain_by_points(&normal_a, &elem->p0, &elem->p1, &elem->p2);
1846 evas_vec4_plain_by_points(&normal_b, &elem->p0, &elem->p1, next); 1595 evas_vec3_plain_by_points(&normal_b, &elem->p0, &elem->p1, next);
1847 1596
1848 /* MIN_DIFF because vertices that belong to plain shouldn't be included */ 1597 /* MIN_DIFF because vertices that belong to plain shouldn't be included */
1849 if (fabs(normal_a.x * data[j] + normal_a.y * data[j + 1] + normal_a.z * data[j + 2] + normal_a.w) < MIN_DIFF) 1598 if (fabs(normal_a.x * data[j] + normal_a.y * data[j + 1] + normal_a.z * data[j + 2] + normal_a.w) < MIN_DIFF)
@@ -1860,11 +1609,11 @@ evas_convex_hull_get(float *data, int count, int stride, Eina_Inarray *vertex,
1860 else 1609 else
1861 { 1610 {
1862 if (normal_a.x * data[j] + normal_a.y * data[j+1] + normal_a.z * data[j+2] + normal_a.w < 0) 1611 if (normal_a.x * data[j] + normal_a.y * data[j+1] + normal_a.z * data[j+2] + normal_a.w < 0)
1863 evas_vec4_scale(&normal_a, &normal_a, -1); 1612 eina_quaternion_scale(&normal_a, &normal_a, -1);
1864 if (normal_b.x * elem->p2.x + normal_b.y * elem->p2.y + normal_b.z * elem->p2.z + normal_b.w < 0) 1613 if (normal_b.x * elem->p2.x + normal_b.y * elem->p2.y + normal_b.z * elem->p2.z + normal_b.w < 0)
1865 evas_vec4_scale(&normal_b, &normal_b, -1); 1614 eina_quaternion_scale(&normal_b, &normal_b, -1);
1866 1615
1867 new_cos = evas_vec4_angle_plains(&normal_a, &normal_b); 1616 new_cos = eina_quaternion_angle_plains(&normal_a, &normal_b);
1868 } 1617 }
1869 1618
1870 /* MIN_DIFF is more useful for dihedral angles apparently */ 1619 /* MIN_DIFF is more useful for dihedral angles apparently */
@@ -1911,7 +1660,7 @@ evas_convex_hull_get(float *data, int count, int stride, Eina_Inarray *vertex,
1911 { 1660 {
1912 Evas_Vec3 angle_from, angle_to; 1661 Evas_Vec3 angle_from, angle_to;
1913 next_2d = eina_array_data_get(&arr_candidates, 0); 1662 next_2d = eina_array_data_get(&arr_candidates, 0);
1914 evas_vec4_plain_by_points(&normal_b, &elem->p1, &elem->p0, next_2d); 1663 evas_vec3_plain_by_points(&normal_b, &elem->p1, &elem->p0, next_2d);
1915 1664
1916 if (normal_b.x * elem->p2.x + normal_b.y * elem->p2.y + normal_b.z * elem->p2.z + normal_b.w > 0) 1665 if (normal_b.x * elem->p2.x + normal_b.y * elem->p2.y + normal_b.z * elem->p2.z + normal_b.w > 0)
1917 { 1666 {
@@ -1959,8 +1708,8 @@ evas_convex_hull_get(float *data, int count, int stride, Eina_Inarray *vertex,
1959 { 1708 {
1960 evas_vec3_subtract(&angle_to, next_2d, &elem->p0); 1709 evas_vec3_subtract(&angle_to, next_2d, &elem->p0);
1961 1710
1962 evas_vec4_plain_by_points(&normal_a, &elem->p0, &elem->p1, &elem->p2); 1711 evas_vec3_plain_by_points(&normal_a, &elem->p0, &elem->p1, &elem->p2);
1963 evas_vec4_plain_by_points(&normal_b, &elem->p0, &elem->p1, next_2d); 1712 evas_vec3_plain_by_points(&normal_b, &elem->p0, &elem->p1, next_2d);
1964 if ((normal_a.x * normal_b.x <= 0) && (normal_a.y * normal_b.y <= 0) && (normal_a.z * normal_b.z <= 0)) 1713 if ((normal_a.x * normal_b.x <= 0) && (normal_a.y * normal_b.y <= 0) && (normal_a.z * normal_b.z <= 0))
1965 { 1714 {
1966 new_cos = evas_vec3_dot_product(&angle_from, &angle_to) / 1715 new_cos = evas_vec3_dot_product(&angle_from, &angle_to) /
@@ -1983,7 +1732,7 @@ evas_convex_hull_get(float *data, int count, int stride, Eina_Inarray *vertex,
1983 else 1732 else
1984 best = eina_array_data_get(&arr_candidates, 0); 1733 best = eina_array_data_get(&arr_candidates, 0);
1985 1734
1986 evas_vec4_plain_by_points(&normal_b, &elem->p0, &elem->p1, best); 1735 evas_vec3_plain_by_points(&normal_b, &elem->p0, &elem->p1, best);
1987 1736
1988 if_two = 0; 1737 if_two = 0;
1989 first_exist_twice = 0; 1738 first_exist_twice = 0;
@@ -2172,7 +1921,7 @@ evas_tangent_space_get(float *data, float *tex_data, float *normal_data, unsigne
2172 Evas_Triangle3 triangle; 1921 Evas_Triangle3 triangle;
2173 Evas_Vec2 tex1, tex2, tex3; 1922 Evas_Vec2 tex1, tex2, tex3;
2174 Evas_Vec3 big_tangent, little_tangent, normal; 1923 Evas_Vec3 big_tangent, little_tangent, normal;
2175 Evas_Vec4 *plain = NULL; 1924 Eina_Quaternion *plain = NULL;
2176 int i, j, k, l, m, found_index = 0; 1925 int i, j, k, l, m, found_index = 0;
2177 int indexes[3]; 1926 int indexes[3];
2178 1927
@@ -2241,9 +1990,9 @@ evas_tangent_space_get(float *data, float *tex_data, float *normal_data, unsigne
2241 evas_vec3_set(&triangle.p2, data[indexes[2] * stride], data[indexes[2] * stride + 1], data[indexes[2] * stride + 2]); 1990 evas_vec3_set(&triangle.p2, data[indexes[2] * stride], data[indexes[2] * stride + 1], data[indexes[2] * stride + 2]);
2242 if (plain) 1991 if (plain)
2243 free(plain); 1992 free(plain);
2244 plain = malloc(sizeof(Evas_Vec4)); 1993 plain = malloc(sizeof(Eina_Quaternion));
2245 1994
2246 evas_vec4_plain_by_points(plain, &triangle.p0, &triangle.p1, &triangle.p2); 1995 evas_vec3_plain_by_points(plain, &triangle.p0, &triangle.p1, &triangle.p2);
2247 tex1.x = tex_data[indexes[0] * tex_stride]; 1996 tex1.x = tex_data[indexes[0] * tex_stride];
2248 tex1.y = tex_data[indexes[0] * tex_stride + 1]; 1997 tex1.y = tex_data[indexes[0] * tex_stride + 1];
2249 tex2.x = tex_data[indexes[1] * tex_stride]; 1998 tex2.x = tex_data[indexes[1] * tex_stride];