summaryrefslogtreecommitdiff
path: root/legacy/ephysics
diff options
context:
space:
mode:
authorBruno Dilly <bdilly@profusion.mobi>2012-10-10 19:17:29 +0000
committerBruno Dilly <bdilly@profusion.mobi>2012-10-10 19:17:29 +0000
commit71583d30e3bf8b32d1b8183ac7b764893aa90b24 (patch)
tree98f0ae113d400e6b4fa8f73f105fb40ff64542a1 /legacy/ephysics
parentf7c20099107400f6fa6c8424b6fd0be3735fe242 (diff)
ephysics: support angular and linear velocity on 3
axes SVN revision: 77779
Diffstat (limited to 'legacy/ephysics')
-rw-r--r--legacy/ephysics/src/bin/ephysics_sandbox.c8
-rw-r--r--legacy/ephysics/src/bin/test_forces.c4
-rw-r--r--legacy/ephysics/src/bin/test_no_gravity.c6
-rw-r--r--legacy/ephysics/src/bin/test_rotating_forever.c2
-rw-r--r--legacy/ephysics/src/bin/test_sleeping_threshold.c4
-rw-r--r--legacy/ephysics/src/bin/test_velocity.c4
-rw-r--r--legacy/ephysics/src/lib/EPhysics.h24
-rw-r--r--legacy/ephysics/src/lib/ephysics_body.cpp38
8 files changed, 52 insertions, 38 deletions
diff --git a/legacy/ephysics/src/bin/ephysics_sandbox.c b/legacy/ephysics/src/bin/ephysics_sandbox.c
index fab33c4133..3710c11d40 100644
--- a/legacy/ephysics/src/bin/ephysics_sandbox.c
+++ b/legacy/ephysics/src/bin/ephysics_sandbox.c
@@ -392,7 +392,8 @@ _body_linear_velocity_x_cb(void *data, Evas_Object *obj,
392 double ylinear; 392 double ylinear;
393 393
394 ylinear = elm_spinner_value_get(evas_object_data_get(obj, "y")); 394 ylinear = elm_spinner_value_get(evas_object_data_get(obj, "y"));
395 ephysics_body_linear_velocity_set(body, elm_spinner_value_get(obj), ylinear); 395 ephysics_body_linear_velocity_set(body, elm_spinner_value_get(obj), ylinear,
396 0);
396} 397}
397 398
398static void 399static void
@@ -403,7 +404,8 @@ _body_linear_velocity_y_cb(void *data, Evas_Object *obj,
403 double xlinear; 404 double xlinear;
404 405
405 xlinear = elm_spinner_value_get(evas_object_data_get(obj, "x")); 406 xlinear = elm_spinner_value_get(evas_object_data_get(obj, "x"));
406 ephysics_body_linear_velocity_set(body, xlinear, elm_spinner_value_get(obj)); 407 ephysics_body_linear_velocity_set(body, xlinear, elm_spinner_value_get(obj),
408 0);
407} 409}
408 410
409static void 411static void
@@ -411,7 +413,7 @@ _body_angular_velocity_cb(void *data, Evas_Object *obj,
411 void *event_info __UNUSED__) 413 void *event_info __UNUSED__)
412{ 414{
413 EPhysics_Body *body = data; 415 EPhysics_Body *body = data;
414 ephysics_body_angular_velocity_set(body, elm_spinner_value_get(obj)); 416 ephysics_body_angular_velocity_set(body, 0, 0, elm_spinner_value_get(obj));
415} 417}
416/* 418/*
417static void 419static void
diff --git a/legacy/ephysics/src/bin/test_forces.c b/legacy/ephysics/src/bin/test_forces.c
index b3089b4871..a2377dc5a1 100644
--- a/legacy/ephysics/src/bin/test_forces.c
+++ b/legacy/ephysics/src/bin/test_forces.c
@@ -13,8 +13,8 @@ _update_object_cb(void *data __UNUSED__, EPhysics_Body *body, void *event_info _
13 ephysics_body_forces_get(body, &x, &y, &torque); 13 ephysics_body_forces_get(body, &x, &y, &torque);
14 DBG("Body %p, fx: %lf, fy: %lf, torque: %lf", body, x, y, torque); 14 DBG("Body %p, fx: %lf, fy: %lf, torque: %lf", body, x, y, torque);
15 15
16 ephysics_body_linear_velocity_get(body, &vx, &vy); 16 ephysics_body_linear_velocity_get(body, &vx, &vy, NULL);
17 va = ephysics_body_angular_velocity_get(body); 17 ephysics_body_angular_velocity_get(body, NULL, NULL, &va);
18 DBG("Body %p, vx: %lf, vy: %lf, va: %lf", body, vx, vy, va); 18 DBG("Body %p, vx: %lf, vy: %lf, va: %lf", body, vx, vy, va);
19} 19}
20 20
diff --git a/legacy/ephysics/src/bin/test_no_gravity.c b/legacy/ephysics/src/bin/test_no_gravity.c
index 5bf65fd892..32e5569e36 100644
--- a/legacy/ephysics/src/bin/test_no_gravity.c
+++ b/legacy/ephysics/src/bin/test_no_gravity.c
@@ -42,7 +42,7 @@ _world_populate(Test_Data *test_data)
42 update_object_cb, sh1); 42 update_object_cb, sh1);
43 ephysics_body_restitution_set(box_body1, 0.7); 43 ephysics_body_restitution_set(box_body1, 0.7);
44 ephysics_body_friction_set(box_body1, 0); 44 ephysics_body_friction_set(box_body1, 0);
45 ephysics_body_linear_velocity_set(box_body1, -30, 40); 45 ephysics_body_linear_velocity_set(box_body1, -30, 40, 0);
46 ephysics_body_sleeping_threshold_set(box_body1, 0.1, 0.1); 46 ephysics_body_sleeping_threshold_set(box_body1, 0.1, 0.1);
47 test_data->bodies = eina_list_append(test_data->bodies, box_body1); 47 test_data->bodies = eina_list_append(test_data->bodies, box_body1);
48 48
@@ -68,8 +68,8 @@ _world_populate(Test_Data *test_data)
68 update_object_cb, sh2); 68 update_object_cb, sh2);
69 ephysics_body_restitution_set(box_body2, 0.7); 69 ephysics_body_restitution_set(box_body2, 0.7);
70 ephysics_body_friction_set(box_body2, 0); 70 ephysics_body_friction_set(box_body2, 0);
71 ephysics_body_linear_velocity_set(box_body2, 40, -30); 71 ephysics_body_linear_velocity_set(box_body2, 40, -30, 0);
72 ephysics_body_angular_velocity_set(box_body2, 36); 72 ephysics_body_angular_velocity_set(box_body2, 0, 0, 36);
73 ephysics_body_sleeping_threshold_set(box_body2, 0.1, 0.1); 73 ephysics_body_sleeping_threshold_set(box_body2, 0.1, 0.1);
74 test_data->bodies = eina_list_append(test_data->bodies, box_body2); 74 test_data->bodies = eina_list_append(test_data->bodies, box_body2);
75 test_data->data = box_body2; 75 test_data->data = box_body2;
diff --git a/legacy/ephysics/src/bin/test_rotating_forever.c b/legacy/ephysics/src/bin/test_rotating_forever.c
index ebda69b0fb..40c2a0c77e 100644
--- a/legacy/ephysics/src/bin/test_rotating_forever.c
+++ b/legacy/ephysics/src/bin/test_rotating_forever.c
@@ -69,7 +69,7 @@ _update_object_cb(void *data __UNUSED__, EPhysics_Body *body, void *event_info _
69 double rot, vrot, torque; 69 double rot, vrot, torque;
70 70
71 ephysics_body_rotation_get(body, NULL, NULL, &rot); 71 ephysics_body_rotation_get(body, NULL, NULL, &rot);
72 vrot = ephysics_body_angular_velocity_get(body); 72 ephysics_body_angular_velocity_get(body, NULL, NULL, &vrot);
73 ephysics_body_forces_get(body, NULL, NULL, &torque); 73 ephysics_body_forces_get(body, NULL, NULL, &torque);
74 74
75 ephysics_body_evas_object_update(body); 75 ephysics_body_evas_object_update(body);
diff --git a/legacy/ephysics/src/bin/test_sleeping_threshold.c b/legacy/ephysics/src/bin/test_sleeping_threshold.c
index f9682ee1de..c78d642cee 100644
--- a/legacy/ephysics/src/bin/test_sleeping_threshold.c
+++ b/legacy/ephysics/src/bin/test_sleeping_threshold.c
@@ -35,7 +35,7 @@ _world_populate(Test_Data *test_data)
35 ephysics_body_restitution_set(sphere_body1, 1); 35 ephysics_body_restitution_set(sphere_body1, 1);
36 ephysics_body_friction_set(sphere_body1, 0.4); 36 ephysics_body_friction_set(sphere_body1, 0.4);
37 ephysics_body_sleeping_threshold_set(sphere_body1, 60, 360); 37 ephysics_body_sleeping_threshold_set(sphere_body1, 60, 360);
38 ephysics_body_linear_velocity_set(sphere_body1, 100, 0); 38 ephysics_body_linear_velocity_set(sphere_body1, 100, 0, 0);
39 ephysics_body_damping_set(sphere_body1, 0.5, 0.5); 39 ephysics_body_damping_set(sphere_body1, 0.5, 0.5);
40 test_data->bodies = eina_list_append(test_data->bodies, sphere_body1); 40 test_data->bodies = eina_list_append(test_data->bodies, sphere_body1);
41 41
@@ -63,7 +63,7 @@ _world_populate(Test_Data *test_data)
63 ephysics_body_restitution_set(sphere_body2, 1); 63 ephysics_body_restitution_set(sphere_body2, 1);
64 ephysics_body_friction_set(sphere_body2, 0.4); 64 ephysics_body_friction_set(sphere_body2, 0.4);
65 ephysics_body_sleeping_threshold_set(sphere_body2, 10, 360); 65 ephysics_body_sleeping_threshold_set(sphere_body2, 10, 360);
66 ephysics_body_linear_velocity_set(sphere_body2, -100, 0); 66 ephysics_body_linear_velocity_set(sphere_body2, -100, 0, 0);
67 ephysics_body_damping_set(sphere_body2, 0.5, 0.5); 67 ephysics_body_damping_set(sphere_body2, 0.5, 0.5);
68 test_data->bodies = eina_list_append(test_data->bodies, sphere_body2); 68 test_data->bodies = eina_list_append(test_data->bodies, sphere_body2);
69 69
diff --git a/legacy/ephysics/src/bin/test_velocity.c b/legacy/ephysics/src/bin/test_velocity.c
index ed53d3a483..1862bb7412 100644
--- a/legacy/ephysics/src/bin/test_velocity.c
+++ b/legacy/ephysics/src/bin/test_velocity.c
@@ -52,8 +52,8 @@ _update_vel_cb(void *data, EPhysics_Body *body, void *event_info __UNUSED__)
52 delta_time = time_now - velocity_data->last_time; 52 delta_time = time_now - velocity_data->last_time;
53 velocity_data->last_time = time_now; 53 velocity_data->last_time = time_now;
54 54
55 vaz = ephysics_body_angular_velocity_get(body); 55 ephysics_body_angular_velocity_get(body, NULL, NULL, &vaz);
56 ephysics_body_linear_velocity_get(body, &vx, &vy); 56 ephysics_body_linear_velocity_get(body, &vx, &vy, NULL);
57 vx = (vx > 0 || vx <= -0.01) ? vx : 0; 57 vx = (vx > 0 || vx <= -0.01) ? vx : 0;
58 vy = (vy > 0 || vy <= -0.01) ? vy : 0; 58 vy = (vy > 0 || vy <= -0.01) ? vy : 0;
59 59
diff --git a/legacy/ephysics/src/lib/EPhysics.h b/legacy/ephysics/src/lib/EPhysics.h
index 1c1e90c5c2..99bd96e126 100644
--- a/legacy/ephysics/src/lib/EPhysics.h
+++ b/legacy/ephysics/src/lib/EPhysics.h
@@ -2102,11 +2102,12 @@ EAPI double ephysics_body_mass_get(const EPhysics_Body *body);
2102 2102
2103/** 2103/**
2104 * @brief 2104 * @brief
2105 * Set body's linear velocity on x and y axis. 2105 * Set body's linear velocity on x, y and z axes.
2106 * 2106 *
2107 * @param body The physics body. 2107 * @param body The physics body.
2108 * @param x The linear velocity on axis x. 2108 * @param x The linear velocity on axis x.
2109 * @param y The linear velocity on axis y. 2109 * @param y The linear velocity on axis y.
2110 * @param z The linear velocity on axis z.
2110 * 2111 *
2111 * @note EPhysics unit for linear velocity is Evas coordinates per second. 2112 * @note EPhysics unit for linear velocity is Evas coordinates per second.
2112 * 2113 *
@@ -2115,15 +2116,16 @@ EAPI double ephysics_body_mass_get(const EPhysics_Body *body);
2115 * 2116 *
2116 * @ingroup EPhysics_Body 2117 * @ingroup EPhysics_Body
2117 */ 2118 */
2118EAPI void ephysics_body_linear_velocity_set(EPhysics_Body *body, double x, double y); 2119EAPI void ephysics_body_linear_velocity_set(EPhysics_Body *body, double x, double y, double z);
2119 2120
2120/** 2121/**
2121 * @brief 2122 * @brief
2122 * Get body's linear velocity on x and y axis. 2123 * Get body's linear velocity on x, y and z axes.
2123 * 2124 *
2124 * @param body The physics body. 2125 * @param body The physics body.
2125 * @param x The linear velocity on axis x. 2126 * @param x The linear velocity on axis x.
2126 * @param y The linear velocity on axis y. 2127 * @param y The linear velocity on axis y.
2128 * @param z The linear velocity on axis z.
2127 * 2129 *
2128 * @note EPhysics unit for linear velocity is Evas coordinates per second. 2130 * @note EPhysics unit for linear velocity is Evas coordinates per second.
2129 * 2131 *
@@ -2132,13 +2134,15 @@ EAPI void ephysics_body_linear_velocity_set(EPhysics_Body *body, double x, doubl
2132 * 2134 *
2133 * @ingroup EPhysics_Body 2135 * @ingroup EPhysics_Body
2134 */ 2136 */
2135EAPI void ephysics_body_linear_velocity_get(const EPhysics_Body *body, double *x, double *y); 2137EAPI void ephysics_body_linear_velocity_get(const EPhysics_Body *body, double *x, double *y, double *z);
2136 2138
2137/** 2139/**
2138 * @brief 2140 * @brief
2139 * Set body's angular velocity on z axis. 2141 * Set body's angular velocity on x, y and z axes.
2140 * 2142 *
2141 * @param body The physics body. 2143 * @param body The physics body.
2144 * @param x The angular velocity on axis x.
2145 * @param y The angular velocity on axis y.
2142 * @param z The angular velocity on axis z. 2146 * @param z The angular velocity on axis z.
2143 * 2147 *
2144 * @note EPhysics unit for angular velocity is degrees per second. 2148 * @note EPhysics unit for angular velocity is degrees per second.
@@ -2148,14 +2152,16 @@ EAPI void ephysics_body_linear_velocity_get(const EPhysics_Body *body, double *x
2148 * 2152 *
2149 * @ingroup EPhysics_Body 2153 * @ingroup EPhysics_Body
2150 */ 2154 */
2151EAPI void ephysics_body_angular_velocity_set(EPhysics_Body *body, double z); 2155EAPI void ephysics_body_angular_velocity_set(EPhysics_Body *body, double x, double y, double z);
2152 2156
2153/** 2157/**
2154 * @brief 2158 * @brief
2155 * Get body's angular velocity on z axis. 2159 * Get body's angular velocity on x, y and z axes.
2156 * 2160 *
2157 * @param body The physics body. 2161 * @param body The physics body.
2158 * @return The angular velocity on axis z, or 0 on error. 2162 * @param x The angular velocity on axis x.
2163 * @param y The angular velocity on axis y.
2164 * @param z The angular velocity on axis z.
2159 * 2165 *
2160 * @note EPhysics unit for angular velocity is degrees per second. 2166 * @note EPhysics unit for angular velocity is degrees per second.
2161 * 2167 *
@@ -2164,7 +2170,7 @@ EAPI void ephysics_body_angular_velocity_set(EPhysics_Body *body, double z);
2164 * 2170 *
2165 * @ingroup EPhysics_Body 2171 * @ingroup EPhysics_Body
2166 */ 2172 */
2167EAPI double ephysics_body_angular_velocity_get(const EPhysics_Body *body); 2173EAPI void ephysics_body_angular_velocity_get(const EPhysics_Body *body, double *x, double *y, double *z);
2168 2174
2169/** 2175/**
2170 * @brief 2176 * @brief
diff --git a/legacy/ephysics/src/lib/ephysics_body.cpp b/legacy/ephysics/src/lib/ephysics_body.cpp
index 7ed117bca4..f3cdd78c3f 100644
--- a/legacy/ephysics/src/lib/ephysics_body.cpp
+++ b/legacy/ephysics/src/lib/ephysics_body.cpp
@@ -479,10 +479,11 @@ _ephysics_body_sleeping_threshold_set(EPhysics_Body *body, double linear_thresho
479} 479}
480 480
481static inline void 481static inline void
482_ephysics_body_linear_velocity_set(EPhysics_Body *body, double x, double y, double rate) 482_ephysics_body_linear_velocity_set(EPhysics_Body *body, double x, double y, double z, double rate)
483{ 483{
484 ephysics_body_activate(body, EINA_TRUE); 484 ephysics_body_activate(body, EINA_TRUE);
485 body->rigid_body->setLinearVelocity(btVector3(x / rate, -y / rate, 0)); 485 body->rigid_body->setLinearVelocity(btVector3(x / rate, -y / rate,
486 z / rate));
486} 487}
487 488
488static void 489static void
@@ -1087,14 +1088,14 @@ void
1087ephysics_body_recalc(EPhysics_Body *body, double rate) 1088ephysics_body_recalc(EPhysics_Body *body, double rate)
1088{ 1089{
1089 Evas_Coord x, y, z, w, h, d; 1090 Evas_Coord x, y, z, w, h, d;
1090 double vx, vy, lt, at; 1091 double vx, vy, vz, lt, at;
1091 1092
1092 ephysics_body_geometry_get(body, &x, &y, &z, &w, &h, &d); 1093 ephysics_body_geometry_get(body, &x, &y, &z, &w, &h, &d);
1093 ephysics_body_linear_velocity_get(body, &vx, &vy); 1094 ephysics_body_linear_velocity_get(body, &vx, &vy, &vz);
1094 ephysics_body_sleeping_threshold_get(body, &lt, &at); 1095 ephysics_body_sleeping_threshold_get(body, &lt, &at);
1095 1096
1096 _ephysics_body_geometry_set(body, x, y, z, w, h, d, rate); 1097 _ephysics_body_geometry_set(body, x, y, z, w, h, d, rate);
1097 _ephysics_body_linear_velocity_set(body, vx, vy, rate); 1098 _ephysics_body_linear_velocity_set(body, vx, vy, vz, rate);
1098 _ephysics_body_sleeping_threshold_set(body, lt, at, rate); 1099 _ephysics_body_sleeping_threshold_set(body, lt, at, rate);
1099} 1100}
1100 1101
@@ -2076,7 +2077,7 @@ ephysics_body_mass_get(const EPhysics_Body *body)
2076} 2077}
2077 2078
2078EAPI void 2079EAPI void
2079ephysics_body_linear_velocity_set(EPhysics_Body *body, double x, double y) 2080ephysics_body_linear_velocity_set(EPhysics_Body *body, double x, double y, double z)
2080{ 2081{
2081 if (!body) 2082 if (!body)
2082 { 2083 {
@@ -2084,13 +2085,13 @@ ephysics_body_linear_velocity_set(EPhysics_Body *body, double x, double y)
2084 return; 2085 return;
2085 } 2086 }
2086 2087
2087 _ephysics_body_linear_velocity_set(body, x, y, 2088 _ephysics_body_linear_velocity_set(body, x, y, z,
2088 ephysics_world_rate_get(body->world)); 2089 ephysics_world_rate_get(body->world));
2089 DBG("Linear velocity of body %p set to %lf, %lf", body, x, y); 2090 DBG("Linear velocity of body %p set to (%lf, %lf, %lf).", body, x, y, z);
2090} 2091}
2091 2092
2092EAPI void 2093EAPI void
2093ephysics_body_linear_velocity_get(const EPhysics_Body *body, double *x, double *y) 2094ephysics_body_linear_velocity_get(const EPhysics_Body *body, double *x, double *y, double *z)
2094{ 2095{
2095 double rate; 2096 double rate;
2096 2097
@@ -2103,10 +2104,11 @@ ephysics_body_linear_velocity_get(const EPhysics_Body *body, double *x, double *
2103 rate = ephysics_world_rate_get(body->world); 2104 rate = ephysics_world_rate_get(body->world);
2104 if (x) *x = body->rigid_body->getLinearVelocity().getX() * rate; 2105 if (x) *x = body->rigid_body->getLinearVelocity().getX() * rate;
2105 if (y) *y = -body->rigid_body->getLinearVelocity().getY() * rate; 2106 if (y) *y = -body->rigid_body->getLinearVelocity().getY() * rate;
2107 if (z) *z = body->rigid_body->getLinearVelocity().getZ() * rate;
2106} 2108}
2107 2109
2108EAPI void 2110EAPI void
2109ephysics_body_angular_velocity_set(EPhysics_Body *body, double z) 2111ephysics_body_angular_velocity_set(EPhysics_Body *body, double x, double y, double z)
2110{ 2112{
2111 if (!body) 2113 if (!body)
2112 { 2114 {
@@ -2115,21 +2117,25 @@ ephysics_body_angular_velocity_set(EPhysics_Body *body, double z)
2115 } 2117 }
2116 2118
2117 ephysics_world_lock_take(body->world); 2119 ephysics_world_lock_take(body->world);
2118 body->rigid_body->setAngularVelocity(btVector3(0, 0, -z/RAD_TO_DEG)); 2120 body->rigid_body->setAngularVelocity(btVector3(-x / RAD_TO_DEG,
2119 DBG("Angular velocity of body %p set to %lf", body, z); 2121 -y / RAD_TO_DEG,
2122 -z/RAD_TO_DEG));
2123 DBG("Angular velocity of body %p set to (%lf, %lf, %lf).", body, x, y, z);
2120 ephysics_world_lock_release(body->world); 2124 ephysics_world_lock_release(body->world);
2121} 2125}
2122 2126
2123EAPI double 2127EAPI void
2124ephysics_body_angular_velocity_get(const EPhysics_Body *body) 2128ephysics_body_angular_velocity_get(const EPhysics_Body *body, double *x, double *y, double *z)
2125{ 2129{
2126 if (!body) 2130 if (!body)
2127 { 2131 {
2128 ERR("Can't get angular velocity, body is null."); 2132 ERR("Can't get angular velocity, body is null.");
2129 return 0; 2133 return;
2130 } 2134 }
2131 2135
2132 return -body->rigid_body->getAngularVelocity().getZ() * RAD_TO_DEG; 2136 if (x) *x = -body->rigid_body->getAngularVelocity().getX() * RAD_TO_DEG;
2137 if (y) *y = -body->rigid_body->getAngularVelocity().getY() * RAD_TO_DEG;
2138 if (z) *z = -body->rigid_body->getAngularVelocity().getZ() * RAD_TO_DEG;
2133} 2139}
2134 2140
2135EAPI void 2141EAPI void