summaryrefslogtreecommitdiff
path: root/src/examples
diff options
context:
space:
mode:
authorBogdan Devichev <b.devichev@samsung.com>2015-03-03 10:58:58 +0900
committerChunEon Park <chuneon.park@samsung.com>2015-03-03 10:58:59 +0900
commit6353e17f0bdf709db8e637735d0d26634b9e33e3 (patch)
tree811d0bb32bbb17712632e1b4356422dee491c372 /src/examples
parentbe862c1d7f19049445f0d0a3aca94c649088c6da (diff)
evas-3d: deleted some unneccesary resources and moon-space example
Summary: This example is deprecated. We have another (pick) to show functionality of it. Test Plan: Need merged D2044 to run pick example. Reviewers: cedric, raster, Hermet Subscribers: cedric Differential Revision: https://phab.enlightenment.org/D2074
Diffstat (limited to 'src/examples')
-rw-r--r--src/examples/evas/.gitignore1
-rw-r--r--src/examples/evas/Makefile.am8
-rw-r--r--src/examples/evas/evas-3d-moon-space.c774
-rw-r--r--src/examples/evas/evas-3d-pick.c2
-rw-r--r--src/examples/evas/resources/images/EarthDiffuse.pngbin124978 -> 0 bytes
-rw-r--r--src/examples/evas/resources/images/bg_space.jpgbin24430 -> 0 bytes
-rw-r--r--src/examples/evas/resources/images/moon.pngbin82520 -> 0 bytes
7 files changed, 1 insertions, 784 deletions
diff --git a/src/examples/evas/.gitignore b/src/examples/evas/.gitignore
index b6b4af5..05fc412 100644
--- a/src/examples/evas/.gitignore
+++ b/src/examples/evas/.gitignore
@@ -26,7 +26,6 @@
26/evas_cxx_rectangle 26/evas_cxx_rectangle
27/evas_3d_aabb 27/evas_3d_aabb
28/evas_3d_frustum 28/evas_3d_frustum
29/evas_3d_moon_space
30/evas_3d_obj 29/evas_3d_obj
31/evas_3d_ply 30/evas_3d_ply
32/evas_3d_cube_rotate 31/evas_3d_cube_rotate
diff --git a/src/examples/evas/Makefile.am b/src/examples/evas/Makefile.am
index fee3fac..ddf4b47 100644
--- a/src/examples/evas/Makefile.am
+++ b/src/examples/evas/Makefile.am
@@ -232,11 +232,6 @@ evas_3d_frustum_SOURCES = evas-3d-frustum.c
232evas_3d_frustum_LDADD = $(ECORE_EVAS_COMMON_LDADD) @EFL_PTHREAD_LIBS@ 232evas_3d_frustum_LDADD = $(ECORE_EVAS_COMMON_LDADD) @EFL_PTHREAD_LIBS@
233evas_3d_frustum_CPPFLAGS = $(ECORE_EVAS_COMMON_CPPFLAGS) 233evas_3d_frustum_CPPFLAGS = $(ECORE_EVAS_COMMON_CPPFLAGS)
234 234
235EXTRA_PROGRAMS += evas_3d_moon_space
236evas_3d_moon_space_SOURCES = evas-3d-moon-space.c
237evas_3d_moon_space_LDADD = $(ECORE_EVAS_COMMON_LDADD) @EFL_PTHREAD_LIBS@
238evas_3d_moon_space_CPPFLAGS = $(ECORE_EVAS_COMMON_CPPFLAGS)
239
240EXTRA_PROGRAMS += evas_3d_aabb 235EXTRA_PROGRAMS += evas_3d_aabb
241evas_3d_aabb_SOURCES = evas-3d-aabb.c 236evas_3d_aabb_SOURCES = evas-3d-aabb.c
242evas_3d_aabb_LDADD = $(ECORE_EVAS_COMMON_LDADD) @EFL_PTHREAD_LIBS@ 237evas_3d_aabb_LDADD = $(ECORE_EVAS_COMMON_LDADD) @EFL_PTHREAD_LIBS@
@@ -336,12 +331,9 @@ resources/images/enlightenment.png \
336resources/images/red.png \ 331resources/images/red.png \
337resources/images/im1.png \ 332resources/images/im1.png \
338resources/images/cube1.png \ 333resources/images/cube1.png \
339resources/images/bg_space.jpg \
340resources/images/eagle.png \ 334resources/images/eagle.png \
341resources/images/EarthDiffuse.png \
342resources/images/M15.png \ 335resources/images/M15.png \
343resources/images/M15_1.png \ 336resources/images/M15_1.png \
344resources/images/moon.png \
345resources/images/normal_lego.png \ 337resources/images/normal_lego.png \
346resources/images/sonic.png \ 338resources/images/sonic.png \
347resources/images/sweet_home_reversed.png \ 339resources/images/sweet_home_reversed.png \
diff --git a/src/examples/evas/evas-3d-moon-space.c b/src/examples/evas/evas-3d-moon-space.c
deleted file mode 100644
index 0a77a17..0000000
--- a/src/examples/evas/evas-3d-moon-space.c
+++ /dev/null
@@ -1,774 +0,0 @@
1/**
2 * This example illustrates the work of different callbacks of events from mouse
3 * and keyboard.
4 *
5 * Next tests are available:
6 * 1. All animations of scene will stop on mouse click on the background.
7 * 2. Clicking of any object on scene causes stop of its movement, but if click on
8 * the moon while it is in front of a planet will stop them both.
9 * 3. Camera position can be changed by pressing 'down' or 'up' key. Position of
10 * the camera changes in the respective direction.
11 * 4. The 'n' key pressing returns camera to its default position.
12 * 5. One of four types of vertex assembly of planet could be chosen by clicking on
13 * a number from 1 to 4 on keyboard.
14 *
15 * @verbatim
16 * gcc -o evas-3d-moon-space evas-3d-moon-space.c -g `pkg-config --libs --cflags evas ecore ecore-evas eo` -lm
17 * @endverbatim
18 */
19
20#ifdef HAVE_CONFIG_H
21#include "config.h"
22#else
23#define PACKAGE_EXAMPLES_DIR "."
24#define EFL_EO_API_SUPPORT
25#define EFL_BETA_API_SUPPORT
26#endif
27
28#include <Ecore_Evas.h>
29#include <Ecore.h>
30#include <Evas.h>
31#include <stdio.h>
32#include <math.h>
33#include <Eo.h>
34#include "evas-common.h"
35
36#define WIDTH 1024
37#define HEIGHT 1024
38
39static const char *bg_image = PACKAGE_EXAMPLES_DIR EVAS_IMAGE_FOLDER "/bg_space.jpg";
40static const char *moon_image = PACKAGE_EXAMPLES_DIR EVAS_IMAGE_FOLDER "/moon.png";
41static const char *earth_image = PACKAGE_EXAMPLES_DIR EVAS_IMAGE_FOLDER "/EarthDiffuse.png";
42
43typedef struct _Scene_Data
44{
45 Eo *texture_diffuse_moon;
46 Eo *texture_diffuse_planet;
47 Eo *root_node;
48 Eo *camera_node;
49 Eo *light_node;
50 Eo *mesh_node_cube;
51 Eo *mesh_node_planet;
52 Eo *mesh_node_moon;
53
54 Eo *scene;
55 Eo *camera;
56 Eo *light;
57 Eo *mesh_cube;
58 Eo *mesh_planet;
59 Eo *mesh_moon;
60 Eo *material_planet;
61 Eo *material_moon;
62 Eo *material_cube;
63} Scene_Data;
64
65Evas_3D_Vertex_Assembly assembly = EVAS_3D_VERTEX_ASSEMBLY_LINES;
66Ecore_Evas *ecore_evas = NULL;
67Evas *evas = NULL;
68Eo *background = NULL;
69Eo *image = NULL;
70float d_angle_planet = 0.1;
71float d_angle_moon = 0.4;
72float d_angle_cube = 0.5;
73float camera_position = 15.0;
74int d_i = 1;
75
76static const float cube_vertices[] =
77{
78 /* Front */
79 -1.0, 1.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0, 1.0, 0.0, 1.0,
80 1.0, 1.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0, 1.0, 1.0, 1.0,
81 -1.0, -1.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0,
82 1.0, -1.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0,
83
84 /* Back */
85 1.0, 1.0, -1.0, 0.0, 0.0, -1.0, 0.0, 0.0, 1.0, 1.0, 0.0, 1.0,
86 -1.0, 1.0, -1.0, 0.0, 0.0, -1.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0,
87 1.0, -1.0, -1.0, 0.0, 0.0, -1.0, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0,
88 -1.0, -1.0, -1.0, 0.0, 0.0, -1.0, 0.0, 0.0, 1.0, 1.0, 1.0, 0.0,
89
90 /* Left */
91 -1.0, 1.0, -1.0, -1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0,
92 -1.0, 1.0, 1.0, -1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 1.0, 1.0, 1.0,
93 -1.0, -1.0, -1.0, -1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 1.0, 0.0, 0.0,
94 -1.0, -1.0, 1.0, -1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 1.0, 1.0, 0.0,
95
96 /* Right */
97 1.0, 1.0, 1.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0, 1.0, 0.0, 1.0,
98 1.0, 1.0, -1.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0, 1.0, 1.0, 1.0,
99 1.0, -1.0, 1.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0, 1.0, 0.0, 0.0,
100 1.0, -1.0, -1.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0, 1.0, 1.0, 0.0,
101
102 /* Top */
103 -1.0, 1.0, -1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 1.0, 0.0, 1.0,
104 1.0, 1.0, -1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 1.0, 1.0, 1.0,
105 -1.0, 1.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 1.0, 0.0, 0.0,
106 1.0, 1.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 1.0, 1.0, 0.0,
107
108 /* Bottom */
109 1.0, -1.0, -1.0, 0.0, -1.0, 0.0, 0.0, 1.0, 1.0, 1.0, 0.0, 1.0,
110 -1.0, -1.0, -1.0, 0.0, -1.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0, 1.0,
111 1.0, -1.0, 1.0, 0.0, -1.0, 0.0, 0.0, 1.0, 1.0, 1.0, 0.0, 0.0,
112 -1.0, -1.0, 1.0, 0.0, -1.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0, 0.0,
113};
114
115static const unsigned short cube_indices[] =
116{
117 /* Front */
118 0, 1, 2, 2, 1, 3,
119
120 /* Back */
121 4, 5, 6, 6, 5, 7,
122
123 /* Left */
124 8, 9, 10, 10, 9, 11,
125
126 /* Right */
127 12, 13, 14, 14, 13, 15,
128
129 /* Top */
130 16, 17, 18, 18, 17, 19,
131
132 /* Bottom */
133 20, 21, 22, 22, 21, 23
134};
135
136typedef struct _vec4
137{
138 float x;
139 float y;
140 float z;
141 float w;
142} vec4;
143
144typedef struct _vec3
145{
146 float x;
147 float y;
148 float z;
149} vec3;
150
151typedef struct _vec2
152{
153 float x;
154 float y;
155} vec2;
156
157typedef struct _vertex
158{
159 vec3 position;
160 vec3 normal;
161 vec3 tangent;
162 vec4 color;
163 vec3 texcoord;
164} vertex;
165
166static int vertex_count = 0;
167static vertex *vertices = NULL;
168static int index_count = 0;
169static unsigned short *indices = NULL;
170
171static inline vec3
172_normalize(const vec3 *v)
173{
174 double l;
175 vec3 vec;
176
177 l = sqrt((v->x * v->x) + (v->y * v->y) + (v->z * v->z));
178
179 if (l != 0)
180 {
181 vec.x = v->x / l;
182 vec.y = v->y / l;
183 vec.z = v->z / l;
184 }
185
186 return vec;
187}
188
189static void
190_sphere_fini()
191{
192 free(vertices);
193 free(indices);
194}
195
196static void
197_sphere_init(int precision)
198{
199 int i, j;
200 unsigned short *index;
201
202 vertex_count = (precision + 1) * (precision + 1);
203 index_count = precision * precision * 6;
204
205 /* Allocate buffer. */
206 vertices = malloc(sizeof(vertex) * vertex_count);
207 indices = malloc(sizeof(unsigned short) * index_count);
208
209 /* Calculate vertices position of the sphere mesh by using
210 splitting of sphere by latitude and longitude. */
211 for (i = 0; i <= precision; i++)
212 {
213 double lati, y, r;
214
215 lati = (M_PI * (double)i) / (double)precision;
216 y = cos(lati);
217 r = fabs(sin(lati));
218
219 for (j = 0; j <= precision; j++)
220 {
221 double longi;
222 vertex *v;
223
224 longi = (M_PI * 2.0 * j) / precision;
225 v = &vertices[(i * (precision + 1)) + j];
226
227 if ((j == 0) || (j == precision)) v->position.x = 0.0;
228 else v->position.x = r * sin(longi);
229
230 v->position.y = y;
231
232 if ((j == 0) || (j == precision)) v->position.z = r;
233 else v->position.z = r * cos(longi);
234
235 v->normal = v->position;
236
237 if (v->position.x > 0.0)
238 {
239 v->tangent.x = -v->normal.y;
240 v->tangent.y = v->normal.x;
241 v->tangent.z = v->normal.z;
242 }
243 else
244 {
245 v->tangent.x = v->normal.y;
246 v->tangent.y = -v->normal.x;
247 v->tangent.z = v->normal.z;
248 }
249
250 v->color.x = v->position.x;
251 v->color.y = v->position.y;
252 v->color.z = v->position.z;
253 v->color.w = 1.0;
254
255 if (j == precision) v->texcoord.x = 1.0;
256 else if (j == 0) v->texcoord.x = 0.0;
257 else v->texcoord.x = (double)j / (double)precision;
258
259 if (i == precision) v->texcoord.y = 1.0;
260 else if (i == 0) v->texcoord.y = 0.0;
261 else v->texcoord.y = 1.0 - ((double)i / (double)precision);
262 }
263 }
264
265 index = &indices[0];
266
267 /* Calculate and fill in the buffer of indices,
268 prepare stage for gl triangulation. */
269 for (i = 0; i < precision; i++)
270 {
271 for (j = 0; j < precision; j++)
272 {
273 *index++ = (i * (precision + 1)) + j;
274 *index++ = (i * (precision + 1)) + j + 1;
275 *index++ = ((i + 1) * (precision + 1)) + j;
276
277 *index++ = ((i + 1) * (precision + 1)) + j;
278 *index++ = (i * (precision + 1)) + j + 1;
279 *index++ = ((i + 1) * (precision + 1)) + j + 1;
280 }
281 }
282
283 /* Triangulation of sphere mesh in appliance with buffer of indices. */
284 for (i = 0; i < index_count; i += 3)
285 {
286 vec3 e1, e2;
287 float du1, du2, dv1, dv2, f;
288 vec3 tangent;
289
290 vertex *v0 = &vertices[indices[i + 0]];
291 vertex *v1 = &vertices[indices[i + 1]];
292 vertex *v2 = &vertices[indices[i + 2]];
293
294 e1.x = v1->position.x - v0->position.x;
295 e1.y = v1->position.y - v0->position.y;
296 e1.z = v1->position.z - v0->position.z;
297
298 e2.x = v2->position.x - v0->position.x;
299 e2.y = v2->position.y - v0->position.y;
300 e2.z = v2->position.z - v0->position.z;
301
302 du1 = v1->texcoord.x - v0->texcoord.x;
303 dv1 = v1->texcoord.y - v0->texcoord.y;
304
305 du2 = v2->texcoord.x - v0->texcoord.x;
306 dv2 = v2->texcoord.y - v0->texcoord.y;
307
308 f = 1.0 / ((du1 * dv2) - (du2 * dv1));
309
310 tangent.x = f * ((dv2 * e1.x) - (dv1 * e2.x));
311 tangent.y = f * ((dv2 * e1.y) - (dv1 * e2.y));
312 tangent.z = f * ((dv2 * e1.z) - (dv1 * e2.z));
313
314 v0->tangent = tangent;
315 }
316
317 /* Coupling between vertices by calculation of tangent parametr correct value. */
318 for (i = 0; i <= precision; i++)
319 {
320 for (j = 0; j <= precision; j++)
321 {
322 if (j == precision)
323 {
324 vertex *v;
325 v = &vertices[(i * (precision + 1)) + j];
326 v->tangent = vertices[i * (precision + 1)].tangent;
327 }
328 }
329 }
330}
331
332static void
333_on_delete(Ecore_Evas *ee EINA_UNUSED)
334{
335 ecore_main_loop_quit();
336}
337
338static void
339_on_canvas_resize(Ecore_Evas *ee)
340{
341 int w, h;
342
343 ecore_evas_geometry_get(ee, NULL, NULL, &w, &h);
344
345 evas_object_resize(background, w, h);
346 evas_object_resize(image, w, h);
347}
348
349static void
350_key_down(void *data EINA_UNUSED,
351 Evas *e EINA_UNUSED,
352 Evas_Object *eo EINA_UNUSED,
353 void *event_info)
354{
355 Evas_Event_Key_Down *ev = event_info;
356 if (!strcmp(ev->key, "Up"))
357 {
358 if (camera_position < 99.0)
359 camera_position += 0.5;
360 }
361 else if (!strcmp(ev->key, "Down"))
362 {
363 if (camera_position > 5.0)
364 camera_position -= 0.5;
365 }
366 else if (!strcmp(ev->key, "n"))
367 camera_position = 15.0;
368 else if (!strcmp(ev->key, "1"))
369 {
370 assembly = EVAS_3D_VERTEX_ASSEMBLY_LINES;
371 printf("Vertex assembly = EVAS_3D_VERTEX_ASSEMBLY_LINES\n");
372 }
373 else if (!strcmp(ev->key, "2"))
374 {
375 assembly = EVAS_3D_VERTEX_ASSEMBLY_LINE_STRIP;
376 printf("Vertex assembly = EVAS_3D_VERTEX_ASSEMBLY_LINE_STRIP\n");
377 }
378 else if (!strcmp(ev->key, "3"))
379 {
380 assembly = EVAS_3D_VERTEX_ASSEMBLY_TRIANGLES;
381 printf("Vertex assembly = EVAS_3D_VERTEX_ASSEMBLY_TRIANGLES\n");
382 }
383 else if (!strcmp(ev->key, "4"))
384 {
385 assembly = EVAS_3D_VERTEX_ASSEMBLY_TRIANGLE_FAN;
386 printf("Vertex assembly = EVAS_3D_VERTEX_ASSEMBLY_TRIANGLE_FAN\n");
387 }
388}
389
390static void
391_camera_setup(Scene_Data *data)
392{
393 data->camera = eo_add(EVAS_3D_CAMERA_CLASS, evas);
394 eo_do(data->camera,
395 evas_3d_camera_projection_perspective_set(30.0, 1.0, 1.0, 100.0));
396
397 data->camera_node = eo_add(EVAS_3D_NODE_CLASS, evas,
398 evas_3d_node_constructor(EVAS_3D_NODE_TYPE_CAMERA));
399 eo_do(data->camera_node,
400 evas_3d_node_camera_set(data->camera),
401 evas_3d_node_position_set(0.0, 0.0, 15.0),
402 evas_3d_node_look_at_set(EVAS_3D_SPACE_PARENT, 0.0, 0.0, 0.0, EVAS_3D_SPACE_PARENT, 0.0, 1.0, 0.0));
403
404 eo_do(data->root_node, evas_3d_node_member_add(data->camera_node));
405}
406
407static void
408_light_setup(Scene_Data *data)
409{
410 data->light = eo_add(EVAS_3D_LIGHT_CLASS, evas);
411
412 eo_do(data->light,
413 evas_3d_light_ambient_set(0.2, 0.2, 0.2, 1.0),
414 evas_3d_light_diffuse_set(1.0, 1.0, 1.0, 1.0),
415 evas_3d_light_specular_set(1.0, 1.0, 1.0, 1.0));
416
417 data->light_node = eo_add(EVAS_3D_NODE_CLASS, evas,
418 evas_3d_node_constructor(EVAS_3D_NODE_TYPE_LIGHT));
419 eo_do(data->light_node,
420 evas_3d_node_light_set(data->light),
421 evas_3d_node_position_set(0.0, 0.0, 10.0),
422 evas_3d_node_look_at_set(EVAS_3D_SPACE_PARENT, 0.0, 0.0, 0.0, EVAS_3D_SPACE_PARENT, 0.0, 1.0, 0.0));
423 eo_do(data->root_node, evas_3d_node_member_add(data->light_node));
424}
425
426static void
427_mesh_setup(Scene_Data *data)
428{
429 _sphere_init(100);
430
431 data->mesh_planet = eo_add(EVAS_3D_MESH_CLASS, evas);
432 data->mesh_cube = eo_add(EVAS_3D_MESH_CLASS, evas);
433 data->mesh_moon = eo_add(EVAS_3D_MESH_CLASS, evas);
434
435 data->material_planet = eo_add(EVAS_3D_MATERIAL_CLASS, evas);
436 data->material_cube = eo_add(EVAS_3D_MATERIAL_CLASS, evas);
437 data->material_moon = eo_add(EVAS_3D_MATERIAL_CLASS, evas);
438
439 data->texture_diffuse_planet = eo_add(EVAS_3D_TEXTURE_CLASS, evas);
440 data->texture_diffuse_moon = eo_add(EVAS_3D_TEXTURE_CLASS, evas);
441
442 data->mesh_node_planet = eo_add(EVAS_3D_NODE_CLASS, evas,
443 evas_3d_node_constructor(EVAS_3D_NODE_TYPE_MESH));
444 data->mesh_node_cube = eo_add(EVAS_3D_NODE_CLASS, evas,
445 evas_3d_node_constructor(EVAS_3D_NODE_TYPE_MESH));
446 data->mesh_node_moon = eo_add(EVAS_3D_NODE_CLASS, evas,
447 evas_3d_node_constructor(EVAS_3D_NODE_TYPE_MESH));
448
449 /* Setup material for cube. */
450 eo_do(data->material_cube,
451 evas_3d_material_enable_set(EVAS_3D_MATERIAL_AMBIENT, EINA_TRUE),
452 evas_3d_material_enable_set(EVAS_3D_MATERIAL_DIFFUSE, EINA_TRUE),
453 evas_3d_material_enable_set(EVAS_3D_MATERIAL_SPECULAR, EINA_TRUE),
454 evas_3d_material_color_set(EVAS_3D_MATERIAL_AMBIENT, 0.2, 0.2, 0.2, 1.0),
455 evas_3d_material_color_set(EVAS_3D_MATERIAL_DIFFUSE, 0.8, 0.8, 0.8, 1.0),
456 evas_3d_material_color_set(EVAS_3D_MATERIAL_SPECULAR, 1.0, 1.0, 1.0, 1.0),
457 evas_3d_material_shininess_set(70.0));
458
459 /* Setup material and texture for planet. */
460 eo_do(data->texture_diffuse_planet,
461 evas_3d_texture_file_set(earth_image, NULL),
462 evas_3d_texture_filter_set(EVAS_3D_TEXTURE_FILTER_LINEAR, EVAS_3D_TEXTURE_FILTER_LINEAR));
463
464 eo_do(data->material_planet,
465 evas_3d_material_texture_set(EVAS_3D_MATERIAL_DIFFUSE, data->texture_diffuse_planet),
466 evas_3d_material_enable_set(EVAS_3D_MATERIAL_AMBIENT, EINA_TRUE),
467 evas_3d_material_enable_set(EVAS_3D_MATERIAL_DIFFUSE, EINA_TRUE),
468 evas_3d_material_enable_set(EVAS_3D_MATERIAL_SPECULAR, EINA_TRUE),
469 evas_3d_material_color_set(EVAS_3D_MATERIAL_AMBIENT, 0.01, 0.01, 0.01, 1.0),
470 evas_3d_material_color_set(EVAS_3D_MATERIAL_DIFFUSE, 1.0, 1.0, 1.0, 1.0),
471 evas_3d_material_color_set(EVAS_3D_MATERIAL_SPECULAR, 1.0, 1.0, 1.0, 1.0),
472 evas_3d_material_shininess_set(50.0));
473
474 /* Setup material and texture for moon. */
475 eo_do(data->texture_diffuse_moon,
476 evas_3d_texture_file_set(moon_image, NULL),
477 evas_3d_texture_filter_set(EVAS_3D_TEXTURE_FILTER_LINEAR, EVAS_3D_TEXTURE_FILTER_LINEAR));
478
479 eo_do(data->material_moon,
480 evas_3d_material_texture_set(EVAS_3D_MATERIAL_DIFFUSE, data->texture_diffuse_moon),
481 evas_3d_material_enable_set(EVAS_3D_MATERIAL_AMBIENT, EINA_TRUE),
482 evas_3d_material_enable_set(EVAS_3D_MATERIAL_DIFFUSE, EINA_TRUE),
483 evas_3d_material_enable_set(EVAS_3D_MATERIAL_SPECULAR, EINA_TRUE),
484 evas_3d_material_color_set(EVAS_3D_MATERIAL_AMBIENT, 0.01, 0.01, 0.01, 1.0),
485 evas_3d_material_color_set(EVAS_3D_MATERIAL_DIFFUSE, 1.0, 1.0, 1.0, 1.0),
486 evas_3d_material_color_set(EVAS_3D_MATERIAL_SPECULAR, 1.0, 1.0, 1.0, 1.0),
487 evas_3d_material_shininess_set(50.0));
488
489 /* Setup mesh for moon. */
490 eo_do(data->mesh_moon,
491 evas_3d_mesh_vertex_count_set(vertex_count),
492 evas_3d_mesh_frame_add(0),
493 evas_3d_mesh_frame_vertex_data_set(0, EVAS_3D_VERTEX_POSITION,
494 sizeof(vertex), &vertices[0].position),
495 evas_3d_mesh_frame_vertex_data_set(0, EVAS_3D_VERTEX_NORMAL,
496 sizeof(vertex), &vertices[0].normal),
497 evas_3d_mesh_frame_vertex_data_set(0, EVAS_3D_VERTEX_TANGENT,
498 sizeof(vertex), &vertices[0].tangent),
499 evas_3d_mesh_frame_vertex_data_set(0, EVAS_3D_VERTEX_COLOR,
500 sizeof(vertex), &vertices[0].color),
501 evas_3d_mesh_frame_vertex_data_set(0, EVAS_3D_VERTEX_TEXCOORD,
502 sizeof(vertex), &vertices[0].texcoord),
503 evas_3d_mesh_index_data_set(EVAS_3D_INDEX_FORMAT_UNSIGNED_SHORT, index_count, &indices[0]),
504 evas_3d_mesh_vertex_assembly_set(EVAS_3D_VERTEX_ASSEMBLY_TRIANGLES),
505 evas_3d_mesh_shade_mode_set(EVAS_3D_SHADE_MODE_DIFFUSE),
506 evas_3d_mesh_frame_material_set(0, data->material_moon));
507
508 eo_do(data->root_node,
509 evas_3d_node_member_add(data->mesh_node_moon));
510
511 eo_do(data->mesh_node_moon,
512 evas_3d_node_mesh_add(data->mesh_moon));
513
514 eo_do(data->mesh_node_moon, evas_3d_node_scale_set(0.2, 0.2, 0.2));
515
516 /* Setup mesh for cube. */
517 eo_do(data->mesh_cube,
518 evas_3d_mesh_vertex_count_set(24),
519 evas_3d_mesh_frame_add(0),
520 evas_3d_mesh_frame_vertex_data_set(0, EVAS_3D_VERTEX_POSITION,
521 12 * sizeof(float), &cube_vertices[ 0]),
522 evas_3d_mesh_frame_vertex_data_set(0, EVAS_3D_VERTEX_NORMAL,
523 12 * sizeof(float), &cube_vertices[ 3]),
524 evas_3d_mesh_frame_vertex_data_set(0, EVAS_3D_VERTEX_COLOR,
525 12 * sizeof(float), &cube_vertices[ 6]),
526 evas_3d_mesh_frame_vertex_data_set(0, EVAS_3D_VERTEX_TEXCOORD,
527 12 * sizeof(float), &cube_vertices[10]),
528 evas_3d_mesh_index_data_set(EVAS_3D_INDEX_FORMAT_UNSIGNED_SHORT,
529 36, &cube_indices[0]),
530 evas_3d_mesh_vertex_assembly_set(EVAS_3D_VERTEX_ASSEMBLY_TRIANGLES),
531 evas_3d_mesh_shade_mode_set(EVAS_3D_SHADE_MODE_PHONG),
532 evas_3d_mesh_frame_material_set(0, data->material_cube));
533
534 eo_do(data->root_node,
535 evas_3d_node_member_add(data->mesh_node_cube));
536
537 eo_do(data->mesh_node_cube,
538 evas_3d_node_mesh_add(data->mesh_cube));
539
540 eo_do(data->mesh_node_cube,
541 evas_3d_node_scale_set(0.55, 0.55, 0.55));
542
543 /* Setup mesh for planet. */
544 eo_do(data->mesh_planet,
545 evas_3d_mesh_vertex_count_set(vertex_count),
546 evas_3d_mesh_frame_add(0),
547 evas_3d_mesh_frame_vertex_data_set(0, EVAS_3D_VERTEX_POSITION,
548 sizeof(vertex), &vertices[0].position),
549 evas_3d_mesh_frame_vertex_data_set(0, EVAS_3D_VERTEX_NORMAL,
550 sizeof(vertex), &vertices[0].normal),
551 evas_3d_mesh_frame_vertex_data_set(0, EVAS_3D_VERTEX_TANGENT,
552 sizeof(vertex), &vertices[0].tangent),
553 evas_3d_mesh_frame_vertex_data_set(0, EVAS_3D_VERTEX_COLOR,
554 sizeof(vertex), &vertices[0].color),
555 evas_3d_mesh_frame_vertex_data_set(0, EVAS_3D_VERTEX_TEXCOORD,
556 sizeof(vertex), &vertices[0].texcoord),
557 evas_3d_mesh_index_data_set(EVAS_3D_INDEX_FORMAT_UNSIGNED_SHORT, index_count, &indices[0]),
558 evas_3d_mesh_vertex_assembly_set(EVAS_3D_VERTEX_ASSEMBLY_LINES),
559 evas_3d_mesh_shade_mode_set(EVAS_3D_SHADE_MODE_DIFFUSE),
560 evas_3d_mesh_frame_material_set(0, data->material_planet));
561
562 eo_do(data->root_node,
563 evas_3d_node_member_add(data->mesh_node_planet));
564
565 eo_do(data->mesh_node_planet,
566 evas_3d_node_mesh_add(data->mesh_planet));
567}
568
569static void
570_scene_setup(Scene_Data *data)
571{
572 data->scene = eo_add(EVAS_3D_SCENE_CLASS, evas);
573
574 /* Add the root node for the scene. */
575 data->root_node = eo_add(EVAS_3D_NODE_CLASS, evas,
576 evas_3d_node_constructor(EVAS_3D_NODE_TYPE_NODE));
577
578 eo_do(data->scene,
579 evas_3d_scene_size_set(WIDTH, HEIGHT),
580 evas_3d_scene_background_color_set(0.0, 0.0, 0.0, 0.0));
581
582 _camera_setup(data);
583 _light_setup(data);
584 _mesh_setup(data);
585
586 eo_do(data->scene,
587 evas_3d_scene_root_node_set(data->root_node),
588 evas_3d_scene_camera_node_set(data->camera_node));
589}
590
591static void
592_stop_scene(void *data,
593 Evas *e EINA_UNUSED,
594 Evas_Object *eo EINA_UNUSED,
595 void *event_info)
596{
597 Evas_Event_Mouse_Down *ev = event_info;
598 Evas_3D_Node *n;
599 Evas_3D_Mesh *m;
600 Evas_Real s, t;
601 Scene_Data *d = (Scene_Data *)data;
602 Evas_3D_Node *pick;
603 const Eina_List *nodes = NULL;
604 Eina_List *picked_nodes = NULL;
605 int root_count = 0, picked_count = 0;
606
607 eo_do(d->scene,
608 evas_3d_scene_pick(ev->canvas.x, ev->canvas.y, &n, &m, &s, &t));
609
610 if (d->mesh_cube == m)
611 d_angle_cube = 0;
612 else if (d->mesh_moon == m)
613 {
614 d_angle_moon = 0;
615 d_i = 0;
616 }
617 else if (d->mesh_planet == m)
618 d_angle_planet = 0;
619 else
620 {
621 d_angle_planet = 0;
622 d_angle_cube = 0;
623 d_angle_moon = 0;
624 d_i = 0;
625 }
626
627 eo_do(d->scene,
628 pick = evas_3d_scene_exist(ev->canvas.x, ev->canvas.y, d->mesh_node_planet));
629
630 if (pick) d_angle_planet = 0;
631
632 eo_do(d->root_node, nodes = evas_3d_node_member_list_get());
633 eo_do(d->scene, picked_nodes = evas_3d_scene_pick_member_list_get(ev->canvas.x, ev->canvas.y));
634
635 root_count = eina_list_count(nodes);
636 picked_count = eina_list_count(picked_nodes);
637
638 printf("Count of members in the root node = %d, count of the picked members = %d\n", root_count, picked_count);
639}
640
641static void
642_play_scene(void *data EINA_UNUSED,
643 Evas *e EINA_UNUSED,
644 Evas_Object *eo EINA_UNUSED,
645 void *event_info EINA_UNUSED)
646{
647 d_angle_planet = 0.1;
648 d_angle_cube = 0.5;
649 d_angle_moon = 0.4;
650 d_i = 1;
651}
652
653static Eina_Bool
654_animate_planet(void *data)
655{
656 static float angle = 0.0f;
657 Scene_Data *scene = (Scene_Data *)data;
658
659 angle += d_angle_planet;
660
661 eo_do(scene->mesh_node_planet,
662 evas_3d_node_orientation_angle_axis_set(angle, 0.0, 1.0, 0.0));
663 eo_do(scene->mesh_planet,
664 evas_3d_mesh_vertex_assembly_set(assembly));
665
666 /* Rotate */
667 if (angle > 360.0) angle -= 360.0f;
668
669 return EINA_TRUE;
670}
671
672static Eina_Bool
673_animate_moon(void *data)
674{
675 static float angle = 0.0f;
676 static float longi = 0.0f;
677 static int i = 0;
678 Scene_Data *scene = (Scene_Data *)data;
679
680 i += d_i;
681 longi = (2 * M_PI * i)/2000;
682 angle += d_angle_moon;
683
684 eo_do(scene->mesh_node_moon,
685 evas_3d_node_orientation_angle_axis_set(angle, 0.0, 1.0, 0.0),
686 evas_3d_node_position_set(2.0 * sin(longi), 0.7 * sin(longi), 2.0 * cos(longi)));
687
688 /* Rotate */
689 if (angle > 360.0) angle -= 360.0f;
690
691 return EINA_TRUE;
692}
693
694static Eina_Bool
695_animate_cube(void *data)
696{
697 static float angle = 0.0f;
698 Scene_Data *scene = (Scene_Data *)data;
699
700 angle += d_angle_cube;
701
702 eo_do(scene->mesh_node_cube,
703 evas_3d_node_orientation_angle_axis_set(angle, 1.0, 0.0, 1.0));
704
705 /* Rotate */
706 if (angle > 360.0) angle -= 360.0f;
707
708 return EINA_TRUE;
709}
710
711static Eina_Bool
712_animate_camera(void *data)
713{
714 Scene_Data *scene = (Scene_Data *)data;
715
716 eo_do(scene->camera_node,
717 evas_3d_node_position_set(0.0, 0.0, camera_position));
718
719 return EINA_TRUE;
720}
721
722int
723main(void)
724{
725 Scene_Data data;
726
727 //Unless Evas 3D supports Software renderer, we set gl backened forcely.
728 setenv("ECORE_EVAS_ENGINE", "opengl_x11", 1);
729
730 if (!ecore_evas_init()) return 0;
731
732 ecore_evas = ecore_evas_new(NULL, 10, 10, WIDTH, HEIGHT, NULL);
733
734 if (!ecore_evas) return 0;
735
736 ecore_evas_callback_delete_request_set(ecore_evas, _on_delete);
737 ecore_evas_callback_resize_set(ecore_evas, _on_canvas_resize);
738 ecore_evas_show(ecore_evas);
739
740 evas = ecore_evas_get(ecore_evas);
741
742 _scene_setup(&data);
743
744 /* Add evas objects. */
745 background = evas_object_image_filled_add(evas);
746 evas_object_image_file_set(background, bg_image, NULL),
747 evas_object_resize(background, WIDTH, HEIGHT),
748 evas_object_show(background);
749
750 image = evas_object_image_filled_add(evas);
751 evas_object_resize(image, WIDTH, HEIGHT),
752 evas_object_show(image),
753 evas_object_focus_set(image, EINA_TRUE);
754
755 eo_do(image,
756 evas_obj_image_scene_set(data.scene));
757
758 evas_object_event_callback_add(image, EVAS_CALLBACK_MOUSE_DOWN, _stop_scene, &data);
759 evas_object_event_callback_add(image, EVAS_CALLBACK_MOUSE_UP, _play_scene, &data);
760 evas_object_event_callback_add(image, EVAS_CALLBACK_KEY_DOWN, _key_down, &data);
761
762 ecore_timer_add(0.016, _animate_cube, &data);
763 ecore_timer_add(0.016, _animate_camera, &data);
764 ecore_timer_add(0.01, _animate_planet, &data);
765 ecore_timer_add(0.01, _animate_moon, &data);
766
767 ecore_main_loop_begin();
768
769 ecore_evas_free(ecore_evas);
770 ecore_evas_shutdown();
771 _sphere_fini();
772
773 return 0;
774}
diff --git a/src/examples/evas/evas-3d-pick.c b/src/examples/evas/evas-3d-pick.c
index 1e53f56..360e72c 100644
--- a/src/examples/evas/evas-3d-pick.c
+++ b/src/examples/evas/evas-3d-pick.c
@@ -28,7 +28,7 @@
28#define WIDTH 400 28#define WIDTH 400
29#define HEIGHT 400 29#define HEIGHT 400
30 30
31static const char *earth_image = PACKAGE_EXAMPLES_DIR EVAS_IMAGE_FOLDER "/EarthDiffuse.png"; 31static const char *earth_image = PACKAGE_EXAMPLES_DIR EVAS_IMAGE_FOLDER "/wood.jpg";
32 32
33typedef struct _vec4 33typedef struct _vec4
34{ 34{
diff --git a/src/examples/evas/resources/images/EarthDiffuse.png b/src/examples/evas/resources/images/EarthDiffuse.png
deleted file mode 100644
index 28bacd7..0000000
--- a/src/examples/evas/resources/images/EarthDiffuse.png
+++ /dev/null
Binary files differ
diff --git a/src/examples/evas/resources/images/bg_space.jpg b/src/examples/evas/resources/images/bg_space.jpg
deleted file mode 100644
index 5c5f41e..0000000
--- a/src/examples/evas/resources/images/bg_space.jpg
+++ /dev/null
Binary files differ
diff --git a/src/examples/evas/resources/images/moon.png b/src/examples/evas/resources/images/moon.png
deleted file mode 100644
index b4dfeb6..0000000
--- a/src/examples/evas/resources/images/moon.png
+++ /dev/null
Binary files differ