summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarsten Haitzler <raster@rasterman.com>2009-11-02 08:52:23 +0000
committerCarsten Haitzler <raster@rasterman.com>2009-11-02 08:52:23 +0000
commit2510cad2f0fa8c2e2d2578d78e99fb7748909a58 (patch)
tree33bf8d9e406c0b5bf8045d35d16ffd0789a4909c
parentc645c312d24c157b328fc6df1cb2a38d1a468b6e (diff)
some more util calls for 3d goop. not 100% sure i like it atm, but.. here goes.
SVN revision: 43411
-rw-r--r--legacy/evas/src/lib/Evas.h9
-rw-r--r--legacy/evas/src/lib/canvas/evas_map.c173
2 files changed, 175 insertions, 7 deletions
diff --git a/legacy/evas/src/lib/Evas.h b/legacy/evas/src/lib/Evas.h
index e0f737ba3f..8c682a6e1a 100644
--- a/legacy/evas/src/lib/Evas.h
+++ b/legacy/evas/src/lib/Evas.h
@@ -855,6 +855,15 @@ extern "C" {
855 855
856 EAPI void evas_map_util_rotate (Evas_Map *m, double degrees, Evas_Coord cx, Evas_Coord cy); 856 EAPI void evas_map_util_rotate (Evas_Map *m, double degrees, Evas_Coord cx, Evas_Coord cy);
857 EAPI void evas_map_util_zoom (Evas_Map *m, double zoomx, double zoomy, Evas_Coord cx, Evas_Coord cy); 857 EAPI void evas_map_util_zoom (Evas_Map *m, double zoomx, double zoomy, Evas_Coord cx, Evas_Coord cy);
858 EAPI void evas_map_util_rotate_3d (Evas_Map *m, double dx, double dy, double dz,
859 Evas_Coord cx, Evas_Coord cy, Evas_Coord cz,
860 Evas_Coord px, Evas_Coord py,
861 Evas_Coord z0, Evas_Coord foc);
862 EAPI void evas_map_util_perspective (Evas_Map *m,
863 Evas_Coord px, Evas_Coord py,
864 Evas_Coord z0, Evas_Coord foc);
865 EAPI Eina_Bool evas_map_util_clockwise_get (Evas_Map *m);
866
858 867
859 EAPI Evas_Map *evas_map_new (int count); 868 EAPI Evas_Map *evas_map_new (int count);
860 EAPI void evas_map_smooth_set (Evas_Map *m, Eina_Bool enabled); 869 EAPI void evas_map_smooth_set (Evas_Map *m, Eina_Bool enabled);
diff --git a/legacy/evas/src/lib/canvas/evas_map.c b/legacy/evas/src/lib/canvas/evas_map.c
index bc3f484d1e..fea1d20afa 100644
--- a/legacy/evas/src/lib/canvas/evas_map.c
+++ b/legacy/evas/src/lib/canvas/evas_map.c
@@ -578,7 +578,7 @@ evas_map_point_color_set(Evas_Map *m, int idx, int r, int g, int b, int a)
578EAPI void 578EAPI void
579evas_map_point_color_get(const Evas_Map *m, int idx, int *r, int *g, int *b, int *a) 579evas_map_point_color_get(const Evas_Map *m, int idx, int *r, int *g, int *b, int *a)
580{ 580{
581 Evas_Map_Point *p; 581 const Evas_Map_Point *p;
582 if (!m) return; 582 if (!m) return;
583 if (idx >= m->count) return; 583 if (idx >= m->count) return;
584 p = m->points + idx; 584 p = m->points + idx;
@@ -616,10 +616,8 @@ evas_map_util_rotate(Evas_Map *m, double degrees, Evas_Coord cx, Evas_Coord cy)
616 Evas_Map_Point *p, *p_end; 616 Evas_Map_Point *p, *p_end;
617 617
618 if (!m) return; 618 if (!m) return;
619 if (m->count != 4) return;
620
621 p = m->points; 619 p = m->points;
622 p_end = p + 4; 620 p_end = p + m->count;
623 621
624 for (; p < p_end; p++) 622 for (; p < p_end; p++)
625 { 623 {
@@ -662,10 +660,8 @@ evas_map_util_zoom(Evas_Map *m, double zoomx, double zoomy, Evas_Coord cx, Evas_
662 Evas_Map_Point *p, *p_end; 660 Evas_Map_Point *p, *p_end;
663 661
664 if (!m) return; 662 if (!m) return;
665 if (m->count != 4) return;
666
667 p = m->points; 663 p = m->points;
668 p_end = p + 4; 664 p_end = p + m->count;
669 665
670 for (; p < p_end; p++) 666 for (; p < p_end; p++)
671 { 667 {
@@ -681,3 +677,166 @@ evas_map_util_zoom(Evas_Map *m, double zoomx, double zoomy, Evas_Coord cx, Evas_
681 p->y = y + cy; 677 p->y = y + cy;
682 } 678 }
683} 679}
680
681/**
682 * XXX
683 *
684 * xxx
685 *
686 * @param m map to change.
687 * @param dx amount of degrees from 0.0 to 360.0 to rotate.
688 * @param cx rotation's center horizontal positon.
689 * @param cy rotation's center vertical positon.
690 *
691 * @see evas_map_point_coord_set()
692 * @see evas_map_util_zoom()
693 */
694EAPI void
695evas_map_util_rotate_3d(Evas_Map *m, double dx, double dy, double dz,
696 Evas_Coord cx, Evas_Coord cy, Evas_Coord cz,
697 Evas_Coord px, Evas_Coord py,
698 Evas_Coord z0, Evas_Coord foc)
699{
700 double rz = (dz * M_PI) / 180.0;
701 double rx = (dx * M_PI) / 180.0;
702 double ry = (dy * M_PI) / 180.0;
703 Evas_Map_Point *p, *p_end;
704
705 if (!m) return;
706 p = m->points;
707 p_end = p + m->count;
708
709 for (; p < p_end; p++)
710 {
711 double x, y, z, xx, yy, zz;
712
713 x = p->x - cx;
714 y = p->y - cy;
715 z = p->z - cz;
716
717 if (rz != 0.0)
718 {
719 xx = x * cos(rz);
720 yy = x * sin(rz);
721 x = xx + (y * cos(rz + M_PI_2));
722 y = yy + (y * sin(rz + M_PI_2));
723 }
724
725 if (ry != 0.0)
726 {
727 xx = x * cos(ry);
728 zz = x * sin(ry);
729 x = xx + (z * cos(ry + M_PI_2));
730 z = zz + (z * sin(ry + M_PI_2));
731 }
732
733 if (rx != 0.0)
734 {
735 zz = z * cos(rx);
736 yy = z * sin(rx);
737 z = zz + (y * cos(rx + M_PI_2));
738 y = yy + (y * sin(rx + M_PI_2));
739 }
740
741 x = x + cx;
742 y = y + cy;
743 z = z + cz;
744
745 if (foc > 0)
746 {
747 x = x - px;
748 y = y - py;
749
750 zz = ((z - z0) + foc);
751
752 if (zz > 0)
753 {
754 x = (x * foc) / zz;
755 y = (y * foc) / zz;
756 }
757
758 x = px + x;
759 y = py + y;
760 }
761
762 p->x = x;
763 p->y = y;
764 p->z = z;
765 }
766}
767
768/**
769 * XXX
770 *
771 * xxx
772 *
773 * @param m map to change.
774 */
775EAPI void
776evas_map_util_perspective(Evas_Map *m,
777 Evas_Coord px, Evas_Coord py,
778 Evas_Coord z0, Evas_Coord foc)
779{
780 Evas_Map_Point *p, *p_end;
781
782 if (!m) return;
783 p = m->points;
784 p_end = p + m->count;
785
786 for (; p < p_end; p++)
787 {
788 Evas_Coord x, y, zz;
789
790 if (foc > 0)
791 {
792 x = p->x - px;
793 y = p->y - py;
794
795 zz = ((p->z - z0) + foc);
796
797 if (zz > 0)
798 {
799 x = (x * foc) / zz;
800 y = (y * foc) / zz;
801 }
802
803 p->x = px + x;
804 p->y = py + y;
805 }
806 }
807}
808
809/**
810 * XXX
811 *
812 * xxx
813 *
814 * @param m map to query.
815 * @return 1 if clockwise, 0 otherwise
816 */
817EAPI Eina_Bool
818evas_map_util_clockwise_get(Evas_Map *m)
819{
820 int i, j, k, count;
821 long long c;
822
823 if (!m) return 0;
824 if (m->count < 3) return 0;
825
826 count = 0;
827 for (i = 0; i < m->count; i++)
828 {
829 j = (i + 1) % m->count;
830 k = (i + 2) % m->count;
831 c =
832 ((m->points[j].x - m->points[i].x) *
833 (m->points[k].y - m->points[j].y))
834 -
835 ((m->points[j].y - m->points[i].y) *
836 (m->points[k].x - m->points[j].x));
837 if (c < 0) count--;
838 else if (c > 0) count++;
839 }
840 if (count > 0) return 1;
841 return 0;
842}