summaryrefslogtreecommitdiff
path: root/src/examples
diff options
context:
space:
mode:
authorBogdan Devichev <b.devichev@samsung.com>2015-04-07 09:17:23 +0900
committerChunEon Park <chuneon.park@samsung.com>2015-04-07 09:17:24 +0900
commit509304645a38131dfcef5c0cda927d9fa3846a86 (patch)
treeebf0752e06fcd0f869f2c2f97dce80fb4b07e50f /src/examples
parent7fc3e1e3c24ec45cb48020624970c082d694179e (diff)
evas-3d: blending example uses spheres from primitives
Reviewers: Hermet, raster, cedric Subscribers: cedric Differential Revision: https://phab.enlightenment.org/D2162
Diffstat (limited to 'src/examples')
-rw-r--r--src/examples/evas/evas-3d-blending.c94
1 files changed, 16 insertions, 78 deletions
diff --git a/src/examples/evas/evas-3d-blending.c b/src/examples/evas/evas-3d-blending.c
index 5e47739..2176fde 100644
--- a/src/examples/evas/evas-3d-blending.c
+++ b/src/examples/evas/evas-3d-blending.c
@@ -4,18 +4,18 @@
4 * For more detailes see https://www.opengl.org/sdk/docs/man2/xhtml/glBlendFunc.xml 4 * For more detailes see https://www.opengl.org/sdk/docs/man2/xhtml/glBlendFunc.xml
5 * 5 *
6 * @verbatim 6 * @verbatim
7 * gcc -o evas-3d-blending evas-3d-blending.c `pkg-config --libs --cflags evas ecore ecore-evas eo`-lm 7 * gcc -o evas-3d-blending evas-3d-blending.c evas-3d-primitives.c `pkg-config --libs --cflags evas ecore ecore-evas eo`-lm
8 * @endverbatim 8 * @endverbatim
9 */ 9 */
10 10
11#define EFL_EO_API_SUPPORT 11#define EFL_EO_API_SUPPORT
12#define EFL_BETA_API_SUPPORT 12#define EFL_BETA_API_SUPPORT
13 13
14#include <math.h>
15#include <Eo.h> 14#include <Eo.h>
16#include <Evas.h> 15#include <Evas.h>
17#include <Ecore.h> 16#include <Ecore.h>
18#include <Ecore_Evas.h> 17#include <Ecore_Evas.h>
18#include "evas-3d-primitives.h"
19 19
20#define WIDTH 1024 20#define WIDTH 1024
21#define HEIGHT 1024 21#define HEIGHT 1024
@@ -71,20 +71,7 @@ typedef struct _Scene_Data
71 Eo *material1; 71 Eo *material1;
72} Scene_Data; 72} Scene_Data;
73 73
74typedef struct _vec3 74static const vec2 tex_scale = {1, 1};
75{
76 float x;
77 float y;
78 float z;
79} vec3;
80
81typedef struct _vec4
82{
83 float x;
84 float y;
85 float z;
86 float w;
87} vec4;
88 75
89Evas *evas = NULL; 76Evas *evas = NULL;
90Eo *background = NULL; 77Eo *background = NULL;
@@ -200,65 +187,11 @@ _light_setup(Scene_Data *data)
200static void 187static void
201_set_ball(Eo *mesh, int p, Evas_3D_Material *material) 188_set_ball(Eo *mesh, int p, Evas_3D_Material *material)
202{ 189{
203 int vcount, icount, vccount, i, j; 190
204 double dtheta, dfi, sinth, costh, fi, theta, sinfi, cosfi; 191 evas_3d_add_sphere_frame(mesh, 0, p, tex_scale);
205 unsigned short *indices, *index; 192 eo_do(mesh,
206 193 evas_3d_mesh_frame_material_set(0, material),
207 icount = p * p * 6; 194 evas_3d_mesh_shade_mode_set(EVAS_3D_SHADE_MODE_PHONG));
208 vccount = p + 1;
209 vcount = vccount * vccount;
210
211 dtheta = M_PI / p;
212 dfi = 2 * M_PI / p;
213
214 vec3 *vertices = malloc(sizeof(vec3) * vcount);
215 vec3 *normals = malloc(sizeof(vec3) * vcount);
216
217 for (j = 0; j < vccount; j++)
218 {
219 theta = j * dtheta;
220 sinth = sin(theta);
221 costh = cos(theta);
222 for (i = 0; i < vccount; i++)
223 {
224 fi = i * dfi;
225 sinfi = sin(fi);
226 cosfi = cos(fi);
227 vertices[i + j * vccount].x = sinth * cosfi;
228 vertices[i + j * vccount].y = sinth * sinfi;
229 vertices[i + j * vccount].z = costh;
230
231 normals[i + j * vccount].x = sinth * cosfi;
232 normals[i + j * vccount].y = sinth * sinfi;
233 normals[i + j * vccount].z = costh;
234 }
235 }
236
237 indices = malloc(sizeof(short) * icount);
238 index = &indices[0];
239
240 for(j = 0; j < p; j++)
241 for(i = 0; i < p; i++)
242 {
243 *index++ = (unsigned short)(i + vccount * j);
244 *index++ = i + vccount * (j + 1);
245 *index++ = i + 1 + vccount * (j + 1);
246
247 *index++ = i + vccount * j;
248 *index++ = i + 1 + vccount * j;
249 *index++ = i + vccount * (j + 1) + 1;
250 }
251
252 eo_do(mesh, evas_3d_mesh_vertex_count_set(vcount),
253 evas_3d_mesh_frame_add(0);
254 evas_3d_mesh_frame_vertex_data_set(0, EVAS_3D_VERTEX_POSITION,
255 sizeof(vec3), &vertices[0]);
256 evas_3d_mesh_frame_vertex_data_set(0, EVAS_3D_VERTEX_NORMAL,
257 sizeof(vec3), &normals[0]);
258 evas_3d_mesh_index_data_set(EVAS_3D_INDEX_FORMAT_UNSIGNED_SHORT,
259 icount , &indices[0]);
260 evas_3d_mesh_shade_mode_set(EVAS_3D_SHADE_MODE_PHONG);
261 evas_3d_mesh_frame_material_set(0, material));
262} 195}
263 196
264static void 197static void
@@ -291,8 +224,8 @@ _mesh_setup(Scene_Data *data)
291 data->mesh = eo_add(EVAS_3D_MESH_CLASS, evas); 224 data->mesh = eo_add(EVAS_3D_MESH_CLASS, evas);
292 data->mesh1 = eo_add(EVAS_3D_MESH_CLASS, evas); 225 data->mesh1 = eo_add(EVAS_3D_MESH_CLASS, evas);
293 226
294 _set_ball(data->mesh, 100, data->material); 227 _set_ball(data->mesh, 50, data->material);
295 _set_ball(data->mesh1, 100, data->material1); 228 _set_ball(data->mesh1, 50, data->material1);
296 229
297 data->mesh_node = 230 data->mesh_node =
298 eo_add(EVAS_3D_NODE_CLASS, evas, 231 eo_add(EVAS_3D_NODE_CLASS, evas,
@@ -311,8 +244,13 @@ _mesh_setup(Scene_Data *data)
311 eo_do(data->mesh1, evas_3d_mesh_blending_enable_set(EINA_TRUE), 244 eo_do(data->mesh1, evas_3d_mesh_blending_enable_set(EINA_TRUE),
312 evas_3d_mesh_blending_func_set(func1, func2)); 245 evas_3d_mesh_blending_func_set(func1, func2));
313 246
247 eo_do(data->mesh_node,
248 evas_3d_node_scale_set(2.0, 2.0, 2.0),
249 evas_3d_node_orientation_angle_axis_set(90.0, 1.0, 0.0, 0.0));
250
314 eo_do(data->mesh_node1, 251 eo_do(data->mesh_node1,
315 evas_3d_node_scale_set(2.5, 2.5, 2.5)); 252 evas_3d_node_scale_set(5.0, 5.0, 5.0),
253 evas_3d_node_orientation_angle_axis_set(90.0, 1.0, 0.0, 0.0));
316} 254}
317 255
318static void 256static void