evas: cube2 example uses cube primitives.
authorBogdan Devichev <b.devichev@samsung.com>
Wed, 18 Mar 2015 13:35:37 +0000 (14:35 +0100)
committerCedric BAIL <cedric@osg.samsung.com>
Wed, 18 Mar 2015 14:22:20 +0000 (15:22 +0100)
Reviewers: Hermet, raster, cedric

Reviewed By: cedric

Subscribers: cedric

Differential Revision: https://phab.enlightenment.org/D2164

Signed-off-by: Cedric BAIL <cedric@osg.samsung.com>
src/examples/evas/evas-3d-cube2.c

index ead599a..4a1afaa 100644 (file)
@@ -3,7 +3,7 @@
  * by interpolation between frames.
  *
  * @verbatim
- * gcc -o evas-3d-cube2 evas-3d-cube2.c `pkg-config --libs --cflags evas ecore ecore-evas eo`
+ * gcc -o evas-3d-cube2 evas-3d-cube2.c evas-3d-primitives.c `pkg-config --libs --cflags evas ecore ecore-evas eo` -lm
  * @endverbatim
  */
 
@@ -19,6 +19,7 @@
 #include <Evas.h>
 #include <Ecore.h>
 #include <Ecore_Evas.h>
+#include "evas-3d-primitives.h"
 #include "evas-common.h"
 
 #define  WIDTH          400
@@ -50,66 +51,6 @@ static Evas *evas = NULL;
 static Eo *background = NULL;
 static Eo *image = NULL;
 
