forked from enlightenment/efl
evas/evas_3d: rewrite evas_3d_cube eo based.
still evas_3d_node_add() call should be changed to eo_add().
This commit is contained in:
parent
fac0ab79b0
commit
4a70c3aea8
|
@ -1,30 +1,34 @@
|
|||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <Ecore.h>
|
||||
#include <Ecore_Evas.h>
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
#include <Evas.h>
|
||||
|
||||
#define WIDTH 1024
|
||||
#define HEIGHT 1024
|
||||
#define WIDTH 400
|
||||
#define HEIGHT 400
|
||||
|
||||
typedef struct _Scene_Data
|
||||
{
|
||||
Evas_3D_Scene *scene;
|
||||
Evas_3D_Node *root_node;
|
||||
Evas_3D_Node *camera_node;
|
||||
Evas_3D_Node *light_node;
|
||||
Evas_3D_Node *mesh_node;
|
||||
Eo *scene;
|
||||
Eo *root_node;
|
||||
Eo *camera_node;
|
||||
Eo *light_node;
|
||||
Eo *mesh_node;
|
||||
|
||||
Evas_3D_Camera *camera;
|
||||
Evas_3D_Light *light;
|
||||
Evas_3D_Mesh *mesh;
|
||||
Evas_3D_Material *material;
|
||||
Eo *camera;
|
||||
Eo *light;
|
||||
Eo *mesh;
|
||||
Eo *material;
|
||||
} Scene_Data;
|
||||
|
||||
Ecore_Evas *ecore_evas = NULL;
|
||||
Evas *evas = NULL;
|
||||
Evas_Object *background = NULL;
|
||||
Evas_Object *image = NULL;
|
||||
Ecore_Evas *ecore_evas = NULL;
|
||||
Evas *evas = NULL;
|
||||
Eo *background = NULL;
|
||||
Eo *image = NULL;
|
||||
|
||||
static const float cube_vertices[] =
|
||||
{
|
||||
|
@ -98,10 +102,8 @@ _on_canvas_resize(Ecore_Evas *ee)
|
|||
int w, h;
|
||||
|
||||
ecore_evas_geometry_get(ee, NULL, NULL, &w, &h);
|
||||
|
||||
evas_object_resize(background, w, h);
|
||||
evas_object_resize(image, w, h);
|
||||
evas_object_move(image, 0, 0);
|
||||
eo_do(background, evas_obj_size_set(w, h));
|
||||
eo_do(image, evas_obj_size_set(w, h));
|
||||
}
|
||||
|
||||
static Eina_Bool
|
||||
|
@ -112,11 +114,11 @@ _animate_scene(void *data)
|
|||
|
||||
angle += 0.5;
|
||||
|
||||
evas_3d_node_orientation_angle_axis_set(scene->mesh_node, angle, 1.0, 1.0, 1.0);
|
||||
eo_do(scene->mesh_node,
|
||||
evas_3d_node_orientation_angle_axis_set(angle, 1.0, 1.0, 1.0));
|
||||
|
||||
/* Rotate */
|
||||
if (angle > 360.0)
|
||||
angle -= 360.0f;
|
||||
if (angle > 360.0) angle -= 360.0f;
|
||||
|
||||
return EINA_TRUE;
|
||||
}
|
||||
|
@ -124,90 +126,108 @@ _animate_scene(void *data)
|
|||
static void
|
||||
_camera_setup(Scene_Data *data)
|
||||
{
|
||||
data->camera = evas_3d_camera_add(evas);
|
||||
evas_3d_camera_projection_perspective_set(data->camera, 60.0, 1.0, 2.0, 50.0);
|
||||
data->camera = eo_add(EVAS_3D_CAMERA_CLASS, evas);
|
||||
eo_do(data->camera,
|
||||
evas_3d_camera_projection_perspective_set(60.0, 1.0, 2.0, 50.0));
|
||||
|
||||
// data->camera_node =
|
||||
// eo_add(EVAS_3D_NODE_CLASS, evas, EVAS_3D_NODE_TYPE_CAMERA);
|
||||
data->camera_node = evas_3d_node_add(evas, EVAS_3D_NODE_TYPE_CAMERA);
|
||||
evas_3d_node_camera_set(data->camera_node, data->camera);
|
||||
evas_3d_node_member_add(data->root_node, data->camera_node);
|
||||
evas_3d_node_position_set(data->camera_node, 0.0, 0.0, 10.0);
|
||||
evas_3d_node_look_at_set(data->camera_node, EVAS_3D_SPACE_PARENT, 0.0, 0.0, 0.0,
|
||||
EVAS_3D_SPACE_PARENT, 0.0, 1.0, 0.0);
|
||||
eo_do(data->camera_node,
|
||||
evas_3d_node_camera_set(data->camera));
|
||||
eo_do(data->root_node,
|
||||
evas_3d_node_member_add(data->camera_node));
|
||||
eo_do(data->camera_node,
|
||||
evas_3d_node_position_set(0.0, 0.0, 10.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));
|
||||
}
|
||||
|
||||
static void
|
||||
_light_setup(Scene_Data *data)
|
||||
{
|
||||
data->light = evas_3d_light_add(evas);
|
||||
evas_3d_light_ambient_set(data->light, 0.2, 0.2, 0.2, 1.0);
|
||||
evas_3d_light_diffuse_set(data->light, 1.0, 1.0, 1.0, 1.0);
|
||||
evas_3d_light_specular_set(data->light, 1.0, 1.0, 1.0, 1.0);
|
||||
data->light = eo_add(EVAS_3D_LIGHT_CLASS, evas);
|
||||
eo_do(data->light,
|
||||
evas_3d_light_ambient_set(0.2, 0.2, 0.2, 1.0),
|
||||
evas_3d_light_diffuse_set(1.0, 1.0, 1.0, 1.0),
|
||||
evas_3d_light_specular_set(1.0, 1.0, 1.0, 1.0));
|
||||
|
||||
// data->light_node = eo_add(EVAS_3D_NODE_CLASS, evas, EVAS_3D_NODE_TYPE_LIGHT);
|
||||
data->light_node = evas_3d_node_add(evas, EVAS_3D_NODE_TYPE_LIGHT);
|
||||
evas_3d_node_light_set(data->light_node, data->light);
|
||||
evas_3d_node_member_add(data->root_node, data->light_node);
|
||||
evas_3d_node_position_set(data->light_node, 0.0, 0.0, 10.0);
|
||||
evas_3d_node_look_at_set(data->light_node, EVAS_3D_SPACE_PARENT, 0.0, 0.0, 0.0,
|
||||
EVAS_3D_SPACE_PARENT, 0.0, 1.0, 0.0);
|
||||
eo_do(data->light_node,
|
||||
evas_3d_node_light_set(data->light));
|
||||
eo_do(data->root_node,
|
||||
evas_3d_node_member_add(data->light_node));
|
||||
eo_do(data->light_node,
|
||||
evas_3d_node_position_set(0.0, 0.0, 10.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));
|
||||
}
|
||||
|
||||
static void
|
||||
_mesh_setup(Scene_Data *data)
|
||||
{
|
||||
/* Setup material. */
|
||||
data->material = evas_3d_material_add(evas);
|
||||
|
||||
evas_3d_material_enable_set(data->material, EVAS_3D_MATERIAL_AMBIENT, EINA_TRUE);
|
||||
evas_3d_material_enable_set(data->material, EVAS_3D_MATERIAL_DIFFUSE, EINA_TRUE);
|
||||
evas_3d_material_enable_set(data->material, EVAS_3D_MATERIAL_SPECULAR, EINA_TRUE);
|
||||
|
||||
evas_3d_material_color_set(data->material, EVAS_3D_MATERIAL_AMBIENT, 0.2, 0.2, 0.2, 1.0);
|
||||
evas_3d_material_color_set(data->material, EVAS_3D_MATERIAL_DIFFUSE, 0.8, 0.8, 0.8, 1.0);
|
||||
evas_3d_material_color_set(data->material, EVAS_3D_MATERIAL_SPECULAR, 1.0, 1.0, 1.0, 1.0);
|
||||
evas_3d_material_shininess_set(data->material, 100.0);
|
||||
data->material = eo_add(EVAS_3D_MATERIAL_CLASS, evas);
|
||||
eo_do(data->material,
|
||||
evas_3d_material_enable_set(EVAS_3D_MATERIAL_AMBIENT, EINA_TRUE),
|
||||
evas_3d_material_enable_set(EVAS_3D_MATERIAL_DIFFUSE, EINA_TRUE),
|
||||
evas_3d_material_enable_set(EVAS_3D_MATERIAL_SPECULAR, EINA_TRUE);
|
||||
evas_3d_material_color_set(EVAS_3D_MATERIAL_AMBIENT,
|
||||
0.2, 0.2, 0.2, 1.0),
|
||||
evas_3d_material_color_set(EVAS_3D_MATERIAL_DIFFUSE,
|
||||
0.8, 0.8, 0.8, 1.0),
|
||||
evas_3d_material_color_set(EVAS_3D_MATERIAL_SPECULAR,
|
||||
1.0, 1.0, 1.0, 1.0),
|
||||
evas_3d_material_shininess_set(100.0));
|
||||
|
||||
/* Setup mesh. */
|
||||
data->mesh = evas_3d_mesh_add(evas);
|
||||
evas_3d_mesh_vertex_count_set(data->mesh, 24);
|
||||
evas_3d_mesh_frame_add(data->mesh, 0);
|
||||
|
||||
evas_3d_mesh_frame_vertex_data_set(data->mesh, 0, EVAS_3D_VERTEX_POSITION,
|
||||
12 * sizeof(float), &cube_vertices[ 0]);
|
||||
evas_3d_mesh_frame_vertex_data_set(data->mesh, 0, EVAS_3D_VERTEX_NORMAL,
|
||||
12 * sizeof(float), &cube_vertices[ 3]);
|
||||
evas_3d_mesh_frame_vertex_data_set(data->mesh, 0, EVAS_3D_VERTEX_COLOR,
|
||||
12 * sizeof(float), &cube_vertices[ 6]);
|
||||
evas_3d_mesh_frame_vertex_data_set(data->mesh, 0, EVAS_3D_VERTEX_TEXCOORD,
|
||||
12 * sizeof(float), &cube_vertices[10]);
|
||||
|
||||
evas_3d_mesh_index_data_set(data->mesh, EVAS_3D_INDEX_FORMAT_UNSIGNED_SHORT,
|
||||
36, &cube_indices[0]);
|
||||
evas_3d_mesh_vertex_assembly_set(data->mesh, EVAS_3D_VERTEX_ASSEMBLY_TRIANGLES);
|
||||
|
||||
evas_3d_mesh_shade_mode_set(data->mesh, EVAS_3D_SHADE_MODE_PHONG);
|
||||
|
||||
evas_3d_mesh_frame_material_set(data->mesh, 0, data->material);
|
||||
data->mesh = eo_add(EVAS_3D_MESH_CLASS, evas);
|
||||
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_PHONG),
|
||||
evas_3d_mesh_frame_material_set(0, data->material));
|
||||
|
||||
// data->mesh_node = eo_add(EVAS_3D_NODE_CLASS, evas, EVAS_3D_NODE_TYPE_MESH);
|
||||
data->mesh_node = evas_3d_node_add(evas, EVAS_3D_NODE_TYPE_MESH);
|
||||
evas_3d_node_member_add(data->root_node, data->mesh_node);
|
||||
evas_3d_node_mesh_add(data->mesh_node, data->mesh);
|
||||
eo_do(data->root_node,
|
||||
evas_3d_node_member_add(data->mesh_node));
|
||||
eo_do(data->mesh_node,
|
||||
evas_3d_node_mesh_add(data->mesh));
|
||||
}
|
||||
|
||||
static void
|
||||
_scene_setup(Scene_Data *data)
|
||||
{
|
||||
data->scene = evas_3d_scene_add(evas);
|
||||
evas_3d_scene_size_set(data->scene, WIDTH, HEIGHT);
|
||||
evas_3d_scene_background_color_set(data->scene, 0.0, 0.0, 0.0, 0.0);
|
||||
data->scene = eo_add(EVAS_3D_SCENE_CLASS, evas);
|
||||
eo_do(data->scene, evas_3d_scene_size_set(WIDTH, HEIGHT),
|
||||
evas_3d_scene_background_color_set(0.0, 0.0, 0.0, 0.0));
|
||||
|
||||
// data->root_node = eo_add(EVAS_3D_NODE_CLASS, evas, EVAS_3D_NODE_TYPE_NODE);
|
||||
data->root_node = evas_3d_node_add(evas, EVAS_3D_NODE_TYPE_NODE);
|
||||
|
||||
_camera_setup(data);
|
||||
_light_setup(data);
|
||||
_mesh_setup(data);
|
||||
|
||||
evas_3d_scene_root_node_set(data->scene, data->root_node);
|
||||
evas_3d_scene_camera_node_set(data->scene, data->camera_node);
|
||||
eo_do(data->scene,
|
||||
evas_3d_scene_root_node_set(data->root_node),
|
||||
evas_3d_scene_camera_node_set(data->camera_node));
|
||||
}
|
||||
|
||||
int
|
||||
|
@ -215,13 +235,10 @@ main(void)
|
|||
{
|
||||
Scene_Data data;
|
||||
|
||||
if (!ecore_evas_init())
|
||||
return 0;
|
||||
if (!ecore_evas_init()) return 0;
|
||||
|
||||
ecore_evas = ecore_evas_new(NULL, 10, 10, WIDTH, HEIGHT, NULL);
|
||||
|
||||
if (!ecore_evas)
|
||||
return 0;
|
||||
if (!ecore_evas) return 0;
|
||||
|
||||
ecore_evas_callback_delete_request_set(ecore_evas, _on_delete);
|
||||
ecore_evas_callback_resize_set(ecore_evas, _on_canvas_resize);
|
||||
|
@ -233,19 +250,19 @@ main(void)
|
|||
|
||||
/* Add a background rectangle objects. */
|
||||
background = evas_object_rectangle_add(evas);
|
||||
evas_object_color_set(background, 0, 0, 0, 255);
|
||||
evas_object_move(background, 0, 0);
|
||||
evas_object_resize(background, WIDTH, HEIGHT);
|
||||
evas_object_show(background);
|
||||
eo_do(background,
|
||||
evas_obj_color_set(0, 0, 0, 255),
|
||||
evas_obj_size_set(WIDTH, HEIGHT),
|
||||
evas_obj_visibility_set(EINA_TRUE));
|
||||
|
||||
/* Add an image object for 3D scene rendering. */
|
||||
/* Add an image object for 3D scene rendering. */
|
||||
image = evas_object_image_filled_add(evas);
|
||||
evas_object_move(image, 0, 0);
|
||||
evas_object_resize(image, WIDTH, HEIGHT);
|
||||
evas_object_show(image);
|
||||
eo_do(image,
|
||||
evas_obj_size_set(WIDTH, HEIGHT),
|
||||
evas_obj_visibility_set(EINA_TRUE));
|
||||
|
||||
/* Set the image object as render target for 3D scene. */
|
||||
evas_object_image_scene_set(image, data.scene);
|
||||
eo_do(image, evas_obj_image_scene_set(data.scene));
|
||||
|
||||
/* Add animation timer callback. */
|
||||
ecore_timer_add(0.016, _animate_scene, &data);
|
||||
|
|
Loading…
Reference in New Issue