containing ui setup steps in the profiling again.
[platform/upstream/expedite.git] / src / bin / image_map_3d_5.c
1 #undef FNAME
2 #undef NAME
3 #undef ICON
4
5 /* metadata */
6 #define FNAME image_map_3d_5_start
7 #define NAME "Image Map 3D 5"
8 #define ICON "3d.png"
9
10 #ifndef PROTO
11 # ifndef UI
12 #  include "main.h"
13
14 typedef struct _Point
15 {
16    Evas_Coord x, y, z, u, v;
17 } Point;
18
19 typedef struct _Side
20 {
21    Evas_Object *o;
22    Point pt[4];
23 } Side;
24
25 typedef struct _Cube
26 {
27    Side side[6];
28 } Cube;
29
30 /* standard var */
31 static int done = 0;
32
33 /* private data */
34 static Cube *cubes[1];
35
36 #define POINT(n, p, xx, yy, zz, uu, vv) \
37    c->side[n].pt[p].x = xx; \
38    c->side[n].pt[p].y = yy; \
39    c->side[n].pt[p].z = zz; \
40    c->side[n].pt[p].u = uu; \
41    c->side[n].pt[p].v = vv
42
43 static Cube *
44 _cube_new(Evas_Coord w, Evas_Coord h, Evas_Coord d)
45 {
46    Cube *c;
47    int i;
48
49    w -= (w / 2);
50    h -= (h / 2);
51    d -= (d / 2);
52    c = calloc(1, sizeof(Cube));
53    for (i = 0; i < 6; i++)
54      {
55         Evas_Object *o;
56         char buf[256];
57         o = efl_add(EFL_CANVAS_IMAGE_CLASS, evas);
58         c->side[i].o = o;
59         snprintf(buf, sizeof(buf), "im%i.png", (i % 2) + 1);
60         efl_file_simple_load(o, build_path(buf), NULL);
61         efl_gfx_fill_set(o, EINA_RECT(0, 0, 720, 420));
62         efl_gfx_entity_size_set(o, EINA_SIZE2D(720, 420));
63         efl_gfx_image_smooth_scale_set(o, 0);
64         efl_gfx_entity_visible_set(o, EINA_TRUE);
65      }
66    POINT(0, 0, -w, -h, -d,   0,   0);
67    POINT(0, 1,  w, -h, -d, 720,   0);
68    POINT(0, 2,  w,  h, -d, 720, 420);
69    POINT(0, 3, -w,  h, -d,   0, 420);
70
71    POINT(1, 0,  w, -h, -d,   0,   0);
72    POINT(1, 1,  w, -h,  d, 720,   0);
73    POINT(1, 2,  w,  h,  d, 720, 420);
74    POINT(1, 3,  w,  h, -d,   0, 420);
75
76    POINT(2, 0,  w, -h,  d,   0,   0);
77    POINT(2, 1, -w, -h,  d, 720,   0);
78    POINT(2, 2, -w,  h,  d, 720, 420);
79    POINT(2, 3,  w,  h,  d,   0, 420);
80
81    POINT(3, 0, -w, -h,  d,   0,   0);
82    POINT(3, 1, -w, -h, -d, 720,   0);
83    POINT(3, 2, -w,  h, -d, 720, 420);
84    POINT(3, 3, -w,  h,  d,   0, 420);
85
86    POINT(4, 0, -w, -h,  d,   0,   0);
87    POINT(4, 1,  w, -h,  d, 720,   0);
88    POINT(4, 2,  w, -h, -d, 720, 420);
89    POINT(4, 3, -w, -h, -d,   0, 420);
90
91    POINT(5, 0, -w,  h, -d,   0,   0);
92    POINT(5, 1,  w,  h, -d, 720,   0);
93    POINT(5, 2,  w,  h,  d, 720, 420);
94    POINT(5, 3, -w,  h,  d,   0, 420);
95
96    return c;
97 }
98
99 static void
100 _cube_pos(Cube *c,
101           Evas_Coord x, Evas_Coord y, Evas_Coord z,
102           double dx, double dy, double dz)
103 {
104    static Evas_Map *m = NULL;
105    int i, j, order[6], sorted;
106    Evas_Coord mz[6];
107
108    if (!m) m = evas_map_new(4);
109    evas_map_smooth_set(m, 0);
110
111    for (i = 0; i < 6; i++)
112      {
113         Evas_Coord tz[4];
114
115         for (j = 0; j < 4; j++)
116           {
117              evas_map_point_coord_set(m, j,
118                                       c->side[i].pt[j].x + x,
119                                       c->side[i].pt[j].y + y,
120                                       c->side[i].pt[j].z + z);
121              evas_map_point_image_uv_set(m, j,
122                                       c->side[i].pt[j].u,
123                                       c->side[i].pt[j].v);
124              evas_map_point_color_set(m, j, 255, 255, 255, 255);
125           }
126         evas_map_util_3d_rotate(m, dx, dy, dz, x, y, z);
127         evas_map_util_3d_lighting(m, -1000, win_h / 2, -1000,
128                                   255, 255, 255,
129                                   20, 20, 20);
130         evas_map_util_3d_perspective(m, (win_w / 2), (win_h / 2), -360, 720);
131         if (evas_map_util_clockwise_get(m))
132           {
133              evas_object_map_enable_set(c->side[i].o, 1);
134              evas_object_map_set(c->side[i].o, m);
135              efl_gfx_entity_visible_set(c->side[i].o, EINA_TRUE);
136           }
137         else
138           {
139              efl_gfx_entity_visible_set(c->side[i].o, EINA_FALSE);
140           }
141
142         order[i] = i;
143         for (j = 0; j < 4; j++)
144           evas_map_point_coord_get(m, j, NULL, NULL, &(tz[j]));
145         mz[i] = (tz[0] + tz[1] + tz[2] + tz[3]) / 4;
146      }
147    sorted = 0;
148    do
149      {
150         sorted = 1;
151         for (i = 0; i < 5; i++)
152           {
153              if (mz[order[i]] > mz[order[i + 1]])
154                {
155                   j = order[i];
156                   order[i] = order[i + 1];
157                   order[i + 1] = j;
158                   sorted = 0;
159                }
160           }
161      }
162    while (!sorted);
163
164    efl_gfx_stack_raise_to_top(c->side[order[0]].o);
165    for (i = 1; i < 6; i++)
166      efl_gfx_stack_below(c->side[order[i]].o, c->side[order[i - 1]].o);
167 }
168
169 static void
170 _cube_free(Cube *c)
171 {
172    int i;
173
174    for (i = 0; i < 6; i++) efl_del(c->side[i].o);
175    free(c);
176 }
177
178 /* setup */
179 static void _setup(void)
180 {
181    cubes[0] = _cube_new(720, 420, 720);
182
183    done = 0;
184 }
185
186 /* cleanup */
187 static void _cleanup(void)
188 {
189    _cube_free(cubes[0]);
190 }
191
192 /* loop - do things */
193 static void _loop(double t, int f)
194 {
195    _cube_pos(cubes[0],
196              (win_w / 2), (win_h / 2), 0,
197              0, f, 0);
198    FPS_STD(NAME);
199 }
200
201 /* prepend special key handlers if interactive (before STD) */
202 static void _key(const char *key)
203 {
204    KEY_STD;
205 }
206
207
208
209
210
211
212
213
214
215
216
217
218 /* template stuff - ignore */
219 # endif
220 #endif
221
222 #ifdef UI
223 _ui_menu_item_add(ICON, NAME, FNAME);
224 #endif
225
226 #ifdef PROTO
227 void FNAME(void);
228 #endif
229
230 #ifndef PROTO
231 # ifndef UI
232 void FNAME(void)
233 {
234    ui_func_set(_key, _loop, _setup);
235 }
236 # endif
237 #endif
238 #undef FNAME
239 #undef NAME
240 #undef ICON