From 95d791b9dbdcb6bb27a9ee2ce5aa17cdf9a933bf Mon Sep 17 00:00:00 2001 From: David Walter Seikel Date: Tue, 6 May 2014 00:37:13 +1000 Subject: Camera no longer needs ourGlobals. --- src/extantz/camera.c | 77 ++++++++++++++++++++++++--------------------------- src/extantz/extantz.c | 4 ++- src/extantz/extantz.h | 6 ++-- src/extantz/scenri.c | 2 +- 4 files changed, 43 insertions(+), 46 deletions(-) diff --git a/src/extantz/camera.c b/src/extantz/camera.c index c4b4757..ad628b5 100644 --- a/src/extantz/camera.c +++ b/src/extantz/camera.c @@ -1,17 +1,15 @@ #include "extantz.h" -Eina_Bool animateCamera(globals *ourGlobals) +Eina_Bool animateCamera(Scene_Data *scene) { Evas_Real x, y, z, w; EPhysics_Quaternion *quat = ephysics_quaternion_new(); EPhysics_Quaternion *quat1 = ephysics_quaternion_new(); EPhysics_Quaternion *result = ephysics_quaternion_new(); - Scene_Data *scene = ourGlobals->scene; - // Camera movement. - ephysics_quaternion_euler_set(quat1, ourGlobals->gld.move->r, ourGlobals->gld.move->s, ourGlobals->gld.move->t); + ephysics_quaternion_euler_set(quat1, scene->move->r, scene->move->s, scene->move->t); eo_do(scene->camera_node, evas_3d_node_orientation_get(EVAS_3D_SPACE_PARENT, &x, &y, &z, &w)); ephysics_quaternion_set(quat, x, y, z, w); ephysics_quaternion_multiply(quat, quat1, result); @@ -20,9 +18,9 @@ Eina_Bool animateCamera(globals *ourGlobals) eo_do(scene->camera_node, evas_3d_node_orientation_set(x, y, z, w)); eo_do(scene->camera_node, evas_3d_node_position_get(EVAS_3D_SPACE_PARENT, &x, &y, &z)); - x -= ourGlobals->gld.move->x; - y -= ourGlobals->gld.move->y; - z -= ourGlobals->gld.move->z; + x -= scene->move->x; + y -= scene->move->y; + z -= scene->move->z; eo_do(scene->camera_node, evas_3d_node_position_set(x, y, z)); free(result); @@ -34,11 +32,10 @@ Eina_Bool animateCamera(globals *ourGlobals) static void _on_camera_input_down(void *data, Evas *evas, Evas_Object *obj, void *event_info) { - globals *ourGlobals = data; - GLData *gld = &ourGlobals->gld; - Evas_Event_Key_Down *ev = event_info; + cameraMove *move = data; + Evas_Event_Key_Down *ev = event_info; - if (gld->move) + if (move) { // TODO - Careful, gld->move MIGHT be read at the other end by another thread. MIGHT, coz I really don't know at what point the camera animate routine is actually called. @@ -47,15 +44,15 @@ static void _on_camera_input_down(void *data, Evas *evas, Evas_Object *obj, void if (0 == strcmp(ev->key, "Escape")) { } - else if (0 == strcmp(ev->key, "Left")) gld->move->r = 2.0; - else if (0 == strcmp(ev->key, "Right")) gld->move->r = -2.0; - else if (0 == strcmp(ev->key, "Up")) gld->move->x = 2.0; - else if (0 == strcmp(ev->key, "Down")) gld->move->x = -2.0; - else if (0 == strcmp(ev->key, "Prior")) gld->move->z = -2.0; - else if (0 == strcmp(ev->key, "Next")) gld->move->z = 2.0; - else if (0 == strcmp(ev->key, "Home")) gld->move->y = 2.0; - else if (0 == strcmp(ev->key, "End")) gld->move->y = -2.0; - else if (0 == strcmp(ev->key, "space")) gld->move->jump = 1.0; + else if (0 == strcmp(ev->key, "Left")) move->r = 2.0; + else if (0 == strcmp(ev->key, "Right")) move->r = -2.0; + else if (0 == strcmp(ev->key, "Up")) move->x = 2.0; + else if (0 == strcmp(ev->key, "Down")) move->x = -2.0; + else if (0 == strcmp(ev->key, "Prior")) move->z = -2.0; + else if (0 == strcmp(ev->key, "Next")) move->z = 2.0; + else if (0 == strcmp(ev->key, "Home")) move->y = 2.0; + else if (0 == strcmp(ev->key, "End")) move->y = -2.0; + else if (0 == strcmp(ev->key, "space")) move->jump = 1.0; else printf("Unexpected down keystroke - %s\n", ev->key); } else printf("Camera input not ready\n"); @@ -127,11 +124,10 @@ static void _on_camera_input_down(void *data, Evas *evas, Evas_Object *obj, void static void _on_camera_input_up(void *data, Evas *evas, Evas_Object *obj, void *event_info) { - globals *ourGlobals = data; - GLData *gld = &ourGlobals->gld; - Evas_Event_Key_Up *ev = event_info; + cameraMove *move = data; + Evas_Event_Key_Up *ev = event_info; - if (gld->move) + if (move) { // TODO - Careful, gld->move MIGHT be read at the other end by another thread. MIGHT, coz I really don't know at what point the camera animate routine is actually called. @@ -140,15 +136,15 @@ static void _on_camera_input_up(void *data, Evas *evas, Evas_Object *obj, void * if (0 == strcmp(ev->key, "Escape")) { } - else if (0 == strcmp(ev->key, "Left")) gld->move->r = 0.0; - else if (0 == strcmp(ev->key, "Right")) gld->move->r = 0.0; - else if (0 == strcmp(ev->key, "Up")) gld->move->x = 0.0; - else if (0 == strcmp(ev->key, "Down")) gld->move->x = 0.0; - else if (0 == strcmp(ev->key, "Prior")) gld->move->z = 0.0; - else if (0 == strcmp(ev->key, "Next")) gld->move->z = 0.0; - else if (0 == strcmp(ev->key, "Home")) gld->move->y = 0.0; - else if (0 == strcmp(ev->key, "End")) gld->move->y = 0.0; - else if (0 == strcmp(ev->key, "space")) gld->move->jump = 0.0; + else if (0 == strcmp(ev->key, "Left")) move->r = 0.0; + else if (0 == strcmp(ev->key, "Right")) move->r = 0.0; + else if (0 == strcmp(ev->key, "Up")) move->x = 0.0; + else if (0 == strcmp(ev->key, "Down")) move->x = 0.0; + else if (0 == strcmp(ev->key, "Prior")) move->z = 0.0; + else if (0 == strcmp(ev->key, "Next")) move->z = 0.0; + else if (0 == strcmp(ev->key, "Home")) move->y = 0.0; + else if (0 == strcmp(ev->key, "End")) move->y = 0.0; + else if (0 == strcmp(ev->key, "space")) move->jump = 0.0; else printf("Unexpected up keystroke - %s\n", ev->key); } else printf("Camera input not ready\n"); @@ -182,16 +178,16 @@ static Eina_Bool _cb_event_GL(void *data, Evas_Object *obj, Evas_Object *src, Ev return processed; } -Evas_3D_Node *cameraAdd(globals *ourGlobals, Scene_Data *scene, Evas_Object *image) +Evas_3D_Node *cameraAdd(Evas *evas, Scene_Data *scene, Evas_Object *image) { Evas_3D_Node *result = NULL; Evas_3D_Camera *camera; - camera = eo_add(EVAS_3D_CAMERA_CLASS, ourGlobals->evas, + camera = eo_add(EVAS_3D_CAMERA_CLASS, evas, evas_3d_camera_projection_perspective_set(60.0, 1.0, 1.0, 500.0) ); - result = evas_3d_node_add(ourGlobals->evas, EVAS_3D_NODE_TYPE_CAMERA); + result = evas_3d_node_add(evas, EVAS_3D_NODE_TYPE_CAMERA); eo_do(result, evas_3d_node_camera_set(camera), evas_3d_node_position_set(50.0, 0.0, 20.0), @@ -201,12 +197,11 @@ Evas_3D_Node *cameraAdd(globals *ourGlobals, Scene_Data *scene, Evas_Object *ima eo_do(scene->root_node, evas_3d_node_member_add(result)); eo_do(scene->scene, evas_3d_scene_camera_node_set(result)); + scene->move = calloc(1, sizeof(cameraMove)); // In this code, we are making our own camera, so grab it's input when we are focused. - evas_object_event_callback_add(image, EVAS_CALLBACK_KEY_DOWN, _on_camera_input_down, ourGlobals); - evas_object_event_callback_add(image, EVAS_CALLBACK_KEY_UP, _on_camera_input_up, ourGlobals); - elm_object_event_callback_add(image, _cb_event_GL, ourGlobals); - - ourGlobals->gld.move = calloc(1, sizeof(cameraMove)); + evas_object_event_callback_add(image, EVAS_CALLBACK_KEY_DOWN, _on_camera_input_down, scene->move); + evas_object_event_callback_add(image, EVAS_CALLBACK_KEY_UP, _on_camera_input_up, scene->move); + elm_object_event_callback_add(image, _cb_event_GL, NULL); return result; } diff --git a/src/extantz/extantz.c b/src/extantz/extantz.c index 11f1d4e..b7de3a7 100644 --- a/src/extantz/extantz.c +++ b/src/extantz/extantz.c @@ -170,7 +170,7 @@ static void _draw_gl(Evas_Object *obj) #endif _animate_scene(ourGlobals); - animateCamera(ourGlobals); + animateCamera(ourGlobals->scene); #if USE_IRR drawIrr_end(ourGlobals); @@ -487,6 +487,8 @@ EAPI_MAIN int elm_main(int argc, char **argv) init_evas_gl(&ourGlobals); Evas_3D_Demo_add(&ourGlobals); + // TODO - Just a temporary hack so Irrlicht and Evas_3D can share the camera move. + ourGlobals.gld.move = ourGlobals.scene->move; evas_object_data_set(elm_image_object_get(ourGlobals.scene->image), "glob", &ourGlobals); evas_object_image_pixels_get_callback_set(elm_image_object_get(ourGlobals.scene->image), on_pixels, &ourGlobals); diff --git a/src/extantz/extantz.h b/src/extantz/extantz.h index c22a61d..1c12843 100644 --- a/src/extantz/extantz.h +++ b/src/extantz/extantz.h @@ -158,6 +158,7 @@ typedef struct _Scene_Data Evas_3D_Material *material3; Evas_3D_Texture *texture_diffuse; + cameraMove *move; } Scene_Data; // Elm GL view related data here. @@ -178,7 +179,6 @@ typedef struct _GLData IVideoDriver *driver; ISceneManager *smgr; ICameraSceneNode *camera; - cameraMove *move; #if DO_GEARS @@ -255,8 +255,8 @@ Eina_Bool _animate_scene(globals *ourGlobals); void Evas_3D_Demo_fini(globals *ourGlobals); Scene_Data *scenriAdd(globals *ourGlobals); -Evas_3D_Node *cameraAdd(globals *ourGlobals, Scene_Data *scene, Evas_Object *win); -Eina_Bool animateCamera(globals *ourGlobals); +Evas_3D_Node *cameraAdd(Evas *evas, Scene_Data *scene, Evas_Object *win); +Eina_Bool animateCamera(Scene_Data *scene); winFang *chat_add(globals *ourGlobals); winFang *filesAdd(globals *ourGlobals, char *path, Eina_Bool multi, Eina_Bool save); diff --git a/src/extantz/scenri.c b/src/extantz/scenri.c index 0805108..0c71ba2 100644 --- a/src/extantz/scenri.c +++ b/src/extantz/scenri.c @@ -113,7 +113,7 @@ Scene_Data *scenriAdd(globals *ourGlobals) elm_object_tooltip_text_set(obj, ""); elm_object_tooltip_hide(obj); scene->image = obj; - scene->camera_node = cameraAdd(ourGlobals, scene, obj); + scene->camera_node = cameraAdd(ourGlobals->evas, scene, obj); scene->light = eo_add(EVAS_3D_LIGHT_CLASS, ourGlobals->evas, evas_3d_light_ambient_set(1.0, 1.0, 1.0, 1.0), -- cgit v1.1