summaryrefslogtreecommitdiff
path: root/src/examples
diff options
context:
space:
mode:
authorBogdan Devichev <b.devichev@samsung.com>2015-04-07 09:14:41 +0900
committerChunEon Park <chuneon.park@samsung.com>2015-04-07 09:14:42 +0900
commit7fc3e1e3c24ec45cb48020624970c082d694179e (patch)
treefec107a58ab09bb108b07e1724131033afd95fda /src/examples
parentc3dc01ef3244383458d2d2288762adcc79d19f20 (diff)
evas-3d: fog example uses spheres from primitives
Reviewers: Hermet, raster, cedric Subscribers: cedric Differential Revision: https://phab.enlightenment.org/D2166
Diffstat (limited to 'src/examples')
-rw-r--r--src/examples/evas/evas-3d-fog.c106
1 files changed, 21 insertions, 85 deletions
diff --git a/src/examples/evas/evas-3d-fog.c b/src/examples/evas/evas-3d-fog.c
index 573b8e7..fb93ad5 100644
--- a/src/examples/evas/evas-3d-fog.c
+++ b/src/examples/evas/evas-3d-fog.c
@@ -2,7 +2,7 @@
2 * Example illustrating usage of fog effect. 2 * Example illustrating usage of fog effect.
3 * 3 *
4 * @verbatim 4 * @verbatim
5 * gcc -o evas-3d-fog evas-3d-fog.c `pkg-config --libs --cflags evas ecore ecore-evas eo`-lm 5 * gcc -o evas-3d-fog evas-3d-fog.c evas-3d-primitives.c `pkg-config --libs --cflags evas ecore ecore-evas eo`-lm
6 * @endverbatim 6 * @endverbatim
7 */ 7 */
8 8
@@ -14,6 +14,7 @@
14#include <Evas.h> 14#include <Evas.h>
15#include <Ecore.h> 15#include <Ecore.h>
16#include <Ecore_Evas.h> 16#include <Ecore_Evas.h>
17#include "evas-3d-primitives.h"
17 18
18#define WIDTH 1024 19#define WIDTH 1024
19#define HEIGHT 1024 20#define HEIGHT 1024
@@ -30,6 +31,7 @@ typedef struct _Scene_Data
30 Eo *light_node; 31 Eo *light_node;
31 Eo *mesh_node; 32 Eo *mesh_node;
32 Eo *mesh_node1; 33 Eo *mesh_node1;
34 Eo *animation_node;
33 35
34 Eo *camera; 36 Eo *camera;
35 Eo *light; 37 Eo *light;
@@ -38,27 +40,13 @@ typedef struct _Scene_Data
38 Eo *material; 40 Eo *material;
39} Scene_Data; 41} Scene_Data;
40 42
41typedef struct _vec3 43static const vec2 tex_scale = {1, 1};
42{
43 float x;
44 float y;
45 float z;
46} vec3;
47
48typedef struct _vec4
49{
50 float x;
51 float y;
52 float z;
53 float w;
54} vec4;
55 44
56Ecore_Evas *ecore_evas = NULL; 45Ecore_Evas *ecore_evas = NULL;
57Evas *evas = NULL; 46Evas *evas = NULL;
58Eo *background = NULL; 47Eo *background = NULL;
59Eo *image = NULL; 48Eo *image = NULL;
60 49
61
62static void 50static void
63_on_delete(Ecore_Evas *ee EINA_UNUSED) 51_on_delete(Ecore_Evas *ee EINA_UNUSED)
64{ 52{
@@ -85,7 +73,7 @@ _animate_scene(void *data)
85 73
86 angle += 0.5; 74 angle += 0.5;
87 75
88 eo_do(scene->mesh_node, 76 eo_do(scene->animation_node,
89 evas_3d_node_orientation_angle_axis_set(angle, 0.0, 1.0, 0.0)); 77 evas_3d_node_orientation_angle_axis_set(angle, 0.0, 1.0, 0.0));
90 78
91 if (angle > 360.0) angle -= 360.0f; 79 if (angle > 360.0) angle -= 360.0f;
@@ -135,68 +123,12 @@ _light_setup(Scene_Data *data)
135} 123}
136 124
137static void 125static void
138_set_ball(Eo *mesh, double r, double x, double y, double z, int p, Evas_3D_Material *material) 126_set_ball(Eo *mesh, int p, Evas_3D_Material *material)
139{ 127{
140 int vcount, icount, vccount, i, j; 128 evas_3d_add_sphere_frame(mesh, 0, p, tex_scale);
141 double dtheta, dfi, sinth, costh, fi, theta, sinfi, cosfi; 129
142 unsigned short *indices, *index; 130 eo_do(mesh, evas_3d_mesh_shade_mode_set(EVAS_3D_SHADE_MODE_PHONG),
143 131 evas_3d_mesh_frame_material_set(0, material));
144 icount = p * p * 6;
145 vccount = p + 1;
146 vcount = vccount * vccount;
147
148 dtheta = pi / p;
149 dfi = 2 * pi / p;
150
151 vec3 *vertices = malloc(sizeof(vec3) * vcount);
152 vec3 *normals = malloc(sizeof(vec3) * vcount);
153
154 for (j = 0; j < vccount; j++)
155 {
156 theta = j * dtheta;
157 sinth = sin(theta);
158 costh = cos(theta);
159 for (i = 0; i < vccount; i++)
160 {
161 fi = i * dfi;
162 sinfi = sin(fi);
163 cosfi = cos(fi);
164 vertices[i + j * vccount].x = r * sinth * cosfi + x;
165 vertices[i + j * vccount].y = r * sinth * sinfi + y;
166 vertices[i + j * vccount].z = r * costh + z;
167
168 normals[i + j * vccount].x = sinth * cosfi;
169 normals[i + j * vccount].y = sinth * sinfi;
170 normals[i + j * vccount].z = costh;
171 }
172 }
173
174 indices = malloc(sizeof(short) * icount);
175 index = &indices[0];
176
177 for(j = 0; j < p; j++)
178 for(i = 0; i < p; i++)
179 {
180 *index++ = (unsigned short)(i + vccount * j);
181 *index++ = i + vccount * (j + 1);
182 *index++ = i + 1 + vccount * (j + 1);
183
184 *index++ = i + vccount * j;
185 *index++ = i + 1 + vccount * j;
186 *index++ = i + vccount * (j + 1) + 1;
187 }
188
189 eo_do(mesh, evas_3d_mesh_vertex_count_set(vcount),
190 evas_3d_mesh_frame_add(0);
191 evas_3d_mesh_frame_vertex_data_set(0, EVAS_3D_VERTEX_POSITION,
192 sizeof(vec3), &vertices[0]);
193 evas_3d_mesh_frame_vertex_data_set(0, EVAS_3D_VERTEX_NORMAL,
194 sizeof(vec3), &normals[0]);
195 evas_3d_mesh_index_data_set(EVAS_3D_INDEX_FORMAT_UNSIGNED_SHORT,
196 icount , &indices[0]);
197 evas_3d_mesh_vertex_assembly_set(EVAS_3D_VERTEX_ASSEMBLY_TRIANGLES);
198 evas_3d_mesh_shade_mode_set(EVAS_3D_SHADE_MODE_PHONG);
199 evas_3d_mesh_frame_material_set(0, material));
200} 132}
201 133
202 134
@@ -218,23 +150,29 @@ _mesh_setup(Scene_Data *data)
218 data->mesh = eo_add(EVAS_3D_MESH_CLASS, evas); 150 data->mesh = eo_add(EVAS_3D_MESH_CLASS, evas);
219 data->mesh1 = eo_add(EVAS_3D_MESH_CLASS, evas); 151 data->mesh1 = eo_add(EVAS_3D_MESH_CLASS, evas);
220 152
153 _set_ball(data->mesh, 100, data->material);
154 _set_ball(data->mesh1, 100, data->material);
221 155
222 _set_ball(data->mesh, 1, 4, 0, 0, 100, data->material); 156 data->animation_node =
223 _set_ball(data->mesh1, 2, 0, 0, 0, 100, data->material); 157 eo_add(EVAS_3D_NODE_CLASS, evas,
158 evas_3d_node_constructor(EVAS_3D_NODE_TYPE_NODE));
224 159
225 data->mesh_node = 160 data->mesh_node =
226 eo_add(EVAS_3D_NODE_CLASS, evas, 161 eo_add(EVAS_3D_NODE_CLASS, evas,
227 evas_3d_node_constructor(EVAS_3D_NODE_TYPE_MESH)); 162 evas_3d_node_constructor(EVAS_3D_NODE_TYPE_MESH));
228 163
229 eo_do(data->root_node, evas_3d_node_member_add(data->mesh_node)); 164 eo_do(data->animation_node, evas_3d_node_member_add(data->mesh_node));
230 eo_do(data->mesh_node, evas_3d_node_mesh_add(data->mesh)); 165 eo_do(data->root_node, evas_3d_node_member_add(data->animation_node));
166 eo_do(data->mesh_node, evas_3d_node_mesh_add(data->mesh),
167 evas_3d_node_position_set(0.0, 0.0, 3.0));
231 168
232 data->mesh_node1 = 169 data->mesh_node1 =
233 eo_add(EVAS_3D_NODE_CLASS, evas, 170 eo_add(EVAS_3D_NODE_CLASS, evas,
234 evas_3d_node_constructor(EVAS_3D_NODE_TYPE_MESH)); 171 evas_3d_node_constructor(EVAS_3D_NODE_TYPE_MESH));
235 172
236 eo_do(data->root_node, evas_3d_node_member_add(data->mesh_node1)); 173 eo_do(data->root_node, evas_3d_node_member_add(data->mesh_node1));
237 eo_do(data->mesh_node1, evas_3d_node_mesh_add(data->mesh1)); 174 eo_do(data->mesh_node1, evas_3d_node_mesh_add(data->mesh1),
175 evas_3d_node_scale_set(3, 3, 3));
238 176
239 eo_do(data->mesh, evas_3d_mesh_fog_enable_set(EINA_TRUE), evas_3d_mesh_fog_color_set(FOG_COLOR, FOG_FACTOR)); 177 eo_do(data->mesh, evas_3d_mesh_fog_enable_set(EINA_TRUE), evas_3d_mesh_fog_color_set(FOG_COLOR, FOG_FACTOR));
240 eo_do(data->mesh1, evas_3d_mesh_fog_enable_set(EINA_TRUE), evas_3d_mesh_fog_color_set(FOG_COLOR, FOG_FACTOR)); 178 eo_do(data->mesh1, evas_3d_mesh_fog_enable_set(EINA_TRUE), evas_3d_mesh_fog_color_set(FOG_COLOR, FOG_FACTOR));
@@ -265,7 +203,6 @@ _scene_setup(Scene_Data *data)
265int 203int
266main(void) 204main(void)
267{ 205{
268
269 //Unless Evas 3D supports Software renderer, we set gl backened forcely. 206 //Unless Evas 3D supports Software renderer, we set gl backened forcely.
270 setenv("ECORE_EVAS_ENGINE", "opengl_x11", 1); 207 setenv("ECORE_EVAS_ENGINE", "opengl_x11", 1);
271 Scene_Data data; 208 Scene_Data data;
@@ -302,7 +239,6 @@ main(void)
302 /* Set the image object as render target for 3D scene. */ 239 /* Set the image object as render target for 3D scene. */
303 eo_do(image, evas_obj_image_scene_set(data.scene)); 240 eo_do(image, evas_obj_image_scene_set(data.scene));
304 241
305
306 /* Add animation timer callback. */ 242 /* Add animation timer callback. */
307 ecore_animator_frametime_set(0.008); 243 ecore_animator_frametime_set(0.008);
308 anim = ecore_animator_add(_animate_scene, &data); 244 anim = ecore_animator_add(_animate_scene, &data);