aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/libraries/elementary/src/bin/test_3d.c
diff options
context:
space:
mode:
Diffstat (limited to 'libraries/elementary/src/bin/test_3d.c')
-rw-r--r--libraries/elementary/src/bin/test_3d.c341
1 files changed, 341 insertions, 0 deletions
diff --git a/libraries/elementary/src/bin/test_3d.c b/libraries/elementary/src/bin/test_3d.c
new file mode 100644
index 0000000..6a960fb
--- /dev/null
+++ b/libraries/elementary/src/bin/test_3d.c
@@ -0,0 +1,341 @@
1#include "test.h"
2#ifdef HAVE_CONFIG_H
3# include "elementary_config.h"
4#endif
5#include <Elementary.h>
6#ifndef ELM_LIB_QUICKLAUNCH
7
8typedef struct _Point
9{
10 Evas_Coord x, y, z, u, v;
11} Point;
12
13typedef struct _Side
14{
15 Evas_Object *o;
16 Point pt[4];
17} Side;
18
19typedef struct _Cube
20{
21 Side side[6];
22} Cube;
23
24static Cube *cube;
25static double rotx = 0.0, roty = 0.0, rotz = 0.0;
26static double cxo = 0.0, cyo = 0.0, focv = 256.0, z0v = 0.0;
27#define POINT(n, p, xx, yy, zz, uu, vv) \
28 c->side[n].pt[p].x = xx; \
29 c->side[n].pt[p].y = yy; \
30 c->side[n].pt[p].z = zz; \
31 c->side[n].pt[p].u = uu; \
32 c->side[n].pt[p].v = vv
33
34static Cube *
35_cube_new(Evas *evas, Evas_Coord w, Evas_Coord h, Evas_Coord d)
36{
37 Cube *c;
38 int i;
39
40 w -= (w / 2);
41 h -= (h / 2);
42 d -= (d / 2);
43 c = calloc(1, sizeof(Cube));
44 for (i = 0; i < 6; i++)
45 {
46 Evas_Object *o;
47 char buf[PATH_MAX];
48 o = evas_object_image_add(evas);
49 c->side[i].o = o;
50 snprintf(buf, sizeof(buf), "%s/images/%s",
51 elm_app_data_dir_get(), "twofish.jpg");
52 evas_object_image_file_set(o, buf, NULL);
53 evas_object_image_fill_set(o, 0, 0, 256, 256);
54 evas_object_resize(o, 256, 256);
55 evas_object_image_smooth_scale_set(o, 0);
56 evas_object_show(o);
57 }
58 POINT(0, 0, -w, -h, -d, 0, 0);
59 POINT(0, 1, w, -h, -d, 256, 0);
60 POINT(0, 2, w, h, -d, 256, 256);
61 POINT(0, 3, -w, h, -d, 0, 256);
62
63 POINT(1, 0, w, -h, -d, 0, 0);
64 POINT(1, 1, w, -h, d, 256, 0);
65 POINT(1, 2, w, h, d, 256, 256);
66 POINT(1, 3, w, h, -d, 0, 256);
67
68 POINT(2, 0, w, -h, d, 0, 0);
69 POINT(2, 1, -w, -h, d, 256, 0);
70 POINT(2, 2, -w, h, d, 256, 256);
71 POINT(2, 3, w, h, d, 0, 256);
72
73 POINT(3, 0, -w, -h, d, 0, 0);
74 POINT(3, 1, -w, -h, -d, 256, 0);
75 POINT(3, 2, -w, h, -d, 256, 256);
76 POINT(3, 3, -w, h, d, 0, 256);
77
78 POINT(4, 0, -w, -h, d, 0, 0);
79 POINT(4, 1, w, -h, d, 256, 0);
80 POINT(4, 2, w, -h, -d, 256, 256);
81 POINT(4, 3, -w, -h, -d, 0, 256);
82
83 POINT(5, 0, -w, h, -d, 0, 0);
84 POINT(5, 1, w, h, -d, 256, 0);
85 POINT(5, 2, w, h, d, 256, 256);
86 POINT(5, 3, -w, h, d, 0, 256);
87
88 return c;
89}
90
91static void
92_cube_pos(Cube *c,
93 Evas_Coord x, Evas_Coord y, Evas_Coord z,
94 double dx, double dy, double dz,
95 Evas_Coord cx, Evas_Coord cy, Evas_Coord foc, Evas_Coord z0)
96{
97 Evas_Map *m;
98 int i, j, order[6], sorted;
99 Evas_Coord mz[6];
100
101 m = evas_map_new(4);
102 evas_map_smooth_set(m, 0);
103
104 for (i = 0; i < 6; i++)
105 {
106 Evas_Coord tz[4];
107
108 for (j = 0; j < 4; j++)
109 {
110 evas_map_point_coord_set(m, j,
111 c->side[i].pt[j].x + x,
112 c->side[i].pt[j].y + y,
113 c->side[i].pt[j].z + z);
114 evas_map_point_image_uv_set(m, j,
115 c->side[i].pt[j].u,
116 c->side[i].pt[j].v);
117 evas_map_point_color_set(m, j, 255, 255, 255, 255);
118 }
119 evas_map_util_3d_rotate(m, dx, dy, dz, x, y, z);
120 evas_map_util_3d_lighting(m, -1000, -1000, -1000,
121 255, 255, 255,
122 20, 20, 20);
123 evas_map_util_3d_perspective(m, cx, cy, foc, z0);
124 if (evas_map_util_clockwise_get(m))
125 {
126 evas_object_map_enable_set(c->side[i].o, 1);
127 evas_object_map_set(c->side[i].o, m);
128 evas_object_show(c->side[i].o);
129 }
130 else
131 evas_object_hide(c->side[i].o);
132
133 order[i] = i;
134 for (j = 0; j < 4; j++)
135 evas_map_point_coord_get(m, j, NULL, NULL, &(tz[j]));
136 mz[i] = (tz[0] + tz[1] + tz[2] + tz[3]) / 4;
137 }
138 sorted = 0;
139 do
140 {
141 sorted = 1;
142 for (i = 0; i < 5; i++)
143 {
144 if (mz[order[i]] > mz[order[i + 1]])
145 {
146 j = order[i];
147 order[i] = order[i + 1];
148 order[i + 1] = j;
149 sorted = 0;
150 }
151 }
152 }
153 while (!sorted);
154
155 evas_object_raise(c->side[order[0]].o);
156 for (i = 1; i < 6; i++)
157 evas_object_stack_below(c->side[order[i]].o, c->side[order[i - 1]].o);
158 evas_map_free(m);
159}
160
161/*
162static void
163_cube_free(Cube *c)
164{
165 int i;
166
167 for (i = 0; i < 6; i++) evas_object_del(c->side[i].o);
168 free(c);
169}
170*/
171
172static void
173_cube_update(Evas_Object *win, Cube *c)
174{
175 Evas_Coord w, h;
176
177 evas_object_geometry_get(win, NULL, NULL, &w, &h);
178 _cube_pos(c,
179 (w / 2), (h / 2), 512,
180 rotx, roty, rotz,
181 (w / 2) + cxo, (h / 2) + cyo, z0v, focv);
182}
183
184void
185_ch_rot_x(void *data, Evas_Object *obj, void *event_info __UNUSED__)
186{
187 Evas_Object *win = data;
188 rotx = elm_slider_value_get(obj);
189 _cube_update(win, cube);
190}
191
192void
193_ch_rot_y(void *data, Evas_Object *obj, void *event_info __UNUSED__)
194{
195 Evas_Object *win = data;
196 roty = elm_slider_value_get(obj);
197 _cube_update(win, cube);
198}
199
200void
201_ch_rot_z(void *data, Evas_Object *obj, void *event_info __UNUSED__)
202{
203 Evas_Object *win = data;
204 rotz = elm_slider_value_get(obj);
205 _cube_update(win, cube);
206}
207
208void
209_ch_cx(void *data, Evas_Object *obj, void *event_info __UNUSED__)
210{
211 Evas_Object *win = data;
212 cxo = elm_slider_value_get(obj);
213 _cube_update(win, cube);
214}
215
216void
217_ch_cy(void *data, Evas_Object *obj, void *event_info __UNUSED__)
218{
219 Evas_Object *win = data;
220 cyo = elm_slider_value_get(obj);
221 _cube_update(win, cube);
222}
223
224void
225_ch_foc(void *data, Evas_Object *obj, void *event_info __UNUSED__)
226{
227 Evas_Object *win = data;
228 focv = elm_slider_value_get(obj);
229 _cube_update(win, cube);
230}
231
232void
233_ch_z0(void *data, Evas_Object *obj, void *event_info __UNUSED__)
234{
235 Evas_Object *win = data;
236 z0v = elm_slider_value_get(obj);
237 _cube_update(win, cube);
238}
239
240void
241test_3d(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
242{
243 Evas_Object *win, *bx, *sl;
244
245 win = elm_win_util_standard_add("box-vert", "Box Vert");
246 elm_win_autodel_set(win, EINA_TRUE);
247
248 cube = _cube_new(evas_object_evas_get(win), 240, 240, 240);
249
250 bx = elm_box_add(win);
251 evas_object_layer_set(bx, 10);
252 evas_object_size_hint_weight_set(bx, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
253 elm_win_resize_object_add(win, bx);
254 evas_object_show(bx);
255
256 sl = elm_slider_add(win);
257 elm_object_text_set(sl, "Rot X");
258 elm_slider_unit_format_set(sl, "%1.0f units");
259 elm_slider_span_size_set(sl, 360);
260 elm_slider_min_max_set(sl, 0, 360);
261 evas_object_size_hint_align_set(sl, EVAS_HINT_FILL, 0.5);
262 evas_object_size_hint_weight_set(sl, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
263 elm_box_pack_end(bx, sl);
264 evas_object_smart_callback_add(sl, "changed", _ch_rot_x, win);
265 evas_object_show(sl);
266
267 sl = elm_slider_add(win);
268 elm_object_text_set(sl, "Rot Y");
269 elm_slider_unit_format_set(sl, "%1.0f units");
270 elm_slider_span_size_set(sl, 360);
271 elm_slider_min_max_set(sl, 0, 360);
272 evas_object_size_hint_align_set(sl, EVAS_HINT_FILL, 0.5);
273 evas_object_size_hint_weight_set(sl, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
274 elm_box_pack_end(bx, sl);
275 evas_object_smart_callback_add(sl, "changed", _ch_rot_y, win);
276 evas_object_show(sl);
277
278 sl = elm_slider_add(win);
279 elm_object_text_set(sl, "Rot Z");
280 elm_slider_unit_format_set(sl, "%1.0f units");
281 elm_slider_span_size_set(sl, 360);
282 elm_slider_min_max_set(sl, 0, 360);
283 evas_object_size_hint_align_set(sl, EVAS_HINT_FILL, 0.5);
284 evas_object_size_hint_weight_set(sl, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
285 elm_box_pack_end(bx, sl);
286 evas_object_smart_callback_add(sl, "changed", _ch_rot_z, win);
287 evas_object_show(sl);
288
289 sl = elm_slider_add(win);
290 elm_object_text_set(sl, "CX Off");
291 elm_slider_unit_format_set(sl, "%1.0f units");
292 elm_slider_span_size_set(sl, 360);
293 elm_slider_min_max_set(sl, -320, 320);
294 elm_slider_value_set(sl, cxo);
295 evas_object_size_hint_align_set(sl, EVAS_HINT_FILL, 0.5);
296 evas_object_size_hint_weight_set(sl, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
297 elm_box_pack_end(bx, sl);
298 evas_object_smart_callback_add(sl, "changed", _ch_cx, win);
299 evas_object_show(sl);
300
301 sl = elm_slider_add(win);
302 elm_object_text_set(sl, "CY Off");
303 elm_slider_unit_format_set(sl, "%1.0f units");
304 elm_slider_span_size_set(sl, 360);
305 elm_slider_min_max_set(sl, -320, 320);
306 elm_slider_value_set(sl, cyo);
307 evas_object_size_hint_align_set(sl, EVAS_HINT_FILL, 0.5);
308 evas_object_size_hint_weight_set(sl, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
309 elm_box_pack_end(bx, sl);
310 evas_object_smart_callback_add(sl, "changed", _ch_cy, win);
311 evas_object_show(sl);
312
313 sl = elm_slider_add(win);
314 elm_object_text_set(sl, "Foc");
315 elm_slider_unit_format_set(sl, "%1.0f units");
316 elm_slider_span_size_set(sl, 360);
317 elm_slider_min_max_set(sl, 1, 2000);
318 elm_slider_value_set(sl, focv);
319 evas_object_size_hint_align_set(sl, EVAS_HINT_FILL, 0.5);
320 evas_object_size_hint_weight_set(sl, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
321 elm_box_pack_end(bx, sl);
322 evas_object_smart_callback_add(sl, "changed", _ch_foc, win);
323 evas_object_show(sl);
324
325 sl = elm_slider_add(win);
326 elm_object_text_set(sl, "Z0");
327 elm_slider_unit_format_set(sl, "%1.0f units");
328 elm_slider_span_size_set(sl, 360);
329 elm_slider_min_max_set(sl, -2000, 2000);
330 elm_slider_value_set(sl, z0v);
331 evas_object_size_hint_align_set(sl, EVAS_HINT_FILL, 0.5);
332 evas_object_size_hint_weight_set(sl, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
333 elm_box_pack_end(bx, sl);
334 evas_object_smart_callback_add(sl, "changed", _ch_z0, win);
335 evas_object_show(sl);
336
337 evas_object_resize(win, 480, 480);
338 _cube_update(win, cube);
339 evas_object_show(win);
340}
341#endif