summaryrefslogtreecommitdiff
path: root/src/bin/image_map_3d_flow.c
blob: 2f373f4942e68403616e125025138919fb7936e9 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
#undef FNAME
#undef NAME
#undef ICON

/* metadata */
#define FNAME image_map_3d_flow_start
#define NAME "Image Map 3D Flow"
#define ICON "3d.png"

#ifndef PROTO
# ifndef UI
#  include "main.h"

/* standard var */
static int done = 0;

#define CNUM 48

/* private data */
static Evas_Object *o_images[CNUM];
static Evas_Object *o_reflec[CNUM];

/* setup */
static void _setup(void)
{
   int i;
   Evas_Object *o;
   for (i = 0; i < CNUM; i++)
     {
        char buf[256];

        o = eo_add(EVAS_IMAGE_CLASS, evas);
        o_images[i] = o;
        snprintf(buf, sizeof(buf), "cube%i.png", (i % 6) + 1);
        eo_do(o,
              evas_obj_image_file_set(build_path(buf), NULL),
              evas_obj_image_fill_set(0, 0, 256, 256),
              evas_obj_size_set(256, 256),
              evas_obj_image_smooth_scale_set(0),
              evas_obj_visibility_set(EINA_TRUE));

        o = eo_add(EVAS_IMAGE_CLASS, evas);
        o_reflec[i] = o;
        snprintf(buf, sizeof(buf), "cube%i.png", (i % 6) + 1);
        eo_do(o,
              evas_obj_image_file_set(build_path(buf), NULL),
              evas_obj_image_fill_set(0, 0, 256, 256),
              evas_obj_size_set(256, 256),
              evas_obj_image_smooth_scale_set(0),
              evas_obj_visibility_set(EINA_TRUE));
     }
   done = 0;
}

/* cleanup */
static void _cleanup(void)
{
   int i;
   for (i = 0; i < CNUM; i++)
     {
        eo_del(o_images[i]);
        eo_del(o_reflec[i]);
     }
}

/* loop - do things */
static void _loop(double t, int f)
{
   int i;
   static Evas_Map *m = NULL;
   Evas_Coord x, y, xx, yy, w, h, c, z;
   int center = 150;
   double ang, n;
   
   if (!m) m = evas_map_new(4);
   evas_map_smooth_set(m, 0);
   
   for (i = 0; i < CNUM; i++)
     {
        x = (win_w / 2);
        y = (win_h / 2);
        w = 256;
        h = 256;
        
        c = (i - (CNUM / 2)) * (w / 4);
        c += (f % (6 * (w / 4)));
        
        ang = (double)c / (double)center;
        if (ang > 0.0) ang = ang * ang;
        else           ang = -ang * ang;
        ang *= -90.0;
        if (ang > 90.0) ang = 90.0;
        else if (ang < -90.0) ang = -90.0;

        if ((c > (-center)) && (c <= (center)))
          {
             n = (double)c / (double)center;
             if (c > 0)
               {
                  n = 1.0 - n;
                  n = 1.0 - (n * n);
               }
             else
               {
                  n = -(-1.0 - n);
                  n = -(1.0 - (n * n));
               }
             c = n * center * 2.0;
          }
        else if (c <= (-center))
          c = (c + center) - (center * 2);
        else if (c > (center))
          c = (c - center) + (center * 2);

        z = 0;
        if ((c > (-center)) && (c <= (center)))
          {
             z = (c * (w / 2)) / center;
             if (z < 0) z = -z;
             z = (w / 2) - z;
          }

        x += c;

        x -= (w / 2);
        xx = x + w;

        y -= (h / 2);
        yy = y + h;

        if (c <= 0)
          {
             eo_do(o_images[i], evas_obj_raise());
             eo_do(o_reflec[i], evas_obj_raise());
          }
        else
          {
             eo_do(o_images[i], evas_obj_lower());
             eo_do(o_reflec[i], evas_obj_lower());
          }

        evas_map_point_coord_set   (m, 0, x, y, -z);
        evas_map_point_image_uv_set(m, 0, 0, 0);
        evas_map_point_color_set   (m, 0, 255, 255, 255, 255);

        evas_map_point_coord_set   (m, 1, xx, y, -z);
        evas_map_point_image_uv_set(m, 1, 256, 0);
        evas_map_point_color_set   (m, 1, 255, 255, 255, 255);

        evas_map_point_coord_set   (m, 2, xx, yy, -z);
        evas_map_point_image_uv_set(m, 2, 256, 256);
        evas_map_point_color_set   (m, 2, 255, 255, 255, 255);

        evas_map_point_coord_set   (m, 3, x, yy, -z);
        evas_map_point_image_uv_set(m, 3, 0, 256);
        evas_map_point_color_set   (m, 3, 255, 255, 255, 255);

        evas_map_util_3d_rotate(m, 0, ang, 0,
                                x + (w / 2), y + (h / 2), 0);
        evas_map_util_3d_perspective(m, (win_w / 2), (win_h / 2), -256, 512);

        eo_do(o_images[i],
              evas_obj_map_enable_set(1),
              evas_obj_map_set(m));

        evas_map_point_coord_set   (m, 0, x, yy, -z);
        evas_map_point_image_uv_set(m, 0, 0, 256);
        evas_map_point_color_set   (m, 0, 128, 128, 128, 128);

        evas_map_point_coord_set   (m, 1, xx, yy, -z);
        evas_map_point_image_uv_set(m, 1, 256, 256);
        evas_map_point_color_set   (m, 1, 128, 128, 128, 128);

        evas_map_point_coord_set   (m, 2, xx, yy + h, -z);
        evas_map_point_image_uv_set(m, 2, 256, 0);
        evas_map_point_color_set   (m, 2, 0, 0, 0, 0);

        evas_map_point_coord_set   (m, 3, x, yy + h, -z);
        evas_map_point_image_uv_set(m, 3, 0, 0);
        evas_map_point_color_set   (m, 3, 0, 0, 0, 0);

        evas_map_util_3d_rotate(m, 0, ang, 0,
                                x + (w / 2), y + (h / 2), 0);
        evas_map_util_3d_perspective(m, (win_w / 2), (win_h / 2), -256, 512);

        eo_do(o_reflec[i],
              evas_obj_map_enable_set(1),
              evas_obj_map_set(m));
     }

   FPS_STD(NAME);
}

/* prepend special key handlers if interactive (before STD) */
static void _key(char *key)
{
   KEY_STD;
}












/* template stuff - ignore */
# endif
#endif

#ifdef UI
_ui_menu_item_add(ICON, NAME, FNAME);
#endif

#ifdef PROTO
void FNAME(void);
#endif

#ifndef PROTO
# ifndef UI
void FNAME(void)
{
   _setup();
   ui_func_set(_key, _loop);
}
# endif
#endif
#undef FNAME
#undef NAME
#undef ICON