summaryrefslogtreecommitdiff
path: root/src/examples/evas/evas-3d-cube2.c
diff options
context:
space:
mode:
authorChunEon Park <hermet@hermet.pe.kr>2014-04-30 21:40:47 +0900
committerChunEon Park <hermet@hermet.pe.kr>2014-04-30 21:40:47 +0900
commit4c35b22c2a48177135446989db83d225d53b0a2f (patch)
treeab98fa84415a0f748718ff6938b83165b12f280c /src/examples/evas/evas-3d-cube2.c
parent862488083b51ca5cc3acc86a6cd55781404db29e (diff)
evas/evas3d: rewrite evas-3d-cube2 example with eo based.
Diffstat (limited to 'src/examples/evas/evas-3d-cube2.c')
-rw-r--r--src/examples/evas/evas-3d-cube2.c291
1 files changed, 158 insertions, 133 deletions
diff --git a/src/examples/evas/evas-3d-cube2.c b/src/examples/evas/evas-3d-cube2.c
index 6603e85..7c90d1d 100644
--- a/src/examples/evas/evas-3d-cube2.c
+++ b/src/examples/evas/evas-3d-cube2.c
@@ -1,35 +1,38 @@
1#ifdef HAVE_CONFIG_H
2#include "config.h"
3#endif
4
5#include <Eo.h>
6#include <Evas.h>
1#include <Ecore.h> 7#include <Ecore.h>
2#include <Ecore_Evas.h> 8#include <Ecore_Evas.h>
3#include <stdio.h>
4#include <math.h>
5#include <Evas.h>
6 9
7#define WIDTH 1024 10#define WIDTH 400
8#define HEIGHT 1024 11#define HEIGHT 400
9 12
10typedef struct _Scene_Data 13typedef struct _Scene_Data
11{ 14{
12 Evas_3D_Scene *scene; 15 Eo *scene;
13 Evas_3D_Node *root_node; 16 Eo *root_node;
14 Evas_3D_Node *camera_node; 17 Eo *camera_node;
15 Evas_3D_Node *light_node; 18 Eo *light_node;
16 Evas_3D_Node *mesh_node; 19 Eo *mesh_node;
17 20
18 Evas_3D_Camera *camera; 21 Eo *camera;
19 Evas_3D_Light *light; 22 Eo *light;
20 Evas_3D_Mesh *mesh; 23 Eo *mesh;
21 Evas_3D_Material *material0; 24 Eo *material0;
22 Evas_3D_Material *material1; 25 Eo *material1;
23 26
24 Evas_3D_Texture *texture0; 27 Eo *texture0;
25 Evas_3D_Texture *texture1; 28 Eo *texture1;
26 Evas_3D_Texture *texture_normal; 29 Eo *texture_normal;
27} Scene_Data; 30} Scene_Data;
28 31
29Ecore_Evas *ecore_evas = NULL; 32static Ecore_Evas *ecore_evas = NULL;
30Evas *evas = NULL; 33static Evas *evas = NULL;
31Evas_Object *background = NULL; 34static Eo *background = NULL;
32Evas_Object *image = NULL; 35static Eo *image = NULL;
33 36
34static const float cube_vertices[] = 37static const float cube_vertices[] =
35{ 38{
@@ -119,10 +122,8 @@ _on_canvas_resize(Ecore_Evas *ee)
119 int w, h; 122 int w, h;
120 123
121 ecore_evas_geometry_get(ee, NULL, NULL, &w, &h); 124 ecore_evas_geometry_get(ee, NULL, NULL, &w, &h);
122 125 eo_do(background, evas_obj_size_set(w, h));
123 evas_object_resize(background, w, h); 126 eo_do(image, evas_obj_size_set(w, h));
124 evas_object_resize(image, w, h);
125 evas_object_move(image, 0, 0);
126} 127}
127 128
128static Eina_Bool 129static Eina_Bool
@@ -135,20 +136,18 @@ _animate_scene(void *data)
135 136
136 angle += 0.2; 137 angle += 0.2;
137 138
138 evas_3d_node_orientation_angle_axis_set(scene->mesh_node, angle, 1.0, 1.0, 1.0); 139 eo_do(scene->mesh_node,
140 evas_3d_node_orientation_angle_axis_set(angle, 1.0, 1.0, 1.0));
139 141
140 /* Rotate */ 142 /* Rotate */
141 if (angle > 360.0) 143 if (angle > 360.0) angle -= 360.0f;
142 angle -= 360.0f;
143 144
144 frame += inc; 145 frame += inc;
145 146
146 if (frame >= 20) 147 if (frame >= 20) inc = -1;
147 inc = -1; 148 else if (frame <= 0) inc = 1;
148 else if (frame <= 0)
149 inc = 1;
150 149
151 evas_3d_node_mesh_frame_set(scene->mesh_node, scene->mesh, frame); 150 eo_do(scene->mesh_node, evas_3d_node_mesh_frame_set(scene->mesh, frame));
152 151
153 return EINA_TRUE; 152 return EINA_TRUE;
154} 153}
@@ -156,119 +155,147 @@ _animate_scene(void *data)
156static void 155static void
157_camera_setup(Scene_Data *data) 156_camera_setup(Scene_Data *data)
158{ 157{
159 data->camera = evas_3d_camera_add(evas); 158 data->camera = eo_add(EVAS_3D_CAMERA_CLASS, evas);
160 evas_3d_camera_projection_perspective_set(data->camera, 60.0, 1.0, 2.0, 50.0); 159 eo_do(data->camera,
160 evas_3d_camera_projection_perspective_set(60.0, 1.0, 2.0, 50.0));
161 161
162// data->camera_node =
163// eo_add(EVAS_3D_NODE_CLASS, evas, EVAS_3D_NODE_TYPE_CAMERA);
162 data->camera_node = evas_3d_node_add(evas, EVAS_3D_NODE_TYPE_CAMERA); 164 data->camera_node = evas_3d_node_add(evas, EVAS_3D_NODE_TYPE_CAMERA);
163 evas_3d_node_camera_set(data->camera_node, data->camera); 165 eo_do(data->camera_node,
164 evas_3d_node_member_add(data->root_node, data->camera_node); 166 evas_3d_node_camera_set(data->camera));
165 evas_3d_node_position_set(data->camera_node, 0.0, 0.0, 10.0); 167 eo_do(data->root_node,
166 evas_3d_node_look_at_set(data->camera_node, EVAS_3D_SPACE_PARENT, 0.0, 0.0, 0.0, 168 evas_3d_node_member_add(data->camera_node));
167 EVAS_3D_SPACE_PARENT, 0.0, 1.0, 0.0); 169 eo_do(data->camera_node,
170 evas_3d_node_position_set(0.0, 0.0, 10.0),
171 evas_3d_node_look_at_set(EVAS_3D_SPACE_PARENT, 0.0, 0.0, 0.0,
172 EVAS_3D_SPACE_PARENT, 0.0, 1.0, 0.0));
168} 173}
169 174
170static void 175static void
171_light_setup(Scene_Data *data) 176_light_setup(Scene_Data *data)
172{ 177{
173 data->light = evas_3d_light_add(evas); 178 data->light = eo_add(EVAS_3D_LIGHT_CLASS, evas);
174 evas_3d_light_ambient_set(data->light, 0.2, 0.2, 0.2, 1.0); 179 eo_do(data->light,
175 evas_3d_light_diffuse_set(data->light, 1.0, 1.0, 1.0, 1.0); 180 evas_3d_light_ambient_set(0.2, 0.2, 0.2, 1.0),
176 evas_3d_light_specular_set(data->light, 1.0, 1.0, 1.0, 1.0); 181 evas_3d_light_diffuse_set(1.0, 1.0, 1.0, 1.0),
182 evas_3d_light_specular_set(1.0, 1.0, 1.0, 1.0));
177 183
184// data->light_node = eo_add(EVAS_3D_NODE_CLASS, evas, EVAS_3D_NODE_TYPE_LIGHT);
178 data->light_node = evas_3d_node_add(evas, EVAS_3D_NODE_TYPE_LIGHT); 185 data->light_node = evas_3d_node_add(evas, EVAS_3D_NODE_TYPE_LIGHT);
179 evas_3d_node_light_set(data->light_node, data->light); 186 eo_do(data->light_node,
180 evas_3d_node_member_add(data->root_node, data->light_node); 187 evas_3d_node_light_set(data->light));
181 evas_3d_node_position_set(data->light_node, 0.0, 0.0, 10.0); 188 eo_do(data->root_node,
182 evas_3d_node_look_at_set(data->light_node, EVAS_3D_SPACE_PARENT, 0.0, 0.0, 0.0, 189 evas_3d_node_member_add(data->light_node));
183 EVAS_3D_SPACE_PARENT, 0.0, 1.0, 0.0); 190 eo_do(data->light_node,
191 evas_3d_node_position_set(0.0, 0.0, 10.0),
192 evas_3d_node_look_at_set(EVAS_3D_SPACE_PARENT, 0.0, 0.0, 0.0,
193 EVAS_3D_SPACE_PARENT, 0.0, 1.0, 0.0));
184} 194}
185 195
186static void 196static void
187_mesh_setup(Scene_Data *data) 197_mesh_setup(Scene_Data *data)
188{ 198{
189 /* Setup material. */ 199 /* Setup material. */
190 data->material0 = evas_3d_material_add(evas); 200 data->material0 = eo_add(EVAS_3D_MATERIAL_CLASS, evas);
191 data->material1 = evas_3d_material_add(evas); 201 eo_do(data->material0,
192 202 evas_3d_material_enable_set(EVAS_3D_MATERIAL_AMBIENT, EINA_TRUE),
193 evas_3d_material_enable_set(data->material0, EVAS_3D_MATERIAL_AMBIENT, EINA_TRUE); 203 evas_3d_material_enable_set(EVAS_3D_MATERIAL_DIFFUSE, EINA_TRUE),
194 evas_3d_material_enable_set(data->material0, EVAS_3D_MATERIAL_DIFFUSE, EINA_TRUE); 204 evas_3d_material_enable_set(EVAS_3D_MATERIAL_SPECULAR, EINA_TRUE);
195 evas_3d_material_enable_set(data->material0, EVAS_3D_MATERIAL_SPECULAR, EINA_TRUE); 205 evas_3d_material_color_set(EVAS_3D_MATERIAL_AMBIENT,
196 evas_3d_material_enable_set(data->material0, EVAS_3D_MATERIAL_NORMAL, EINA_TRUE); 206 0.2, 0.2, 0.2, 1.0),
197 207 evas_3d_material_color_set(EVAS_3D_MATERIAL_DIFFUSE,
198 evas_3d_material_color_set(data->material0, EVAS_3D_MATERIAL_AMBIENT, 0.2, 0.2, 0.2, 1.0); 208 0.8, 0.8, 0.8, 1.0),
199 evas_3d_material_color_set(data->material0, EVAS_3D_MATERIAL_DIFFUSE, 0.8, 0.8, 0.8, 1.0); 209 evas_3d_material_color_set(EVAS_3D_MATERIAL_SPECULAR,
200 evas_3d_material_color_set(data->material0, EVAS_3D_MATERIAL_SPECULAR, 1.0, 1.0, 1.0, 1.0); 210 1.0, 1.0, 1.0, 1.0),
201 evas_3d_material_shininess_set(data->material0, 100.0); 211 evas_3d_material_shininess_set(100.0));
202 212
203 evas_3d_material_enable_set(data->material1, EVAS_3D_MATERIAL_AMBIENT, EINA_TRUE); 213 data->material1 = eo_add(EVAS_3D_MATERIAL_CLASS, evas);
204 evas_3d_material_enable_set(data->material1, EVAS_3D_MATERIAL_DIFFUSE, EINA_TRUE); 214 eo_do(data->material1,
205 evas_3d_material_enable_set(data->material1, EVAS_3D_MATERIAL_SPECULAR, EINA_TRUE); 215 evas_3d_material_enable_set(EVAS_3D_MATERIAL_AMBIENT, EINA_TRUE),
206 evas_3d_material_enable_set(data->material1, EVAS_3D_MATERIAL_NORMAL, EINA_TRUE); 216 evas_3d_material_enable_set(EVAS_3D_MATERIAL_DIFFUSE, EINA_TRUE),
207 217 evas_3d_material_enable_set(EVAS_3D_MATERIAL_SPECULAR, EINA_TRUE),
208 evas_3d_material_color_set(data->material1, EVAS_3D_MATERIAL_AMBIENT, 0.2, 0.2, 0.2, 1.0); 218 evas_3d_material_enable_set(EVAS_3D_MATERIAL_NORMAL, EINA_TRUE);
209 evas_3d_material_color_set(data->material1, EVAS_3D_MATERIAL_DIFFUSE, 0.8, 0.8, 0.8, 1.0); 219 evas_3d_material_color_set(EVAS_3D_MATERIAL_AMBIENT,
210 evas_3d_material_color_set(data->material1, EVAS_3D_MATERIAL_SPECULAR, 1.0, 1.0, 1.0, 1.0); 220 0.2, 0.2, 0.2, 1.0),
211 evas_3d_material_shininess_set(data->material1, 100.0); 221 evas_3d_material_color_set(EVAS_3D_MATERIAL_DIFFUSE,
212 222 0.8, 0.8, 0.8, 1.0),
213 data->texture0 = evas_3d_texture_add(evas); 223 evas_3d_material_color_set(EVAS_3D_MATERIAL_SPECULAR,
214 data->texture1 = evas_3d_texture_add(evas); 224 1.0, 1.0, 1.0, 1.0),
215 data->texture_normal = evas_3d_texture_add(evas); 225 evas_3d_material_shininess_set(100.0));
216 226
217 evas_3d_texture_data_set(data->texture0, EVAS_3D_COLOR_FORMAT_RGBA, 227 /* Texture 1 */
218 EVAS_3D_PIXEL_FORMAT_8888, 4, 4, &pixels0[0]); 228 data->texture0 = eo_add(EVAS_3D_TEXTURE_CLASS, evas);
219 evas_3d_texture_data_set(data->texture1, EVAS_3D_COLOR_FORMAT_RGBA, 229 eo_do(data->texture0, evas_3d_texture_data_set(EVAS_3D_COLOR_FORMAT_RGBA,
220 EVAS_3D_PIXEL_FORMAT_8888, 4, 4, &pixels1[0]); 230 EVAS_3D_PIXEL_FORMAT_8888, 4,
221 evas_3d_texture_file_set(data->texture_normal, "normal_lego.png", NULL); 231 4, &pixels0[0]));
222 232 eo_do(data->material0, evas_3d_material_texture_set(EVAS_3D_MATERIAL_DIFFUSE,
223 evas_3d_material_texture_set(data->material0, EVAS_3D_MATERIAL_DIFFUSE, data->texture0); 233 data->texture0));
224 evas_3d_material_texture_set(data->material1, EVAS_3D_MATERIAL_DIFFUSE, data->texture1); 234 /* Texture 2 */
225 evas_3d_material_texture_set(data->material1, EVAS_3D_MATERIAL_NORMAL, data->texture_normal); 235 data->texture1 = eo_add(EVAS_3D_TEXTURE_CLASS, evas);
226 236 eo_do(data->texture1, evas_3d_texture_data_set(EVAS_3D_COLOR_FORMAT_RGBA,
237 EVAS_3D_PIXEL_FORMAT_8888, 4,
238 4, &pixels1[0]));
239 eo_do(data->material1, evas_3d_material_texture_set(EVAS_3D_MATERIAL_DIFFUSE,
240 data->texture1));
241 /* Normal texture */
242 data->texture_normal = eo_add(EVAS_3D_TEXTURE_CLASS, evas);
243
244 eo_do(data->texture_normal, evas_3d_texture_file_set("normal_lego.png",
245 NULL));
246
247 eo_do(data->material1, evas_3d_material_texture_set(EVAS_3D_MATERIAL_NORMAL,
248 data->texture_normal));
227 /* Setup mesh. */ 249 /* Setup mesh. */
228 data->mesh = evas_3d_mesh_add(evas); 250 data->mesh = eo_add(EVAS_3D_MESH_CLASS, evas);
229 evas_3d_mesh_vertex_count_set(data->mesh, 24); 251 eo_do(data->mesh,
230 evas_3d_mesh_frame_add(data->mesh, 0); 252 evas_3d_mesh_vertex_count_set(24),
231 253 evas_3d_mesh_frame_add(0),
232 evas_3d_mesh_frame_vertex_data_set(data->mesh, 0, EVAS_3D_VERTEX_POSITION, 254 evas_3d_mesh_frame_vertex_data_set(0, EVAS_3D_VERTEX_POSITION,
233 12 * sizeof(float), &cube_vertices[ 0]); 255 12 * sizeof(float),
234 evas_3d_mesh_frame_vertex_data_set(data->mesh, 0, EVAS_3D_VERTEX_NORMAL, 256 &cube_vertices[0]),
235 12 * sizeof(float), &cube_vertices[ 3]); 257 evas_3d_mesh_frame_vertex_data_set(0, EVAS_3D_VERTEX_NORMAL,
236 evas_3d_mesh_frame_vertex_data_set(data->mesh, 0, EVAS_3D_VERTEX_COLOR, 258 12 * sizeof(float),
237 12 * sizeof(float), &cube_vertices[ 6]); 259 &cube_vertices[3]),
238 evas_3d_mesh_frame_vertex_data_set(data->mesh, 0, EVAS_3D_VERTEX_TEXCOORD, 260 evas_3d_mesh_frame_vertex_data_set(0, EVAS_3D_VERTEX_COLOR,
239 12 * sizeof(float), &cube_vertices[10]); 261 12 * sizeof(float),
240 262 &cube_vertices[6]),
241 evas_3d_mesh_index_data_set(data->mesh, EVAS_3D_INDEX_FORMAT_UNSIGNED_SHORT, 263 evas_3d_mesh_frame_vertex_data_set(0, EVAS_3D_VERTEX_TEXCOORD,
242 36, &cube_indices[0]); 264 12 * sizeof(float),
243 evas_3d_mesh_vertex_assembly_set(data->mesh, EVAS_3D_VERTEX_ASSEMBLY_TRIANGLES); 265 &cube_vertices[10]),
244 266 evas_3d_mesh_index_data_set(EVAS_3D_INDEX_FORMAT_UNSIGNED_SHORT,
245 evas_3d_mesh_shade_mode_set(data->mesh, EVAS_3D_SHADE_MODE_NORMAL_MAP); 267 36, &cube_indices[0]),
246 268 evas_3d_mesh_vertex_assembly_set(EVAS_3D_VERTEX_ASSEMBLY_TRIANGLES),
247 evas_3d_mesh_frame_material_set(data->mesh, 0, data->material0); 269 evas_3d_mesh_shade_mode_set(EVAS_3D_SHADE_MODE_NORMAL_MAP),
248 270 evas_3d_mesh_frame_material_set(0, data->material0),
249 evas_3d_mesh_frame_add(data->mesh, 20); 271 evas_3d_mesh_frame_add(20),
250 evas_3d_mesh_frame_material_set(data->mesh, 20, data->material1); 272 evas_3d_mesh_frame_material_set(20, data->material1));
251 273
274// data->mesh_node = eo_add(EVAS_3D_NODE_CLASS, evas, EVAS_3D_NODE_TYPE_MESH);
252 data->mesh_node = evas_3d_node_add(evas, EVAS_3D_NODE_TYPE_MESH); 275 data->mesh_node = evas_3d_node_add(evas, EVAS_3D_NODE_TYPE_MESH);
253 evas_3d_node_member_add(data->root_node, data->mesh_node); 276 eo_do(data->root_node,
254 evas_3d_node_mesh_add(data->mesh_node, data->mesh); 277 evas_3d_node_member_add(data->mesh_node));
278 eo_do(data->mesh_node,
279 evas_3d_node_mesh_add(data->mesh));
255} 280}
256 281
257static void 282static void
258_scene_setup(Scene_Data *data) 283_scene_setup(Scene_Data *data)
259{ 284{
260 data->scene = evas_3d_scene_add(evas); 285 data->scene = eo_add(EVAS_3D_SCENE_CLASS, evas);
261 evas_3d_scene_size_set(data->scene, WIDTH, HEIGHT); 286 eo_do(data->scene, evas_3d_scene_size_set(WIDTH, HEIGHT),
262 evas_3d_scene_background_color_set(data->scene, 0.0, 0.0, 0.0, 0.0); 287 evas_3d_scene_background_color_set(0.0, 0.0, 0.0, 0.0));
263 288
289// data->root_node = eo_add(EVAS_3D_NODE_CLASS, evas, EVAS_3D_NODE_TYPE_NODE);
264 data->root_node = evas_3d_node_add(evas, EVAS_3D_NODE_TYPE_NODE); 290 data->root_node = evas_3d_node_add(evas, EVAS_3D_NODE_TYPE_NODE);
265 291
266 _camera_setup(data); 292 _camera_setup(data);
267 _light_setup(data); 293 _light_setup(data);
268 _mesh_setup(data); 294 _mesh_setup(data);
269 295
270 evas_3d_scene_root_node_set(data->scene, data->root_node); 296 eo_do(data->scene,
271 evas_3d_scene_camera_node_set(data->scene, data->camera_node); 297 evas_3d_scene_root_node_set(data->root_node),
298 evas_3d_scene_camera_node_set(data->camera_node));
272} 299}
273 300
274int 301int
@@ -276,13 +303,11 @@ main(void)
276{ 303{
277 Scene_Data data; 304 Scene_Data data;
278 305
279 if (!ecore_evas_init()) 306 if (!ecore_evas_init()) return 0;
280 return 0;
281 307
282 ecore_evas = ecore_evas_new(NULL, 10, 10, WIDTH, HEIGHT, NULL); 308 ecore_evas = ecore_evas_new(NULL, 10, 10, WIDTH, HEIGHT, NULL);
283 309
284 if (!ecore_evas) 310 if (!ecore_evas) return 0;
285 return 0;
286 311
287 ecore_evas_callback_delete_request_set(ecore_evas, _on_delete); 312 ecore_evas_callback_delete_request_set(ecore_evas, _on_delete);
288 ecore_evas_callback_resize_set(ecore_evas, _on_canvas_resize); 313 ecore_evas_callback_resize_set(ecore_evas, _on_canvas_resize);
@@ -293,20 +318,20 @@ main(void)
293 _scene_setup(&data); 318 _scene_setup(&data);
294 319
295 /* Add a background rectangle objects. */ 320 /* Add a background rectangle objects. */
296 background = evas_object_rectangle_add(evas); 321 background = eo_add(EVAS_OBJ_RECTANGLE_CLASS, evas);
297 evas_object_color_set(background, 0, 0, 0, 255); 322 eo_do(background,
298 evas_object_move(background, 0, 0); 323 evas_obj_color_set(0, 0, 0, 255),
299 evas_object_resize(background, WIDTH, HEIGHT); 324 evas_obj_size_set(WIDTH, HEIGHT),
300 evas_object_show(background); 325 evas_obj_visibility_set(EINA_TRUE));
301 326
302 /* Add an image object for 3D scene rendering. */ 327 /* Add an image object for 3D scene rendering. */
303 image = evas_object_image_filled_add(evas); 328 image = evas_object_image_filled_add(evas);
304 evas_object_move(image, 0, 0); 329 eo_do(image,
305 evas_object_resize(image, WIDTH, HEIGHT); 330 evas_obj_size_set(WIDTH, HEIGHT),
306 evas_object_show(image); 331 evas_obj_visibility_set(EINA_TRUE));
307 332
308 /* Set the image object as render target for 3D scene. */ 333 /* Set the image object as render target for 3D scene. */
309 evas_object_image_scene_set(image, data.scene); 334 eo_do(image, evas_obj_image_scene_set(data.scene));
310 335
311 /* Add animation timer callback. */ 336 /* Add animation timer callback. */
312 ecore_timer_add(0.01, _animate_scene, &data); 337 ecore_timer_add(0.01, _animate_scene, &data);