aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorDavid Walter Seikel2015-12-31 13:12:27 +1000
committerDavid Walter Seikel2015-12-31 13:12:27 +1000
commitae5931413b97f3f7f5e24bd4c42ab6d85946df02 (patch)
tree5dd3c92b018b04b98791b468daede908853cc2af
parentFailed experiment, but let's keep it for now. (diff)
downloadSledjHamr-ae5931413b97f3f7f5e24bd4c42ab6d85946df02.zip
SledjHamr-ae5931413b97f3f7f5e24bd4c42ab6d85946df02.tar.gz
SledjHamr-ae5931413b97f3f7f5e24bd4c42ab6d85946df02.tar.bz2
SledjHamr-ae5931413b97f3f7f5e24bd4c42ab6d85946df02.tar.xz
Replace cube and sphere code with Evas_3D primitives.
Clicking on them works again. B-)
-rw-r--r--src/extantz/extantz.c1
-rw-r--r--src/extantz/extantz.h2
-rw-r--r--src/extantz/scenri.c251
3 files changed, 12 insertions, 242 deletions
diff --git a/src/extantz/extantz.c b/src/extantz/extantz.c
index 310f9b9..355a195 100644
--- a/src/extantz/extantz.c
+++ b/src/extantz/extantz.c
@@ -745,7 +745,6 @@ EAPI_MAIN int elm_main(int argc, char **argv)
745 { 745 {
746 ecore_animator_del(ourGlobals.animator); 746 ecore_animator_del(ourGlobals.animator);
747#if USE_EVAS_3D 747#if USE_EVAS_3D
748 Evas_3D_Demo_fini(&ourGlobals);
749 scenriDel(ourGlobals.scene); 748 scenriDel(ourGlobals.scene);
750#endif 749#endif
751// eo_unref(ourGlobals.tb); 750// eo_unref(ourGlobals.tb);
diff --git a/src/extantz/extantz.h b/src/extantz/extantz.h
index 8e06948..c7edc07 100644
--- a/src/extantz/extantz.h
+++ b/src/extantz/extantz.h
@@ -279,9 +279,7 @@ EAPI void finishIrr(globals *ourGlobals);
279 279
280void overlay_add(globals *ourGlobals); 280void overlay_add(globals *ourGlobals);
281 281
282EAPI void Evas_3D_Demo_add(globals *ourGlobals, char *file);
283Eina_Bool animateScene(globals *ourGlobals); 282Eina_Bool animateScene(globals *ourGlobals);
284void Evas_3D_Demo_fini(globals *ourGlobals);
285 283
286Scene_Data *scenriAdd(Evas_Object *win); 284Scene_Data *scenriAdd(Evas_Object *win);
287Eo *cameraAdd(Evas *evas, Scene_Data *scene, Evas_Object *win); 285Eo *cameraAdd(Evas *evas, Scene_Data *scene, Evas_Object *win);
diff --git a/src/extantz/scenri.c b/src/extantz/scenri.c
index 76f4513..f871500 100644
--- a/src/extantz/scenri.c
+++ b/src/extantz/scenri.c
@@ -503,66 +503,6 @@ void scenriDel(Scene_Data *scene)
503} 503}
504 504
505 505
506static const float cube_vertices[] =
507{
508 /* Front */
509 -1.0, 1.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0, 1.0, 0.0, 1.0,
510 1.0, 1.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0, 1.0, 1.0, 1.0,
511 -1.0, -1.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0,
512 1.0, -1.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0,
513
514 /* Back */
515 1.0, 1.0, -1.0, 0.0, 0.0, -1.0, 0.0, 0.0, 1.0, 1.0, 0.0, 1.0,
516 -1.0, 1.0, -1.0, 0.0, 0.0, -1.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0,
517 1.0, -1.0, -1.0, 0.0, 0.0, -1.0, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0,
518 -1.0, -1.0, -1.0, 0.0, 0.0, -1.0, 0.0, 0.0, 1.0, 1.0, 1.0, 0.0,
519
520 /* Left */
521 -1.0, 1.0, -1.0, -1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0,
522 -1.0, 1.0, 1.0, -1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 1.0, 1.0, 1.0,
523 -1.0, -1.0, -1.0, -1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 1.0, 0.0, 0.0,
524 -1.0, -1.0, 1.0, -1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 1.0, 1.0, 0.0,
525
526 /* Right */
527 1.0, 1.0, 1.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0, 1.0, 0.0, 1.0,
528 1.0, 1.0, -1.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0, 1.0, 1.0, 1.0,
529 1.0, -1.0, 1.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0, 1.0, 0.0, 0.0,
530 1.0, -1.0, -1.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0, 1.0, 1.0, 0.0,
531
532 /* Top */
533 -1.0, 1.0, -1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 1.0, 0.0, 1.0,
534 1.0, 1.0, -1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 1.0, 1.0, 1.0,
535 -1.0, 1.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 1.0, 0.0, 0.0,
536 1.0, 1.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 1.0, 1.0, 0.0,
537
538 /* Bottom */
539 1.0, -1.0, -1.0, 0.0, -1.0, 0.0, 0.0, 1.0, 1.0, 1.0, 0.0, 1.0,
540 -1.0, -1.0, -1.0, 0.0, -1.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0, 1.0,
541 1.0, -1.0, 1.0, 0.0, -1.0, 0.0, 0.0, 1.0, 1.0, 1.0, 0.0, 0.0,
542 -1.0, -1.0, 1.0, 0.0, -1.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0, 0.0,
543};
544
545static const unsigned short cube_indices[] =
546{
547 /* Front */
548 0, 1, 2, 2, 1, 3,
549
550 /* Back */
551 4, 5, 6, 6, 5, 7,
552
553 /* Left */
554 8, 9, 10, 10, 9, 11,
555
556 /* Right */
557 12, 13, 14, 14, 13, 15,
558
559 /* Top */
560 16, 17, 18, 18, 17, 19,
561
562 /* Bottom */
563 20, 21, 22, 22, 21, 23
564};
565
566static const unsigned int pixels0[] = 506static const unsigned int pixels0[] =
567{ 507{
568 0xff0000ff, 0xff0000ff, 0xffff0000, 0xffff0000, 508 0xff0000ff, 0xff0000ff, 0xffff0000, 0xffff0000,
@@ -580,158 +520,6 @@ static const unsigned int pixels1[] =
580}; 520};
581 521
582 522
583static int vertex_count = 0;
584static vertex *sphere_vertices = NULL;
585
586static int index_count = 0;
587static unsigned short *sphere_indices = NULL;
588
589
590static inline vec3 _normalize(const vec3 *v)
591{
592 double l = sqrt(v->x * v->x + v->y * v->y + v->z * v->z);
593 vec3 vec;
594
595 vec.x = v->x / l;
596 vec.y = v->y / l;
597 vec.z = v->z / l;
598
599 return vec;
600}
601
602static void _sphere_init(int precision)
603{
604 int i, j;
605 unsigned short *index;
606
607 vertex_count = (precision + 1) * (precision + 1);
608 index_count = precision * precision * 6;
609
610 /* Allocate buffer. */
611 sphere_vertices = malloc(sizeof(vertex) * vertex_count);
612 sphere_indices = malloc(sizeof(unsigned short) * index_count);
613
614 for (i = 0; i <= precision; i++)
615 {
616 double lati = (M_PI * (double)i) / (double)precision;
617 double y = cos(lati);
618 double r = fabs(sin(lati));
619
620 for (j = 0; j <= precision; j++)
621 {
622 double longi = (M_PI * 2.0 * j) / precision;
623 vertex *v = &sphere_vertices[i * (precision + 1) + j];
624
625 if (j == 0 || j == precision)
626 v->position.x = 0.0;
627 else
628 v->position.x = r * sin(longi);
629
630 v->position.y = y;
631
632 if (j == 0 || j == precision)
633 v->position.z = r;
634 else
635 v->position.z = r * cos(longi);
636
637 v->normal = v->position;
638
639 if (v->position.x > 0.0)
640 {
641 v->tangent.x = -v->normal.y;
642 v->tangent.y = v->normal.x;
643 v->tangent.z = v->normal.z;
644 }
645 else
646 {
647 v->tangent.x = v->normal.y;
648 v->tangent.y = -v->normal.x;
649 v->tangent.z = v->normal.z;
650 }
651
652 v->color.x = v->position.x;
653 v->color.y = v->position.y;
654 v->color.z = v->position.z;
655 v->color.w = 1.0;
656
657 if (j == precision)
658 v->texcoord.x = 1.0;
659 else if (j == 0)
660 v->texcoord.x = 0.0;
661 else
662 v->texcoord.x = (double)j / (double)precision;
663
664 if (i == precision)
665 v->texcoord.y = 1.0;
666 else if (i == 0)
667 v->texcoord.y = 0.0;
668 else
669 v->texcoord.y = 1.0 - (double)i / (double)precision;
670 }
671 }
672
673 index = &sphere_indices[0];
674
675 for (i = 0; i < precision; i++)
676 {
677 for (j = 0; j < precision; j++)
678 {
679 *index++ = i * (precision + 1) + j;
680 *index++ = i * (precision + 1) + j + 1;
681 *index++ = (i + 1) * (precision + 1) + j;
682
683 *index++ = (i + 1) * (precision + 1) + j;
684 *index++ = i * (precision + 1) + j + 1;
685 *index++ = (i + 1) * (precision + 1) + j + 1;
686 }
687 }
688
689 for (i = 0; i < index_count; i += 3)
690 {
691 vertex *v0 = &sphere_vertices[sphere_indices[i + 0]];
692 vertex *v1 = &sphere_vertices[sphere_indices[i + 1]];
693 vertex *v2 = &sphere_vertices[sphere_indices[i + 2]];
694
695 vec3 e1, e2;
696 float du1, du2, dv1, dv2, f;
697 vec3 tangent;
698
699 e1.x = v1->position.x - v0->position.x;
700 e1.y = v1->position.y - v0->position.y;
701 e1.z = v1->position.z - v0->position.z;
702
703 e2.x = v2->position.x - v0->position.x;
704 e2.y = v2->position.y - v0->position.y;
705 e2.z = v2->position.z - v0->position.z;
706
707 du1 = v1->texcoord.x - v0->texcoord.x;
708 dv1 = v1->texcoord.y - v0->texcoord.y;
709
710 du2 = v2->texcoord.x - v0->texcoord.x;
711 dv2 = v2->texcoord.y - v0->texcoord.y;
712
713 f = 1.0 / (du1 * dv2 - du2 * dv1);
714
715 tangent.x = f * (dv2 * e1.x - dv1 * e2.x);
716 tangent.y = f * (dv2 * e1.y - dv1 * e2.y);
717 tangent.z = f * (dv2 * e1.z - dv1 * e2.z);
718
719 v0->tangent = tangent;
720 }
721
722 for (i = 0; i <= precision; i++)
723 {
724 for (j = 0; j <= precision; j++)
725 {
726 if (j == precision)
727 {
728 vertex *v = &sphere_vertices[i * (precision + 1) + j];
729 v->tangent = sphere_vertices[i * (precision + 1)].tangent;
730 }
731 }
732 }
733}
734
735void stuffsSetup(ExtantzStuffs *stuffs, Scene_Data *scene, int fake) 523void stuffsSetup(ExtantzStuffs *stuffs, Scene_Data *scene, int fake)
736{ 524{
737 char buf[PATH_MAX]; 525 char buf[PATH_MAX];
@@ -829,19 +617,15 @@ void stuffsSetup(ExtantzStuffs *stuffs, Scene_Data *scene, int fake)
829 // TODO - Write real generic cube and sphere stuff later. 617 // TODO - Write real generic cube and sphere stuff later.
830 if (MT_CUBE == stuffs->stuffs.details.mesh->type) 618 if (MT_CUBE == stuffs->stuffs.details.mesh->type)
831 { 619 {
620 Eo *cube;
621
832 eina_accessor_data_get(stuffs->aMaterial, 0, (void **) &mi); 622 eina_accessor_data_get(stuffs->aMaterial, 0, (void **) &mi);
833 eina_accessor_data_get(stuffs->aMaterial, 1, (void **) &mj); 623 eina_accessor_data_get(stuffs->aMaterial, 1, (void **) &mj);
834 me = eo_add(EVAS_CANVAS3D_MESH_CLASS, scene->evas,
835 evas_canvas3d_mesh_vertex_count_set(24),
836 evas_canvas3d_mesh_frame_add(0),
837
838 evas_canvas3d_mesh_frame_vertex_data_set(0, EVAS_CANVAS3D_VERTEX_ATTRIB_POSITION, 12 * sizeof(float), &cube_vertices[ 0]),
839 evas_canvas3d_mesh_frame_vertex_data_set(0, EVAS_CANVAS3D_VERTEX_ATTRIB_NORMAL, 12 * sizeof(float), &cube_vertices[ 3]),
840 evas_canvas3d_mesh_frame_vertex_data_set(0, EVAS_CANVAS3D_VERTEX_ATTRIB_COLOR, 12 * sizeof(float), &cube_vertices[ 6]),
841 evas_canvas3d_mesh_frame_vertex_data_set(0, EVAS_CANVAS3D_VERTEX_ATTRIB_TEXCOORD, 12 * sizeof(float), &cube_vertices[10]),
842 624
843 evas_canvas3d_mesh_index_data_set(EVAS_CANVAS3D_INDEX_FORMAT_UNSIGNED_SHORT, 36, &cube_indices[0]), 625 cube = eo_add(EVAS_CANVAS3D_PRIMITIVE_CLASS, scene->evas);
844 evas_canvas3d_mesh_vertex_assembly_set(EVAS_CANVAS3D_VERTEX_ASSEMBLY_TRIANGLES), 626 eo_do(cube, evas_canvas3d_primitive_form_set(EVAS_CANVAS3D_MESH_PRIMITIVE_CUBE));
627 me = eo_add(EVAS_CANVAS3D_MESH_CLASS, scene->evas,
628 evas_canvas3d_mesh_from_primitive_set(0, cube),
845 629
846 evas_canvas3d_mesh_shade_mode_set(EVAS_CANVAS3D_SHADE_MODE_NORMAL_MAP), 630 evas_canvas3d_mesh_shade_mode_set(EVAS_CANVAS3D_SHADE_MODE_NORMAL_MAP),
847 631
@@ -854,20 +638,15 @@ void stuffsSetup(ExtantzStuffs *stuffs, Scene_Data *scene, int fake)
854 } 638 }
855 else if (MT_SPHERE == stuffs->stuffs.details.mesh->type) 639 else if (MT_SPHERE == stuffs->stuffs.details.mesh->type)
856 { 640 {
857 _sphere_init(100); 641 Eo *sphere;
858 642
859 eina_accessor_data_get(stuffs->aMaterial, 0, (void **) &mi); 643 eina_accessor_data_get(stuffs->aMaterial, 0, (void **) &mi);
644
645 sphere = eo_add(EVAS_CANVAS3D_PRIMITIVE_CLASS, scene->evas);
646 eo_do(sphere, evas_canvas3d_primitive_form_set(EVAS_CANVAS3D_MESH_PRIMITIVE_SPHERE));
647
860 me = eo_add(EVAS_CANVAS3D_MESH_CLASS, scene->evas, 648 me = eo_add(EVAS_CANVAS3D_MESH_CLASS, scene->evas,
861 evas_canvas3d_mesh_vertex_count_set(vertex_count), 649 evas_canvas3d_mesh_from_primitive_set(0, sphere),
862 evas_canvas3d_mesh_frame_add(0),
863 evas_canvas3d_mesh_frame_vertex_data_set(0, EVAS_CANVAS3D_VERTEX_ATTRIB_POSITION, sizeof(vertex), &sphere_vertices[0].position),
864 evas_canvas3d_mesh_frame_vertex_data_set(0, EVAS_CANVAS3D_VERTEX_ATTRIB_NORMAL, sizeof(vertex), &sphere_vertices[0].normal),
865 evas_canvas3d_mesh_frame_vertex_data_set(0, EVAS_CANVAS3D_VERTEX_ATTRIB_TANGENT, sizeof(vertex), &sphere_vertices[0].tangent),
866 evas_canvas3d_mesh_frame_vertex_data_set(0, EVAS_CANVAS3D_VERTEX_ATTRIB_COLOR, sizeof(vertex), &sphere_vertices[0].color),
867 evas_canvas3d_mesh_frame_vertex_data_set(0, EVAS_CANVAS3D_VERTEX_ATTRIB_TEXCOORD, sizeof(vertex), &sphere_vertices[0].texcoord),
868
869 evas_canvas3d_mesh_index_data_set(EVAS_CANVAS3D_INDEX_FORMAT_UNSIGNED_SHORT, index_count, &sphere_indices[0]),
870 evas_canvas3d_mesh_vertex_assembly_set(EVAS_CANVAS3D_VERTEX_ASSEMBLY_TRIANGLES),
871 evas_canvas3d_mesh_frame_material_set(0, mi), 650 evas_canvas3d_mesh_frame_material_set(0, mi),
872 651
873 evas_canvas3d_mesh_shade_mode_set(EVAS_CANVAS3D_SHADE_MODE_DIFFUSE) 652 evas_canvas3d_mesh_shade_mode_set(EVAS_CANVAS3D_SHADE_MODE_DIFFUSE)
@@ -946,9 +725,3 @@ void addMaterial(ExtantzStuffs *e, int face, TextureType type, char *file)
946 strcpy(result->texture, file); 725 strcpy(result->texture, file);
947 eina_inarray_push(e->stuffs.details.mesh->materials, result); 726 eina_inarray_push(e->stuffs.details.mesh->materials, result);
948} 727}
949
950void Evas_3D_Demo_fini(globals *ourGlobals)
951{
952 free(sphere_vertices);
953 free(sphere_indices);
954}