2015-02-23 08:59:05 -08:00
|
|
|
/**
|
2015-06-17 07:31:14 -07:00
|
|
|
* This example shows how to attach mechanism of pick.
|
2015-02-23 08:59:05 -08:00
|
|
|
*
|
2015-06-17 07:31:14 -07:00
|
|
|
* Here shown which transformation should be applied to event_info of
|
|
|
|
* _on_mouse_down to make them usable in evas_canvas3d_scene_pick()
|
2015-02-23 08:59:05 -08:00
|
|
|
* and parameters which can be got from this function.
|
|
|
|
*
|
|
|
|
* @verbatim
|
2015-05-29 09:14:08 -07:00
|
|
|
* gcc -o evas-3d-pick evas-3d-pick.c `pkg-config --libs --cflags efl evas ecore ecore-evas eo` -lm
|
2015-02-23 08:59:05 -08:00
|
|
|
* @endverbatim
|
|
|
|
*/
|
|
|
|
|
2015-02-20 03:02:08 -08:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#else
|
|
|
|
#define PACKAGE_EXAMPLES_DIR "."
|
2014-05-01 02:01:56 -07:00
|
|
|
#define EFL_EO_API_SUPPORT
|
|
|
|
#define EFL_BETA_API_SUPPORT
|
2015-02-20 08:59:27 -08:00
|
|
|
#endif
|
2014-05-11 21:30:50 -07:00
|
|
|
|
2013-12-27 03:31:39 -08:00
|
|
|
#include <math.h>
|
2014-05-11 21:30:50 -07:00
|
|
|
#include <Eo.h>
|
2014-04-14 18:32:39 -07:00
|
|
|
#include <Evas.h>
|
2014-05-11 21:30:50 -07:00
|
|
|
#include <Ecore.h>
|
|
|
|
#include <Ecore_Evas.h>
|
2015-02-20 08:59:27 -08:00
|
|
|
#include "evas-common.h"
|
2013-12-27 03:31:39 -08:00
|
|
|
|
2014-05-07 00:55:50 -07:00
|
|
|
#define WIDTH 400
|
|
|
|
#define HEIGHT 400
|
2013-12-27 03:31:39 -08:00
|
|
|
|
2015-03-18 06:47:50 -07:00
|
|
|
static const char *image_path = PACKAGE_EXAMPLES_DIR EVAS_IMAGE_FOLDER "/wood.jpg";
|
2014-05-11 21:30:50 -07:00
|
|
|
|
|
|
|
static Ecore_Evas *ecore_evas = NULL;
|
|
|
|
static Evas *evas = NULL;
|
|
|
|
static Eo *background = NULL;
|
|
|
|
static Eo *image = NULL;
|
|
|
|
static Eo *scene = NULL;
|
|
|
|
static Eo *root_node = NULL;
|
|
|
|
static Eo *camera_node = NULL;
|
|
|
|
static Eo *camera = NULL;
|
|
|
|
static Eo *mesh_node = NULL;
|
|
|
|
static Eo *mesh = NULL;
|
|
|
|
static Eo *material = NULL;
|
|
|
|
static Eo *texture_diffuse = NULL;
|
2015-05-29 09:14:08 -07:00
|
|
|
static Eo *sphere = NULL;
|
2013-12-27 03:31:39 -08:00
|
|
|
|
|
|
|
static Eina_Bool
|
|
|
|
_animate_scene(void *data)
|
|
|
|
{
|
|
|
|
static float angle = 0.0f;
|
|
|
|
|
|
|
|
angle += 0.3;
|
|
|
|
|
2015-06-17 07:31:14 -07:00
|
|
|
eo_do((Evas_Canvas3D_Node *)data,
|
|
|
|
evas_canvas3d_node_orientation_angle_axis_set(angle, 0.0, 1.0, 0.0));
|
2013-12-27 03:31:39 -08:00
|
|
|
|
|
|
|
/* Rotate */
|
2014-05-11 21:30:50 -07:00
|
|
|
if (angle > 360.0) angle -= 360.0f;
|
2013-12-27 03:31:39 -08:00
|
|
|
|
|
|
|
return EINA_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_on_delete(Ecore_Evas *ee EINA_UNUSED)
|
|
|
|
{
|
|
|
|
ecore_main_loop_quit();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_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);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2014-05-11 21:30:50 -07:00
|
|
|
_on_mouse_down(void *data EINA_UNUSED, Evas *e EINA_UNUSED, Evas_Object *obj,
|
|
|
|
void *event_info)
|
2013-12-27 03:31:39 -08:00
|
|
|
{
|
2014-05-11 21:30:50 -07:00
|
|
|
Evas_Event_Mouse_Down *ev = event_info;
|
2014-05-01 02:01:56 -07:00
|
|
|
Evas_Coord x, y, w, h;
|
|
|
|
Evas_Coord obj_x, obj_y;
|
|
|
|
int scene_w, scene_h;
|
|
|
|
Evas_Real scene_x, scene_y;
|
|
|
|
Evas_Real s, t;
|
2015-06-17 07:31:14 -07:00
|
|
|
Evas_Canvas3D_Node *n;
|
|
|
|
Evas_Canvas3D_Mesh *m;
|
2014-05-01 02:01:56 -07:00
|
|
|
Eina_Bool pick;
|
2013-12-27 03:31:39 -08:00
|
|
|
|
2014-05-11 21:30:50 -07:00
|
|
|
evas_object_geometry_get(obj, &x, &y, &w, &h);
|
2013-12-27 03:31:39 -08:00
|
|
|
|
2014-05-01 02:01:56 -07:00
|
|
|
obj_x = ev->canvas.x - x;
|
|
|
|
obj_y = ev->canvas.y - y;
|
2013-12-27 03:31:39 -08:00
|
|
|
|
2015-06-17 07:31:14 -07:00
|
|
|
eo_do(scene, evas_canvas3d_scene_size_get(&scene_w, &scene_h));
|
2013-12-27 03:31:39 -08:00
|
|
|
|
2014-05-01 02:01:56 -07:00
|
|
|
scene_x = obj_x * scene_w / (Evas_Real)w;
|
|
|
|
scene_y = obj_y * scene_h / (Evas_Real)h;
|
2013-12-27 03:31:39 -08:00
|
|
|
|
2015-06-17 07:31:14 -07:00
|
|
|
eo_do(scene, pick = evas_canvas3d_scene_pick(scene_x, scene_y, &n, &m, &s, &t));
|
2014-05-11 21:30:50 -07:00
|
|
|
if (pick) printf("Picked : ");
|
|
|
|
else printf("Not picked : ");
|
|
|
|
|
|
|
|
printf("output(%d, %d) canvas(%d, %d) object(%d, %d) scene(%f, %f) texcoord(%f, %f) "
|
|
|
|
"node(%p) mesh(%p)\n",
|
|
|
|
ev->output.x, ev->output.y,
|
|
|
|
ev->canvas.x, ev->canvas.y,
|
|
|
|
obj_x, obj_y,
|
|
|
|
scene_x, scene_y,
|
|
|
|
s, t, n, m);
|
2013-12-27 03:31:39 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
main(void)
|
|
|
|
{
|
2014-05-06 23:32:11 -07:00
|
|
|
//Unless Evas 3D supports Software renderer, we set gl backened forcely.
|
|
|
|
setenv("ECORE_EVAS_ENGINE", "opengl_x11", 1);
|
|
|
|
|
2014-05-11 21:30:50 -07:00
|
|
|
if (!ecore_evas_init()) return 0;
|
2013-12-27 03:31:39 -08:00
|
|
|
|
|
|
|
ecore_evas = ecore_evas_new(NULL, 10, 10, WIDTH, HEIGHT, NULL);
|
|
|
|
|
2014-05-11 21:30:50 -07:00
|
|
|
if (!ecore_evas) return 0;
|
2013-12-27 03:31:39 -08:00
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
/* Add a scene object .*/
|
2015-06-17 07:31:14 -07:00
|
|
|
scene = eo_add(EVAS_CANVAS3D_SCENE_CLASS, evas);
|
2013-12-27 03:31:39 -08:00
|
|
|
|
|
|
|
/* Add the root node for the scene. */
|
2015-06-17 07:31:14 -07:00
|
|
|
root_node = eo_add(EVAS_CANVAS3D_NODE_CLASS, evas,
|
|
|
|
evas_canvas3d_node_constructor(EVAS_CANVAS3D_NODE_TYPE_NODE));
|
2013-12-27 03:31:39 -08:00
|
|
|
|
|
|
|
/* Add the camera. */
|
2015-06-17 07:31:14 -07:00
|
|
|
camera = eo_add(EVAS_CANVAS3D_CAMERA_CLASS, evas);
|
2014-05-11 21:30:50 -07:00
|
|
|
eo_do(camera,
|
2015-06-17 07:31:14 -07:00
|
|
|
evas_canvas3d_camera_projection_perspective_set(30.0, 1.0, 1.0, 100.0));
|
2013-12-27 03:31:39 -08:00
|
|
|
|
2014-05-07 06:33:15 -07:00
|
|
|
camera_node =
|
2015-06-17 07:31:14 -07:00
|
|
|
eo_add(EVAS_CANVAS3D_NODE_CLASS, evas,
|
|
|
|
evas_canvas3d_node_constructor(EVAS_CANVAS3D_NODE_TYPE_CAMERA));
|
2014-05-01 02:01:56 -07:00
|
|
|
eo_do(camera_node,
|
2015-06-17 07:31:14 -07:00
|
|
|
evas_canvas3d_node_camera_set(camera),
|
|
|
|
evas_canvas3d_node_position_set(0.0, 0.0, 2.5),
|
|
|
|
evas_canvas3d_node_look_at_set(EVAS_CANVAS3D_SPACE_PARENT, 0.0, 0.0, 0.0,
|
|
|
|
EVAS_CANVAS3D_SPACE_PARENT, 0.0, 1.0, 0.0));
|
|
|
|
eo_do(root_node, evas_canvas3d_node_member_add(camera_node));
|
2013-12-27 03:31:39 -08:00
|
|
|
|
2015-06-17 07:31:14 -07:00
|
|
|
sphere = eo_add(EVAS_CANVAS3D_PRIMITIVE_CLASS, evas);
|
2015-05-29 09:14:08 -07:00
|
|
|
eo_do(sphere,
|
2015-06-17 07:31:14 -07:00
|
|
|
evas_canvas3d_primitive_form_set(EVAS_CANVAS3D_MESH_PRIMITIVE_SPHERE),
|
|
|
|
evas_canvas3d_primitive_precision_set(50));
|
2013-12-27 03:31:39 -08:00
|
|
|
|
2015-06-17 07:31:14 -07:00
|
|
|
mesh = eo_add(EVAS_CANVAS3D_MESH_CLASS, evas);
|
|
|
|
eo_do(mesh, evas_canvas3d_mesh_from_primitive_set(0, sphere));
|
2014-05-01 02:01:56 -07:00
|
|
|
|
2015-06-17 07:31:14 -07:00
|
|
|
material = eo_add(EVAS_CANVAS3D_MATERIAL_CLASS, evas);
|
2014-05-01 02:01:56 -07:00
|
|
|
|
2015-06-17 07:31:14 -07:00
|
|
|
texture_diffuse = eo_add(EVAS_CANVAS3D_TEXTURE_CLASS, evas);
|
2014-05-01 02:01:56 -07:00
|
|
|
eo_do(texture_diffuse,
|
2015-06-17 07:31:14 -07:00
|
|
|
evas_canvas3d_texture_file_set(image_path, NULL),
|
|
|
|
evas_canvas3d_texture_filter_set(EVAS_CANVAS3D_TEXTURE_FILTER_LINEAR,
|
|
|
|
EVAS_CANVAS3D_TEXTURE_FILTER_LINEAR));
|
2014-05-01 02:01:56 -07:00
|
|
|
eo_do(material,
|
2015-07-14 03:19:35 -07:00
|
|
|
evas_canvas3d_material_texture_set(EVAS_CANVAS3D_MATERIAL_ATTRIB_DIFFUSE,
|
2014-05-11 21:30:50 -07:00
|
|
|
texture_diffuse),
|
2015-07-14 03:19:35 -07:00
|
|
|
evas_canvas3d_material_enable_set(EVAS_CANVAS3D_MATERIAL_ATTRIB_AMBIENT, EINA_TRUE),
|
|
|
|
evas_canvas3d_material_enable_set(EVAS_CANVAS3D_MATERIAL_ATTRIB_DIFFUSE, EINA_TRUE),
|
|
|
|
evas_canvas3d_material_enable_set(EVAS_CANVAS3D_MATERIAL_ATTRIB_SPECULAR, EINA_TRUE),
|
2014-05-01 02:01:56 -07:00
|
|
|
|
2015-07-14 03:19:35 -07:00
|
|
|
evas_canvas3d_material_color_set(EVAS_CANVAS3D_MATERIAL_ATTRIB_AMBIENT, 0.01, 0.01, 0.01,
|
2014-05-11 21:30:50 -07:00
|
|
|
1.0),
|
2015-07-14 03:19:35 -07:00
|
|
|
evas_canvas3d_material_color_set(EVAS_CANVAS3D_MATERIAL_ATTRIB_DIFFUSE, 1.0, 1.0, 1.0,
|
2014-05-11 21:30:50 -07:00
|
|
|
1.0),
|
2015-07-14 03:19:35 -07:00
|
|
|
evas_canvas3d_material_color_set(EVAS_CANVAS3D_MATERIAL_ATTRIB_SPECULAR, 1.0, 1.0, 1.0,
|
2014-05-11 21:30:50 -07:00
|
|
|
1.0),
|
2015-06-17 07:31:14 -07:00
|
|
|
evas_canvas3d_material_shininess_set(50.0));
|
2013-12-27 03:31:39 -08:00
|
|
|
|
2015-06-17 07:31:14 -07:00
|
|
|
mesh_node = eo_add(EVAS_CANVAS3D_NODE_CLASS, evas,
|
|
|
|
evas_canvas3d_node_constructor(EVAS_CANVAS3D_NODE_TYPE_MESH));
|
2014-05-07 06:33:15 -07:00
|
|
|
|
2015-06-17 07:31:14 -07:00
|
|
|
eo_do(root_node, evas_canvas3d_node_member_add(mesh_node));
|
|
|
|
eo_do(mesh_node, evas_canvas3d_node_mesh_add(mesh));
|
|
|
|
eo_do(mesh, evas_canvas3d_mesh_shade_mode_set(EVAS_CANVAS3D_SHADE_MODE_DIFFUSE),
|
|
|
|
evas_canvas3d_mesh_frame_material_set(0, material));
|
2013-12-27 03:31:39 -08:00
|
|
|
|
|
|
|
/* Set up scene. */
|
2014-05-01 02:01:56 -07:00
|
|
|
eo_do(scene,
|
2015-06-17 07:31:14 -07:00
|
|
|
evas_canvas3d_scene_root_node_set(root_node),
|
|
|
|
evas_canvas3d_scene_camera_node_set(camera_node),
|
|
|
|
evas_canvas3d_scene_size_set(WIDTH, HEIGHT));
|
2013-12-27 03:31:39 -08:00
|
|
|
|
|
|
|
/* Add evas objects. */
|
2014-06-03 15:45:37 -07:00
|
|
|
background = eo_add(EVAS_RECTANGLE_CLASS, evas);
|
2014-05-11 21:30:50 -07:00
|
|
|
eo_do(background,
|
2015-04-03 07:30:47 -07:00
|
|
|
efl_gfx_color_set(0, 0, 0, 255),
|
|
|
|
efl_gfx_size_set(WIDTH, HEIGHT),
|
|
|
|
efl_gfx_visible_set(EINA_TRUE));
|
2013-12-27 03:31:39 -08:00
|
|
|
|
|
|
|
image = evas_object_image_filled_add(evas);
|
2014-05-11 21:30:50 -07:00
|
|
|
eo_do(image,
|
|
|
|
evas_obj_image_scene_set(scene),
|
2015-04-03 07:30:47 -07:00
|
|
|
efl_gfx_size_set(WIDTH, HEIGHT),
|
|
|
|
efl_gfx_visible_set(EINA_TRUE));
|
2014-05-11 21:30:50 -07:00
|
|
|
evas_object_event_callback_add(image, EVAS_CALLBACK_MOUSE_DOWN,
|
|
|
|
_on_mouse_down, NULL);
|
2013-12-27 03:31:39 -08:00
|
|
|
|
|
|
|
ecore_timer_add(0.01, _animate_scene, mesh_node);
|
|
|
|
|
|
|
|
ecore_main_loop_begin();
|
|
|
|
|
|
|
|
ecore_evas_free(ecore_evas);
|
|
|
|
ecore_evas_shutdown();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|