summaryrefslogtreecommitdiff
path: root/src/examples/evas/evas-3d-aabb.c
diff options
context:
space:
mode:
authorBogdan Devichev <b.devichev@samsung.com>2015-03-18 14:33:25 +0100
committerCedric BAIL <cedric@osg.samsung.com>2015-03-18 15:22:20 +0100
commite1b4303df3cdd36b5fb33fcc9a0a39a41233784a (patch)
tree01b7aa5b3abc1c157ec5aaf4631384063be1e50a /src/examples/evas/evas-3d-aabb.c
parenta2065e3b10a0125f5c42e0889245f30c5aa80157 (diff)
evas: aabb example uses cube primitives.
Reviewers: Hermet, raster, cedric Reviewed By: cedric Subscribers: cedric Differential Revision: https://phab.enlightenment.org/D2161 Signed-off-by: Cedric BAIL <cedric@osg.samsung.com>
Diffstat (limited to 'src/examples/evas/evas-3d-aabb.c')
-rw-r--r--src/examples/evas/evas-3d-aabb.c79
1 files changed, 12 insertions, 67 deletions
diff --git a/src/examples/evas/evas-3d-aabb.c b/src/examples/evas/evas-3d-aabb.c
index f6009ba..8791b75 100644
--- a/src/examples/evas/evas-3d-aabb.c
+++ b/src/examples/evas/evas-3d-aabb.c
@@ -1,11 +1,11 @@
1/** 1/**
2 * This example shows how to get and draw axis-aligned bounding box. 2 * This example shows how to get and draw axis-aligned bounding box.
3 * 3 *
4 * @see _mesh_aabb(Evas_3D_Mesh **mesh_b, const Evas_3D_Node *node); 4 * @see _redraw_aabb();
5 * Rotate axises (keys 1-4) for model and bounding box view from another angle. 5 * Rotate axises (keys 1-4) for model and bounding box view from another angle.
6 * 6 *
7 * @verbatim 7 * @verbatim
8 * gcc -o evas-3d-aabb evas-3d-aabb.c `pkg-config --libs --cflags efl evas ecore ecore-evas eo` 8 * gcc -o evas-3d-aabb evas-3d-aabb.c evas-3d-primitives.c `pkg-config --libs --cflags efl evas ecore ecore-evas eo` -lm
9 * @endverbatim 9 * @endverbatim
10 */ 10 */
11 11
@@ -22,6 +22,7 @@
22#include <Ecore.h> 22#include <Ecore.h>
23#include <Ecore_Evas.h> 23#include <Ecore_Evas.h>
24#include "evas-common.h" 24#include "evas-common.h"
25#include "evas-3d-primitives.h"
25 26
26#define WIDTH 400 27#define WIDTH 400
27#define HEIGHT 400 28#define HEIGHT 400
@@ -50,7 +51,7 @@ Eo *light = NULL;
50 51
51 52
52static Eina_Bool 53static Eina_Bool
53_mesh_aabb(Evas_3D_Mesh **mesh_b); 54_redraw_aabb();
54 55
55static Eina_Bool 56static Eina_Bool
56_animate_scene(void *data) 57_animate_scene(void *data)
@@ -59,7 +60,7 @@ _animate_scene(void *data)
59 60
60 eo_do((Evas_3D_Node *)data, evas_3d_node_mesh_frame_set(mesh, frame)); 61 eo_do((Evas_3D_Node *)data, evas_3d_node_mesh_frame_set(mesh, frame));
61 62
62 _mesh_aabb(&mesh_box); 63 _redraw_aabb();
63 64
64 frame += 32; 65 frame += 32;
65 66
@@ -116,68 +117,13 @@ _on_canvas_resize(Ecore_Evas *ee)
116} 117}
117 118
118static Eina_Bool 119static Eina_Bool
119_mesh_aabb(Evas_3D_Mesh **mesh_b) 120_redraw_aabb()
120{ 121{
121 Evas_Real x0, y0, z0, x1, y1, z1; 122 Evas_Real x0, y0, z0, x1, y1, z1;
122 123
123 eo_do(mesh_node, evas_3d_node_bounding_box_get(&x0, &y0, &z0, &x1, &y1, &z1)); 124 eo_do(mesh_node, evas_3d_node_bounding_box_get(&x0, &y0, &z0, &x1, &y1, &z1));
124 125 eo_do(mesh_box_node, evas_3d_node_position_set((x0 + x1)/2, (y0 + y1)/2, (z0 + z1)/2),
125 float vertices[] = 126 evas_3d_node_scale_set(x1 - x0, y1 - y0, z1 - z0));
126 {
127 x0, y0, z1,
128 x0, y1, z1,
129 x1, y1, z1,
130 x1, y0, z1,
131
132 x0, y0, z0,
133 x1, y0, z0,
134 x0, y1, z0,
135 x1, y1, z0,
136
137 x0, y0, z0,
138 x0, y1, z0,
139 x0, y0, z1,
140 x0, y1, z1,
141
142 x1, y0, z0,
143 x1, y1, z0,
144 x1, y1, z1,
145 x1, y0, z1,
146
147 x0, y1, z0,
148 x1, y1, z0,
149 x0, y1, z1,
150 x1, y1, z1,
151
152 x0, y0, z0,
153 x1, y0, z0,
154 x1, y0, z1,
155 x0, y0, z1
156 };
157
158 unsigned short indices[] =
159 {
160 0, 1, 2, 3, 1, 2, 0, 3,
161 4, 5, 5, 7, 7, 6, 6, 4,
162 8, 9, 9, 11, 11, 10, 10, 8,
163 12, 13, 13, 14, 14, 15, 15, 12,
164 16, 17, 17, 19, 19, 18, 18, 16,
165 20, 21, 21, 22, 22, 23, 23, 20
166 };
167
168 float *cube_vertices = (float *) malloc(1 * sizeof(vertices));
169 unsigned short *cube_indices = (unsigned short *) malloc(1 * sizeof(indices));
170 memcpy(cube_vertices, vertices, sizeof(vertices));
171 memcpy(cube_indices, indices, sizeof(indices));
172
173 eo_do(*mesh_b,
174 evas_3d_mesh_frame_vertex_data_copy_set(0, EVAS_3D_VERTEX_POSITION,
175 3 * sizeof(float),
176 &cube_vertices[ 0]),
177 evas_3d_mesh_index_data_copy_set(EVAS_3D_INDEX_FORMAT_UNSIGNED_SHORT,
178 48, &cube_indices[0]));
179 free(cube_vertices);
180 free(cube_indices);
181 127
182 return EINA_TRUE; 128 return EINA_TRUE;
183} 129}
@@ -272,14 +218,13 @@ main(void)
272 material_box = eo_add(EVAS_3D_MATERIAL_CLASS, evas); 218 material_box = eo_add(EVAS_3D_MATERIAL_CLASS, evas);
273 eo_do(material_box, evas_3d_material_enable_set(EVAS_3D_MATERIAL_DIFFUSE, EINA_TRUE)); 219 eo_do(material_box, evas_3d_material_enable_set(EVAS_3D_MATERIAL_DIFFUSE, EINA_TRUE));
274 220
275 mesh_box = eo_add(EVAS_3D_MESH_CLASS, evas); 221 mesh_box = eo_add(EVAS_3D_MESH_CLASS, evas);
276 eo_do(mesh_box, 222 evas_3d_add_cube_frame(mesh_box, 0);
277 evas_3d_mesh_vertex_count_set(24), 223 eo_do(mesh_box,
278 evas_3d_mesh_frame_add(0),
279 evas_3d_mesh_vertex_assembly_set(EVAS_3D_VERTEX_ASSEMBLY_LINES), 224 evas_3d_mesh_vertex_assembly_set(EVAS_3D_VERTEX_ASSEMBLY_LINES),
280 evas_3d_mesh_shade_mode_set(EVAS_3D_SHADE_MODE_DIFFUSE), 225 evas_3d_mesh_shade_mode_set(EVAS_3D_SHADE_MODE_DIFFUSE),
281 evas_3d_mesh_frame_material_set(0, material_box)); 226 evas_3d_mesh_frame_material_set(0, material_box));
282 _mesh_aabb(&mesh_box); 227 _redraw_aabb();
283 228
284 eo_do(root_node, 229 eo_do(root_node,
285 evas_3d_node_member_add(mesh_box_node)); 230 evas_3d_node_member_add(mesh_box_node));