aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/GuiLua/GuiLua.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/GuiLua/GuiLua.c707
1 files changed, 1 insertions, 706 deletions
diff --git a/src/GuiLua/GuiLua.c b/src/GuiLua/GuiLua.c
index 8bfe3fb..d9d2541 100644
--- a/src/GuiLua/GuiLua.c
+++ b/src/GuiLua/GuiLua.c
@@ -148,602 +148,6 @@ globals ourGlobals;
148static const char *globName = "ourGlobals"; 148static const char *globName = "ourGlobals";
149 149
150 150
151
152typedef struct _Scene_Data
153{
154 Evas_Object *image; // Our Elm image.
155 Evas_3D_Scene *scene;
156 Evas_3D_Node *root_node;
157 Evas_3D_Node *camera_node;
158 Evas_3D_Node *light_node;
159
160 Evas_3D_Camera *camera;
161 Evas_3D_Light *light;
162
163 Evas_3D_Mesh *mesh;
164 Evas_3D_Node *mesh_node;
165 Evas_3D_Material *material0;
166 Evas_3D_Material *material1;
167 Evas_3D_Texture *texture0;
168 Evas_3D_Texture *texture1;
169 Evas_3D_Texture *texture_normal;
170
171 Evas_3D_Mesh *mesh2;
172 Evas_3D_Node *mesh2_node;
173 Evas_3D_Material *material2;
174 Evas_3D_Texture *texture2;
175
176 Evas_3D_Mesh *mesh3;
177 Evas_3D_Node *mesh3_node;
178 Evas_3D_Material *material3;
179 Evas_3D_Texture *texture_diffuse;
180
181} Scene_Data;
182
183static Scene_Data ourScene;
184
185
186static const float cube_vertices[] =
187{
188 /* Front */
189 -1.0, 1.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0, 1.0, 0.0, 1.0,
190 1.0, 1.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0, 1.0, 1.0, 1.0,
191 -1.0, -1.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0,
192 1.0, -1.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0,
193
194 /* Back */
195 1.0, 1.0, -1.0, 0.0, 0.0, -1.0, 0.0, 0.0, 1.0, 1.0, 0.0, 1.0,
196 -1.0, 1.0, -1.0, 0.0, 0.0, -1.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0,
197 1.0, -1.0, -1.0, 0.0, 0.0, -1.0, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0,
198 -1.0, -1.0, -1.0, 0.0, 0.0, -1.0, 0.0, 0.0, 1.0, 1.0, 1.0, 0.0,
199
200 /* Left */
201 -1.0, 1.0, -1.0, -1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0,
202 -1.0, 1.0, 1.0, -1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 1.0, 1.0, 1.0,
203 -1.0, -1.0, -1.0, -1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 1.0, 0.0, 0.0,
204 -1.0, -1.0, 1.0, -1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 1.0, 1.0, 0.0,
205
206 /* Right */
207 1.0, 1.0, 1.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0, 1.0, 0.0, 1.0,
208 1.0, 1.0, -1.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0, 1.0, 1.0, 1.0,
209 1.0, -1.0, 1.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0, 1.0, 0.0, 0.0,
210 1.0, -1.0, -1.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0, 1.0, 1.0, 0.0,
211
212 /* Top */
213 -1.0, 1.0, -1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 1.0, 0.0, 1.0,
214 1.0, 1.0, -1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 1.0, 1.0, 1.0,
215 -1.0, 1.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 1.0, 0.0, 0.0,
216 1.0, 1.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 1.0, 1.0, 0.0,
217
218 /* Bottom */
219 1.0, -1.0, -1.0, 0.0, -1.0, 0.0, 0.0, 1.0, 1.0, 1.0, 0.0, 1.0,
220 -1.0, -1.0, -1.0, 0.0, -1.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0, 1.0,
221 1.0, -1.0, 1.0, 0.0, -1.0, 0.0, 0.0, 1.0, 1.0, 1.0, 0.0, 0.0,
222 -1.0, -1.0, 1.0, 0.0, -1.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0, 0.0,
223};
224
225static const unsigned short cube_indices[] =
226{
227 /* Front */
228 0, 1, 2, 2, 1, 3,
229
230 /* Back */
231 4, 5, 6, 6, 5, 7,
232
233 /* Left */
234 8, 9, 10, 10, 9, 11,
235
236 /* Right */
237 12, 13, 14, 14, 13, 15,
238
239 /* Top */
240 16, 17, 18, 18, 17, 19,
241
242 /* Bottom */
243 20, 21, 22, 22, 21, 23
244};
245
246static const unsigned int pixels0[] =
247{
248 0xff0000ff, 0xff0000ff, 0xffff0000, 0xffff0000,
249 0xff0000ff, 0xff0000ff, 0xffff0000, 0xffff0000,
250 0xff00ff00, 0xff00ff00, 0xff000000, 0xff000000,
251 0xff00ff00, 0xff00ff00, 0xff000000, 0xff000000,
252};
253
254static const unsigned int pixels1[] =
255{
256 0xffff0000, 0xffff0000, 0xff00ff00, 0xff00ff00,
257 0xffff0000, 0xffff0000, 0xff00ff00, 0xff00ff00,
258 0xff0000ff, 0xff0000ff, 0xffffffff, 0xffffffff,
259 0xff0000ff, 0xff0000ff, 0xffffffff, 0xffffffff,
260};
261
262
263typedef struct _vec4
264{
265 float x;
266 float y;
267 float z;
268 float w;
269} vec4;
270
271typedef struct _vec3
272{
273 float x;
274 float y;
275 float z;
276} vec3;
277
278typedef struct _vec2
279{
280 float x;
281 float y;
282} vec2;
283
284typedef struct _vertex
285{
286 vec3 position;
287 vec3 normal;
288 vec3 tangent;
289 vec4 color;
290 vec3 texcoord;
291} vertex;
292
293static int vertex_count = 0;
294static vertex *sphere_vertices = NULL;
295
296static int index_count = 0;
297static unsigned short *sphere_indices = NULL;
298
299static inline vec3
300_normalize(const vec3 *v)
301{
302 double l = sqrt(v->x * v->x + v->y * v->y + v->z * v->z);
303 vec3 vec;
304
305 vec.x = v->x / l;
306 vec.y = v->y / l;
307 vec.z = v->z / l;
308
309 return vec;
310}
311
312static void
313_sphere_fini()
314{
315 if (sphere_vertices)
316 free(sphere_vertices);
317
318 if (sphere_indices)
319 free(sphere_indices);
320}
321
322static void
323_sphere_init(int precision)
324{
325 int i, j;
326 unsigned short *index;
327
328 vertex_count = (precision + 1) * (precision + 1);
329 index_count = precision * precision * 6;
330
331 /* Allocate buffer. */
332 sphere_vertices = malloc(sizeof(vertex) * vertex_count);
333 sphere_indices = malloc(sizeof(unsigned short) * index_count);
334
335 for (i = 0; i <= precision; i++)
336 {
337 double lati = (M_PI * (double)i) / (double)precision;
338 double y = cos(lati);
339 double r = fabs(sin(lati));
340
341 for (j = 0; j <= precision; j++)
342 {
343 double longi = (M_PI * 2.0 * j) / precision;
344 vertex *v = &sphere_vertices[i * (precision + 1) + j];
345
346 if (j == 0 || j == precision)
347 v->position.x = 0.0;
348 else
349 v->position.x = r * sin(longi);
350
351 v->position.y = y;
352
353 if (j == 0 || j == precision)
354 v->position.z = r;
355 else
356 v->position.z = r * cos(longi);
357
358 v->normal = v->position;
359
360 if (v->position.x > 0.0)
361 {
362 v->tangent.x = -v->normal.y;
363 v->tangent.y = v->normal.x;
364 v->tangent.z = v->normal.z;
365 }
366 else
367 {
368 v->tangent.x = v->normal.y;
369 v->tangent.y = -v->normal.x;
370 v->tangent.z = v->normal.z;
371 }
372
373 v->color.x = v->position.x;
374 v->color.y = v->position.y;
375 v->color.z = v->position.z;
376 v->color.w = 1.0;
377
378 if (j == precision)
379 v->texcoord.x = 1.0;
380 else if (j == 0)
381 v->texcoord.x = 0.0;
382 else
383 v->texcoord.x = (double)j / (double)precision;
384
385 if (i == precision)
386 v->texcoord.y = 1.0;
387 else if (i == 0)
388 v->texcoord.y = 0.0;
389 else
390 v->texcoord.y = 1.0 - (double)i / (double)precision;
391 }
392 }
393
394 index = &sphere_indices[0];
395
396 for (i = 0; i < precision; i++)
397 {
398 for (j = 0; j < precision; j++)
399 {
400 *index++ = i * (precision + 1) + j;
401 *index++ = i * (precision + 1) + j + 1;
402 *index++ = (i + 1) * (precision + 1) + j;
403
404 *index++ = (i + 1) * (precision + 1) + j;
405 *index++ = i * (precision + 1) + j + 1;
406 *index++ = (i + 1) * (precision + 1) + j + 1;
407 }
408 }
409
410 for (i = 0; i < index_count; i += 3)
411 {
412 vertex *v0 = &sphere_vertices[sphere_indices[i + 0]];
413 vertex *v1 = &sphere_vertices[sphere_indices[i + 1]];
414 vertex *v2 = &sphere_vertices[sphere_indices[i + 2]];
415
416 vec3 e1, e2;
417 float du1, du2, dv1, dv2, f;
418 vec3 tangent;
419
420 e1.x = v1->position.x - v0->position.x;
421 e1.y = v1->position.y - v0->position.y;
422 e1.z = v1->position.z - v0->position.z;
423
424 e2.x = v2->position.x - v0->position.x;
425 e2.y = v2->position.y - v0->position.y;
426 e2.z = v2->position.z - v0->position.z;
427
428 du1 = v1->texcoord.x - v0->texcoord.x;
429 dv1 = v1->texcoord.y - v0->texcoord.y;
430
431 du2 = v2->texcoord.x - v0->texcoord.x;
432 dv2 = v2->texcoord.y - v0->texcoord.y;
433
434 f = 1.0 / (du1 * dv2 - du2 * dv1);
435
436 tangent.x = f * (dv2 * e1.x - dv1 * e2.x);
437 tangent.y = f * (dv2 * e1.y - dv1 * e2.y);
438 tangent.z = f * (dv2 * e1.z - dv1 * e2.z);
439
440 v0->tangent = tangent;
441 }
442
443 for (i = 0; i <= precision; i++)
444 {
445 for (j = 0; j <= precision; j++)
446 {
447 if (j == precision)
448 {
449 vertex *v = &sphere_vertices[i * (precision + 1) + j];
450 v->tangent = sphere_vertices[i * (precision + 1)].tangent;
451 }
452 }
453 }
454}
455
456
457static Eina_Bool
458_animate_scene(void *data)
459{
460 static float angle = 0.0f;
461 static float earthAngle = 0.0f;
462 static int frame = 0;
463 static int inc = 1;
464 static int sonicFrame = 0;
465
466 Scene_Data *scene = (Scene_Data *)data;
467
468 // Animate cube.
469 angle += 0.5;
470 if (angle > 360.0) angle -= 360.0f;
471
472 frame += inc;
473 if (frame >= 20) inc = -1;
474 else if (frame <= 0) inc = 1;
475
476 eo_do(scene->mesh_node,
477 evas_3d_node_orientation_angle_axis_set(angle, 1.0, 1.0, 1.0),
478 evas_3d_node_mesh_frame_set(scene->mesh, frame)
479 );
480
481 // Animate sonic.
482 sonicFrame += 32;
483 if (sonicFrame > 256 * 50) sonicFrame = 0;
484 eo_do(scene->mesh2_node,
485 evas_3d_node_mesh_frame_set(scene->mesh2, sonicFrame)
486 );
487
488 // Animate earth.
489 earthAngle += 0.3;
490 if (earthAngle > 360.0) earthAngle -= 360.0f;
491 eo_do(scene->mesh3_node,
492 evas_3d_node_orientation_angle_axis_set(angle, 0.0, 1.0, 0.0)
493 );
494
495 return EINA_TRUE;
496}
497
498
499static void
500_camera_setup(globals *ourGlobals, Scene_Data *scene)
501{
502 scene->camera = eo_add(EVAS_3D_CAMERA_CLASS, ourGlobals->evas);
503 eo_do(scene->camera,
504 evas_3d_camera_projection_perspective_set(60.0, 1.0, 1.0, 500.0)
505 );
506
507 scene->camera_node = evas_3d_node_add(ourGlobals->evas, EVAS_3D_NODE_TYPE_CAMERA);
508 eo_do(scene->camera_node,
509 evas_3d_node_camera_set(scene->camera)
510 );
511 eo_do(scene->root_node, evas_3d_node_member_add(scene->camera_node));
512 eo_do(scene->camera_node,
513 evas_3d_node_position_set(50.0, 0.0, 20.0),
514 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)
515 );
516}
517
518static void
519_light_setup(globals *ourGlobals, Scene_Data *scene)
520{
521 scene->light = eo_add(EVAS_3D_LIGHT_CLASS, ourGlobals->evas);
522 eo_do(scene->light,
523 evas_3d_light_ambient_set(1.0, 1.0, 1.0, 1.0),
524 evas_3d_light_diffuse_set(1.0, 1.0, 1.0, 1.0),
525 evas_3d_light_specular_set(1.0, 1.0, 1.0, 1.0),
526 evas_3d_light_directional_set(EINA_TRUE)
527 );
528
529 scene->light_node = evas_3d_node_add(ourGlobals->evas, EVAS_3D_NODE_TYPE_LIGHT);
530 eo_do(scene->light_node,
531 evas_3d_node_light_set(scene->light)
532 );
533 eo_do(scene->root_node,
534 evas_3d_node_member_add(scene->light_node)
535 );
536 eo_do(scene->light_node,
537 evas_3d_node_position_set(1000.0, 0.0, 1000.0),
538 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)
539 );
540}
541
542static void _cube_setup(globals *ourGlobals, Scene_Data *scene)
543{
544 // Setup cube materials.
545 scene->material0 = eo_add(EVAS_3D_MATERIAL_CLASS, ourGlobals->evas);
546 scene->material1 = eo_add(EVAS_3D_MATERIAL_CLASS, ourGlobals->evas);
547
548 eo_do(scene->material0,
549 evas_3d_material_enable_set(EVAS_3D_MATERIAL_AMBIENT, EINA_TRUE),
550 evas_3d_material_enable_set(EVAS_3D_MATERIAL_DIFFUSE, EINA_TRUE),
551 evas_3d_material_enable_set(EVAS_3D_MATERIAL_SPECULAR, EINA_TRUE),
552 evas_3d_material_enable_set(EVAS_3D_MATERIAL_NORMAL, EINA_TRUE),
553
554 evas_3d_material_color_set(EVAS_3D_MATERIAL_AMBIENT, 0.2, 0.2, 0.2, 1.0),
555 evas_3d_material_color_set(EVAS_3D_MATERIAL_DIFFUSE, 0.8, 0.8, 0.8, 1.0),
556 evas_3d_material_color_set(EVAS_3D_MATERIAL_SPECULAR, 1.0, 1.0, 1.0, 1.0),
557 evas_3d_material_shininess_set(100.0)
558 );
559
560 eo_do(scene->material1,
561 evas_3d_material_enable_set(EVAS_3D_MATERIAL_AMBIENT, EINA_TRUE),
562 evas_3d_material_enable_set(EVAS_3D_MATERIAL_DIFFUSE, EINA_TRUE),
563 evas_3d_material_enable_set(EVAS_3D_MATERIAL_SPECULAR, EINA_TRUE),
564 evas_3d_material_enable_set(EVAS_3D_MATERIAL_NORMAL, EINA_TRUE),
565
566 evas_3d_material_color_set(EVAS_3D_MATERIAL_AMBIENT, 0.2, 0.2, 0.2, 1.0),
567 evas_3d_material_color_set(EVAS_3D_MATERIAL_DIFFUSE, 0.8, 0.8, 0.8, 1.0),
568 evas_3d_material_color_set(EVAS_3D_MATERIAL_SPECULAR, 1.0, 1.0, 1.0, 1.0),
569 evas_3d_material_shininess_set(100.0)
570 );
571
572 scene->texture0 = eo_add(EVAS_3D_TEXTURE_CLASS, ourGlobals->evas);
573 scene->texture1 = eo_add(EVAS_3D_TEXTURE_CLASS, ourGlobals->evas);
574 scene->texture_normal = eo_add(EVAS_3D_TEXTURE_CLASS, ourGlobals->evas);
575
576 eo_do(scene->texture0,
577 evas_3d_texture_data_set(EVAS_3D_COLOR_FORMAT_RGBA, EVAS_3D_PIXEL_FORMAT_8888, 4, 4, &pixels0[0])
578 );
579 eo_do(scene->texture1,
580 evas_3d_texture_data_set(EVAS_3D_COLOR_FORMAT_RGBA, EVAS_3D_PIXEL_FORMAT_8888, 4, 4, &pixels1[0])
581 );
582 eo_do(scene->texture_normal, evas_3d_texture_file_set("../../media/normal_lego.png", NULL));
583
584 eo_do(scene->material0, evas_3d_material_texture_set(EVAS_3D_MATERIAL_DIFFUSE, scene->texture0));
585 eo_do(scene->material1, evas_3d_material_texture_set(EVAS_3D_MATERIAL_DIFFUSE, scene->texture1));
586 eo_do(scene->material1, evas_3d_material_texture_set(EVAS_3D_MATERIAL_NORMAL, scene->texture_normal));
587
588 // Setup CUBE mesh.
589 scene->mesh = eo_add(EVAS_3D_MESH_CLASS, ourGlobals->evas);
590 eo_do(scene->mesh,
591 evas_3d_mesh_vertex_count_set(24),
592 evas_3d_mesh_frame_add(0),
593
594 evas_3d_mesh_frame_vertex_data_set(0, EVAS_3D_VERTEX_POSITION, 12 * sizeof(float), &cube_vertices[ 0]),
595 evas_3d_mesh_frame_vertex_data_set(0, EVAS_3D_VERTEX_NORMAL, 12 * sizeof(float), &cube_vertices[ 3]),
596 evas_3d_mesh_frame_vertex_data_set(0, EVAS_3D_VERTEX_COLOR, 12 * sizeof(float), &cube_vertices[ 6]),
597 evas_3d_mesh_frame_vertex_data_set(0, EVAS_3D_VERTEX_TEXCOORD, 12 * sizeof(float), &cube_vertices[10]),
598
599 evas_3d_mesh_index_data_set(EVAS_3D_INDEX_FORMAT_UNSIGNED_SHORT, 36, &cube_indices[0]),
600 evas_3d_mesh_vertex_assembly_set(EVAS_3D_VERTEX_ASSEMBLY_TRIANGLES),
601
602 evas_3d_mesh_shade_mode_set(EVAS_3D_SHADE_MODE_NORMAL_MAP),
603
604 evas_3d_mesh_frame_material_set(0, scene->material0),
605
606 evas_3d_mesh_frame_add(20),
607 evas_3d_mesh_frame_material_set(20, scene->material1)
608 );
609 scene->mesh_node = evas_3d_node_add(ourGlobals->evas, EVAS_3D_NODE_TYPE_MESH);
610 eo_do(scene->root_node, evas_3d_node_member_add(scene->mesh_node));
611 eo_do(scene->mesh_node,
612 eo_key_data_set("Name", "cube", NULL),
613 evas_3d_node_position_set(40.0, 3.5, 23.0),
614 evas_3d_node_mesh_add(scene->mesh)
615 );
616}
617
618static void _sonic_setup(globals *ourGlobals, Scene_Data *scene)
619{
620 // Setup an MD2 mesh.
621 scene->mesh2 = eo_add(EVAS_3D_MESH_CLASS, ourGlobals->evas);
622 eo_do(scene->mesh2,
623 evas_3d_mesh_file_set(EVAS_3D_MESH_FILE_TYPE_MD2, "../../media/sonic.md2", NULL)
624 );
625
626 scene->material2 = eo_add(EVAS_3D_MATERIAL_CLASS, ourGlobals->evas);
627 eo_do(scene->mesh2,
628 evas_3d_mesh_frame_material_set(0, scene->material2)
629 );
630
631 scene->texture2 = eo_add(EVAS_3D_TEXTURE_CLASS, ourGlobals->evas);
632 eo_do(scene->texture2,
633 evas_3d_texture_file_set("../../media/sonic.png", NULL),
634 evas_3d_texture_filter_set(EVAS_3D_TEXTURE_FILTER_NEAREST, EVAS_3D_TEXTURE_FILTER_NEAREST),
635 evas_3d_texture_wrap_set(EVAS_3D_WRAP_MODE_REPEAT, EVAS_3D_WRAP_MODE_REPEAT)
636 );
637
638 eo_do(scene->material2,
639 evas_3d_material_texture_set(EVAS_3D_MATERIAL_DIFFUSE, scene->texture2),
640
641 evas_3d_material_enable_set(EVAS_3D_MATERIAL_AMBIENT, EINA_TRUE),
642 evas_3d_material_enable_set(EVAS_3D_MATERIAL_DIFFUSE, EINA_TRUE),
643 evas_3d_material_enable_set(EVAS_3D_MATERIAL_SPECULAR, EINA_TRUE),
644 evas_3d_material_enable_set(EVAS_3D_MATERIAL_NORMAL, EINA_TRUE),
645
646 evas_3d_material_color_set(EVAS_3D_MATERIAL_AMBIENT, 0.01, 0.01, 0.01, 1.0),
647 evas_3d_material_color_set(EVAS_3D_MATERIAL_DIFFUSE, 1.0, 1.0, 1.0, 1.0),
648 evas_3d_material_color_set(EVAS_3D_MATERIAL_SPECULAR, 1.0, 1.0, 1.0, 1.0),
649 evas_3d_material_shininess_set(50.0)
650 );
651
652 scene->mesh2_node = evas_3d_node_add(ourGlobals->evas, EVAS_3D_NODE_TYPE_MESH);
653 eo_do(scene->root_node,
654 evas_3d_node_member_add(scene->mesh2_node)
655 );
656 eo_do(scene->mesh2_node,
657 eo_key_data_set("Name", "sonic", NULL),
658 evas_3d_node_mesh_add(scene->mesh2)
659 );
660
661 eo_do(scene->mesh2,
662 evas_3d_mesh_shade_mode_set(EVAS_3D_SHADE_MODE_PHONG)
663 );
664}
665
666static void _earth_setup(globals *ourGlobals, Scene_Data *scene)
667{
668 // Setup earth material.
669 scene->material3 = eo_add(EVAS_3D_MATERIAL_CLASS, ourGlobals->evas);
670
671 scene->texture_diffuse = eo_add(EVAS_3D_TEXTURE_CLASS, ourGlobals->evas);
672 eo_do(scene->texture_diffuse,
673 evas_3d_texture_file_set("../../media/EarthDiffuse.png", NULL),
674 evas_3d_texture_filter_set(EVAS_3D_TEXTURE_FILTER_LINEAR, EVAS_3D_TEXTURE_FILTER_LINEAR));
675 eo_do(scene->material3,
676 evas_3d_material_texture_set(EVAS_3D_MATERIAL_DIFFUSE, scene->texture_diffuse),
677
678 evas_3d_material_enable_set(EVAS_3D_MATERIAL_AMBIENT, EINA_TRUE),
679 evas_3d_material_enable_set(EVAS_3D_MATERIAL_DIFFUSE, EINA_TRUE),
680 evas_3d_material_enable_set(EVAS_3D_MATERIAL_SPECULAR, EINA_TRUE),
681
682 evas_3d_material_color_set(EVAS_3D_MATERIAL_AMBIENT, 0.01, 0.01, 0.01, 1.0),
683 evas_3d_material_color_set(EVAS_3D_MATERIAL_DIFFUSE, 1.0, 1.0, 1.0, 1.0),
684 evas_3d_material_color_set(EVAS_3D_MATERIAL_SPECULAR, 1.0, 1.0, 1.0, 1.0),
685 evas_3d_material_shininess_set(50.0));
686
687 // Setup earth mesh.
688 _sphere_init(100);
689
690 scene->mesh3 = eo_add(EVAS_3D_MESH_CLASS, ourGlobals->evas);
691 eo_do(scene->mesh3,
692 evas_3d_mesh_vertex_count_set(vertex_count),
693 evas_3d_mesh_frame_add(0),
694 evas_3d_mesh_frame_vertex_data_set(0, EVAS_3D_VERTEX_POSITION, sizeof(vertex), &sphere_vertices[0].position),
695 evas_3d_mesh_frame_vertex_data_set(0, EVAS_3D_VERTEX_NORMAL, sizeof(vertex), &sphere_vertices[0].normal),
696 evas_3d_mesh_frame_vertex_data_set(0, EVAS_3D_VERTEX_TANGENT, sizeof(vertex), &sphere_vertices[0].tangent),
697 evas_3d_mesh_frame_vertex_data_set(0, EVAS_3D_VERTEX_COLOR, sizeof(vertex), &sphere_vertices[0].color),
698 evas_3d_mesh_frame_vertex_data_set(0, EVAS_3D_VERTEX_TEXCOORD, sizeof(vertex), &sphere_vertices[0].texcoord),
699
700 evas_3d_mesh_index_data_set(EVAS_3D_INDEX_FORMAT_UNSIGNED_SHORT, index_count, &sphere_indices[0]),
701 evas_3d_mesh_vertex_assembly_set(EVAS_3D_VERTEX_ASSEMBLY_TRIANGLES),
702 evas_3d_mesh_frame_material_set(0, scene->material3)
703 );
704
705 scene->mesh3_node = evas_3d_node_add(ourGlobals->evas, EVAS_3D_NODE_TYPE_MESH);
706 eo_do(scene->root_node,
707 evas_3d_node_member_add(scene->mesh3_node)
708 );
709 eo_do(scene->mesh3_node,
710 eo_key_data_set("Name", "earth", NULL),
711 evas_3d_node_position_set(40.0, -3.5, 23.0),
712 evas_3d_node_mesh_add(scene->mesh3)
713 );
714
715 eo_do(scene->mesh3,
716 evas_3d_mesh_shade_mode_set(EVAS_3D_SHADE_MODE_DIFFUSE)
717 );
718}
719
720
721static void
722_scene_setup(globals *ourGlobals, Scene_Data *scene)
723{
724 scene->scene = eo_add(EVAS_3D_SCENE_CLASS, ourGlobals->evas);
725 eo_do(scene->scene,
726 evas_3d_scene_size_set(512, 512),
727 evas_3d_scene_background_color_set(0.0, 0.0, 0.0, 0.0)
728 );
729
730 // TODO - I have no idea how this should work.
731 // It seems the people that wrote the examples don't know either. lol
732// scene->root_node = eo_add(EVAS_3D_NODE_CLASS, ourGlobals->evas, EVAS_3D_NODE_TYPE_NODE);
733 scene->root_node = evas_3d_node_add(ourGlobals->evas, EVAS_3D_NODE_TYPE_NODE);
734
735 _camera_setup(ourGlobals, scene);
736 _light_setup(ourGlobals, scene);
737 _cube_setup(ourGlobals, scene);
738 _sonic_setup(ourGlobals, scene);
739 _earth_setup(ourGlobals, scene);
740
741 eo_do(scene->scene,
742 evas_3d_scene_root_node_set(scene->root_node),
743 evas_3d_scene_camera_node_set(scene->camera_node)
744 );
745}
746
747/* Sooo, how to do this - 151/* Sooo, how to do this -
748widget has to be a light userdata 152widget has to be a light userdata
749The rest can be Lua sub things? Each with a C function to update the widget. 153The rest can be Lua sub things? Each with a C function to update the widget.
@@ -786,89 +190,6 @@ static void _on_click(void *data, Evas_Object *obj, void *event_info EINA_UNUSED
786 } 190 }
787} 191}
788 192
789static void _on_mouse_move(void *data, Evas *e EINA_UNUSED, Evas_Object *o, void *einfo)
790{
791 Scene_Data *scene = data;
792 Evas_Event_Mouse_Move *ev = einfo;
793 Evas_Coord x, y, w, h;
794 Evas_Coord obj_x, obj_y;
795 int scene_w, scene_h;
796 Evas_Real scene_x, scene_y;
797 Evas_Real s, t;
798 Evas_3D_Node *n;
799 Evas_3D_Mesh *m;
800 Eina_Bool pick;
801 char *name = NULL;
802
803 evas_object_geometry_get(o, &x, &y, &w, &h);
804
805 obj_x = ev->cur.canvas.x - x;
806 obj_y = ev->cur.canvas.y - y;
807
808 eo_do(scene->scene, evas_3d_scene_size_get(&scene_w, &scene_h));
809
810 scene_x = obj_x * scene_w / (Evas_Real)w;
811 scene_y = obj_y * scene_h / (Evas_Real)h;
812
813 eo_do(scene->scene, pick = evas_3d_scene_pick(scene_x, scene_y, &n, &m, &s, &t));
814 if (pick)
815 name = evas_object_data_get(n, "Name");
816 // This is a raw Evas callback, on the Elm image internal Evas_Object.
817 // So we need to get the Elm Image back from the raw Evas_Object.
818 // Which is why we stuffed it in the scene structure.
819 if (name)
820 {
821 elm_object_tooltip_text_set(scene->image, name);
822 elm_object_tooltip_show(scene->image);
823 }
824 else
825 elm_object_tooltip_hide(scene->image);
826}
827
828static void _on_mouse_down(void *data, Evas *e EINA_UNUSED, Evas_Object *o, void *einfo)
829{
830 Scene_Data *scene = data;
831 Evas_Event_Mouse_Down *ev = einfo;
832 Evas_Coord x, y, w, h;
833 Evas_Coord obj_x, obj_y;
834 int scene_w, scene_h;
835 Evas_Real scene_x, scene_y;
836 Evas_Real s, t;
837 Evas_3D_Node *n;
838 Evas_3D_Mesh *m;
839 Eina_Bool pick;
840 char *name;
841
842 evas_object_geometry_get(o, &x, &y, &w, &h);
843
844 obj_x = ev->canvas.x - x;
845 obj_y = ev->canvas.y - y;
846
847 eo_do(scene->scene, evas_3d_scene_size_get(&scene_w, &scene_h));
848
849 scene_x = obj_x * scene_w / (Evas_Real)w;
850 scene_y = obj_y * scene_h / (Evas_Real)h;
851
852 eo_do(scene->scene, pick = evas_3d_scene_pick(scene_x, scene_y, &n, &m, &s, &t));
853 if (pick)
854 {
855 name = evas_object_data_get(n, "Name");
856 printf("Picked : ");
857 }
858 else
859 printf("Not picked : ");
860 if (NULL == name)
861 name = "";
862
863 printf("output(%d, %d) canvas(%d, %d) object(%d, %d) scene(%f, %f) texcoord(%f, %f) "
864 "node(%p) %s mesh(%p)\n",
865 ev->output.x, ev->output.y,
866 ev->canvas.x, ev->canvas.y,
867 obj_x, obj_y,
868 scene_x, scene_y,
869 s, t, n, name, m);
870}
871
872static void _on_done(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED) 193static void _on_done(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
873{ 194{
874// globals *ourGlobals = data; 195// globals *ourGlobals = data;
@@ -956,7 +277,7 @@ static int window(lua_State *L)
956 globals *ourGlobals; 277 globals *ourGlobals;
957 char *name = "GuiLua"; 278 char *name = "GuiLua";
958 char *title = "GuiLua test harness"; 279 char *title = "GuiLua test harness";
959 Evas_Object *obj, *temp; 280 Evas_Object *obj;
960 int result = 0; 281 int result = 0;
961 int w = WIDTH, h = HEIGHT; 282 int w = WIDTH, h = HEIGHT;
962 283
@@ -980,8 +301,6 @@ static int window(lua_State *L)
980 // Get the Evas / canvas from the elm window (that the Evas_Object "lives on"), which is itself an Evas_Object created by Elm, so not sure if it was created internally with Ecore_Evas. 301 // Get the Evas / canvas from the elm window (that the Evas_Object "lives on"), which is itself an Evas_Object created by Elm, so not sure if it was created internally with Ecore_Evas.
981 ourGlobals->evas = evas_object_evas_get(ourGlobals->win); 302 ourGlobals->evas = evas_object_evas_get(ourGlobals->win);
982 303
983 _scene_setup(ourGlobals, &ourScene);
984
985 // Add a background image object. 304 // Add a background image object.
986 obj = eo_add(ELM_OBJ_IMAGE_CLASS, ourGlobals->win); 305 obj = eo_add(ELM_OBJ_IMAGE_CLASS, ourGlobals->win);
987 eo_do(obj, 306 eo_do(obj,
@@ -993,28 +312,6 @@ static int window(lua_State *L)
993 elm_win_resize_object_add(ourGlobals->win, obj); 312 elm_win_resize_object_add(ourGlobals->win, obj);
994 eo_unref(obj); 313 eo_unref(obj);
995 314
996 // Add an image object for 3D scene rendering.
997 obj = eo_add(ELM_OBJ_IMAGE_CLASS, ourGlobals->win);
998 ourScene.image = obj;
999 eo_do(obj,
1000 evas_obj_size_hint_weight_set(EVAS_HINT_EXPAND, EVAS_HINT_EXPAND),
1001 elm_obj_image_fill_outside_set(EINA_TRUE),
1002 evas_obj_visibility_set(EINA_TRUE),
1003 temp = elm_obj_image_object_get()
1004 );
1005 eo_do(temp,
1006 evas_obj_image_scene_set(ourScene.scene)
1007 );
1008 elm_object_tooltip_text_set(obj, "");
1009 elm_object_tooltip_hide(obj);
1010 // Elm can't seem to be able to tell us WHERE an image was clicked, so use raw Evas calbacks instead.
1011 evas_object_event_callback_add(temp, EVAS_CALLBACK_MOUSE_MOVE, _on_mouse_move, &ourScene);
1012 evas_object_event_callback_add(temp, EVAS_CALLBACK_MOUSE_DOWN, _on_mouse_down, &ourScene);
1013 elm_win_resize_object_add(ourGlobals->win, obj);
1014
1015 // Add animation timer callback.
1016 ecore_timer_add(0.016, _animate_scene, &ourScene);
1017
1018 lua_pushlightuserdata(L, &ourGlobals->win); 315 lua_pushlightuserdata(L, &ourGlobals->win);
1019 result = 1; 316 result = 1;
1020 } 317 }
@@ -1076,9 +373,7 @@ static int closeWindow(lua_State *L)
1076 { 373 {
1077 eo_unref(wid->obj); 374 eo_unref(wid->obj);
1078 } 375 }
1079 eo_unref(ourScene.image);
1080 evas_object_del(ourGlobals->win); 376 evas_object_del(ourGlobals->win);
1081 _sphere_fini();
1082 } 377 }
1083 378
1084 if (ourGlobals->logDom >= 0) 379 if (ourGlobals->logDom >= 0)