-static const float cube_vertices[] =
-{
-   /* Front */
-   -1.0,  1.0,  1.0,     0.0,  0.0,  1.0,     1.0, 0.0, 0.0, 1.0,     0.0,  1.0,
-    1.0,  1.0,  1.0,     0.0,  0.0,  1.0,     1.0, 0.0, 0.0, 1.0,     1.0,  1.0,
-   -1.0, -1.0,  1.0,     0.0,  0.0,  1.0,     1.0, 0.0, 0.0, 1.0,     0.0,  0.0,
-    1.0, -1.0,  1.0,     0.0,  0.0,  1.0,     1.0, 0.0, 0.0, 1.0,     1.0,  0.0,
-
-   /* Back */
-    1.0,  1.0, -1.0,     0.0,  0.0, -1.0,     0.0, 0.0, 1.0, 1.0,     0.0,  1.0,
-   -1.0,  1.0, -1.0,     0.0,  0.0, -1.0,     0.0, 0.0, 1.0, 1.0,     1.0,  1.0,
-    1.0, -1.0, -1.0,     0.0,  0.0, -1.0,     0.0, 0.0, 1.0, 1.0,     0.0,  0.0,
-   -1.0, -1.0, -1.0,     0.0,  0.0, -1.0,     0.0, 0.0, 1.0, 1.0,     1.0,  0.0,
-
-   /* Left */
-   -1.0,  1.0, -1.0,    -1.0,  0.0,  0.0,     0.0, 1.0, 0.0, 1.0,     0.0,  1.0,
-   -1.0,  1.0,  1.0,    -1.0,  0.0,  0.0,     0.0, 1.0, 0.0, 1.0,     1.0,  1.0,
-   -1.0, -1.0, -1.0,    -1.0,  0.0,  0.0,     0.0, 1.0, 0.0, 1.0,     0.0,  0.0,
-   -1.0, -1.0,  1.0,    -1.0,  0.0,  0.0,     0.0, 1.0, 0.0, 1.0,     1.0,  0.0,
-
-   /* Right */
-    1.0,  1.0,  1.0,     1.0,  0.0,  0.0,     1.0, 1.0, 0.0, 1.0,     0.0,  1.0,
-    1.0,  1.0, -1.0,     1.0,  0.0,  0.0,     1.0, 1.0, 0.0, 1.0,     1.0,  1.0,
-    1.0, -1.0,  1.0,     1.0,  0.0,  0.0,     1.0, 1.0, 0.0, 1.0,     0.0,  0.0,
-    1.0, -1.0, -1.0,     1.0,  0.0,  0.0,     1.0, 1.0, 0.0, 1.0,     1.0,  0.0,
-
-   /* Top */
-   -1.0,  1.0, -1.0,     0.0,  1.0,  0.0,     1.0, 0.0, 1.0, 1.0,     0.0,  1.0,
-    1.0,  1.0, -1.0,     0.0,  1.0,  0.0,     1.0, 0.0, 1.0, 1.0,     1.0,  1.0,
-   -1.0,  1.0,  1.0,     0.0,  1.0,  0.0,     1.0, 0.0, 1.0, 1.0,     0.0,  0.0,
-    1.0,  1.0,  1.0,     0.0,  1.0,  0.0,     1.0, 0.0, 1.0, 1.0,     1.0,  0.0,
-
-   /* Bottom */
-    1.0, -1.0, -1.0,     0.0, -1.0,  0.0,     0.0, 1.0, 1.0, 1.0,     0.0,  1.0,
-   -1.0, -1.0, -1.0,     0.0, -1.0,  0.0,     0.0, 1.0, 1.0, 1.0,     1.0,  1.0,
-    1.0, -1.0,  1.0,     0.0, -1.0,  0.0,     0.0, 1.0, 1.0, 1.0,     0.0,  0.0,
-   -1.0, -1.0,  1.0,     0.0, -1.0,  0.0,     0.0, 1.0, 1.0, 1.0,     1.0,  0.0,
-};
-
-static const unsigned short cube_indices[] =
-{
-   /* Front */
-   0,   1,  2,  2,  1,  3,
-
-   /* Back */
-   4,   5,  6,  6,  5,  7,
-
-   /* Left */
-   8,   9, 10, 10,  9, 11,
-
-   /* Right */
-   12, 13, 14, 14, 13, 15,
-
-   /* Top */
-   16, 17, 18, 18, 17, 19,
-
-   /* Bottom */
-   20, 21, 22, 22, 21, 23
-};
-
 static const unsigned int pixels0[] =
 {
    0xff0000ff, 0xff0000ff, 0xffff0000, 0xffff0000,
@@ -180,7 +121,7 @@ _camera_setup(Scene_Data *data)
                     evas_3d_node_constructor(EVAS_3D_NODE_TYPE_CAMERA));
    eo_do(data->camera_node,
          evas_3d_node_camera_set(data->camera),
-         evas_3d_node_position_set(0.0, 0.0, 10.0),
+         evas_3d_node_position_set(0.0, 0.0, 3.0),
          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));
    eo_do(data->root_node,
@@ -258,29 +199,12 @@ _mesh_setup(Scene_Data *data)
 
    /* Setup mesh. */
    data->mesh = eo_add(EVAS_3D_MESH_CLASS, evas);
+   evas_3d_add_cube_frame(data->mesh, 0);
    eo_do(data->mesh,
-         evas_3d_mesh_vertex_count_set(24),
-         evas_3d_mesh_frame_add(0),
-
-         evas_3d_mesh_frame_vertex_data_set(0, EVAS_3D_VERTEX_POSITION,
-                                            12 * sizeof(float), &cube_vertices[0]),
-         evas_3d_mesh_frame_vertex_data_set(0, EVAS_3D_VERTEX_NORMAL,
-                                            12 * sizeof(float), &cube_vertices[3]),
-         evas_3d_mesh_frame_vertex_data_set(0, EVAS_3D_VERTEX_COLOR,
-                                            12 * sizeof(float), &cube_vertices[6]),
-         evas_3d_mesh_frame_vertex_data_set(0, EVAS_3D_VERTEX_TEXCOORD,
-                                            12 * sizeof(float), &cube_vertices[10]),
-
-         evas_3d_mesh_index_data_set(EVAS_3D_INDEX_FORMAT_UNSIGNED_SHORT,
-                                     36, &cube_indices[0]),
-         evas_3d_mesh_vertex_assembly_set(EVAS_3D_VERTEX_ASSEMBLY_TRIANGLES),
-
-         evas_3d_mesh_shade_mode_set(EVAS_3D_SHADE_MODE_NORMAL_MAP),
-
          evas_3d_mesh_frame_material_set(0, data->material0),
-
          evas_3d_mesh_frame_add(20),
-         evas_3d_mesh_frame_material_set(20, data->material1));
+         evas_3d_mesh_frame_material_set(20, data->material1),
+         evas_3d_mesh_shade_mode_set(EVAS_3D_SHADE_MODE_NORMAL_MAP));
 
    data->mesh_node =
       eo_add(EVAS_3D_NODE_CLASS, evas,