diff options
author | David Walter Seikel | 2016-03-07 21:06:40 +1000 |
---|---|---|
committer | David Walter Seikel | 2016-03-07 21:06:40 +1000 |
commit | 5fe062e149c4acf1a0c3543e0870cdc09e293393 (patch) | |
tree | a1f139c78575d27a750728bca2418c12ea3a8c9a /src | |
parent | Document pick bug. (diff) | |
download | SledjHamr-5fe062e149c4acf1a0c3543e0870cdc09e293393.zip SledjHamr-5fe062e149c4acf1a0c3543e0870cdc09e293393.tar.gz SledjHamr-5fe062e149c4acf1a0c3543e0870cdc09e293393.tar.bz2 SledjHamr-5fe062e149c4acf1a0c3543e0870cdc09e293393.tar.xz |
Experimenting with creating my own cube and heightfield.
Diffstat (limited to 'src')
-rw-r--r-- | src/extantz/scenri.c | 125 |
1 files changed, 115 insertions, 10 deletions
diff --git a/src/extantz/scenri.c b/src/extantz/scenri.c index 0e495e4..4f15109 100644 --- a/src/extantz/scenri.c +++ b/src/extantz/scenri.c | |||
@@ -31,6 +31,59 @@ | |||
31 | static Ecore_Idle_Enterer *idler; | 31 | static Ecore_Idle_Enterer *idler; |
32 | 32 | ||
33 | 33 | ||
34 | // Copied from EFL, coz code hiding sucks. | ||
35 | const float cube_vertices[] = | ||
36 | { | ||
37 | /* positions normals vertex_color tex_coords tangents */ | ||
38 | /* Front */ | ||
39 | 0.5, -0.5, 0.5, 0.0, -1.0, 0.0, 0.0, 1.0, 1.0, 1.0, 0.0, 0.0, -1.0, 0.0, 0.0, | ||
40 | -0.5, -0.5, 0.5, 0.0, -1.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0, 0.0, -1.0, 0.0, 0.0, | ||
41 | -0.5, -0.5, -0.5, 0.0, -1.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0, 1.0, -1.0, 0.0, 0.0, | ||
42 | 0.5, -0.5, -0.5, 0.0, -1.0, 0.0, 0.0, 1.0, 1.0, 1.0, 0.0, 1.0, -1.0, 0.0, 0.0, | ||
43 | |||
44 | /* Left */ | ||
45 | -0.5, -0.5, 0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||
63 | -0.5, -0.5, 0.5, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, | ||
64 | -0.5, 0.5, 0.5, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0, 1.0, 0.0, 1.0, 1.0, 0.0, 0.0, | ||
65 | 0.5, 0.5, 0.5, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0, 0.0, 0.0, | ||
66 | 0.5, -0.5, 0.5, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0, 1.0, 0.0, 0.0, | ||
67 | |||
68 | /* Bottom */ | ||
69 | -0.5, -0.5, -0.5, 0.0, 0.0, -1.0, 0.0, 0.0, 1.0, 1.0, 1.0, 0.0, -1.0, 0.0, 0.0, | ||
70 | -0.5, 0.5, -0.5, 0.0, 0.0, -1.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0, -1.0, 0.0, 0.0, | ||
71 | 0.5, 0.5, -0.5, 0.0, 0.0, -1.0, 0.0, 0.0, 1.0, 1.0, 0.0, 1.0, -1.0, 0.0, 0.0, | ||
72 | 0.5, -0.5, -0.5, 0.0, 0.0, -1.0, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0, -1.0, 0.0, 0.0, | ||
73 | }; | ||
74 | |||
75 | // Copied from EFL, coz code hiding sucks. | ||
76 | const unsigned short cube_indices[] = | ||
77 | { | ||
78 | 0, 1, 2, 6, 7, 4, | ||
79 | 4, 5, 6, 10, 11, 8, | ||
80 | 8, 9, 10, 14, 15, 12, | ||
81 | 12, 13, 14, 2, 3, 0, | ||
82 | 19, 16, 17, 17, 18, 19, | ||
83 | 23, 20, 21, 21, 22, 23 | ||
84 | }; | ||
85 | |||
86 | |||
34 | static void _animateCube(ExtantzStuffs *stuffs) | 87 | static void _animateCube(ExtantzStuffs *stuffs) |
35 | { | 88 | { |
36 | static float angle = 0.0f; | 89 | static float angle = 0.0f; |
@@ -525,6 +578,40 @@ static const unsigned int pixels1[] = | |||
525 | }; | 578 | }; |
526 | 579 | ||
527 | 580 | ||
581 | // This sucks, can't pass in a void pointer! | ||
582 | static void _SL_RAW_terrain(Evas_Real *out_x, Evas_Real *out_y, Evas_Real *out_z, Evas_Real x, Evas_Real y) | ||
583 | { | ||
584 | //printf("%f,%f ", x, y); | ||
585 | *out_x = x; | ||
586 | *out_y = y; | ||
587 | *out_z = x + y; | ||
588 | } | ||
589 | |||
590 | // Copied from EFL, coz code hiding sucks. | ||
591 | static void _set_vertex_data_from_array(Evas_Canvas3D_Mesh *mesh, int frame, const float *data, Evas_Canvas3D_Vertex_Attrib attr, | ||
592 | int start, int attr_count, int line, int vcount) | ||
593 | { | ||
594 | float *address, *out; | ||
595 | int stride, i, j; | ||
596 | |||
597 | eo_do(mesh, | ||
598 | evas_canvas3d_mesh_frame_vertex_data_copy_set(frame, attr, 0, NULL), | ||
599 | address = (float *)evas_canvas3d_mesh_frame_vertex_data_map(frame, attr), | ||
600 | stride = evas_canvas3d_mesh_frame_vertex_stride_get(frame, attr) | ||
601 | ); | ||
602 | |||
603 | if (stride == 0) stride = sizeof(float) * attr_count; | ||
604 | |||
605 | for (i = 0; i < vcount; i++) | ||
606 | { | ||
607 | out = (float *)((char *)address + stride * i); | ||
608 | for (j = 0; j < attr_count; j++) | ||
609 | out[j] = data[start + (line * i) + j]; | ||
610 | } | ||
611 | |||
612 | eo_do(mesh, evas_canvas3d_mesh_frame_vertex_data_unmap(frame, attr)); | ||
613 | } | ||
614 | |||
528 | void stuffsSetup(ExtantzStuffs *stuffs, Scene_Data *scene, int fake) | 615 | void stuffsSetup(ExtantzStuffs *stuffs, Scene_Data *scene, int fake) |
529 | { | 616 | { |
530 | char buf[PATH_MAX]; | 617 | char buf[PATH_MAX]; |
@@ -623,23 +710,39 @@ void stuffsSetup(ExtantzStuffs *stuffs, Scene_Data *scene, int fake) | |||
623 | // This could be a switch. | 710 | // This could be a switch. |
624 | if (MT_CUBE == stuffs->stuffs.details.mesh->type) | 711 | if (MT_CUBE == stuffs->stuffs.details.mesh->type) |
625 | { | 712 | { |
626 | Eo *cube; | ||
627 | |||
628 | eina_accessor_data_get(stuffs->aMaterial, 0, (void **) &mi); | 713 | eina_accessor_data_get(stuffs->aMaterial, 0, (void **) &mi); |
629 | eina_accessor_data_get(stuffs->aMaterial, 1, (void **) &mj); | 714 | eina_accessor_data_get(stuffs->aMaterial, 1, (void **) &mj); |
630 | 715 | ||
631 | cube = eo_add(EVAS_CANVAS3D_PRIMITIVE_CLASS, scene->evas); | 716 | #if 0 |
717 | Eo *cube = eo_add(EVAS_CANVAS3D_PRIMITIVE_CLASS, scene->evas); | ||
632 | eo_do(cube, evas_canvas3d_primitive_form_set(EVAS_CANVAS3D_MESH_PRIMITIVE_CUBE)); | 718 | eo_do(cube, evas_canvas3d_primitive_form_set(EVAS_CANVAS3D_MESH_PRIMITIVE_CUBE)); |
633 | me = eo_add(EVAS_CANVAS3D_MESH_CLASS, scene->evas, | 719 | me = eo_add(EVAS_CANVAS3D_MESH_CLASS, scene->evas, |
634 | evas_canvas3d_mesh_from_primitive_set(0, cube), | 720 | evas_canvas3d_mesh_from_primitive_set(0, cube), |
721 | ); | ||
722 | #else | ||
723 | // More or less copied from EFL, so I can create my own primitives. | ||
724 | me = eo_add(EVAS_CANVAS3D_MESH_CLASS, scene->evas, | ||
725 | evas_canvas3d_mesh_frame_add(0), | ||
726 | evas_canvas3d_mesh_vertex_count_set(24), | ||
727 | evas_canvas3d_mesh_index_data_set(EVAS_CANVAS3D_INDEX_FORMAT_UNSIGNED_SHORT, 36, &cube_indices[0]) | ||
728 | ); | ||
635 | 729 | ||
636 | evas_canvas3d_mesh_shade_mode_set(EVAS_CANVAS3D_SHADE_MODE_NORMAL_MAP), | 730 | _set_vertex_data_from_array(me, 0, cube_vertices, EVAS_CANVAS3D_VERTEX_ATTRIB_POSITION, 0, 3, 15, 24); |
731 | _set_vertex_data_from_array(me, 0, cube_vertices, EVAS_CANVAS3D_VERTEX_ATTRIB_NORMAL, 3, 3, 15, 24); | ||
732 | _set_vertex_data_from_array(me, 0, cube_vertices, EVAS_CANVAS3D_VERTEX_ATTRIB_COLOR, 6, 4, 15, 24); | ||
733 | _set_vertex_data_from_array(me, 0, cube_vertices, EVAS_CANVAS3D_VERTEX_ATTRIB_TEXCOORD, 10, 2, 15, 24); | ||
734 | _set_vertex_data_from_array(me, 0, cube_vertices, EVAS_CANVAS3D_VERTEX_ATTRIB_TANGENT, 12, 3, 15, 24); | ||
637 | 735 | ||
638 | evas_canvas3d_mesh_frame_material_set(0, mi), | 736 | #endif |
639 | 737 | ||
738 | eo_do(me, | ||
739 | evas_canvas3d_mesh_vertex_assembly_set(EVAS_CANVAS3D_VERTEX_ASSEMBLY_TRIANGLES), | ||
740 | evas_canvas3d_mesh_shade_mode_set(EVAS_CANVAS3D_SHADE_MODE_NORMAL_MAP), | ||
741 | evas_canvas3d_mesh_frame_material_set(0, mi), | ||
640 | evas_canvas3d_mesh_frame_add(20), | 742 | evas_canvas3d_mesh_frame_add(20), |
641 | evas_canvas3d_mesh_frame_material_set(20, mj) | 743 | evas_canvas3d_mesh_frame_material_set(20, mj) |
642 | ); | 744 | ); |
745 | |||
643 | eina_array_push(stuffs->mesh, me); | 746 | eina_array_push(stuffs->mesh, me); |
644 | } | 747 | } |
645 | else if (MT_SPHERE == stuffs->stuffs.details.mesh->type) | 748 | else if (MT_SPHERE == stuffs->stuffs.details.mesh->type) |
@@ -665,13 +768,16 @@ void stuffsSetup(ExtantzStuffs *stuffs, Scene_Data *scene, int fake) | |||
665 | 768 | ||
666 | eina_accessor_data_get(stuffs->aMaterial, 0, (void **) &mi); | 769 | eina_accessor_data_get(stuffs->aMaterial, 0, (void **) &mi); |
667 | 770 | ||
771 | // Attempt to create a heightfield. | ||
668 | terrain = eo_add(EVAS_CANVAS3D_PRIMITIVE_CLASS, scene->evas); | 772 | terrain = eo_add(EVAS_CANVAS3D_PRIMITIVE_CLASS, scene->evas); |
669 | eo_do(terrain, evas_canvas3d_primitive_form_set(EVAS_CANVAS3D_MESH_PRIMITIVE_TERRAIN)); | 773 | eo_do(terrain, evas_canvas3d_primitive_form_set(EVAS_CANVAS3D_MESH_PRIMITIVE_SURFACE), |
670 | 774 | evas_canvas3d_primitive_precision_set(256), | |
775 | evas_canvas3d_primitive_tex_scale_set(1.0, 1.0), | ||
776 | evas_canvas3d_primitive_surface_set(_SL_RAW_terrain) | ||
777 | ); | ||
671 | me = eo_add(EVAS_CANVAS3D_MESH_CLASS, scene->evas, | 778 | me = eo_add(EVAS_CANVAS3D_MESH_CLASS, scene->evas, |
672 | evas_canvas3d_mesh_from_primitive_set(0, terrain), | 779 | evas_canvas3d_mesh_from_primitive_set(0, terrain), |
673 | evas_canvas3d_mesh_frame_material_set(0, mi), | 780 | evas_canvas3d_mesh_frame_material_set(0, mi), |
674 | |||
675 | evas_canvas3d_mesh_shade_mode_set(EVAS_CANVAS3D_SHADE_MODE_DIFFUSE) | 781 | evas_canvas3d_mesh_shade_mode_set(EVAS_CANVAS3D_SHADE_MODE_DIFFUSE) |
676 | ); | 782 | ); |
677 | eina_array_push(stuffs->mesh, me); | 783 | eina_array_push(stuffs->mesh, me); |
@@ -708,7 +814,6 @@ void stuffsSetup(ExtantzStuffs *stuffs, Scene_Data *scene, int fake) | |||
708 | stuffs->animateStuffs = (aniStuffs) _animateSonic; | 814 | stuffs->animateStuffs = (aniStuffs) _animateSonic; |
709 | // else if (4 == fake) | 815 | // else if (4 == fake) |
710 | // stuffs->animateStuffs = (aniStuffs) _animateSphere; | 816 | // stuffs->animateStuffs = (aniStuffs) _animateSphere; |
711 | |||
712 | } | 817 | } |
713 | 818 | ||
714 | ExtantzStuffs *addStuffs(char *uuid, char *name, char *description, char *owner, | 819 | ExtantzStuffs *addStuffs(char *uuid, char *name, char *description, char *owner, |