aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/extantz/scenri.c
diff options
context:
space:
mode:
authorDavid Walter Seikel2014-05-06 00:12:23 +1000
committerDavid Walter Seikel2014-05-06 00:12:23 +1000
commit95e4dc70ff9118d0abfd5321605385321ab02f5c (patch)
tree656aeb3983e83c22ab00ac404ba4d1448a732390 /src/extantz/scenri.c
parentClean up include files. (diff)
downloadSledjHamr-95e4dc70ff9118d0abfd5321605385321ab02f5c.zip
SledjHamr-95e4dc70ff9118d0abfd5321605385321ab02f5c.tar.gz
SledjHamr-95e4dc70ff9118d0abfd5321605385321ab02f5c.tar.bz2
SledjHamr-95e4dc70ff9118d0abfd5321605385321ab02f5c.tar.xz
Shuffle stuff around into the new scenri.c and camera stuff.
Diffstat (limited to '')
-rw-r--r--src/extantz/scenri.c147
1 files changed, 147 insertions, 0 deletions
diff --git a/src/extantz/scenri.c b/src/extantz/scenri.c
new file mode 100644
index 0000000..0805108
--- /dev/null
+++ b/src/extantz/scenri.c
@@ -0,0 +1,147 @@
1#include "extantz.h"
2#include "scenri.h"
3
4static void _on_mouse_move(void *data, Evas *e EINA_UNUSED, Evas_Object *o, void *einfo)
5{
6 Scene_Data *scene = data;
7 Evas_Event_Mouse_Move *ev = einfo;
8 Evas_Coord x, y, w, h;
9 Evas_Coord obj_x, obj_y;
10 int scene_w, scene_h;
11 Evas_Real scene_x, scene_y;
12 Evas_Real s, t;
13 Evas_3D_Node *n;
14 Evas_3D_Mesh *m;
15 Eina_Bool pick;
16 char *name = NULL;
17
18 evas_object_geometry_get(o, &x, &y, &w, &h);
19
20 obj_x = ev->cur.canvas.x - x;
21 obj_y = ev->cur.canvas.y - y;
22
23 eo_do(scene->scene, evas_3d_scene_size_get(&scene_w, &scene_h));
24
25 scene_x = obj_x * scene_w / (Evas_Real)w;
26 scene_y = obj_y * scene_h / (Evas_Real)h;
27
28 eo_do(scene->scene, pick = evas_3d_scene_pick(scene_x, scene_y, &n, &m, &s, &t));
29 if (pick)
30 name = evas_object_data_get(n, "Name");
31 // This is a raw Evas callback, on the Elm image internal Evas_Object.
32 // So we need to get the Elm Image back from the raw Evas_Object.
33 // Which is why we stuffed it in the scene structure.
34 if (name)
35 {
36 elm_object_tooltip_text_set(scene->image, name);
37 elm_object_tooltip_show(scene->image);
38 }
39 else
40 {
41 elm_object_tooltip_text_set(scene->image, "");
42 elm_object_tooltip_hide(scene->image);
43 }
44}
45
46static void _on_mouse_down(void *data, Evas *e EINA_UNUSED, Evas_Object *o, void *einfo)
47{
48 Scene_Data *scene = data;
49 Evas_Event_Mouse_Down *ev = einfo;
50 Evas_Coord x, y, w, h;
51 Evas_Coord obj_x, obj_y;
52 int scene_w, scene_h;
53 Evas_Real scene_x, scene_y;
54 Evas_Real s, t;
55 Evas_3D_Node *n;
56 Evas_3D_Mesh *m;
57 Eina_Bool pick;
58 char *name = NULL;
59
60 // Set the focus onto us.
61 elm_object_focus_set(o, EINA_TRUE);
62
63 evas_object_geometry_get(o, &x, &y, &w, &h);
64
65 obj_x = ev->canvas.x - x;
66 obj_y = ev->canvas.y - y;
67
68 eo_do(scene->scene, evas_3d_scene_size_get(&scene_w, &scene_h));
69
70 scene_x = obj_x * scene_w / (Evas_Real)w;
71 scene_y = obj_y * scene_h / (Evas_Real)h;
72
73 eo_do(scene->scene, pick = evas_3d_scene_pick(scene_x, scene_y, &n, &m, &s, &t));
74 if (pick)
75 {
76 name = evas_object_data_get(n, "Name");
77 printf("Picked : ");
78 }
79 else
80 printf("Not picked : ");
81 if (NULL == name)
82 name = "";
83
84 printf("output(%d, %d) canvas(%d, %d) object(%d, %d) scene(%f, %f) texcoord(%f, %f) node(%p) %s mesh(%p)\n",
85 ev->output.x, ev->output.y, ev->canvas.x, ev->canvas.y, obj_x, obj_y, scene_x, scene_y, s, t, n, name, m);
86}
87
88Scene_Data *scenriAdd(globals *ourGlobals)
89{
90 Scene_Data *scene;
91 Evas_Object *obj, *temp;
92
93 scene = calloc(1, sizeof(Scene_Data));
94
95 // TODO - I have no idea how this should work.
96 // It seems the people that wrote the examples don't know either. lol
97// scene->root_node = eo_add(EVAS_3D_NODE_CLASS, ourGlobals->evas, EVAS_3D_NODE_TYPE_NODE);
98 scene->root_node = evas_3d_node_add(ourGlobals->evas, EVAS_3D_NODE_TYPE_NODE);
99
100 scene->scene = eo_add(EVAS_3D_SCENE_CLASS, ourGlobals->evas,
101 evas_3d_scene_root_node_set(scene->root_node),
102 evas_3d_scene_size_set(512, 512),
103 evas_3d_scene_background_color_set(0.0, 0.0, 0.0, 0.0)
104 );
105
106 // Add an image object for 3D scene rendering.
107 obj = eo_add(ELM_OBJ_IMAGE_CLASS, ourGlobals->win,
108 evas_obj_size_hint_weight_set(EVAS_HINT_EXPAND, EVAS_HINT_EXPAND),
109 elm_obj_image_fill_outside_set(EINA_TRUE),
110 evas_obj_visibility_set(EINA_TRUE),
111 temp = elm_obj_image_object_get()
112 );
113 elm_object_tooltip_text_set(obj, "");
114 elm_object_tooltip_hide(obj);
115 scene->image = obj;
116 scene->camera_node = cameraAdd(ourGlobals, scene, obj);
117
118 scene->light = eo_add(EVAS_3D_LIGHT_CLASS, ourGlobals->evas,
119 evas_3d_light_ambient_set(1.0, 1.0, 1.0, 1.0),
120 evas_3d_light_diffuse_set(1.0, 1.0, 1.0, 1.0),
121 evas_3d_light_specular_set(1.0, 1.0, 1.0, 1.0),
122 evas_3d_light_directional_set(EINA_TRUE)
123 );
124
125 scene->light_node = evas_3d_node_add(ourGlobals->evas, EVAS_3D_NODE_TYPE_LIGHT);
126 eo_do(scene->light_node,
127 evas_3d_node_light_set(scene->light),
128 evas_3d_node_position_set(1000.0, 0.0, 1000.0),
129 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)
130 );
131
132 eo_do(scene->root_node, evas_3d_node_member_add(scene->light_node));
133
134 eo_do(temp, evas_obj_image_scene_set(scene->scene));
135 // Elm can't seem to be able to tell us WHERE an image was clicked, so use raw Evas calbacks instead.
136 evas_object_event_callback_add(temp, EVAS_CALLBACK_MOUSE_MOVE, _on_mouse_move, scene);
137 evas_object_event_callback_add(temp, EVAS_CALLBACK_MOUSE_DOWN, _on_mouse_down, scene);
138
139 elm_win_resize_object_add(ourGlobals->win, obj);
140
141 return scene;
142}
143
144void scenriDel(globals *ourGlobals)
145{
146 eo_unref(ourGlobals->scene->image);
147}