aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorDavid Walter Seikel2014-05-02 09:12:57 +1000
committerDavid Walter Seikel2014-05-02 09:12:57 +1000
commitf59af398b6c49126b440a4f1879a36bed5ef3c64 (patch)
treef1167dd17d9b7b950f47d0cd87ab910125f84151
parentWhitespace++ (diff)
downloadSledjHamr-f59af398b6c49126b440a4f1879a36bed5ef3c64.zip
SledjHamr-f59af398b6c49126b440a4f1879a36bed5ef3c64.tar.gz
SledjHamr-f59af398b6c49126b440a4f1879a36bed5ef3c64.tar.bz2
SledjHamr-f59af398b6c49126b440a4f1879a36bed5ef3c64.tar.xz
Copy the Evas_3D demo stuff to extantz.
-rw-r--r--src/extantz/Evas_3D_demo.c722
-rwxr-xr-xsrc/extantz/build.lua3
-rw-r--r--src/extantz/extantz.c15
-rw-r--r--src/extantz/extantz.h7
4 files changed, 731 insertions, 16 deletions
diff --git a/src/extantz/Evas_3D_demo.c b/src/extantz/Evas_3D_demo.c
new file mode 100644
index 0000000..b5b4614
--- /dev/null
+++ b/src/extantz/Evas_3D_demo.c
@@ -0,0 +1,722 @@
1#include "extantz.h"
2
3
4typedef struct _Scene_Data
5{
6 Evas_Object *image; // Our Elm image.
7 Evas_3D_Scene *scene;
8 Evas_3D_Node *root_node;
9 Evas_3D_Node *camera_node;
10 Evas_3D_Node *light_node;
11
12 Evas_3D_Camera *camera;
13 Evas_3D_Light *light;
14
15 Evas_3D_Mesh *mesh;
16 Evas_3D_Node *mesh_node;
17 Evas_3D_Material *material0;
18 Evas_3D_Material *material1;
19 Evas_3D_Texture *texture0;
20 Evas_3D_Texture *texture1;
21 Evas_3D_Texture *texture_normal;
22
23 Evas_3D_Mesh *mesh2;
24 Evas_3D_Node *mesh2_node;
25 Evas_3D_Material *material2;
26 Evas_3D_Texture *texture2;
27
28 Evas_3D_Mesh *mesh3;
29 Evas_3D_Node *mesh3_node;
30 Evas_3D_Material *material3;
31 Evas_3D_Texture *texture_diffuse;
32
33} Scene_Data;
34
35static Scene_Data ourScene;
36
37
38static const float cube_vertices[] =
39{
40 /* Front */
41 -1.0, 1.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0, 1.0, 0.0, 1.0,
42 1.0, 1.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0, 1.0, 1.0, 1.0,
43 -1.0, -1.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0,
44 1.0, -1.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0,
45
46 /* Back */
47 1.0, 1.0, -1.0, 0.0, 0.0, -1.0, 0.0, 0.0, 1.0, 1.0, 0.0, 1.0,
48 -1.0, 1.0, -1.0, 0.0, 0.0, -1.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0,
49 1.0, -1.0, -1.0, 0.0, 0.0, -1.0, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0,
50 -1.0, -1.0, -1.0, 0.0, 0.0, -1.0, 0.0, 0.0, 1.0, 1.0, 1.0, 0.0,
51
52 /* Left */
53 -1.0, 1.0, -1.0, -1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0,
54 -1.0, 1.0, 1.0, -1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 1.0, 1.0, 1.0,
55 -1.0, -1.0, -1.0, -1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 1.0, 0.0, 0.0,
56 -1.0, -1.0, 1.0, -1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 1.0, 1.0, 0.0,
57
58 /* Right */
59 1.0, 1.0, 1.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0, 1.0, 0.0, 1.0,
60 1.0, 1.0, -1.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0, 1.0, 1.0, 1.0,
61 1.0, -1.0, 1.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0, 1.0, 0.0, 0.0,
62 1.0, -1.0, -1.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0, 1.0, 1.0, 0.0,
63
64 /* Top */
65 -1.0, 1.0, -1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 1.0, 0.0, 1.0,
66 1.0, 1.0, -1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 1.0, 1.0, 1.0,
67 -1.0, 1.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 1.0, 0.0, 0.0,
68 1.0, 1.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 1.0, 1.0, 0.0,
69
70 /* Bottom */
71 1.0, -1.0, -1.0, 0.0, -1.0, 0.0, 0.0, 1.0, 1.0, 1.0, 0.0, 1.0,
72 -1.0, -1.0, -1.0, 0.0, -1.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0, 1.0,
73 1.0, -1.0, 1.0, 0.0, -1.0, 0.0, 0.0, 1.0, 1.0, 1.0, 0.0, 0.0,
74 -1.0, -1.0, 1.0, 0.0, -1.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0, 0.0,
75};
76
77static const unsigned short cube_indices[] =
78{
79 /* Front */
80 0, 1, 2, 2, 1, 3,
81
82 /* Back */
83 4, 5, 6, 6, 5, 7,
84
85 /* Left */
86 8, 9, 10, 10, 9, 11,
87
88 /* Right */
89 12, 13, 14, 14, 13, 15,
90
91 /* Top */
92 16, 17, 18, 18, 17, 19,
93
94 /* Bottom */
95 20, 21, 22, 22, 21, 23
96};
97
98static const unsigned int pixels0[] =
99{
100 0xff0000ff, 0xff0000ff, 0xffff0000, 0xffff0000,
101 0xff0000ff, 0xff0000ff, 0xffff0000, 0xffff0000,
102 0xff00ff00, 0xff00ff00, 0xff000000, 0xff000000,
103 0xff00ff00, 0xff00ff00, 0xff000000, 0xff000000,
104};
105
106static const unsigned int pixels1[] =
107{
108 0xffff0000, 0xffff0000, 0xff00ff00, 0xff00ff00,
109 0xffff0000, 0xffff0000, 0xff00ff00, 0xff00ff00,
110 0xff0000ff, 0xff0000ff, 0xffffffff, 0xffffffff,
111 0xff0000ff, 0xff0000ff, 0xffffffff, 0xffffffff,
112};
113
114
115typedef struct _vec4
116{
117 float x;
118 float y;
119 float z;
120 float w;
121} vec4;
122
123typedef struct _vec3
124{
125 float x;
126 float y;
127 float z;
128} vec3;
129
130typedef struct _vec2
131{
132 float x;
133 float y;
134} vec2;
135
136typedef struct _vertex
137{
138 vec3 position;
139 vec3 normal;
140 vec3 tangent;
141 vec4 color;
142 vec3 texcoord;
143} vertex;
144
145static int vertex_count = 0;
146static vertex *sphere_vertices = NULL;
147
148static int index_count = 0;
149static unsigned short *sphere_indices = NULL;
150
151static inline vec3
152_normalize(const vec3 *v)
153{
154 double l = sqrt(v->x * v->x + v->y * v->y + v->z * v->z);
155 vec3 vec;
156
157 vec.x = v->x / l;
158 vec.y = v->y / l;
159 vec.z = v->z / l;
160
161 return vec;
162}
163
164static void
165_sphere_fini()
166{
167 if (sphere_vertices)
168 free(sphere_vertices);
169
170 if (sphere_indices)
171 free(sphere_indices);
172}
173
174static void
175_sphere_init(int precision)
176{
177 int i, j;
178 unsigned short *index;
179
180 vertex_count = (precision + 1) * (precision + 1);
181 index_count = precision * precision * 6;
182
183 /* Allocate buffer. */
184 sphere_vertices = malloc(sizeof(vertex) * vertex_count);
185 sphere_indices = malloc(sizeof(unsigned short) * index_count);
186
187 for (i = 0; i <= precision; i++)
188 {
189 double lati = (M_PI * (double)i) / (double)precision;
190 double y = cos(lati);
191 double r = fabs(sin(lati));
192
193 for (j = 0; j <= precision; j++)
194 {
195 double longi = (M_PI * 2.0 * j) / precision;
196 vertex *v = &sphere_vertices[i * (precision + 1) + j];
197
198 if (j == 0 || j == precision)
199 v->position.x = 0.0;
200 else
201 v->position.x = r * sin(longi);
202
203 v->position.y = y;
204
205 if (j == 0 || j == precision)
206 v->position.z = r;
207 else
208 v->position.z = r * cos(longi);
209
210 v->normal = v->position;
211
212 if (v->position.x > 0.0)
213 {
214 v->tangent.x = -v->normal.y;
215 v->tangent.y = v->normal.x;
216 v->tangent.z = v->normal.z;
217 }
218 else
219 {
220 v->tangent.x = v->normal.y;
221 v->tangent.y = -v->normal.x;
222 v->tangent.z = v->normal.z;
223 }
224
225 v->color.x = v->position.x;
226 v->color.y = v->position.y;
227 v->color.z = v->position.z;
228 v->color.w = 1.0;
229
230 if (j == precision)
231 v->texcoord.x = 1.0;
232 else if (j == 0)
233 v->texcoord.x = 0.0;
234 else
235 v->texcoord.x = (double)j / (double)precision;
236
237 if (i == precision)
238 v->texcoord.y = 1.0;
239 else if (i == 0)
240 v->texcoord.y = 0.0;
241 else
242 v->texcoord.y = 1.0 - (double)i / (double)precision;
243 }
244 }
245
246 index = &sphere_indices[0];
247
248 for (i = 0; i < precision; i++)
249 {
250 for (j = 0; j < precision; j++)
251 {
252 *index++ = i * (precision + 1) + j;
253 *index++ = i * (precision + 1) + j + 1;
254 *index++ = (i + 1) * (precision + 1) + j;
255
256 *index++ = (i + 1) * (precision + 1) + j;
257 *index++ = i * (precision + 1) + j + 1;
258 *index++ = (i + 1) * (precision + 1) + j + 1;
259 }
260 }
261
262 for (i = 0; i < index_count; i += 3)
263 {
264 vertex *v0 = &sphere_vertices[sphere_indices[i + 0]];
265 vertex *v1 = &sphere_vertices[sphere_indices[i + 1]];
266 vertex *v2 = &sphere_vertices[sphere_indices[i + 2]];
267
268 vec3 e1, e2;
269 float du1, du2, dv1, dv2, f;
270 vec3 tangent;
271
272 e1.x = v1->position.x - v0->position.x;
273 e1.y = v1->position.y - v0->position.y;
274 e1.z = v1->position.z - v0->position.z;
275
276 e2.x = v2->position.x - v0->position.x;
277 e2.y = v2->position.y - v0->position.y;
278 e2.z = v2->position.z - v0->position.z;
279
280 du1 = v1->texcoord.x - v0->texcoord.x;
281 dv1 = v1->texcoord.y - v0->texcoord.y;
282
283 du2 = v2->texcoord.x - v0->texcoord.x;
284 dv2 = v2->texcoord.y - v0->texcoord.y;
285
286 f = 1.0 / (du1 * dv2 - du2 * dv1);
287
288 tangent.x = f * (dv2 * e1.x - dv1 * e2.x);
289 tangent.y = f * (dv2 * e1.y - dv1 * e2.y);
290 tangent.z = f * (dv2 * e1.z - dv1 * e2.z);
291
292 v0->tangent = tangent;
293 }
294
295 for (i = 0; i <= precision; i++)
296 {
297 for (j = 0; j <= precision; j++)
298 {
299 if (j == precision)
300 {
301 vertex *v = &sphere_vertices[i * (precision + 1) + j];
302 v->tangent = sphere_vertices[i * (precision + 1)].tangent;
303 }
304 }
305 }
306}
307
308
309static Eina_Bool
310_animate_scene(void *data)
311{
312 static float angle = 0.0f;
313 static float earthAngle = 0.0f;
314 static int frame = 0;
315 static int inc = 1;
316 static int sonicFrame = 0;
317
318 Scene_Data *scene = (Scene_Data *)data;
319
320 // Animate cube.
321 angle += 0.5;
322 if (angle > 360.0) angle -= 360.0f;
323
324 frame += inc;
325 if (frame >= 20) inc = -1;
326 else if (frame <= 0) inc = 1;
327
328 eo_do(scene->mesh_node,
329 evas_3d_node_orientation_angle_axis_set(angle, 1.0, 1.0, 1.0),
330 evas_3d_node_mesh_frame_set(scene->mesh, frame)
331 );
332
333 // Animate sonic.
334 sonicFrame += 32;
335 if (sonicFrame > 256 * 50) sonicFrame = 0;
336 eo_do(scene->mesh2_node,
337 evas_3d_node_mesh_frame_set(scene->mesh2, sonicFrame)
338 );
339
340 // Animate earth.
341 earthAngle += 0.3;
342 if (earthAngle > 360.0) earthAngle -= 360.0f;
343 eo_do(scene->mesh3_node,
344 evas_3d_node_orientation_angle_axis_set(angle, 0.0, 1.0, 0.0)
345 );
346
347 return EINA_TRUE;
348}
349
350
351static void
352_camera_setup(globals *ourGlobals, Scene_Data *scene)
353{
354 scene->camera = eo_add(EVAS_3D_CAMERA_CLASS, ourGlobals->evas);
355 eo_do(scene->camera,
356 evas_3d_camera_projection_perspective_set(60.0, 1.0, 1.0, 500.0)
357 );
358
359 scene->camera_node = evas_3d_node_add(ourGlobals->evas, EVAS_3D_NODE_TYPE_CAMERA);
360 eo_do(scene->camera_node,
361 evas_3d_node_camera_set(scene->camera)
362 );
363 eo_do(scene->root_node, evas_3d_node_member_add(scene->camera_node));
364 eo_do(scene->camera_node,
365 evas_3d_node_position_set(50.0, 0.0, 20.0),
366 evas_3d_node_look_at_set(EVAS_3D_SPACE_PARENT, 0.0, 0.0, 20.0, EVAS_3D_SPACE_PARENT, 0.0, 0.0, 1.0)
367 );
368}
369
370static void
371_light_setup(globals *ourGlobals, Scene_Data *scene)
372{
373 scene->light = eo_add(EVAS_3D_LIGHT_CLASS, ourGlobals->evas);
374 eo_do(scene->light,
375 evas_3d_light_ambient_set(1.0, 1.0, 1.0, 1.0),
376 evas_3d_light_diffuse_set(1.0, 1.0, 1.0, 1.0),
377 evas_3d_light_specular_set(1.0, 1.0, 1.0, 1.0),
378 evas_3d_light_directional_set(EINA_TRUE)
379 );
380
381 scene->light_node = evas_3d_node_add(ourGlobals->evas, EVAS_3D_NODE_TYPE_LIGHT);
382 eo_do(scene->light_node,
383 evas_3d_node_light_set(scene->light)
384 );
385 eo_do(scene->root_node,
386 evas_3d_node_member_add(scene->light_node)
387 );
388 eo_do(scene->light_node,
389 evas_3d_node_position_set(1000.0, 0.0, 1000.0),
390 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)
391 );
392}
393
394static void _cube_setup(globals *ourGlobals, Scene_Data *scene)
395{
396 // Setup cube materials.
397 scene->material0 = eo_add(EVAS_3D_MATERIAL_CLASS, ourGlobals->evas);
398 scene->material1 = eo_add(EVAS_3D_MATERIAL_CLASS, ourGlobals->evas);
399
400 eo_do(scene->material0,
401 evas_3d_material_enable_set(EVAS_3D_MATERIAL_AMBIENT, EINA_TRUE),
402 evas_3d_material_enable_set(EVAS_3D_MATERIAL_DIFFUSE, EINA_TRUE),
403 evas_3d_material_enable_set(EVAS_3D_MATERIAL_SPECULAR, EINA_TRUE),
404 evas_3d_material_enable_set(EVAS_3D_MATERIAL_NORMAL, EINA_TRUE),
405
406 evas_3d_material_color_set(EVAS_3D_MATERIAL_AMBIENT, 0.2, 0.2, 0.2, 1.0),
407 evas_3d_material_color_set(EVAS_3D_MATERIAL_DIFFUSE, 0.8, 0.8, 0.8, 1.0),
408 evas_3d_material_color_set(EVAS_3D_MATERIAL_SPECULAR, 1.0, 1.0, 1.0, 1.0),
409 evas_3d_material_shininess_set(100.0)
410 );
411
412 eo_do(scene->material1,
413 evas_3d_material_enable_set(EVAS_3D_MATERIAL_AMBIENT, EINA_TRUE),
414 evas_3d_material_enable_set(EVAS_3D_MATERIAL_DIFFUSE, EINA_TRUE),
415 evas_3d_material_enable_set(EVAS_3D_MATERIAL_SPECULAR, EINA_TRUE),
416 evas_3d_material_enable_set(EVAS_3D_MATERIAL_NORMAL, EINA_TRUE),
417
418 evas_3d_material_color_set(EVAS_3D_MATERIAL_AMBIENT, 0.2, 0.2, 0.2, 1.0),
419 evas_3d_material_color_set(EVAS_3D_MATERIAL_DIFFUSE, 0.8, 0.8, 0.8, 1.0),
420 evas_3d_material_color_set(EVAS_3D_MATERIAL_SPECULAR, 1.0, 1.0, 1.0, 1.0),
421 evas_3d_material_shininess_set(100.0)
422 );
423
424 scene->texture0 = eo_add(EVAS_3D_TEXTURE_CLASS, ourGlobals->evas);
425 scene->texture1 = eo_add(EVAS_3D_TEXTURE_CLASS, ourGlobals->evas);
426 scene->texture_normal = eo_add(EVAS_3D_TEXTURE_CLASS, ourGlobals->evas);
427
428 eo_do(scene->texture0,
429 evas_3d_texture_data_set(EVAS_3D_COLOR_FORMAT_RGBA, EVAS_3D_PIXEL_FORMAT_8888, 4, 4, &pixels0[0])
430 );
431 eo_do(scene->texture1,
432 evas_3d_texture_data_set(EVAS_3D_COLOR_FORMAT_RGBA, EVAS_3D_PIXEL_FORMAT_8888, 4, 4, &pixels1[0])
433 );
434 eo_do(scene->texture_normal, evas_3d_texture_file_set("media/normal_lego.png", NULL));
435
436 eo_do(scene->material0, evas_3d_material_texture_set(EVAS_3D_MATERIAL_DIFFUSE, scene->texture0));
437 eo_do(scene->material1, evas_3d_material_texture_set(EVAS_3D_MATERIAL_DIFFUSE, scene->texture1));
438 eo_do(scene->material1, evas_3d_material_texture_set(EVAS_3D_MATERIAL_NORMAL, scene->texture_normal));
439
440 // Setup CUBE mesh.
441 scene->mesh = eo_add(EVAS_3D_MESH_CLASS, ourGlobals->evas);
442 eo_do(scene->mesh,
443 evas_3d_mesh_vertex_count_set(24),
444 evas_3d_mesh_frame_add(0),
445
446 evas_3d_mesh_frame_vertex_data_set(0, EVAS_3D_VERTEX_POSITION, 12 * sizeof(float), &cube_vertices[ 0]),
447 evas_3d_mesh_frame_vertex_data_set(0, EVAS_3D_VERTEX_NORMAL, 12 * sizeof(float), &cube_vertices[ 3]),
448 evas_3d_mesh_frame_vertex_data_set(0, EVAS_3D_VERTEX_COLOR, 12 * sizeof(float), &cube_vertices[ 6]),
449 evas_3d_mesh_frame_vertex_data_set(0, EVAS_3D_VERTEX_TEXCOORD, 12 * sizeof(float), &cube_vertices[10]),
450
451 evas_3d_mesh_index_data_set(EVAS_3D_INDEX_FORMAT_UNSIGNED_SHORT, 36, &cube_indices[0]),
452 evas_3d_mesh_vertex_assembly_set(EVAS_3D_VERTEX_ASSEMBLY_TRIANGLES),
453
454 evas_3d_mesh_shade_mode_set(EVAS_3D_SHADE_MODE_NORMAL_MAP),
455
456 evas_3d_mesh_frame_material_set(0, scene->material0),
457
458 evas_3d_mesh_frame_add(20),
459 evas_3d_mesh_frame_material_set(20, scene->material1)
460 );
461 scene->mesh_node = evas_3d_node_add(ourGlobals->evas, EVAS_3D_NODE_TYPE_MESH);
462 eo_do(scene->root_node, evas_3d_node_member_add(scene->mesh_node));
463 eo_do(scene->mesh_node,
464 eo_key_data_set("Name", "cube", NULL),
465 evas_3d_node_position_set(40.0, 3.5, 23.0),
466 evas_3d_node_mesh_add(scene->mesh)
467 );
468}
469
470static void _sonic_setup(globals *ourGlobals, Scene_Data *scene)
471{
472 // Setup an MD2 mesh.
473 scene->mesh2 = eo_add(EVAS_3D_MESH_CLASS, ourGlobals->evas);
474 eo_do(scene->mesh2,
475 evas_3d_mesh_file_set(EVAS_3D_MESH_FILE_TYPE_MD2, "media/sonic.md2", NULL)
476 );
477
478 scene->material2 = eo_add(EVAS_3D_MATERIAL_CLASS, ourGlobals->evas);
479 eo_do(scene->mesh2,
480 evas_3d_mesh_frame_material_set(0, scene->material2)
481 );
482
483 scene->texture2 = eo_add(EVAS_3D_TEXTURE_CLASS, ourGlobals->evas);
484 eo_do(scene->texture2,
485 evas_3d_texture_file_set("media/sonic.png", NULL),
486 evas_3d_texture_filter_set(EVAS_3D_TEXTURE_FILTER_NEAREST, EVAS_3D_TEXTURE_FILTER_NEAREST),
487 evas_3d_texture_wrap_set(EVAS_3D_WRAP_MODE_REPEAT, EVAS_3D_WRAP_MODE_REPEAT)
488 );
489
490 eo_do(scene->material2,
491 evas_3d_material_texture_set(EVAS_3D_MATERIAL_DIFFUSE, scene->texture2),
492
493 evas_3d_material_enable_set(EVAS_3D_MATERIAL_AMBIENT, EINA_TRUE),
494 evas_3d_material_enable_set(EVAS_3D_MATERIAL_DIFFUSE, EINA_TRUE),
495 evas_3d_material_enable_set(EVAS_3D_MATERIAL_SPECULAR, EINA_TRUE),
496 evas_3d_material_enable_set(EVAS_3D_MATERIAL_NORMAL, EINA_TRUE),
497
498 evas_3d_material_color_set(EVAS_3D_MATERIAL_AMBIENT, 0.01, 0.01, 0.01, 1.0),
499 evas_3d_material_color_set(EVAS_3D_MATERIAL_DIFFUSE, 1.0, 1.0, 1.0, 1.0),
500 evas_3d_material_color_set(EVAS_3D_MATERIAL_SPECULAR, 1.0, 1.0, 1.0, 1.0),
501 evas_3d_material_shininess_set(50.0)
502 );
503
504 scene->mesh2_node = evas_3d_node_add(ourGlobals->evas, EVAS_3D_NODE_TYPE_MESH);
505 eo_do(scene->root_node,
506 evas_3d_node_member_add(scene->mesh2_node)
507 );
508 eo_do(scene->mesh2_node,
509 eo_key_data_set("Name", "sonic", NULL),
510 evas_3d_node_mesh_add(scene->mesh2)
511 );
512
513 eo_do(scene->mesh2,
514 evas_3d_mesh_shade_mode_set(EVAS_3D_SHADE_MODE_PHONG)
515 );
516}
517
518static void _earth_setup(globals *ourGlobals, Scene_Data *scene)
519{
520 // Setup earth material.
521 scene->material3 = eo_add(EVAS_3D_MATERIAL_CLASS, ourGlobals->evas);
522
523 scene->texture_diffuse = eo_add(EVAS_3D_TEXTURE_CLASS, ourGlobals->evas);
524 eo_do(scene->texture_diffuse,
525 evas_3d_texture_file_set("media/EarthDiffuse.png", NULL),
526 evas_3d_texture_filter_set(EVAS_3D_TEXTURE_FILTER_LINEAR, EVAS_3D_TEXTURE_FILTER_LINEAR));
527 eo_do(scene->material3,
528 evas_3d_material_texture_set(EVAS_3D_MATERIAL_DIFFUSE, scene->texture_diffuse),
529
530 evas_3d_material_enable_set(EVAS_3D_MATERIAL_AMBIENT, EINA_TRUE),
531 evas_3d_material_enable_set(EVAS_3D_MATERIAL_DIFFUSE, EINA_TRUE),
532 evas_3d_material_enable_set(EVAS_3D_MATERIAL_SPECULAR, EINA_TRUE),
533
534 evas_3d_material_color_set(EVAS_3D_MATERIAL_AMBIENT, 0.01, 0.01, 0.01, 1.0),
535 evas_3d_material_color_set(EVAS_3D_MATERIAL_DIFFUSE, 1.0, 1.0, 1.0, 1.0),
536 evas_3d_material_color_set(EVAS_3D_MATERIAL_SPECULAR, 1.0, 1.0, 1.0, 1.0),
537 evas_3d_material_shininess_set(50.0));
538
539 // Setup earth mesh.
540 _sphere_init(100);
541
542 scene->mesh3 = eo_add(EVAS_3D_MESH_CLASS, ourGlobals->evas);
543 eo_do(scene->mesh3,
544 evas_3d_mesh_vertex_count_set(vertex_count),
545 evas_3d_mesh_frame_add(0),
546 evas_3d_mesh_frame_vertex_data_set(0, EVAS_3D_VERTEX_POSITION, sizeof(vertex), &sphere_vertices[0].position),
547 evas_3d_mesh_frame_vertex_data_set(0, EVAS_3D_VERTEX_NORMAL, sizeof(vertex), &sphere_vertices[0].normal),
548 evas_3d_mesh_frame_vertex_data_set(0, EVAS_3D_VERTEX_TANGENT, sizeof(vertex), &sphere_vertices[0].tangent),
549 evas_3d_mesh_frame_vertex_data_set(0, EVAS_3D_VERTEX_COLOR, sizeof(vertex), &sphere_vertices[0].color),
550 evas_3d_mesh_frame_vertex_data_set(0, EVAS_3D_VERTEX_TEXCOORD, sizeof(vertex), &sphere_vertices[0].texcoord),
551
552 evas_3d_mesh_index_data_set(EVAS_3D_INDEX_FORMAT_UNSIGNED_SHORT, index_count, &sphere_indices[0]),
553 evas_3d_mesh_vertex_assembly_set(EVAS_3D_VERTEX_ASSEMBLY_TRIANGLES),
554 evas_3d_mesh_frame_material_set(0, scene->material3)
555 );
556
557 scene->mesh3_node = evas_3d_node_add(ourGlobals->evas, EVAS_3D_NODE_TYPE_MESH);
558 eo_do(scene->root_node,
559 evas_3d_node_member_add(scene->mesh3_node)
560 );
561 eo_do(scene->mesh3_node,
562 eo_key_data_set("Name", "earth", NULL),
563 evas_3d_node_position_set(40.0, -3.5, 23.0),
564 evas_3d_node_mesh_add(scene->mesh3)
565 );
566
567 eo_do(scene->mesh3,
568 evas_3d_mesh_shade_mode_set(EVAS_3D_SHADE_MODE_DIFFUSE)
569 );
570}
571
572
573static void
574_scene_setup(globals *ourGlobals, Scene_Data *scene)
575{
576 scene->scene = eo_add(EVAS_3D_SCENE_CLASS, ourGlobals->evas);
577 eo_do(scene->scene,
578 evas_3d_scene_size_set(512, 512),
579 evas_3d_scene_background_color_set(0.0, 0.0, 0.0, 0.0)
580 );
581
582 // TODO - I have no idea how this should work.
583 // It seems the people that wrote the examples don't know either. lol
584// scene->root_node = eo_add(EVAS_3D_NODE_CLASS, ourGlobals->evas, EVAS_3D_NODE_TYPE_NODE);
585 scene->root_node = evas_3d_node_add(ourGlobals->evas, EVAS_3D_NODE_TYPE_NODE);
586
587 _camera_setup(ourGlobals, scene);
588 _light_setup(ourGlobals, scene);
589 _cube_setup(ourGlobals, scene);
590 _sonic_setup(ourGlobals, scene);
591 _earth_setup(ourGlobals, scene);
592
593 eo_do(scene->scene,
594 evas_3d_scene_root_node_set(scene->root_node),
595 evas_3d_scene_camera_node_set(scene->camera_node)
596 );
597}
598
599
600
601static void _on_mouse_move(void *data, Evas *e EINA_UNUSED, Evas_Object *o, void *einfo)
602{
603 Scene_Data *scene = data;
604 Evas_Event_Mouse_Move *ev = einfo;
605 Evas_Coord x, y, w, h;
606 Evas_Coord obj_x, obj_y;
607 int scene_w, scene_h;
608 Evas_Real scene_x, scene_y;
609 Evas_Real s, t;
610 Evas_3D_Node *n;
611 Evas_3D_Mesh *m;
612 Eina_Bool pick;
613 char *name = NULL;
614
615 evas_object_geometry_get(o, &x, &y, &w, &h);
616
617 obj_x = ev->cur.canvas.x - x;
618 obj_y = ev->cur.canvas.y - y;
619
620 eo_do(scene->scene, evas_3d_scene_size_get(&scene_w, &scene_h));
621
622 scene_x = obj_x * scene_w / (Evas_Real)w;
623 scene_y = obj_y * scene_h / (Evas_Real)h;
624
625 eo_do(scene->scene, pick = evas_3d_scene_pick(scene_x, scene_y, &n, &m, &s, &t));
626 if (pick)
627 name = evas_object_data_get(n, "Name");
628 // This is a raw Evas callback, on the Elm image internal Evas_Object.
629 // So we need to get the Elm Image back from the raw Evas_Object.
630 // Which is why we stuffed it in the scene structure.
631 if (name)
632 {
633 elm_object_tooltip_text_set(scene->image, name);
634 elm_object_tooltip_show(scene->image);
635 }
636 else
637 elm_object_tooltip_hide(scene->image);
638}
639
640static void _on_mouse_down(void *data, Evas *e EINA_UNUSED, Evas_Object *o, void *einfo)
641{
642 Scene_Data *scene = data;
643 Evas_Event_Mouse_Down *ev = einfo;
644 Evas_Coord x, y, w, h;
645 Evas_Coord obj_x, obj_y;
646 int scene_w, scene_h;
647 Evas_Real scene_x, scene_y;
648 Evas_Real s, t;
649 Evas_3D_Node *n;
650 Evas_3D_Mesh *m;
651 Eina_Bool pick;
652 char *name;
653
654 evas_object_geometry_get(o, &x, &y, &w, &h);
655
656 obj_x = ev->canvas.x - x;
657 obj_y = ev->canvas.y - y;
658
659 eo_do(scene->scene, evas_3d_scene_size_get(&scene_w, &scene_h));
660
661 scene_x = obj_x * scene_w / (Evas_Real)w;
662 scene_y = obj_y * scene_h / (Evas_Real)h;
663
664 eo_do(scene->scene, pick = evas_3d_scene_pick(scene_x, scene_y, &n, &m, &s, &t));
665 if (pick)
666 {
667 name = evas_object_data_get(n, "Name");
668 printf("Picked : ");
669 }
670 else
671 printf("Not picked : ");
672 if (NULL == name)
673 name = "";
674
675 printf("output(%d, %d) canvas(%d, %d) object(%d, %d) scene(%f, %f) texcoord(%f, %f) "
676 "node(%p) %s mesh(%p)\n",
677 ev->output.x, ev->output.y,
678 ev->canvas.x, ev->canvas.y,
679 obj_x, obj_y,
680 scene_x, scene_y,
681 s, t, n, name, m);
682}
683
684void Evas_3D_Demo_add(globals *ourGlobals)
685{
686 Evas_Object *obj, *temp;
687
688 _scene_setup(ourGlobals, &ourScene);
689
690 // Add a background image object.
691 obj = eo_add(ELM_OBJ_IMAGE_CLASS, ourGlobals->win);
692 eo_do(obj,
693 evas_obj_size_hint_weight_set(EVAS_HINT_EXPAND, EVAS_HINT_EXPAND),
694 elm_obj_image_fill_outside_set(EINA_TRUE),
695 elm_obj_image_file_set("media/sky_01.jpg", NULL),
696 evas_obj_visibility_set(EINA_TRUE)
697 );
698 elm_win_resize_object_add(ourGlobals->win, obj);
699 eo_unref(obj);
700
701 // Add an image object for 3D scene rendering.
702 obj = eo_add(ELM_OBJ_IMAGE_CLASS, ourGlobals->win);
703 ourScene.image = obj;
704 eo_do(obj,
705 evas_obj_size_hint_weight_set(EVAS_HINT_EXPAND, EVAS_HINT_EXPAND),
706 elm_obj_image_fill_outside_set(EINA_TRUE),
707 evas_obj_visibility_set(EINA_TRUE),
708 temp = elm_obj_image_object_get()
709 );
710 eo_do(temp,
711 evas_obj_image_scene_set(ourScene.scene)
712 );
713 elm_object_tooltip_text_set(obj, "");
714 elm_object_tooltip_hide(obj);
715 // Elm can't seem to be able to tell us WHERE an image was clicked, so use raw Evas calbacks instead.
716 evas_object_event_callback_add(temp, EVAS_CALLBACK_MOUSE_MOVE, _on_mouse_move, &ourScene);
717 evas_object_event_callback_add(temp, EVAS_CALLBACK_MOUSE_DOWN, _on_mouse_down, &ourScene);
718 elm_win_resize_object_add(ourGlobals->win, obj);
719
720 // Add animation timer callback.
721 ecore_timer_add(0.016, _animate_scene, &ourScene);
722}
diff --git a/src/extantz/build.lua b/src/extantz/build.lua
index 0bb2a0b..51551e9 100755
--- a/src/extantz/build.lua
+++ b/src/extantz/build.lua
@@ -23,4 +23,5 @@ runCommand('edje_cc', dir, 'edje_cc ' .. EDJE_FLAGS .. ' extantz.edc ../../medi
23runCommand('Irrlicht files', dir, 'g++ ' .. CFLAGS .. ' -O3 -ffast-math -c crappisspuke.cpp -o crappisspuke.o ' .. LDFLAGS) 23runCommand('Irrlicht files', dir, 'g++ ' .. CFLAGS .. ' -O3 -ffast-math -c crappisspuke.cpp -o crappisspuke.o ' .. LDFLAGS)
24runCommand(nil, dir, 'g++ ' .. CFLAGS .. ' -O3 -ffast-math -c CDemo.cpp -o CDemo.o ' .. LDFLAGS) 24runCommand(nil, dir, 'g++ ' .. CFLAGS .. ' -O3 -ffast-math -c CDemo.cpp -o CDemo.o ' .. LDFLAGS)
25runCommand('extantz', dir, 'g++ ' .. CFLAGS .. ' -O3 -ffast-math -c extantzCamera.cpp -o extantzCamera.o ' .. LDFLAGS) 25runCommand('extantz', dir, 'g++ ' .. CFLAGS .. ' -O3 -ffast-math -c extantzCamera.cpp -o extantzCamera.o ' .. LDFLAGS)
26runCommand(nil, dir, 'gcc ' .. CFLAGS .. ' extantz.c crappisspuke.o CDemo.o extantzCamera.o -o ../../extantz ' .. LDFLAGS .. ' ' .. libs) 26runCommand(nil, dir, 'gcc ' .. CFLAGS .. ' -c Evas_3D_demo.c -o Evas_3D_demo.o ' .. LDFLAGS)
27runCommand(nil, dir, 'gcc ' .. CFLAGS .. ' extantz.c crappisspuke.o CDemo.o extantzCamera.o Evas_3D_demo.o -o ../../extantz ' .. LDFLAGS .. ' ' .. libs)
diff --git a/src/extantz/extantz.c b/src/extantz/extantz.c
index 1176bb9..7eec6dd 100644
--- a/src/extantz/extantz.c
+++ b/src/extantz/extantz.c
@@ -902,7 +902,7 @@ static void init_evas_gl(GLData *gld)
902 evas_object_show(gld->r1); 902 evas_object_show(gld->r1);
903 elm_box_pack_end(gld->bx, gld->r1); 903 elm_box_pack_end(gld->bx, gld->r1);
904 904
905 evas_object_event_callback_add(gld->r1, EVAS_CALLBACK_MOUSE_DOWN, _cb_mouse_down_GL, gld); 905// evas_object_event_callback_add(gld->r1, EVAS_CALLBACK_MOUSE_DOWN, _cb_mouse_down_GL, gld);
906// evas_object_event_callback_add(gld->r1, EVAS_CALLBACK_KEY_DOWN, _on_camera_input_down, gld); 906// evas_object_event_callback_add(gld->r1, EVAS_CALLBACK_KEY_DOWN, _on_camera_input_down, gld);
907// evas_object_event_callback_add(gld->r1, EVAS_CALLBACK_KEY_UP, _on_camera_input_up, gld); 907// evas_object_event_callback_add(gld->r1, EVAS_CALLBACK_KEY_UP, _on_camera_input_up, gld);
908#endif 908#endif
@@ -1423,6 +1423,7 @@ EAPI_MAIN int elm_main(int argc, char **argv)
1423 elm_config_preferred_engine_set("opengl_x11"); 1423 elm_config_preferred_engine_set("opengl_x11");
1424 gld->win = elm_win_add(NULL, "extantz", ELM_WIN_BASIC); 1424 gld->win = elm_win_add(NULL, "extantz", ELM_WIN_BASIC);
1425 gld->win = elm_win_util_standard_add("extantz", "extantz virtual world viewer"); 1425 gld->win = elm_win_util_standard_add("extantz", "extantz virtual world viewer");
1426 ourGlobals.win = gld->win;
1426 1427
1427 // Set preferred engine back to default from config 1428 // Set preferred engine back to default from config
1428 elm_config_preferred_engine_set(NULL); 1429 elm_config_preferred_engine_set(NULL);
@@ -1456,17 +1457,7 @@ EAPI_MAIN int elm_main(int argc, char **argv)
1456 elm_win_resize_object_add(gld->win, obj); 1457 elm_win_resize_object_add(gld->win, obj);
1457 eo_unref(obj); 1458 eo_unref(obj);
1458 1459
1459 // Note, we don't need an Elm_bg, the entire thing gets covered with the GL rendering surface anyway. 1460 Evas_3D_Demo_add(&ourGlobals);
1460#if 0
1461 bg = elm_bg_add(gld->win);
1462 elm_bg_load_size_set(bg, gld->win_w, gld->win_h);
1463 elm_bg_option_set(bg, ELM_BG_OPTION_CENTER);
1464 snprintf(buf, sizeof(buf), "%s/sky_03.jpg", elm_app_data_dir_get());
1465 elm_bg_file_set(bg, buf, NULL);
1466 evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1467 elm_win_resize_object_add(gld->win, bg);
1468 evas_object_show(bg);
1469#endif
1470 1461
1471 gld->bx = elm_box_add(gld->win); 1462 gld->bx = elm_box_add(gld->win);
1472 evas_object_size_hint_weight_set(gld->bx, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); 1463 evas_object_size_hint_weight_set(gld->bx, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
diff --git a/src/extantz/extantz.h b/src/extantz/extantz.h
index 9a27481..ba30405 100644
--- a/src/extantz/extantz.h
+++ b/src/extantz/extantz.h
@@ -1,9 +1,9 @@
1#define USE_EO 0 1#define USE_EO 0
2#define USE_PHYSICS 1 2#define USE_PHYSICS 0
3#define USE_EGL 1 // If using Evas_GL, though it might be via Elm. 3#define USE_EGL 1 // If using Evas_GL, though it might be via Elm.
4#define USE_ELM_GL 1 4#define USE_ELM_GL 1
5#define USE_IRR 1 5#define USE_IRR 0
6#define USE_DEMO 1 6#define USE_DEMO 0
7#define DO_GEARS 0 7#define DO_GEARS 0
8 8
9 9
@@ -205,6 +205,7 @@ EAPI int startIrr(GLData *gld);
205EAPI void drawIrr_start(GLData *gld); 205EAPI void drawIrr_start(GLData *gld);
206EAPI void drawIrr_end(GLData *gld); 206EAPI void drawIrr_end(GLData *gld);
207EAPI void finishIrr(GLData *gld); 207EAPI void finishIrr(GLData *gld);
208EAPI void Evas_3D_Demo_add(globals *ourGlobals);
208 209
209#ifdef __cplusplus 210#ifdef __cplusplus
210} 211}