diff options
Diffstat (limited to 'src/extantz/camera.c')
-rw-r--r-- | src/extantz/camera.c | 77 |
1 files changed, 36 insertions, 41 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 @@ | |||
1 | #include "extantz.h" | 1 | #include "extantz.h" |
2 | 2 | ||
3 | 3 | ||
4 | Eina_Bool animateCamera(globals *ourGlobals) | 4 | Eina_Bool animateCamera(Scene_Data *scene) |
5 | { | 5 | { |
6 | Evas_Real x, y, z, w; | 6 | Evas_Real x, y, z, w; |
7 | EPhysics_Quaternion *quat = ephysics_quaternion_new(); | 7 | EPhysics_Quaternion *quat = ephysics_quaternion_new(); |
8 | EPhysics_Quaternion *quat1 = ephysics_quaternion_new(); | 8 | EPhysics_Quaternion *quat1 = ephysics_quaternion_new(); |
9 | EPhysics_Quaternion *result = ephysics_quaternion_new(); | 9 | EPhysics_Quaternion *result = ephysics_quaternion_new(); |
10 | 10 | ||
11 | Scene_Data *scene = ourGlobals->scene; | ||
12 | |||
13 | // Camera movement. | 11 | // Camera movement. |
14 | ephysics_quaternion_euler_set(quat1, ourGlobals->gld.move->r, ourGlobals->gld.move->s, ourGlobals->gld.move->t); | 12 | ephysics_quaternion_euler_set(quat1, scene->move->r, scene->move->s, scene->move->t); |
15 | eo_do(scene->camera_node, evas_3d_node_orientation_get(EVAS_3D_SPACE_PARENT, &x, &y, &z, &w)); | 13 | 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); | 14 | ephysics_quaternion_set(quat, x, y, z, w); |
17 | ephysics_quaternion_multiply(quat, quat1, result); | 15 | ephysics_quaternion_multiply(quat, quat1, result); |
@@ -20,9 +18,9 @@ Eina_Bool animateCamera(globals *ourGlobals) | |||
20 | eo_do(scene->camera_node, evas_3d_node_orientation_set(x, y, z, w)); | 18 | eo_do(scene->camera_node, evas_3d_node_orientation_set(x, y, z, w)); |
21 | 19 | ||
22 | eo_do(scene->camera_node, evas_3d_node_position_get(EVAS_3D_SPACE_PARENT, &x, &y, &z)); | 20 | eo_do(scene->camera_node, evas_3d_node_position_get(EVAS_3D_SPACE_PARENT, &x, &y, &z)); |
23 | x -= ourGlobals->gld.move->x; | 21 | x -= scene->move->x; |
24 | y -= ourGlobals->gld.move->y; | 22 | y -= scene->move->y; |
25 | z -= ourGlobals->gld.move->z; | 23 | z -= scene->move->z; |
26 | eo_do(scene->camera_node, evas_3d_node_position_set(x, y, z)); | 24 | eo_do(scene->camera_node, evas_3d_node_position_set(x, y, z)); |
27 | 25 | ||
28 | free(result); | 26 | free(result); |
@@ -34,11 +32,10 @@ Eina_Bool animateCamera(globals *ourGlobals) | |||
34 | 32 | ||
35 | static void _on_camera_input_down(void *data, Evas *evas, Evas_Object *obj, void *event_info) | 33 | static void _on_camera_input_down(void *data, Evas *evas, Evas_Object *obj, void *event_info) |
36 | { | 34 | { |
37 | globals *ourGlobals = data; | 35 | cameraMove *move = data; |
38 | GLData *gld = &ourGlobals->gld; | 36 | Evas_Event_Key_Down *ev = event_info; |
39 | Evas_Event_Key_Down *ev = event_info; | ||
40 | 37 | ||
41 | if (gld->move) | 38 | if (move) |
42 | { | 39 | { |
43 | // 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. | 40 | // 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. |
44 | 41 | ||
@@ -47,15 +44,15 @@ static void _on_camera_input_down(void *data, Evas *evas, Evas_Object *obj, void | |||
47 | if (0 == strcmp(ev->key, "Escape")) | 44 | if (0 == strcmp(ev->key, "Escape")) |
48 | { | 45 | { |
49 | } | 46 | } |
50 | else if (0 == strcmp(ev->key, "Left")) gld->move->r = 2.0; | 47 | else if (0 == strcmp(ev->key, "Left")) move->r = 2.0; |
51 | else if (0 == strcmp(ev->key, "Right")) gld->move->r = -2.0; | 48 | else if (0 == strcmp(ev->key, "Right")) move->r = -2.0; |
52 | else if (0 == strcmp(ev->key, "Up")) gld->move->x = 2.0; | 49 | else if (0 == strcmp(ev->key, "Up")) move->x = 2.0; |
53 | else if (0 == strcmp(ev->key, "Down")) gld->move->x = -2.0; | 50 | else if (0 == strcmp(ev->key, "Down")) move->x = -2.0; |
54 | else if (0 == strcmp(ev->key, "Prior")) gld->move->z = -2.0; | 51 | else if (0 == strcmp(ev->key, "Prior")) move->z = -2.0; |
55 | else if (0 == strcmp(ev->key, "Next")) gld->move->z = 2.0; | 52 | else if (0 == strcmp(ev->key, "Next")) move->z = 2.0; |
56 | else if (0 == strcmp(ev->key, "Home")) gld->move->y = 2.0; | 53 | else if (0 == strcmp(ev->key, "Home")) move->y = 2.0; |
57 | else if (0 == strcmp(ev->key, "End")) gld->move->y = -2.0; | 54 | else if (0 == strcmp(ev->key, "End")) move->y = -2.0; |
58 | else if (0 == strcmp(ev->key, "space")) gld->move->jump = 1.0; | 55 | else if (0 == strcmp(ev->key, "space")) move->jump = 1.0; |
59 | else printf("Unexpected down keystroke - %s\n", ev->key); | 56 | else printf("Unexpected down keystroke - %s\n", ev->key); |
60 | } | 57 | } |
61 | else printf("Camera input not ready\n"); | 58 | 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 | |||
127 | 124 | ||
128 | static void _on_camera_input_up(void *data, Evas *evas, Evas_Object *obj, void *event_info) | 125 | static void _on_camera_input_up(void *data, Evas *evas, Evas_Object *obj, void *event_info) |
129 | { | 126 | { |
130 | globals *ourGlobals = data; | 127 | cameraMove *move = data; |
131 | GLData *gld = &ourGlobals->gld; | 128 | Evas_Event_Key_Up *ev = event_info; |
132 | Evas_Event_Key_Up *ev = event_info; | ||
133 | 129 | ||
134 | if (gld->move) | 130 | if (move) |
135 | { | 131 | { |
136 | // 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. | 132 | // 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. |
137 | 133 | ||
@@ -140,15 +136,15 @@ static void _on_camera_input_up(void *data, Evas *evas, Evas_Object *obj, void * | |||
140 | if (0 == strcmp(ev->key, "Escape")) | 136 | if (0 == strcmp(ev->key, "Escape")) |
141 | { | 137 | { |
142 | } | 138 | } |
143 | else if (0 == strcmp(ev->key, "Left")) gld->move->r = 0.0; | 139 | else if (0 == strcmp(ev->key, "Left")) move->r = 0.0; |
144 | else if (0 == strcmp(ev->key, "Right")) gld->move->r = 0.0; | 140 | else if (0 == strcmp(ev->key, "Right")) move->r = 0.0; |
145 | else if (0 == strcmp(ev->key, "Up")) gld->move->x = 0.0; | 141 | else if (0 == strcmp(ev->key, "Up")) move->x = 0.0; |
146 | else if (0 == strcmp(ev->key, "Down")) gld->move->x = 0.0; | 142 | else if (0 == strcmp(ev->key, "Down")) move->x = 0.0; |
147 | else if (0 == strcmp(ev->key, "Prior")) gld->move->z = 0.0; | 143 | else if (0 == strcmp(ev->key, "Prior")) move->z = 0.0; |
148 | else if (0 == strcmp(ev->key, "Next")) gld->move->z = 0.0; | 144 | else if (0 == strcmp(ev->key, "Next")) move->z = 0.0; |
149 | else if (0 == strcmp(ev->key, "Home")) gld->move->y = 0.0; | 145 | else if (0 == strcmp(ev->key, "Home")) move->y = 0.0; |
150 | else if (0 == strcmp(ev->key, "End")) gld->move->y = 0.0; | 146 | else if (0 == strcmp(ev->key, "End")) move->y = 0.0; |
151 | else if (0 == strcmp(ev->key, "space")) gld->move->jump = 0.0; | 147 | else if (0 == strcmp(ev->key, "space")) move->jump = 0.0; |
152 | else printf("Unexpected up keystroke - %s\n", ev->key); | 148 | else printf("Unexpected up keystroke - %s\n", ev->key); |
153 | } | 149 | } |
154 | else printf("Camera input not ready\n"); | 150 | 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 | |||
182 | return processed; | 178 | return processed; |
183 | } | 179 | } |
184 | 180 | ||
185 | Evas_3D_Node *cameraAdd(globals *ourGlobals, Scene_Data *scene, Evas_Object *image) | 181 | Evas_3D_Node *cameraAdd(Evas *evas, Scene_Data *scene, Evas_Object *image) |
186 | { | 182 | { |
187 | Evas_3D_Node *result = NULL; | 183 | Evas_3D_Node *result = NULL; |
188 | Evas_3D_Camera *camera; | 184 | Evas_3D_Camera *camera; |
189 | 185 | ||
190 | camera = eo_add(EVAS_3D_CAMERA_CLASS, ourGlobals->evas, | 186 | camera = eo_add(EVAS_3D_CAMERA_CLASS, evas, |
191 | evas_3d_camera_projection_perspective_set(60.0, 1.0, 1.0, 500.0) | 187 | evas_3d_camera_projection_perspective_set(60.0, 1.0, 1.0, 500.0) |
192 | ); | 188 | ); |
193 | 189 | ||
194 | result = evas_3d_node_add(ourGlobals->evas, EVAS_3D_NODE_TYPE_CAMERA); | 190 | result = evas_3d_node_add(evas, EVAS_3D_NODE_TYPE_CAMERA); |
195 | eo_do(result, | 191 | eo_do(result, |
196 | evas_3d_node_camera_set(camera), | 192 | evas_3d_node_camera_set(camera), |
197 | evas_3d_node_position_set(50.0, 0.0, 20.0), | 193 | 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 | |||
201 | eo_do(scene->root_node, evas_3d_node_member_add(result)); | 197 | eo_do(scene->root_node, evas_3d_node_member_add(result)); |
202 | eo_do(scene->scene, evas_3d_scene_camera_node_set(result)); | 198 | eo_do(scene->scene, evas_3d_scene_camera_node_set(result)); |
203 | 199 | ||
200 | scene->move = calloc(1, sizeof(cameraMove)); | ||
204 | // In this code, we are making our own camera, so grab it's input when we are focused. | 201 | // In this code, we are making our own camera, so grab it's input when we are focused. |
205 | evas_object_event_callback_add(image, EVAS_CALLBACK_KEY_DOWN, _on_camera_input_down, ourGlobals); | 202 | evas_object_event_callback_add(image, EVAS_CALLBACK_KEY_DOWN, _on_camera_input_down, scene->move); |
206 | evas_object_event_callback_add(image, EVAS_CALLBACK_KEY_UP, _on_camera_input_up, ourGlobals); | 203 | evas_object_event_callback_add(image, EVAS_CALLBACK_KEY_UP, _on_camera_input_up, scene->move); |
207 | elm_object_event_callback_add(image, _cb_event_GL, ourGlobals); | 204 | elm_object_event_callback_add(image, _cb_event_GL, NULL); |
208 | |||
209 | ourGlobals->gld.move = calloc(1, sizeof(cameraMove)); | ||
210 | 205 | ||
211 | return result; | 206 | return result; |
212 | } | 207 | } |