aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/extantz
diff options
context:
space:
mode:
authorDavid Walter Seikel2016-02-06 13:12:39 +1000
committerDavid Walter Seikel2016-02-06 13:12:39 +1000
commited42be570bb7e6bd803c864ed56caa1e035fb9d0 (patch)
tree1302e1b8fb726e9f1429507bc38c3f0dcdfb12d5 /src/extantz
parentMove return() to the hashed commands. (diff)
downloadSledjHamr-ed42be570bb7e6bd803c864ed56caa1e035fb9d0.zip
SledjHamr-ed42be570bb7e6bd803c864ed56caa1e035fb9d0.tar.gz
SledjHamr-ed42be570bb7e6bd803c864ed56caa1e035fb9d0.tar.bz2
SledjHamr-ed42be570bb7e6bd803c864ed56caa1e035fb9d0.tar.xz
Switch to eina_quaternion, instead of the copy pasted, coz it's hidden, evas_vec3 stuff.
Diffstat (limited to '')
-rw-r--r--src/extantz/camera.c71
1 files changed, 25 insertions, 46 deletions
diff --git a/src/extantz/camera.c b/src/extantz/camera.c
index 123285c..9a28b15 100644
--- a/src/extantz/camera.c
+++ b/src/extantz/camera.c
@@ -1,15 +1,19 @@
1#include "extantz.h" 1#include "extantz.h"
2 2
3 3
4static inline void evas_euler_to_quaternion(Evas_Vec4 *out, Evas_Vec3 *in) 4
5#define DEGREE_TO_RADIAN(x) (((x) * M_PI) / 180.0)
6
7
8static inline void euler_to_quaternion(Eina_Quaternion *out, Evas_Real x, Evas_Real y, Evas_Real z)
5{ 9{
6 // Assuming the angles are in radians. 10 // Assuming the angles are in radians.
7 Evas_Real c1 = cos(in->y / 2.0); // heading (yaw/spin) .. y 11 Evas_Real c1 = cos(y / 2.0); // heading (yaw/spin) .. y
8 Evas_Real s1 = sin(in->y / 2.0); 12 Evas_Real s1 = sin(y / 2.0);
9 Evas_Real c2 = cos(in->z / 2.0); // attitude (pitch) .. x 13 Evas_Real c2 = cos(z / 2.0); // attitude (pitch) .. x
10 Evas_Real s2 = sin(in->z / 2.0); 14 Evas_Real s2 = sin(z / 2.0);
11 Evas_Real c3 = cos(in->x / 2.0); // bank (roll) .. z 15 Evas_Real c3 = cos(x / 2.0); // bank (roll) .. z
12 Evas_Real s3 = sin(in->x / 2.0); 16 Evas_Real s3 = sin(x / 2.0);
13 Evas_Real c1c2 = c1 * c2; 17 Evas_Real c1c2 = c1 * c2;
14 Evas_Real s1s2 = s1 * s2; 18 Evas_Real s1s2 = s1 * s2;
15 19
@@ -19,52 +23,27 @@ static inline void evas_euler_to_quaternion(Evas_Vec4 *out, Evas_Vec3 *in)
19 out->z =c1 * s2 * c3 - s1 * c2 * s3; 23 out->z =c1 * s2 * c3 - s1 * c2 * s3;
20} 24}
21 25
22static inline void evas_quaternion_normalise(Evas_Vec4 *in)
23{
24 Evas_Real n = sqrt(in->x * in->x + in->y * in->y + in->z * in->z + in->w * in->w);
25 in->x /= n;
26 in->y /= n;
27 in->z /= n;
28 in->w /= n;
29}
30
31static inline void evas_quaternion_multiply(Evas_Vec4 *out, const Evas_Vec4 *q1, const Evas_Vec4 *q2)
32{
33 out->x = q1->x * q2->w + q1->y * q2->z - q1->z * q2->y + q1->w * q2->x;
34 out->y = -q1->x * q2->z + q1->y * q2->w + q1->z * q2->x + q1->w * q2->y;
35 out->z = q1->x * q2->y - q1->y * q2->x + q1->z * q2->w + q1->w * q2->z;
36 out->w = -q1->x * q2->x - q1->y * q2->y - q1->z * q2->z + q1->w * q2->w;
37}
38
39static inline void evas_quaternion_conjugate(Evas_Vec4 *in)
40{
41 in->x = -in->x;
42 in->y = -in->y;
43 in->z = -in->z;
44 in->w = in->w;
45}
46 26
47Eina_Bool animateCamera(Scene_Data *scene) 27Eina_Bool animateCamera(Scene_Data *scene)
48{ 28{
49 Evas_Vec3 pos, rotate; 29 Eina_Quaternion rotate, orient, result, move;
50 Evas_Vec4 orient, rotateQ, result, move; 30 Evas_Real x, y, z;
51 31
52 evas_vec3_set(&rotate, DEGREE_TO_RADIAN(scene->move->r), DEGREE_TO_RADIAN(scene->move->s), DEGREE_TO_RADIAN(scene->move->p));
53 eo_do(scene->camera_node, evas_canvas3d_node_orientation_get(EVAS_CANVAS3D_SPACE_PARENT, &orient.x, &orient.y, &orient.z, &orient.w)); 32 eo_do(scene->camera_node, evas_canvas3d_node_orientation_get(EVAS_CANVAS3D_SPACE_PARENT, &orient.x, &orient.y, &orient.z, &orient.w));
54 evas_euler_to_quaternion(&rotateQ, &rotate); 33 euler_to_quaternion(&rotate, DEGREE_TO_RADIAN(scene->move->r), DEGREE_TO_RADIAN(scene->move->s), DEGREE_TO_RADIAN(scene->move->p));
55 evas_quaternion_multiply(&result, &orient, &rotateQ); 34 eina_quaternion_mul(&result, &orient, &rotate);
56 evas_quaternion_normalise(&result); 35 eina_quaternion_normalized(&result, &result);
57 eo_do(scene->camera_node, evas_canvas3d_node_orientation_set(result.x, result.y, result.z, result.w)); 36 eo_do(scene->camera_node, evas_canvas3d_node_orientation_set(result.x, result.y, result.z, result.w));
58 37
59 evas_vec4_set(&move, scene->move->x, scene->move->y, scene->move->z, 0); 38 eina_quaternion_set(&move, scene->move->x, scene->move->y, scene->move->z, 0);
60 eo_do(scene->camera_node, evas_canvas3d_node_position_get(EVAS_CANVAS3D_SPACE_PARENT, &pos.x, &pos.y, &pos.z)); 39 eo_do(scene->camera_node, evas_canvas3d_node_position_get(EVAS_CANVAS3D_SPACE_PARENT, &x, &y, &z));
61 evas_quaternion_multiply(&rotateQ, &result, &move); 40 eina_quaternion_mul(&rotate, &result, &move);
62 evas_quaternion_conjugate(&result); 41 eina_quaternion_conjugate(&result, &result);
63 evas_quaternion_multiply(&move, &rotateQ, &result); 42 eina_quaternion_mul(&move, &rotate, &result);
64 pos.x += move.x; 43 x += move.x;
65 pos.y += move.y; 44 y += move.y;
66 pos.z += move.z; 45 z += move.z;
67 eo_do(scene->camera_node, evas_canvas3d_node_position_set(pos.x, pos.y, pos.z)); 46 eo_do(scene->camera_node, evas_canvas3d_node_position_set(x, y, z));
68 47
69 return EINA_TRUE; 48 return EINA_TRUE;
70} 49}