aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/extantz
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/extantz/Evas_3D_demo.c243
-rwxr-xr-xsrc/extantz/build.lua4
-rw-r--r--src/extantz/camera.c60
-rw-r--r--src/extantz/extantz.c3
-rw-r--r--src/extantz/extantz.h6
-rw-r--r--src/extantz/extantzCamera.h8
-rw-r--r--src/extantz/scenri.c147
-rw-r--r--src/extantz/scenri.h43
8 files changed, 260 insertions, 254 deletions
diff --git a/src/extantz/Evas_3D_demo.c b/src/extantz/Evas_3D_demo.c
index 7e3e8cd..dbc589d 100644
--- a/src/extantz/Evas_3D_demo.c
+++ b/src/extantz/Evas_3D_demo.c
@@ -1,7 +1,5 @@
1#include "extantz.h" 1#include "extantz.h"
2 2#include "scenri.h"
3
4static Scene_Data ourScene;
5 3
6 4
7static const float cube_vertices[] = 5static const float cube_vertices[] =
@@ -81,36 +79,6 @@ static const unsigned int pixels1[] =
81}; 79};
82 80
83 81
84typedef struct _vec4
85{
86 float x;
87 float y;
88 float z;
89 float w;
90} vec4;
91
92typedef struct _vec3
93{
94 float x;
95 float y;
96 float z;
97} vec3;
98
99typedef struct _vec2
100{
101 float x;
102 float y;
103} vec2;
104
105typedef struct _vertex
106{
107 vec3 position;
108 vec3 normal;
109 vec3 tangent;
110 vec4 color;
111 vec3 texcoord;
112} vertex;
113
114static int vertex_count = 0; 82static int vertex_count = 0;
115static vertex *sphere_vertices = NULL; 83static vertex *sphere_vertices = NULL;
116 84
@@ -265,7 +233,6 @@ _sphere_init(int precision)
265 } 233 }
266} 234}
267 235
268
269Eina_Bool _animate_scene(globals *ourGlobals) 236Eina_Bool _animate_scene(globals *ourGlobals)
270{ 237{
271 static float angle = 0.0f; 238 static float angle = 0.0f;
@@ -273,10 +240,6 @@ Eina_Bool _animate_scene(globals *ourGlobals)
273 static int frame = 0; 240 static int frame = 0;
274 static int inc = 1; 241 static int inc = 1;
275 static int sonicFrame = 0; 242 static int sonicFrame = 0;
276 Evas_Real x, y, z, w;
277 EPhysics_Quaternion *quat = ephysics_quaternion_new();
278 EPhysics_Quaternion *quat1 = ephysics_quaternion_new();
279 EPhysics_Quaternion *result = ephysics_quaternion_new();
280 243
281 Scene_Data *scene = ourGlobals->scene; 244 Scene_Data *scene = ourGlobals->scene;
282 245
@@ -307,67 +270,9 @@ Eina_Bool _animate_scene(globals *ourGlobals)
307 evas_3d_node_orientation_angle_axis_set(angle, 0.0, 1.0, 0.0) 270 evas_3d_node_orientation_angle_axis_set(angle, 0.0, 1.0, 0.0)
308 ); 271 );
309 272
310 // Camera movement.
311 ephysics_quaternion_euler_set(quat1, ourGlobals->gld.move->r, ourGlobals->gld.move->s, ourGlobals->gld.move->t);
312 eo_do(scene->camera_node, evas_3d_node_orientation_get(EVAS_3D_SPACE_PARENT, &x, &y, &z, &w));
313 ephysics_quaternion_set(quat, x, y, z, w);
314 ephysics_quaternion_multiply(quat, quat1, result);
315 ephysics_quaternion_normalize(result);
316 ephysics_quaternion_get(result, &x, &y, &z, &w);
317 eo_do(scene->camera_node, evas_3d_node_orientation_set(x, y, z, w));
318
319 eo_do(scene->camera_node, evas_3d_node_position_get(EVAS_3D_SPACE_PARENT, &x, &y, &z));
320 x -= ourGlobals->gld.move->x;
321 y -= ourGlobals->gld.move->y;
322 z -= ourGlobals->gld.move->z;
323 eo_do(scene->camera_node, evas_3d_node_position_set(x, y, z));
324
325 free(result);
326 free(quat1);
327 free(quat);
328
329 return EINA_TRUE; 273 return EINA_TRUE;
330} 274}
331 275
332
333static void
334_camera_setup(globals *ourGlobals, Scene_Data *scene)
335{
336 scene->camera = eo_add(EVAS_3D_CAMERA_CLASS, ourGlobals->evas,
337 evas_3d_camera_projection_perspective_set(60.0, 1.0, 1.0, 500.0)
338 );
339
340 scene->camera_node = evas_3d_node_add(ourGlobals->evas, EVAS_3D_NODE_TYPE_CAMERA);
341 eo_do(scene->camera_node,
342 evas_3d_node_camera_set(scene->camera),
343 evas_3d_node_position_set(50.0, 0.0, 20.0),
344 evas_3d_node_look_at_set(EVAS_3D_SPACE_PARENT, 0.0, 0.0, 20.0, EVAS_3D_SPACE_PARENT, 0.0, 0.0, 1.0)
345 );
346
347 eo_do(scene->root_node, evas_3d_node_member_add(scene->camera_node));
348}
349
350static void
351_light_setup(globals *ourGlobals, Scene_Data *scene)
352{
353 scene->light = eo_add(EVAS_3D_LIGHT_CLASS, ourGlobals->evas,
354 evas_3d_light_ambient_set(1.0, 1.0, 1.0, 1.0),
355 evas_3d_light_diffuse_set(1.0, 1.0, 1.0, 1.0),
356 evas_3d_light_specular_set(1.0, 1.0, 1.0, 1.0),
357 evas_3d_light_directional_set(EINA_TRUE)
358 );
359
360 scene->light_node = evas_3d_node_add(ourGlobals->evas, EVAS_3D_NODE_TYPE_LIGHT);
361 eo_do(scene->light_node,
362 evas_3d_node_light_set(scene->light),
363 evas_3d_node_position_set(1000.0, 0.0, 1000.0),
364 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)
365 );
366
367 eo_do(scene->root_node, evas_3d_node_member_add(scene->light_node));
368
369}
370
371static void _cube_setup(globals *ourGlobals, Scene_Data *scene) 276static void _cube_setup(globals *ourGlobals, Scene_Data *scene)
372{ 277{
373 char buf[PATH_MAX]; 278 char buf[PATH_MAX];
@@ -541,151 +446,13 @@ static void _earth_setup(globals *ourGlobals, Scene_Data *scene)
541} 446}
542 447
543 448
544static void
545_scene_setup(globals *ourGlobals, Scene_Data *scene)
546{
547 // TODO - I have no idea how this should work.
548 // It seems the people that wrote the examples don't know either. lol
549// scene->root_node = eo_add(EVAS_3D_NODE_CLASS, ourGlobals->evas, EVAS_3D_NODE_TYPE_NODE);
550 scene->root_node = evas_3d_node_add(ourGlobals->evas, EVAS_3D_NODE_TYPE_NODE);
551
552 scene->scene = eo_add(EVAS_3D_SCENE_CLASS, ourGlobals->evas,
553 evas_3d_scene_root_node_set(scene->root_node),
554 evas_3d_scene_size_set(512, 512),
555 evas_3d_scene_background_color_set(0.0, 0.0, 0.0, 0.0)
556 );
557
558 _camera_setup(ourGlobals, scene);
559 _light_setup(ourGlobals, scene);
560 _cube_setup(ourGlobals, scene);
561 _sonic_setup(ourGlobals, scene);
562 _earth_setup(ourGlobals, scene);
563
564 eo_do(scene->scene,
565 evas_3d_scene_camera_node_set(scene->camera_node)
566 );
567}
568
569
570static void _on_mouse_move(void *data, Evas *e EINA_UNUSED, Evas_Object *o, void *einfo)
571{
572 Scene_Data *scene = data;
573 Evas_Event_Mouse_Move *ev = einfo;
574 Evas_Coord x, y, w, h;
575 Evas_Coord obj_x, obj_y;
576 int scene_w, scene_h;
577 Evas_Real scene_x, scene_y;
578 Evas_Real s, t;
579 Evas_3D_Node *n;
580 Evas_3D_Mesh *m;
581 Eina_Bool pick;
582 char *name = NULL;
583
584 evas_object_geometry_get(o, &x, &y, &w, &h);
585
586 obj_x = ev->cur.canvas.x - x;
587 obj_y = ev->cur.canvas.y - y;
588
589 eo_do(scene->scene, evas_3d_scene_size_get(&scene_w, &scene_h));
590
591 scene_x = obj_x * scene_w / (Evas_Real)w;
592 scene_y = obj_y * scene_h / (Evas_Real)h;
593
594 eo_do(scene->scene, pick = evas_3d_scene_pick(scene_x, scene_y, &n, &m, &s, &t));
595 if (pick)
596 name = evas_object_data_get(n, "Name");
597 // This is a raw Evas callback, on the Elm image internal Evas_Object.
598 // So we need to get the Elm Image back from the raw Evas_Object.
599 // Which is why we stuffed it in the scene structure.
600 if (name)
601 {
602 elm_object_tooltip_text_set(scene->image, name);
603 elm_object_tooltip_show(scene->image);
604 }
605 else
606 {
607 elm_object_tooltip_text_set(scene->image, "");
608 elm_object_tooltip_hide(scene->image);
609 }
610}
611
612static void _on_mouse_down(void *data, Evas *e EINA_UNUSED, Evas_Object *o, void *einfo)
613{
614 Scene_Data *scene = data;
615 Evas_Event_Mouse_Down *ev = einfo;
616 Evas_Coord x, y, w, h;
617 Evas_Coord obj_x, obj_y;
618 int scene_w, scene_h;
619 Evas_Real scene_x, scene_y;
620 Evas_Real s, t;
621 Evas_3D_Node *n;
622 Evas_3D_Mesh *m;
623 Eina_Bool pick;
624 char *name = NULL;
625
626 // Set the focus onto us.
627 elm_object_focus_set(o, EINA_TRUE);
628
629 evas_object_geometry_get(o, &x, &y, &w, &h);
630
631 obj_x = ev->canvas.x - x;
632 obj_y = ev->canvas.y - y;
633
634 eo_do(scene->scene, evas_3d_scene_size_get(&scene_w, &scene_h));
635
636 scene_x = obj_x * scene_w / (Evas_Real)w;
637 scene_y = obj_y * scene_h / (Evas_Real)h;
638
639 eo_do(scene->scene, pick = evas_3d_scene_pick(scene_x, scene_y, &n, &m, &s, &t));
640 if (pick)
641 {
642 name = evas_object_data_get(n, "Name");
643 printf("Picked : ");
644 }
645 else
646 printf("Not picked : ");
647 if (NULL == name)
648 name = "";
649
650 printf("output(%d, %d) canvas(%d, %d) object(%d, %d) scene(%f, %f) texcoord(%f, %f) "
651 "node(%p) %s mesh(%p)\n",
652 ev->output.x, ev->output.y,
653 ev->canvas.x, ev->canvas.y,
654 obj_x, obj_y,
655 scene_x, scene_y,
656 s, t, n, name, m);
657}
658
659void Evas_3D_Demo_add(globals *ourGlobals) 449void Evas_3D_Demo_add(globals *ourGlobals)
660{ 450{
661 Evas_Object *obj, *temp; 451 ourGlobals->scene = scenriAdd(ourGlobals);
662
663 ourGlobals->scene = &ourScene;
664 _scene_setup(ourGlobals, &ourScene);
665
666 // Add an image object for 3D scene rendering.
667 obj = eo_add(ELM_OBJ_IMAGE_CLASS, ourGlobals->win,
668 evas_obj_size_hint_weight_set(EVAS_HINT_EXPAND, EVAS_HINT_EXPAND),
669 elm_obj_image_fill_outside_set(EINA_TRUE),
670 evas_obj_visibility_set(EINA_TRUE),
671 temp = elm_obj_image_object_get()
672 );
673 elm_object_tooltip_text_set(obj, "");
674 elm_object_tooltip_hide(obj);
675 ourScene.image = obj;
676
677 eo_do(temp,
678 evas_obj_image_scene_set(ourScene.scene)
679 );
680 // Elm can't seem to be able to tell us WHERE an image was clicked, so use raw Evas calbacks instead.
681 evas_object_event_callback_add(temp, EVAS_CALLBACK_MOUSE_MOVE, _on_mouse_move, &ourScene);
682 evas_object_event_callback_add(temp, EVAS_CALLBACK_MOUSE_DOWN, _on_mouse_down, &ourScene);
683
684 cameraAdd(ourGlobals, obj);
685 elm_win_resize_object_add(ourGlobals->win, obj);
686// elm_box_pack_end(ourGlobals->gld.bx, obj);
687 452
688 ourGlobals->gld.move = calloc(1, sizeof(cameraMove)); 453 _cube_setup(ourGlobals, ourGlobals->scene);
454 _sonic_setup(ourGlobals, ourGlobals->scene);
455 _earth_setup(ourGlobals, ourGlobals->scene);
689} 456}
690 457
691void Evas_3D_Demo_fini(globals *ourGlobals) 458void Evas_3D_Demo_fini(globals *ourGlobals)
diff --git a/src/extantz/build.lua b/src/extantz/build.lua
index 5ea2029..c50f4da 100755
--- a/src/extantz/build.lua
+++ b/src/extantz/build.lua
@@ -18,11 +18,11 @@ LDFLAGS = LDFLAGS .. ' -L../../libraries/irrlicht-1.8.1/lib/Linux'
18libs = libs .. ' -lIrrlicht -lGL -lbz2 -lGuiLua -lwinFang -lRunnr' 18libs = libs .. ' -lIrrlicht -lGL -lbz2 -lGuiLua -lwinFang -lRunnr'
19 19
20removeFiles(dir, {'crappisspuke.o', 'CDemo.o', 'extantzCamera.o', 'gears.o', 'ephysics_demo.o', 'Evas_3D_demo.o', '../../media/extantz.edj'}) 20removeFiles(dir, {'crappisspuke.o', 'CDemo.o', 'extantzCamera.o', 'gears.o', 'ephysics_demo.o', 'Evas_3D_demo.o', '../../media/extantz.edj'})
21removeFiles(dir, {'../../extantz', 'camera.o', 'chat.o', 'files.o', 'woMan.o'}) 21removeFiles(dir, {'../../extantz', 'camera.o', 'chat.o', 'files.o', 'scenri.o', 'woMan.o'})
22 22
23runCommand('edje_cc', dir, 'edje_cc ' .. EDJE_FLAGS .. ' extantz.edc ../../media/extantz.edj') 23runCommand('edje_cc', dir, 'edje_cc ' .. EDJE_FLAGS .. ' extantz.edc ../../media/extantz.edj')
24runCommand('Irrlicht files', dir, 'g++ ' .. CFLAGS .. ' -ffast-math -c crappisspuke.cpp -o crappisspuke.o ' .. LDFLAGS) 24runCommand('Irrlicht files', dir, 'g++ ' .. CFLAGS .. ' -ffast-math -c crappisspuke.cpp -o crappisspuke.o ' .. LDFLAGS)
25runCommand(nil, dir, 'g++ ' .. CFLAGS .. ' -ffast-math -c CDemo.cpp -o CDemo.o ' .. LDFLAGS) 25runCommand(nil, dir, 'g++ ' .. CFLAGS .. ' -ffast-math -c CDemo.cpp -o CDemo.o ' .. LDFLAGS)
26runCommand(nil, dir, 'g++ ' .. CFLAGS .. ' -ffast-math -c extantzCamera.cpp -o extantzCamera.o ' .. LDFLAGS) 26runCommand(nil, dir, 'g++ ' .. CFLAGS .. ' -ffast-math -c extantzCamera.cpp -o extantzCamera.o ' .. LDFLAGS)
27CFLAGS = CFLAGS .. ' -Wl,-export-dynamic' 27CFLAGS = CFLAGS .. ' -Wl,-export-dynamic'
28compileFiles('../../extantz', dir, {'gears', 'ephysics_demo', 'camera', 'Evas_3D_demo', 'chat', 'files', 'woMan', 'extantz'}, 'crappisspuke.o CDemo.o extantzCamera.o') 28compileFiles('../../extantz', dir, {'gears', 'ephysics_demo', 'camera', 'Evas_3D_demo', 'chat', 'files', 'scenri', 'woMan', 'extantz'}, 'crappisspuke.o CDemo.o extantzCamera.o')
diff --git a/src/extantz/camera.c b/src/extantz/camera.c
index d221ea0..c4b4757 100644
--- a/src/extantz/camera.c
+++ b/src/extantz/camera.c
@@ -1,6 +1,37 @@
1#include "extantz.h" 1#include "extantz.h"
2 2
3 3
4Eina_Bool animateCamera(globals *ourGlobals)
5{
6 Evas_Real x, y, z, w;
7 EPhysics_Quaternion *quat = ephysics_quaternion_new();
8 EPhysics_Quaternion *quat1 = ephysics_quaternion_new();
9 EPhysics_Quaternion *result = ephysics_quaternion_new();
10
11 Scene_Data *scene = ourGlobals->scene;
12
13 // Camera movement.
14 ephysics_quaternion_euler_set(quat1, ourGlobals->gld.move->r, ourGlobals->gld.move->s, ourGlobals->gld.move->t);
15 eo_do(scene->camera_node, evas_3d_node_orientation_get(EVAS_3D_SPACE_PARENT, &x, &y, &z, &w));
16 ephysics_quaternion_set(quat, x, y, z, w);
17 ephysics_quaternion_multiply(quat, quat1, result);
18 ephysics_quaternion_normalize(result);
19 ephysics_quaternion_get(result, &x, &y, &z, &w);
20 eo_do(scene->camera_node, evas_3d_node_orientation_set(x, y, z, w));
21
22 eo_do(scene->camera_node, evas_3d_node_position_get(EVAS_3D_SPACE_PARENT, &x, &y, &z));
23 x -= ourGlobals->gld.move->x;
24 y -= ourGlobals->gld.move->y;
25 z -= ourGlobals->gld.move->z;
26 eo_do(scene->camera_node, evas_3d_node_position_set(x, y, z));
27
28 free(result);
29 free(quat1);
30 free(quat);
31
32 return EINA_TRUE;
33}
34
4static void _on_camera_input_down(void *data, Evas *evas, Evas_Object *obj, void *event_info) 35static void _on_camera_input_down(void *data, Evas *evas, Evas_Object *obj, void *event_info)
5{ 36{
6 globals *ourGlobals = data; 37 globals *ourGlobals = data;
@@ -151,10 +182,31 @@ static Eina_Bool _cb_event_GL(void *data, Evas_Object *obj, Evas_Object *src, Ev
151 return processed; 182 return processed;
152} 183}
153 184
154void cameraAdd(globals *ourGlobals, Evas_Object *win) 185Evas_3D_Node *cameraAdd(globals *ourGlobals, Scene_Data *scene, Evas_Object *image)
155{ 186{
187 Evas_3D_Node *result = NULL;
188 Evas_3D_Camera *camera;
189
190 camera = eo_add(EVAS_3D_CAMERA_CLASS, ourGlobals->evas,
191 evas_3d_camera_projection_perspective_set(60.0, 1.0, 1.0, 500.0)
192 );
193
194 result = evas_3d_node_add(ourGlobals->evas, EVAS_3D_NODE_TYPE_CAMERA);
195 eo_do(result,
196 evas_3d_node_camera_set(camera),
197 evas_3d_node_position_set(50.0, 0.0, 20.0),
198 evas_3d_node_look_at_set(EVAS_3D_SPACE_PARENT, 0.0, 0.0, 20.0, EVAS_3D_SPACE_PARENT, 0.0, 0.0, 1.0)
199 );
200
201 eo_do(scene->root_node, evas_3d_node_member_add(result));
202 eo_do(scene->scene, evas_3d_scene_camera_node_set(result));
203
156 // In this code, we are making our own camera, so grab it's input when we are focused. 204 // In this code, we are making our own camera, so grab it's input when we are focused.
157 evas_object_event_callback_add(win, EVAS_CALLBACK_KEY_DOWN, _on_camera_input_down, ourGlobals); 205 evas_object_event_callback_add(image, EVAS_CALLBACK_KEY_DOWN, _on_camera_input_down, ourGlobals);
158 evas_object_event_callback_add(win, EVAS_CALLBACK_KEY_UP, _on_camera_input_up, ourGlobals); 206 evas_object_event_callback_add(image, EVAS_CALLBACK_KEY_UP, _on_camera_input_up, ourGlobals);
159 elm_object_event_callback_add(win, _cb_event_GL, ourGlobals); 207 elm_object_event_callback_add(image, _cb_event_GL, ourGlobals);
208
209 ourGlobals->gld.move = calloc(1, sizeof(cameraMove));
210
211 return result;
160} 212}
diff --git a/src/extantz/extantz.c b/src/extantz/extantz.c
index d0cd8ef..11f1d4e 100644
--- a/src/extantz/extantz.c
+++ b/src/extantz/extantz.c
@@ -170,6 +170,7 @@ static void _draw_gl(Evas_Object *obj)
170#endif 170#endif
171 171
172 _animate_scene(ourGlobals); 172 _animate_scene(ourGlobals);
173 animateCamera(ourGlobals);
173 174
174#if USE_IRR 175#if USE_IRR
175 drawIrr_end(ourGlobals); 176 drawIrr_end(ourGlobals);
@@ -363,7 +364,7 @@ void overlay_add(globals *ourGlobals)
363 // According to the Elm inlined image window example, this is what's needed to. 364 // According to the Elm inlined image window example, this is what's needed to.
364 evas_object_event_callback_add(elm_win_inlined_image_object_get(gld->winwin), EVAS_CALLBACK_MOUSE_DOWN, _cb_mouse_down_elm, NULL); 365 evas_object_event_callback_add(elm_win_inlined_image_object_get(gld->winwin), EVAS_CALLBACK_MOUSE_DOWN, _cb_mouse_down_elm, NULL);
365 // In this code, we are making our own camera, so grab it's input when we are focused. 366 // In this code, we are making our own camera, so grab it's input when we are focused.
366 cameraAdd(ourGlobals, gld->winwin); 367// cameraAdd(ourGlobals, gld->winwin);
367 368
368 elm_win_alpha_set(gld->winwin, EINA_TRUE); 369 elm_win_alpha_set(gld->winwin, EINA_TRUE);
369 // Apparently transparent is not good enough for ELM backgrounds, so make it a rectangle. 370 // Apparently transparent is not good enough for ELM backgrounds, so make it a rectangle.
diff --git a/src/extantz/extantz.h b/src/extantz/extantz.h
index 4ecf8e8..c22a61d 100644
--- a/src/extantz/extantz.h
+++ b/src/extantz/extantz.h
@@ -9,6 +9,7 @@
9 9
10#include "winFang.h" 10#include "winFang.h"
11#include "GuiLua.h" 11#include "GuiLua.h"
12#include "scenri.h"
12 13
13#include <elm_widget_glview.h> 14#include <elm_widget_glview.h>
14#include <Evas_GL.h> 15#include <Evas_GL.h>
@@ -137,7 +138,6 @@ typedef struct _Scene_Data
137 Evas_3D_Node *camera_node; 138 Evas_3D_Node *camera_node;
138 Evas_3D_Node *light_node; 139 Evas_3D_Node *light_node;
139 140
140 Evas_3D_Camera *camera;
141 Evas_3D_Light *light; 141 Evas_3D_Light *light;
142 142
143 Evas_3D_Mesh *mesh; 143 Evas_3D_Mesh *mesh;
@@ -254,7 +254,9 @@ EAPI void Evas_3D_Demo_add(globals *ourGlobals);
254Eina_Bool _animate_scene(globals *ourGlobals); 254Eina_Bool _animate_scene(globals *ourGlobals);
255void Evas_3D_Demo_fini(globals *ourGlobals); 255void Evas_3D_Demo_fini(globals *ourGlobals);
256 256
257void cameraAdd(globals *ourGlobals, Evas_Object *win); 257Scene_Data *scenriAdd(globals *ourGlobals);
258Evas_3D_Node *cameraAdd(globals *ourGlobals, Scene_Data *scene, Evas_Object *win);
259Eina_Bool animateCamera(globals *ourGlobals);
258 260
259winFang *chat_add(globals *ourGlobals); 261winFang *chat_add(globals *ourGlobals);
260winFang *filesAdd(globals *ourGlobals, char *path, Eina_Bool multi, Eina_Bool save); 262winFang *filesAdd(globals *ourGlobals, char *path, Eina_Bool multi, Eina_Bool save);
diff --git a/src/extantz/extantzCamera.h b/src/extantz/extantzCamera.h
index 9d74236..6e9067f 100644
--- a/src/extantz/extantzCamera.h
+++ b/src/extantz/extantzCamera.h
@@ -13,6 +13,7 @@
13#include <SKeyMap.h> 13#include <SKeyMap.h>
14#include <irrArray.h> 14#include <irrArray.h>
15#include <ICameraSceneNode.h> 15#include <ICameraSceneNode.h>
16#include "scenri.h"
16 17
17using namespace irr; 18using namespace irr;
18using namespace scene; 19using namespace scene;
@@ -23,13 +24,6 @@ typedef struct extantzCamera extantzCamera;
23typedef struct ICameraSceneNode ICameraSceneNode; 24typedef struct ICameraSceneNode ICameraSceneNode;
24#endif 25#endif
25 26
26typedef struct
27{
28 float x, y, z;
29 float r, s, t;
30 float jump;
31 float JumpSpeed, RotateSpeed, MoveSpeed;
32} cameraMove;
33 27
34cameraMove *getCameraMove(ICameraSceneNode *camera); 28cameraMove *getCameraMove(ICameraSceneNode *camera);
35 29
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}
diff --git a/src/extantz/scenri.h b/src/extantz/scenri.h
new file mode 100644
index 0000000..1913755
--- /dev/null
+++ b/src/extantz/scenri.h
@@ -0,0 +1,43 @@
1#ifndef _SCENRI_H_
2#define _SCENRI_H_
3
4typedef struct _cameraMove
5{
6 float x, y, z;
7 float r, s, t;
8 float jump;
9 float JumpSpeed, RotateSpeed, MoveSpeed;
10} cameraMove;
11
12typedef struct _vec4
13{
14 float x;
15 float y;
16 float z;
17 float w;
18} vec4;
19
20typedef struct _vec3
21{
22 float x;
23 float y;
24 float z;
25} vec3;
26
27typedef struct _vec2
28{
29 float x;
30 float y;
31} vec2;
32
33typedef struct _vertex
34{
35 vec3 position;
36 vec3 normal;
37 vec3 tangent;
38 vec4 color;
39 vec3 texcoord;
40} vertex;
41
42
43#endif