2015-12-14 21:55:20 -08:00
|
|
|
/**
|
2015-02-10 02:24:48 -08:00
|
|
|
* This example shows how to use color pick algorithm for finding node at scene.
|
|
|
|
* Enable color pick mode of meshes and scene objects.
|
|
|
|
* Click (left for color pick, right for geometry pick) on 3D object and see
|
|
|
|
* in terminal time response of the found node.
|
|
|
|
* Use key UP/DOWN for changing z coordinate of camera
|
|
|
|
* Use key LEFT/RIGHT for scale each node
|
2015-03-06 08:02:15 -08:00
|
|
|
* Use shortcut parameters of commanline: r - rows of objects, c - columns of objects,
|
2015-03-18 04:31:46 -07:00
|
|
|
* p - precision of the spheres, t - path for a texture.
|
2015-03-06 08:02:15 -08:00
|
|
|
*
|
2015-02-23 08:59:05 -08:00
|
|
|
* @verbatim
|
2015-05-29 09:14:08 -07:00
|
|
|
* gcc -o evas-3d-colorpick evas-3d-colorpick.c `pkg-config --libs --cflags evas ecore ecore-evas eo eina efl` -lm
|
2015-02-23 08:59:05 -08:00
|
|
|
* @endverbatim
|
2015-02-10 02:24:48 -08:00
|
|
|
*/
|
|
|
|
|
2015-02-20 03:02:08 -08:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#else
|
|
|
|
#define PACKAGE_EXAMPLES_DIR "."
|
2015-02-10 02:24:48 -08:00
|
|
|
#define EFL_EO_API_SUPPORT
|
|
|
|
#define EFL_BETA_API_SUPPORT
|
2015-02-20 08:59:27 -08:00
|
|
|
#endif
|
2015-02-10 02:24:48 -08:00
|
|
|
|
|
|
|
#include <Eo.h>
|
|
|
|
#include <Evas.h>
|
|
|
|
#include <Ecore.h>
|
|
|
|
#include <Ecore_Evas.h>
|
|
|
|
#include <Ecore_Getopt.h>
|
2015-03-06 08:02:15 -08:00
|
|
|
#include <math.h>
|
2015-02-20 08:59:27 -08:00
|
|
|
#include "evas-common.h"
|
2015-02-10 02:24:48 -08:00
|
|
|
|
|
|
|
#define WIDTH 800
|
|
|
|
#define HEIGHT 600
|
|
|
|
|
2015-03-06 08:02:15 -08:00
|
|
|
#define INIT_SCALE 7.5
|
|
|
|
#define BIG_SCALE 10.0
|
|
|
|
#define SMALL_SCALE 5.0
|
|
|
|
#define SCALE_UNIT 0.5
|
|
|
|
#define VEC_3(value) value, value, value
|
2015-02-10 02:24:48 -08:00
|
|
|
|
2015-03-18 04:31:46 -07:00
|
|
|
static const char *image_path = PACKAGE_EXAMPLES_DIR EVAS_IMAGE_FOLDER "/wood.jpg";
|
2015-02-20 03:02:08 -08:00
|
|
|
|
2015-02-10 02:24:48 -08:00
|
|
|
Ecore_Evas *ecore_evas = NULL;
|
|
|
|
Evas *evas = NULL;
|
|
|
|
Evas_Object *image = NULL, *bg = NULL;
|
|
|
|
|
|
|
|
static const
|
|
|
|
Ecore_Getopt optdesc = {
|
|
|
|
"",
|
|
|
|
NULL,
|
|
|
|
"0.0",
|
|
|
|
"",
|
|
|
|
"",
|
|
|
|
"Example mesh color pick mechanism",
|
|
|
|
0,
|
|
|
|
{
|
2015-03-06 08:02:15 -08:00
|
|
|
ECORE_GETOPT_STORE_INT('r', "row", "Rows of spheres"),
|
|
|
|
ECORE_GETOPT_STORE_INT('c', "column", "Columns of spheres"),
|
|
|
|
ECORE_GETOPT_STORE_INT('p', "precision", "Precision of spheres"),
|
2015-03-18 04:31:46 -07:00
|
|
|
ECORE_GETOPT_STORE_STR('t', "texture", "Name of texture"),
|
2015-02-10 02:24:48 -08:00
|
|
|
ECORE_GETOPT_HELP('h', "help"),
|
|
|
|
ECORE_GETOPT_SENTINEL
|
|
|
|
}
|
|
|
|
};
|
2015-03-06 08:02:15 -08:00
|
|
|
|
|
|
|
typedef struct _Object
|
2015-02-10 02:24:48 -08:00
|
|
|
{
|
2015-05-29 09:14:08 -07:00
|
|
|
Eo *primitive;
|
2015-02-10 02:24:48 -08:00
|
|
|
Eo *node;
|
2015-03-18 04:31:46 -07:00
|
|
|
Eo *mesh;
|
|
|
|
Eo *material;
|
|
|
|
Eo *texture;
|
2015-02-10 02:24:48 -08:00
|
|
|
|
|
|
|
Evas_Real speed;
|
|
|
|
Ecore_Timer *animate;
|
2015-03-18 04:31:46 -07:00
|
|
|
Eina_Bool (*sphere_init)(void *sphere, const char *texture);
|
2015-03-06 08:02:15 -08:00
|
|
|
Eina_Bool (*sphere_animate)(void *data);
|
2015-02-10 02:24:48 -08:00
|
|
|
|
2015-03-06 08:02:15 -08:00
|
|
|
} Test_object;
|
2015-02-10 02:24:48 -08:00
|
|
|
|
|
|
|
typedef struct _Scene
|
|
|
|
{
|
|
|
|
Eo *camera;
|
|
|
|
Eo *light;
|
|
|
|
Eo *scene;
|
|
|
|
Eo *root_node;
|
|
|
|
Eo *camera_node;
|
|
|
|
Eo *light_node;
|
|
|
|
|
|
|
|
int row;
|
|
|
|
int col;
|
2015-03-06 08:02:15 -08:00
|
|
|
int precision;
|
2015-02-10 02:24:48 -08:00
|
|
|
|
2015-03-06 08:02:15 -08:00
|
|
|
Eina_List *spheres;
|
2015-02-10 02:24:48 -08:00
|
|
|
|
2015-03-18 04:31:46 -07:00
|
|
|
Eina_Bool (*scene_init)(const char *texture);
|
2015-02-10 02:24:48 -08:00
|
|
|
|
|
|
|
} Scene_Data;
|
|
|
|
|
|
|
|
Scene_Data globalscene;
|
|
|
|
|
|
|
|
static void
|
|
|
|
_on_delete(Ecore_Evas *ee EINA_UNUSED)
|
|
|
|
{
|
|
|
|
Eina_List *l;
|
2015-03-06 08:02:15 -08:00
|
|
|
Test_object * item;
|
|
|
|
EINA_LIST_FOREACH(globalscene.spheres, l, item)
|
2015-02-10 02:24:48 -08:00
|
|
|
{
|
|
|
|
free(item);
|
|
|
|
}
|
2015-03-06 08:02:15 -08:00
|
|
|
eina_list_free(globalscene.spheres);
|
2015-02-10 02:24:48 -08:00
|
|
|
|
|
|
|
|
|
|
|
ecore_main_loop_quit();
|
|
|
|
}
|
|
|
|
static void
|
|
|
|
_on_canvas_resize(Ecore_Evas *ee)
|
|
|
|
{
|
|
|
|
int w, h;
|
|
|
|
|
|
|
|
ecore_evas_geometry_get(ee, NULL, NULL, &w, &h);
|
2016-03-01 10:06:28 -08:00
|
|
|
efl_gfx_size_set(bg, w, h);
|
|
|
|
efl_gfx_size_set(image, w, h);
|
2015-02-10 02:24:48 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
static Eina_Bool
|
2015-03-18 04:31:46 -07:00
|
|
|
_animate_sphere(void *data)
|
2015-02-10 02:24:48 -08:00
|
|
|
{
|
|
|
|
static int angle = 0.0;
|
2015-03-06 08:02:15 -08:00
|
|
|
Eo *n = (Eo*)(((Test_object *)data)->node);
|
2015-03-18 04:31:46 -07:00
|
|
|
Evas_Real s = ((Test_object *)data)->speed;
|
2016-03-01 10:06:28 -08:00
|
|
|
evas_canvas3d_node_orientation_angle_axis_set(n, angle, s, s - 1, s + 1);
|
2015-02-10 02:24:48 -08:00
|
|
|
angle++;
|
|
|
|
if (angle > 360) angle = 0.0;
|
|
|
|
return EINA_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void _recalculate_position()
|
|
|
|
{
|
|
|
|
int i = 0, j = 0, count = 0;
|
2015-03-18 04:31:46 -07:00
|
|
|
Evas_Real x1, y1, shiftx = 0, shifty = 0;
|
2015-03-06 08:02:15 -08:00
|
|
|
Test_object *m;
|
2015-02-10 02:24:48 -08:00
|
|
|
|
2016-03-01 10:06:28 -08:00
|
|
|
evas_canvas3d_object_update(((Test_object *)eina_list_nth(globalscene.spheres, 0))->node);
|
|
|
|
evas_canvas3d_node_bounding_box_get(((Test_object *)eina_list_nth(globalscene.spheres, 0))->node, NULL, NULL, NULL, &x1, &y1, NULL);
|
2015-02-10 02:24:48 -08:00
|
|
|
|
|
|
|
for (i = 0; i < globalscene.row; ++i)
|
|
|
|
{
|
2015-03-18 04:31:46 -07:00
|
|
|
shiftx = (i * 2 - globalscene.row) * x1;
|
2015-02-10 02:24:48 -08:00
|
|
|
for(j = 0; j < globalscene.col; ++j)
|
|
|
|
{
|
2015-03-18 04:31:46 -07:00
|
|
|
shifty = (j * 2 - globalscene.col) * y1;
|
2015-03-06 08:02:15 -08:00
|
|
|
m = (Test_object *)eina_list_nth(globalscene.spheres, count);
|
2016-03-01 10:06:28 -08:00
|
|
|
evas_canvas3d_node_position_set(m->node, shifty, 0.0, shiftx);
|
2015-02-10 02:24:48 -08:00
|
|
|
count++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
static void
|
|
|
|
_on_key_down(void *data EINA_UNUSED, Evas *e EINA_UNUSED,
|
|
|
|
Evas_Object *eo EINA_UNUSED, void *event_info)
|
|
|
|
{
|
|
|
|
Evas_Event_Key_Down *ev = event_info;
|
|
|
|
Evas_Real x, y, z;
|
|
|
|
Eina_List *l;
|
2015-03-06 08:02:15 -08:00
|
|
|
Test_object * item;
|
2015-02-10 02:24:48 -08:00
|
|
|
if (!strcmp(ev->key, "Down"))
|
|
|
|
{
|
2016-03-01 10:06:28 -08:00
|
|
|
evas_canvas3d_node_position_get(globalscene.camera_node, EVAS_CANVAS3D_SPACE_PARENT, &x, &y, &z);
|
|
|
|
evas_canvas3d_node_position_set(globalscene.camera_node, x, y, (z - 5));
|
2015-02-10 02:24:48 -08:00
|
|
|
}
|
|
|
|
else if (!strcmp(ev->key, "Up"))
|
|
|
|
{
|
2016-03-01 10:06:28 -08:00
|
|
|
evas_canvas3d_node_position_get(globalscene.camera_node, EVAS_CANVAS3D_SPACE_PARENT, &x, &y, &z);
|
|
|
|
evas_canvas3d_node_position_set(globalscene.camera_node, x, y, (z + 5));
|
2015-02-10 02:24:48 -08:00
|
|
|
}
|
|
|
|
else if (!strcmp(ev->key, "Left"))
|
|
|
|
{
|
2016-03-01 10:06:28 -08:00
|
|
|
evas_canvas3d_node_scale_get(((Test_object *)eina_list_nth(globalscene.spheres, 0))->node, EVAS_CANVAS3D_SPACE_PARENT, &x, &y, &z);
|
2015-03-06 08:02:15 -08:00
|
|
|
EINA_LIST_FOREACH(globalscene.spheres, l, item)
|
2015-02-10 02:24:48 -08:00
|
|
|
{
|
2016-03-01 10:06:28 -08:00
|
|
|
evas_canvas3d_node_scale_set(item->node, (x - SCALE_UNIT), (y - SCALE_UNIT), (z - SCALE_UNIT));
|
2015-02-10 02:24:48 -08:00
|
|
|
}
|
|
|
|
_recalculate_position();
|
|
|
|
}
|
|
|
|
else if (!strcmp(ev->key, "Right"))
|
|
|
|
{
|
2016-03-01 10:06:28 -08:00
|
|
|
evas_canvas3d_node_scale_get(((Test_object *)eina_list_nth(globalscene.spheres, 0))->node, EVAS_CANVAS3D_SPACE_PARENT, &x, &y, &z);
|
2015-03-06 08:02:15 -08:00
|
|
|
EINA_LIST_FOREACH(globalscene.spheres, l, item)
|
2015-02-10 02:24:48 -08:00
|
|
|
{
|
2016-03-01 10:06:28 -08:00
|
|
|
evas_canvas3d_node_scale_set(item->node, (x + SCALE_UNIT), (y + SCALE_UNIT), (z + SCALE_UNIT));
|
2015-02-10 02:24:48 -08:00
|
|
|
}
|
|
|
|
_recalculate_position();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
fprintf(stdout, "Down, Up for position of camera; Left, Right for scale of each node");
|
|
|
|
}
|
|
|
|
static void
|
|
|
|
_on_mouse_down(void *data EINA_UNUSED, Evas *e EINA_UNUSED, Evas_Object *eo EINA_UNUSED, void *event_info)
|
|
|
|
{
|
|
|
|
Evas_Event_Mouse_Down *ev = event_info;
|
2015-06-17 07:31:14 -07:00
|
|
|
Evas_Canvas3D_Node *n;
|
|
|
|
Evas_Canvas3D_Mesh *m;
|
2015-02-10 02:24:48 -08:00
|
|
|
Evas_Real s, t;
|
|
|
|
clock_t time;
|
|
|
|
float diff_sec;
|
|
|
|
|
|
|
|
time = clock();
|
|
|
|
Eina_Bool flag;
|
|
|
|
if (ev->button == 1)
|
|
|
|
{
|
2016-03-01 10:06:28 -08:00
|
|
|
evas_canvas3d_scene_color_pick_enable_set(globalscene.scene, EINA_TRUE);
|
|
|
|
flag = evas_canvas3d_scene_pick(globalscene.scene, ev->canvas.x, ev->canvas.y, &n, &m, NULL, NULL);
|
2015-02-10 02:24:48 -08:00
|
|
|
time = clock() - time;
|
|
|
|
diff_sec = ((float)time) / CLOCKS_PER_SEC / 10;
|
|
|
|
if (flag)
|
|
|
|
{
|
|
|
|
fprintf(stdout, "Boom! Time expended for color pick: %2.7f .\n", diff_sec);
|
2016-03-01 10:06:28 -08:00
|
|
|
evas_canvas3d_node_scale_set(n, VEC_3(SMALL_SCALE));
|
2015-02-10 02:24:48 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-03-01 10:06:28 -08:00
|
|
|
evas_canvas3d_scene_color_pick_enable_set(globalscene.scene, EINA_FALSE);
|
|
|
|
flag = evas_canvas3d_scene_pick(globalscene.scene, ev->canvas.x, ev->canvas.y, &n, &m, &s, &t);
|
2015-02-10 02:24:48 -08:00
|
|
|
time = clock() - time;
|
|
|
|
diff_sec = ((float)time) / CLOCKS_PER_SEC / 10;
|
|
|
|
if (flag)
|
|
|
|
{
|
|
|
|
fprintf(stdout, "Boom! Time expended for geometry pick: %2.7f .\n", diff_sec);
|
2016-03-01 10:06:28 -08:00
|
|
|
evas_canvas3d_node_scale_set(n, VEC_3(BIG_SCALE));
|
2015-02-10 02:24:48 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Eina_Bool
|
2015-03-18 04:31:46 -07:00
|
|
|
_init_sphere(void *this, const char *texture)
|
2015-02-10 02:24:48 -08:00
|
|
|
{
|
2015-03-06 08:02:15 -08:00
|
|
|
Test_object *sphere = (Test_object *)this;
|
2016-03-09 07:47:28 -08:00
|
|
|
eo_add(&sphere->primitive, EVAS_CANVAS3D_PRIMITIVE_CLASS, evas);
|
|
|
|
eo_add(&sphere->mesh, EVAS_CANVAS3D_MESH_CLASS, evas);
|
|
|
|
eo_add(&sphere->material, EVAS_CANVAS3D_MATERIAL_CLASS, evas);
|
2016-03-01 10:06:28 -08:00
|
|
|
evas_canvas3d_primitive_form_set(sphere->primitive, EVAS_CANVAS3D_MESH_PRIMITIVE_SPHERE);
|
|
|
|
evas_canvas3d_primitive_precision_set(sphere->primitive, 50);
|
|
|
|
evas_canvas3d_mesh_from_primitive_set(sphere->mesh, 0, sphere->primitive);
|
|
|
|
evas_canvas3d_mesh_frame_material_set(sphere->mesh, 0, sphere->material);
|
|
|
|
evas_canvas3d_mesh_shade_mode_set(sphere->mesh, EVAS_CANVAS3D_SHADE_MODE_PHONG);
|
2015-02-10 02:24:48 -08:00
|
|
|
|
2016-03-01 10:06:28 -08:00
|
|
|
evas_canvas3d_mesh_color_pick_enable_set(sphere->mesh, EINA_TRUE);
|
2015-02-10 02:24:48 -08:00
|
|
|
|
2016-03-09 07:47:28 -08:00
|
|
|
eo_add(&sphere->texture, EVAS_CANVAS3D_TEXTURE_CLASS, evas);
|
2016-03-01 10:06:28 -08:00
|
|
|
evas_canvas3d_texture_file_set(sphere->texture, texture, NULL);
|
|
|
|
evas_canvas3d_texture_filter_set(sphere->texture, EVAS_CANVAS3D_TEXTURE_FILTER_NEAREST, EVAS_CANVAS3D_TEXTURE_FILTER_NEAREST);
|
|
|
|
evas_canvas3d_texture_wrap_set(sphere->texture, EVAS_CANVAS3D_WRAP_MODE_REPEAT, EVAS_CANVAS3D_WRAP_MODE_REPEAT);
|
|
|
|
evas_canvas3d_material_texture_set(sphere->material, EVAS_CANVAS3D_MATERIAL_ATTRIB_DIFFUSE, sphere->texture);
|
|
|
|
evas_canvas3d_material_enable_set(sphere->material, EVAS_CANVAS3D_MATERIAL_ATTRIB_AMBIENT, EINA_TRUE);
|
|
|
|
evas_canvas3d_material_enable_set(sphere->material, EVAS_CANVAS3D_MATERIAL_ATTRIB_DIFFUSE, EINA_TRUE);
|
|
|
|
evas_canvas3d_material_enable_set(sphere->material, EVAS_CANVAS3D_MATERIAL_ATTRIB_SPECULAR, EINA_TRUE);
|
|
|
|
evas_canvas3d_material_enable_set(sphere->material, EVAS_CANVAS3D_MATERIAL_ATTRIB_NORMAL, EINA_TRUE);
|
|
|
|
evas_canvas3d_material_color_set(sphere->material, EVAS_CANVAS3D_MATERIAL_ATTRIB_AMBIENT, 0.01, 0.01, 0.01, 1.0);
|
|
|
|
evas_canvas3d_material_color_set(sphere->material, EVAS_CANVAS3D_MATERIAL_ATTRIB_DIFFUSE, 1.0, 1.0, 1.0, 1.0);
|
|
|
|
evas_canvas3d_material_color_set(sphere->material, EVAS_CANVAS3D_MATERIAL_ATTRIB_SPECULAR, 1.0, 1.0, 1.0, 1.0);
|
|
|
|
evas_canvas3d_material_shininess_set(sphere->material, 50.0);
|
2015-02-10 02:24:48 -08:00
|
|
|
return EINA_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Eina_Bool
|
2015-03-18 04:31:46 -07:00
|
|
|
_init_scene(const char *texture)
|
2015-02-10 02:24:48 -08:00
|
|
|
{
|
2015-03-19 09:20:56 -07:00
|
|
|
int i = 0;
|
2015-03-18 04:31:46 -07:00
|
|
|
Evas_Real tmp;
|
2015-03-06 08:02:15 -08:00
|
|
|
Test_object *m;
|
2015-02-10 02:24:48 -08:00
|
|
|
|
2016-03-11 04:24:06 -08:00
|
|
|
globalscene.scene = eo_add(EVAS_CANVAS3D_SCENE_CLASS, evas);
|
2015-02-10 02:24:48 -08:00
|
|
|
|
2016-03-11 04:24:06 -08:00
|
|
|
globalscene.root_node = eo_add(EVAS_CANVAS3D_NODE_CLASS, evas, evas_canvas3d_node_constructor(eoid, EVAS_CANVAS3D_NODE_TYPE_NODE));
|
2015-02-10 02:24:48 -08:00
|
|
|
|
2016-03-11 04:24:06 -08:00
|
|
|
globalscene.camera = eo_add(EVAS_CANVAS3D_CAMERA_CLASS, evas);
|
2016-03-01 10:06:28 -08:00
|
|
|
evas_canvas3d_camera_projection_perspective_set(globalscene.camera, 30.0, 1.0, 1.0, 1000.0);
|
2015-02-10 02:24:48 -08:00
|
|
|
|
2016-03-11 04:24:06 -08:00
|
|
|
globalscene.camera_node =
|
|
|
|
eo_add(EVAS_CANVAS3D_NODE_CLASS, evas, evas_canvas3d_node_constructor(eoid, EVAS_CANVAS3D_NODE_TYPE_CAMERA));
|
2016-03-01 10:06:28 -08:00
|
|
|
evas_canvas3d_node_camera_set(globalscene.camera_node, globalscene.camera);
|
|
|
|
evas_canvas3d_node_member_add(globalscene.root_node, globalscene.camera_node);
|
|
|
|
evas_canvas3d_node_position_set(globalscene.camera_node, 0.0, 30.0, 800.0);
|
|
|
|
evas_canvas3d_node_look_at_set(globalscene.camera_node, EVAS_CANVAS3D_SPACE_PARENT, 0.0, 0.0, -1000.0, EVAS_CANVAS3D_SPACE_PARENT, 0.0, 1.0, 0.0);
|
2016-03-11 04:24:06 -08:00
|
|
|
globalscene.light = eo_add(EVAS_CANVAS3D_LIGHT_CLASS, evas);
|
2016-03-01 10:06:28 -08:00
|
|
|
evas_canvas3d_light_ambient_set(globalscene.light, 1.0, 1.0, 1.0, 1.0);
|
|
|
|
evas_canvas3d_light_diffuse_set(globalscene.light, 1.0, 1.0, 1.0, 1.0);
|
|
|
|
evas_canvas3d_light_specular_set(globalscene.light, 1.0, 1.0, 1.0, 1.0);
|
|
|
|
evas_canvas3d_light_directional_set(globalscene.light, EINA_TRUE);
|
2015-02-10 02:24:48 -08:00
|
|
|
|
2016-03-11 04:24:06 -08:00
|
|
|
globalscene.light_node =
|
|
|
|
eo_add(EVAS_CANVAS3D_NODE_CLASS, evas, evas_canvas3d_node_constructor(eoid, EVAS_CANVAS3D_NODE_TYPE_LIGHT));
|
2016-03-01 10:06:28 -08:00
|
|
|
evas_canvas3d_node_light_set(globalscene.light_node, globalscene.light);
|
|
|
|
evas_canvas3d_node_position_set(globalscene.light_node, 100.0, 50.0, 300.0);
|
|
|
|
evas_canvas3d_node_look_at_set(globalscene.light_node, EVAS_CANVAS3D_SPACE_PARENT, 0.0, 0.0, 0.0, EVAS_CANVAS3D_SPACE_PARENT, 1.0, 1.0, 1.0);
|
|
|
|
evas_canvas3d_node_member_add(globalscene.root_node, globalscene.light_node);
|
2015-02-10 02:24:48 -08:00
|
|
|
|
|
|
|
tmp = 0.01;
|
2015-03-18 04:31:46 -07:00
|
|
|
for (i = 0; i < globalscene.col * globalscene.row; i++)
|
2015-02-10 02:24:48 -08:00
|
|
|
{
|
2015-03-06 08:02:15 -08:00
|
|
|
Test_object *spheretmp;
|
|
|
|
m = malloc(sizeof(Test_object));
|
|
|
|
m->sphere_init = _init_sphere;
|
2015-02-10 02:24:48 -08:00
|
|
|
if (!i)
|
2015-03-18 04:31:46 -07:00
|
|
|
m->sphere_init(m, texture);
|
2015-02-10 02:24:48 -08:00
|
|
|
else
|
|
|
|
{
|
2015-03-06 08:02:15 -08:00
|
|
|
spheretmp = (Test_object *)eina_list_nth(globalscene.spheres, 0);
|
2015-03-18 04:31:46 -07:00
|
|
|
m->mesh = spheretmp->mesh;
|
|
|
|
m->material = spheretmp->material;
|
|
|
|
m->texture = spheretmp->texture;
|
2015-02-10 02:24:48 -08:00
|
|
|
}
|
2016-03-09 07:47:28 -08:00
|
|
|
eo_add(&m->node, EVAS_CANVAS3D_NODE_CLASS, evas, evas_canvas3d_node_constructor(m->node, EVAS_CANVAS3D_NODE_TYPE_MESH));
|
2015-02-10 02:24:48 -08:00
|
|
|
m->speed = tmp;
|
2015-03-18 04:31:46 -07:00
|
|
|
m->sphere_animate = _animate_sphere;
|
2015-03-06 08:02:15 -08:00
|
|
|
m->animate = ecore_timer_add(m->speed, m->sphere_animate, m);
|
2016-03-01 10:06:28 -08:00
|
|
|
evas_canvas3d_node_member_add(globalscene.root_node, m->node);
|
|
|
|
evas_canvas3d_node_mesh_add(m->node, m->mesh);
|
|
|
|
evas_canvas3d_node_scale_set(m->node, VEC_3(INIT_SCALE));
|
2015-03-06 08:02:15 -08:00
|
|
|
globalscene.spheres = eina_list_append(globalscene.spheres, m);
|
2015-02-10 02:24:48 -08:00
|
|
|
tmp += 0.01;
|
|
|
|
}
|
|
|
|
|
2015-03-18 04:31:46 -07:00
|
|
|
_recalculate_position();
|
2015-02-10 02:24:48 -08:00
|
|
|
|
2016-03-01 10:06:28 -08:00
|
|
|
evas_canvas3d_scene_root_node_set(globalscene.scene, globalscene.root_node);
|
|
|
|
evas_canvas3d_scene_camera_node_set(globalscene.scene, globalscene.camera_node);
|
|
|
|
evas_canvas3d_scene_size_set(globalscene.scene, WIDTH, HEIGHT);
|
2015-02-10 02:24:48 -08:00
|
|
|
return EINA_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
2015-03-06 08:02:15 -08:00
|
|
|
int row = 0, col = 0, precision = 0;
|
2015-03-18 04:31:46 -07:00
|
|
|
char *texture = NULL;
|
2015-02-10 02:24:48 -08:00
|
|
|
Eina_Bool r;
|
|
|
|
|
|
|
|
Ecore_Getopt_Value values[] = {
|
|
|
|
ECORE_GETOPT_VALUE_INT(row),
|
|
|
|
ECORE_GETOPT_VALUE_INT(col),
|
2015-03-06 08:02:15 -08:00
|
|
|
ECORE_GETOPT_VALUE_INT(precision),
|
2015-03-18 04:31:46 -07:00
|
|
|
ECORE_GETOPT_VALUE_STR(texture),
|
2015-02-10 02:24:48 -08:00
|
|
|
ECORE_GETOPT_VALUE_NONE
|
|
|
|
};
|
|
|
|
|
|
|
|
if (!ecore_evas_init()) return 0;
|
|
|
|
if (!ecore_init()) return 0;
|
|
|
|
|
|
|
|
ecore_getopt_parse(&optdesc, values, argc, argv);
|
|
|
|
|
|
|
|
if (!row) row = 2;
|
|
|
|
if (!col) col = 5;
|
2015-03-06 08:02:15 -08:00
|
|
|
if (!precision) precision = 30;
|
2015-03-18 04:31:46 -07:00
|
|
|
if (!texture) texture = (char *)image_path;
|
2015-02-10 02:24:48 -08:00
|
|
|
|
2015-03-18 04:31:46 -07:00
|
|
|
fprintf(stdout, "row - %d, col - %d, precision of spheres - %d, texture - %s\n",
|
|
|
|
row, col, precision, texture);
|
2015-02-10 02:24:48 -08:00
|
|
|
|
|
|
|
ecore_evas = ecore_evas_new("opengl_x11", 10, 10, WIDTH, HEIGHT, NULL);
|
|
|
|
|
|
|
|
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);
|
|
|
|
ecore_evas_show(ecore_evas);
|
|
|
|
|
|
|
|
evas = ecore_evas_get(ecore_evas);
|
|
|
|
|
|
|
|
bg = evas_object_rectangle_add(evas);
|
|
|
|
evas_object_color_set(bg, 100, 100, 100, 255);
|
|
|
|
evas_object_move(bg, 0, 0);
|
|
|
|
evas_object_resize(bg, WIDTH, HEIGHT);
|
|
|
|
evas_object_show(bg);
|
|
|
|
|
|
|
|
globalscene.scene_init = _init_scene;
|
|
|
|
globalscene.row = row;
|
|
|
|
globalscene.col = col;
|
2015-03-06 08:02:15 -08:00
|
|
|
globalscene.precision = precision;
|
2015-03-18 04:31:46 -07:00
|
|
|
globalscene.scene_init(texture);
|
2015-02-10 02:24:48 -08:00
|
|
|
|
|
|
|
image = evas_object_image_filled_add(evas);
|
|
|
|
|
2016-03-01 10:06:28 -08:00
|
|
|
efl_gfx_size_set(image, WIDTH, HEIGHT);
|
|
|
|
efl_gfx_visible_set(image, EINA_TRUE);
|
2015-02-10 02:24:48 -08:00
|
|
|
evas_object_focus_set(image, EINA_TRUE);
|
2016-03-01 10:06:28 -08:00
|
|
|
evas_obj_image_scene_set(image, globalscene.scene);
|
2015-02-10 02:24:48 -08:00
|
|
|
|
|
|
|
r = evas_object_key_grab(image, "Down", 0, 0, EINA_TRUE);
|
|
|
|
r = evas_object_key_grab(image, "Up", 0, 0, EINA_TRUE);
|
|
|
|
r = evas_object_key_grab(image, "Left", 0, 0, EINA_TRUE);
|
|
|
|
r = evas_object_key_grab(image, "Right", 0, 0, EINA_TRUE);
|
|
|
|
|
|
|
|
(void) r;
|
|
|
|
|
|
|
|
evas_object_event_callback_add(image, EVAS_CALLBACK_MOUSE_DOWN, _on_mouse_down, NULL);
|
|
|
|
evas_object_event_callback_add(image, EVAS_CALLBACK_KEY_DOWN, _on_key_down, NULL);
|
|
|
|
|
|
|
|
ecore_main_loop_begin();
|
|
|
|
|
|
|
|
ecore_evas_free(ecore_evas);
|
|
|
|
ecore_evas_shutdown();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|