summaryrefslogtreecommitdiff
path: root/legacy/ephysics
diff options
context:
space:
mode:
authorBruno Dilly <bdilly@profusion.mobi>2012-10-10 19:17:49 +0000
committerBruno Dilly <bdilly@profusion.mobi>2012-10-10 19:17:49 +0000
commit59cc6c6f2fd9f9c991a9d310c2dfc8576304d55c (patch)
tree1473331996adcad92099c485769fbaea9f90f996 /legacy/ephysics
parentbdd5ba211551a4f93d64e886509ce25836f27161 (diff)
ephysics: support forces (and torques) on 3 axes
SVN revision: 77782
Diffstat (limited to 'legacy/ephysics')
-rw-r--r--legacy/ephysics/src/bin/ephysics_sandbox.c14
-rw-r--r--legacy/ephysics/src/bin/test_forces.c7
-rw-r--r--legacy/ephysics/src/bin/test_rotating_forever.c6
-rw-r--r--legacy/ephysics/src/bin/test_shapes.c2
-rw-r--r--legacy/ephysics/src/lib/EPhysics.h48
-rw-r--r--legacy/ephysics/src/lib/ephysics_body.cpp59
-rw-r--r--legacy/ephysics/src/lib/ephysics_private.h5
7 files changed, 105 insertions, 36 deletions
diff --git a/legacy/ephysics/src/bin/ephysics_sandbox.c b/legacy/ephysics/src/bin/ephysics_sandbox.c
index 232b2cf976..edea23d1a1 100644
--- a/legacy/ephysics/src/bin/ephysics_sandbox.c
+++ b/legacy/ephysics/src/bin/ephysics_sandbox.c
@@ -249,7 +249,7 @@ static void
249_body_torque_cb(void *data, Evas_Object *obj, void *event_info __UNUSED__) 249_body_torque_cb(void *data, Evas_Object *obj, void *event_info __UNUSED__)
250{ 250{
251 EPhysics_Body *body = data; 251 EPhysics_Body *body = data;
252 ephysics_body_torque_apply(body, elm_spinner_value_get(obj)); 252 ephysics_body_torque_apply(body, 0, 0, elm_spinner_value_get(obj));
253} 253}
254 254
255static void 255static void
@@ -334,7 +334,8 @@ _body_force_x_x_cb(void *data, Evas_Object *obj, void *event_info __UNUSED__)
334 rel_x = elm_spinner_value_get(evas_object_data_get(obj, "relx")); 334 rel_x = elm_spinner_value_get(evas_object_data_get(obj, "relx"));
335 rel_y = elm_spinner_value_get(evas_object_data_get(obj, "rely")); 335 rel_y = elm_spinner_value_get(evas_object_data_get(obj, "rely"));
336 336
337 ephysics_body_force_apply(body, elm_spinner_value_get(obj), y, rel_x, rel_y); 337 ephysics_body_force_apply(body, elm_spinner_value_get(obj), y, 0,
338 rel_x, rel_y, 0);
338} 339}
339 340
340static void 341static void
@@ -351,7 +352,8 @@ _body_force_x_rel_cb(void *data, Evas_Object *obj, void *event_info __UNUSED__)
351 y = elm_spinner_value_get(evas_object_data_get(aux, "y")); 352 y = elm_spinner_value_get(evas_object_data_get(aux, "y"));
352 rel_y = elm_spinner_value_get(evas_object_data_get(aux, "rely")); 353 rel_y = elm_spinner_value_get(evas_object_data_get(aux, "rely"));
353 354
354 ephysics_body_force_apply(body, x, y, elm_spinner_value_get(obj), rel_y); 355 ephysics_body_force_apply(body, x, y, 0,
356 elm_spinner_value_get(obj), rel_y, 0);
355} 357}
356 358
357static void 359static void
@@ -368,7 +370,8 @@ _body_force_y_y_cb(void *data, Evas_Object *obj, void *event_info __UNUSED__)
368 rel_x = elm_spinner_value_get(evas_object_data_get(aux, "relx")); 370 rel_x = elm_spinner_value_get(evas_object_data_get(aux, "relx"));
369 rel_y = elm_spinner_value_get(evas_object_data_get(aux, "rely")); 371 rel_y = elm_spinner_value_get(evas_object_data_get(aux, "rely"));
370 372
371 ephysics_body_force_apply(body, x, elm_spinner_value_get(obj), rel_x, rel_y); 373 ephysics_body_force_apply(body, x, elm_spinner_value_get(obj), 0,
374 rel_x, rel_y, 0);
372} 375}
373 376
374static void 377static void
@@ -385,7 +388,8 @@ _body_force_y_rel_cb(void *data, Evas_Object *obj, void *event_info __UNUSED__)
385 y = elm_spinner_value_get(evas_object_data_get(aux, "y")); 388 y = elm_spinner_value_get(evas_object_data_get(aux, "y"));
386 rel_x = elm_spinner_value_get(evas_object_data_get(aux, "relx")); 389 rel_x = elm_spinner_value_get(evas_object_data_get(aux, "relx"));
387 390
388 ephysics_body_force_apply(body, x, y, rel_x, elm_spinner_value_get(obj)); 391 ephysics_body_force_apply(body, x, y, 0,
392 rel_x, elm_spinner_value_get(obj), 0);
389} 393}
390 394
391static void 395static void
diff --git a/legacy/ephysics/src/bin/test_forces.c b/legacy/ephysics/src/bin/test_forces.c
index 85ac312f89..d5628c1a82 100644
--- a/legacy/ephysics/src/bin/test_forces.c
+++ b/legacy/ephysics/src/bin/test_forces.c
@@ -10,7 +10,8 @@ _update_object_cb(void *data __UNUSED__, EPhysics_Body *body, void *event_info _
10 double x, y, torque, vx, vy, va; 10 double x, y, torque, vx, vy, va;
11 11
12 ephysics_body_evas_object_update(body); 12 ephysics_body_evas_object_update(body);
13 ephysics_body_forces_get(body, &x, &y, &torque); 13 ephysics_body_forces_get(body, &x, &y, NULL);
14 ephysics_body_torques_get(body, NULL, NULL, &torque);
14 DBG("Body %p, fx: %lf, fy: %lf, torque: %lf", body, x, y, torque); 15 DBG("Body %p, fx: %lf, fy: %lf, torque: %lf", body, x, y, torque);
15 16
16 ephysics_body_linear_velocity_get(body, &vx, &vy, NULL); 17 ephysics_body_linear_velocity_get(body, &vx, &vy, NULL);
@@ -38,7 +39,7 @@ _world_populate(Test_Data *test_data)
38 _update_object_cb, NULL); 39 _update_object_cb, NULL);
39 ephysics_body_restitution_set(box_body1, 0.7); 40 ephysics_body_restitution_set(box_body1, 0.7);
40 ephysics_body_friction_set(box_body1, 0); 41 ephysics_body_friction_set(box_body1, 0);
41 ephysics_body_force_apply(box_body1, 60, 0, 0, 10); 42 ephysics_body_force_apply(box_body1, 60, 0, 0, 0, 10, 0);
42 test_data->bodies = eina_list_append(test_data->bodies, box_body1); 43 test_data->bodies = eina_list_append(test_data->bodies, box_body1);
43 44
44 box2 = elm_image_add(test_data->win); 45 box2 = elm_image_add(test_data->win);
@@ -55,7 +56,7 @@ _world_populate(Test_Data *test_data)
55 _update_object_cb, NULL); 56 _update_object_cb, NULL);
56 ephysics_body_restitution_set(box_body2, 0.7); 57 ephysics_body_restitution_set(box_body2, 0.7);
57 ephysics_body_friction_set(box_body2, 0); 58 ephysics_body_friction_set(box_body2, 0);
58 ephysics_body_central_force_apply(box_body2, 60, 0); 59 ephysics_body_central_force_apply(box_body2, 60, 0, 0);
59 test_data->bodies = eina_list_append(test_data->bodies, box_body2); 60 test_data->bodies = eina_list_append(test_data->bodies, box_body2);
60 test_data->data = box_body2; 61 test_data->data = box_body2;
61} 62}
diff --git a/legacy/ephysics/src/bin/test_rotating_forever.c b/legacy/ephysics/src/bin/test_rotating_forever.c
index d3674e730c..7741036201 100644
--- a/legacy/ephysics/src/bin/test_rotating_forever.c
+++ b/legacy/ephysics/src/bin/test_rotating_forever.c
@@ -22,7 +22,7 @@ _increase_torque_cb(void *data)
22 EPhysics_Body *body = data; 22 EPhysics_Body *body = data;
23 Evas_Object *obj; 23 Evas_Object *obj;
24 24
25 ephysics_body_torque_apply(body, 2); 25 ephysics_body_torque_apply(body, 0, 0, 2);
26 obj = ephysics_body_evas_object_get(body); 26 obj = ephysics_body_evas_object_get(body);
27 evas_object_data_set(obj, "increase_timer", NULL); 27 evas_object_data_set(obj, "increase_timer", NULL);
28 28
@@ -70,7 +70,7 @@ _update_object_cb(void *data __UNUSED__, EPhysics_Body *body, void *event_info _
70 70
71 ephysics_body_rotation_get(body, NULL, NULL, &rot); 71 ephysics_body_rotation_get(body, NULL, NULL, &rot);
72 ephysics_body_angular_velocity_get(body, NULL, NULL, &vrot); 72 ephysics_body_angular_velocity_get(body, NULL, NULL, &vrot);
73 ephysics_body_forces_get(body, NULL, NULL, &torque); 73 ephysics_body_torques_get(body, NULL, NULL, &torque);
74 74
75 ephysics_body_evas_object_update(body); 75 ephysics_body_evas_object_update(body);
76 76
@@ -154,7 +154,7 @@ _world_populate(Test_Data *test_data)
154 EPHYSICS_CALLBACK_BODY_UPDATE, 154 EPHYSICS_CALLBACK_BODY_UPDATE,
155 _update_object_cb, NULL); 155 _update_object_cb, NULL);
156 156
157 ephysics_body_torque_apply(body, 2); 157 ephysics_body_torque_apply(body, 0, 0, 2);
158 ephysics_body_event_callback_add(body, 158 ephysics_body_event_callback_add(body,
159 EPHYSICS_CALLBACK_BODY_DEL, 159 EPHYSICS_CALLBACK_BODY_DEL,
160 _del_torque_cb, cube); 160 _del_torque_cb, cube);
diff --git a/legacy/ephysics/src/bin/test_shapes.c b/legacy/ephysics/src/bin/test_shapes.c
index 8780ee463f..1a55840b04 100644
--- a/legacy/ephysics/src/bin/test_shapes.c
+++ b/legacy/ephysics/src/bin/test_shapes.c
@@ -51,7 +51,7 @@ _world_populate(Test_Data *test_data)
51 ephysics_body_evas_object_set(hexagon_body, hexagon, EINA_TRUE); 51 ephysics_body_evas_object_set(hexagon_body, hexagon, EINA_TRUE);
52 ephysics_body_restitution_set(hexagon_body, 1); 52 ephysics_body_restitution_set(hexagon_body, 1);
53 test_data->bodies = eina_list_append(test_data->bodies, hexagon_body); 53 test_data->bodies = eina_list_append(test_data->bodies, hexagon_body);
54 ephysics_body_torque_apply(hexagon_body, -3); 54 ephysics_body_torque_apply(hexagon_body, 0, 0, -3);
55 55
56 ephysics_shape_del(pentagon_shape); 56 ephysics_shape_del(pentagon_shape);
57 ephysics_shape_del(hexagon_shape); 57 ephysics_shape_del(hexagon_shape);
diff --git a/legacy/ephysics/src/lib/EPhysics.h b/legacy/ephysics/src/lib/EPhysics.h
index e99fdf28e1..d49492d61d 100644
--- a/legacy/ephysics/src/lib/EPhysics.h
+++ b/legacy/ephysics/src/lib/EPhysics.h
@@ -2895,14 +2895,16 @@ EAPI void *ephysics_body_data_get(const EPhysics_Body *body);
2895 * @param body The physics body which over the force will be applied. 2895 * @param body The physics body which over the force will be applied.
2896 * @param x The axis x component of force. 2896 * @param x The axis x component of force.
2897 * @param y The axis y component of force. 2897 * @param y The axis y component of force.
2898 * @param z The axis z component of force.
2898 * 2899 *
2899 * @see ephysics_body_torque_apply(). 2900 * @see ephysics_body_torque_apply().
2900 * @see ephysics_body_force_apply(). 2901 * @see ephysics_body_force_apply().
2901 * @see ephysics_body_forces_get(). 2902 * @see ephysics_body_forces_get().
2903 * @see ephysics_body_torques_get().
2902 * 2904 *
2903 * @ingroup EPhysics_Body 2905 * @ingroup EPhysics_Body
2904 */ 2906 */
2905EAPI void ephysics_body_central_force_apply(EPhysics_Body *body, double x, double y); 2907EAPI void ephysics_body_central_force_apply(EPhysics_Body *body, double x, double y, double z);
2906 2908
2907/** 2909/**
2908 * @brief 2910 * @brief
@@ -2913,17 +2915,24 @@ EAPI void ephysics_body_central_force_apply(EPhysics_Body *body, double x, doubl
2913 * And the body will rotate around Z axis considering this angular velocity. 2915 * And the body will rotate around Z axis considering this angular velocity.
2914 * 2916 *
2915 * @param body The physics body that will receive the torque. 2917 * @param body The physics body that will receive the torque.
2916 * @param torque Torque to change angular acceleration of the body around Z 2918 * @param torque_x Torque to change angular acceleration of the body around X
2919 * axis (rotate on y - z plane).
2920 * Negative values will accelerate it on counter clockwise rotation.
2921 * @param torque_y Torque to change angular acceleration of the body around Y
2922 * axis (rotate on x - z plane).
2923 * Negative values will accelerate it on counter clockwise rotation.
2924 * @param torque_z Torque to change angular acceleration of the body around Z
2917 * axis (rotate on x - y plane). 2925 * axis (rotate on x - y plane).
2918 * Negative values will accelerate it on counter clockwise rotation. 2926 * Negative values will accelerate it on counter clockwise rotation.
2919 * 2927 *
2920 * @see ephysics_body_central_force_apply(). 2928 * @see ephysics_body_central_force_apply().
2921 * @see ephysics_body_force_apply(). 2929 * @see ephysics_body_force_apply().
2922 * @see ephysics_body_forces_get(). 2930 * @see ephysics_body_forces_get().
2931 * @see ephysics_body_torques_get().
2923 * 2932 *
2924 * @ingroup EPhysics_Body 2933 * @ingroup EPhysics_Body
2925 */ 2934 */
2926EAPI void ephysics_body_torque_apply(EPhysics_Body *body, double torque); 2935EAPI void ephysics_body_torque_apply(EPhysics_Body *body, double torque_x, double torque_y, double torque_z);
2927 2936
2928/** 2937/**
2929 * @brief 2938 * @brief
@@ -2938,15 +2947,17 @@ EAPI void ephysics_body_torque_apply(EPhysics_Body *body, double torque);
2938 * @ref ephysics_body_torque_apply(), or can be used to lead to both 2947 * @ref ephysics_body_torque_apply(), or can be used to lead to both
2939 * behaviors with @ref ephysics_body_force_apply(). 2948 * behaviors with @ref ephysics_body_force_apply().
2940 * 2949 *
2941 * It will result in a central force with force (@p x, @p y) and a 2950 * It will result in a central force with force (@p x, @p y, @p z) and a
2942 * torque that will be calculated as a cross product on force 2951 * torque that will be calculated as a cross product on force
2943 * and relative position. 2952 * and relative position.
2944 * 2953 *
2945 * @param body The physics body that will receive the impulse. 2954 * @param body The physics body that will receive the impulse.
2946 * @param x The axis x component of force. 2955 * @param x The axis x component of force.
2947 * @param y The axis y component of force. 2956 * @param y The axis y component of force.
2957 * @param z The axis z component of force.
2948 * @param pos_x The axis x component of the relative position to apply force. 2958 * @param pos_x The axis x component of the relative position to apply force.
2949 * @param pos_y The axis y component of the relative position to apply force. 2959 * @param pos_y The axis y component of the relative position to apply force.
2960 * @param pos_z The axis z component of the relative position to apply force.
2950 * 2961 *
2951 * @note Force is measured in kg * p / s / s and position in p (pixels, or 2962 * @note Force is measured in kg * p / s / s and position in p (pixels, or
2952 * Evas coordinates). 2963 * Evas coordinates).
@@ -2954,10 +2965,11 @@ EAPI void ephysics_body_torque_apply(EPhysics_Body *body, double torque);
2954 * @see ephysics_body_central_force_apply(). 2965 * @see ephysics_body_central_force_apply().
2955 * @see ephysics_body_torque_apply(). 2966 * @see ephysics_body_torque_apply().
2956 * @see ephysics_body_forces_get(). 2967 * @see ephysics_body_forces_get().
2968 * @see ephysics_body_torques_get().
2957 * 2969 *
2958 * @ingroup EPhysics_Body 2970 * @ingroup EPhysics_Body
2959 */ 2971 */
2960EAPI void ephysics_body_force_apply(EPhysics_Body *body, double x, double y, Evas_Coord pos_x, Evas_Coord pos_y); 2972EAPI void ephysics_body_force_apply(EPhysics_Body *body, double x, double y, double z, Evas_Coord pos_x, Evas_Coord pos_y, Evas_Coord pos_z);
2961 2973
2962/** 2974/**
2963 * @brief 2975 * @brief
@@ -2969,17 +2981,38 @@ EAPI void ephysics_body_force_apply(EPhysics_Body *body, double x, double y, Eva
2969 * @param body The physics body. 2981 * @param body The physics body.
2970 * @param x The axis x component of total force. 2982 * @param x The axis x component of total force.
2971 * @param y The axis y component of total force. 2983 * @param y The axis y component of total force.
2972 * @param torque The torque. 2984 * @param z The axis z component of total force.
2973 * 2985 *
2974 * @see ephysics_body_force_apply() for more details. 2986 * @see ephysics_body_force_apply() for more details.
2975 * @see ephysics_body_central_force_apply(). 2987 * @see ephysics_body_central_force_apply().
2976 * @see ephysics_body_torque_apply(). 2988 * @see ephysics_body_torque_apply().
2989 * @see ephysics_body_torques_get().
2977 * @see ephysics_body_forces_clear(). 2990 * @see ephysics_body_forces_clear().
2978 * @see ephysics_world_gravity_set(). 2991 * @see ephysics_world_gravity_set().
2979 * 2992 *
2980 * @ingroup EPhysics_Body 2993 * @ingroup EPhysics_Body
2981 */ 2994 */
2982EAPI void ephysics_body_forces_get(const EPhysics_Body *body, double *x, double *y, double *torque); 2995EAPI void ephysics_body_forces_get(const EPhysics_Body *body, double *x, double *y, double *z);
2996
2997/**
2998 * @brief
2999 * Get physics body torques.
3000 *
3001 * Get all the torques applied over a body.
3002 * Damping is not considered.
3003 *
3004 * @param body The physics body.
3005 * @param x The torque on x axis.
3006 * @param y The torque on y axis.
3007 * @param z The torque on z axis.
3008 *
3009 * @see ephysics_body_torque_apply() for more details.
3010 * @see ephysics_body_force_apply().
3011 * @see ephysics_body_forces_clear().
3012 *
3013 * @ingroup EPhysics_Body
3014 */
3015EAPI void ephysics_body_torques_get(const EPhysics_Body *body, double *x, double *y, double *z);
2983 3016
2984/** 3017/**
2985 * @brief 3018 * @brief
@@ -2999,6 +3032,7 @@ EAPI void ephysics_body_forces_get(const EPhysics_Body *body, double *x, double
2999 * @see ephysics_body_torque_apply(). 3032 * @see ephysics_body_torque_apply().
3000 * @see ephysics_body_force_apply(). 3033 * @see ephysics_body_force_apply().
3001 * @see ephysics_body_forces_get(). 3034 * @see ephysics_body_forces_get().
3035 * @see ephysics_body_torques_get().
3002 * 3036 *
3003 * @ingroup EPhysics_Body 3037 * @ingroup EPhysics_Body
3004 */ 3038 */
diff --git a/legacy/ephysics/src/lib/ephysics_body.cpp b/legacy/ephysics/src/lib/ephysics_body.cpp
index 8779a6dabb..87a5200a1e 100644
--- a/legacy/ephysics/src/lib/ephysics_body.cpp
+++ b/legacy/ephysics/src/lib/ephysics_body.cpp
@@ -467,7 +467,10 @@ _ephysics_body_forces_update(EPhysics_Body *body)
467{ 467{
468 body->force.x = body->rigid_body->getTotalForce().getX(); 468 body->force.x = body->rigid_body->getTotalForce().getX();
469 body->force.y = body->rigid_body->getTotalForce().getY(); 469 body->force.y = body->rigid_body->getTotalForce().getY();
470 body->force.torque = body->rigid_body->getTotalTorque().getZ(); 470 body->force.z = body->rigid_body->getTotalForce().getZ();
471 body->force.torque_x = body->rigid_body->getTotalTorque().getX();
472 body->force.torque_y = body->rigid_body->getTotalTorque().getY();
473 body->force.torque_z = body->rigid_body->getTotalTorque().getZ();
471 body->rigid_body->clearForces(); 474 body->rigid_body->clearForces();
472} 475}
473 476
@@ -1074,14 +1077,19 @@ ephysics_body_forces_apply(EPhysics_Body *body)
1074{ 1077{
1075 double rate; 1078 double rate;
1076 1079
1077 if (!((body->force.x) || (body->force.y) || (body->force.torque))) 1080 if (!((body->force.x) || (body->force.y) || (body->force.z) ||
1081 (body->force.torque_x) || (body->force.torque_y) ||
1082 (body->force.torque_z)))
1078 return; 1083 return;
1079 1084
1080 rate = ephysics_world_rate_get(body->world); 1085 rate = ephysics_world_rate_get(body->world);
1081 ephysics_body_activate(body, EINA_TRUE); 1086 ephysics_body_activate(body, EINA_TRUE);
1082 body->rigid_body->applyCentralForce(btVector3(body->force.x / rate, 1087 body->rigid_body->applyCentralForce(btVector3(body->force.x / rate,
1083 body->force.y / rate, 0)); 1088 body->force.y / rate,
1084 body->rigid_body->applyTorque(btVector3(0, 0, body->force.torque)); 1089 body->force.z / rate));
1090 body->rigid_body->applyTorque(btVector3(body->force.torque_x,
1091 body->force.torque_y,
1092 body->force.torque_z));
1085} 1093}
1086 1094
1087void 1095void
@@ -2607,7 +2615,7 @@ ephysics_body_data_get(const EPhysics_Body *body)
2607} 2615}
2608 2616
2609EAPI void 2617EAPI void
2610ephysics_body_central_force_apply(EPhysics_Body *body, double x, double y) 2618ephysics_body_central_force_apply(EPhysics_Body *body, double x, double y, double z)
2611{ 2619{
2612 double rate; 2620 double rate;
2613 2621
@@ -2620,13 +2628,14 @@ ephysics_body_central_force_apply(EPhysics_Body *body, double x, double y)
2620 ephysics_world_lock_take(body->world); 2628 ephysics_world_lock_take(body->world);
2621 rate = ephysics_world_rate_get(body->world); 2629 rate = ephysics_world_rate_get(body->world);
2622 ephysics_body_forces_apply(body); 2630 ephysics_body_forces_apply(body);
2623 body->rigid_body->applyCentralForce(btVector3(x / rate, - y / rate, 0)); 2631 body->rigid_body->applyCentralForce(btVector3(x / rate, - y / rate,
2632 z / rate));
2624 _ephysics_body_forces_update(body); 2633 _ephysics_body_forces_update(body);
2625 ephysics_world_lock_release(body->world); 2634 ephysics_world_lock_release(body->world);
2626} 2635}
2627 2636
2628EAPI void 2637EAPI void
2629ephysics_body_force_apply(EPhysics_Body *body, double x, double y, Evas_Coord pos_x, Evas_Coord pos_y) 2638ephysics_body_force_apply(EPhysics_Body *body, double x, double y, double z, Evas_Coord pos_x, Evas_Coord pos_y, Evas_Coord pos_z)
2630{ 2639{
2631 double rate; 2640 double rate;
2632 2641
@@ -2639,15 +2648,16 @@ ephysics_body_force_apply(EPhysics_Body *body, double x, double y, Evas_Coord po
2639 rate = ephysics_world_rate_get(body->world); 2648 rate = ephysics_world_rate_get(body->world);
2640 ephysics_world_lock_take(body->world); 2649 ephysics_world_lock_take(body->world);
2641 ephysics_body_forces_apply(body); 2650 ephysics_body_forces_apply(body);
2642 body->rigid_body->applyForce(btVector3(x / rate, - y / rate, 0), 2651 body->rigid_body->applyForce(btVector3(x / rate, - y / rate, z / rate),
2643 btVector3((double) pos_x / rate, 2652 btVector3((double) pos_x / rate,
2644 (double) pos_y / rate, 0)); 2653 (double) pos_y / rate,
2654 (double) pos_z / rate));
2645 _ephysics_body_forces_update(body); 2655 _ephysics_body_forces_update(body);
2646 ephysics_world_lock_release(body->world); 2656 ephysics_world_lock_release(body->world);
2647} 2657}
2648 2658
2649EAPI void 2659EAPI void
2650ephysics_body_torque_apply(EPhysics_Body *body, double torque) 2660ephysics_body_torque_apply(EPhysics_Body *body, double torque_x, double torque_y, double torque_z)
2651{ 2661{
2652 if (!body) 2662 if (!body)
2653 { 2663 {
@@ -2657,15 +2667,15 @@ ephysics_body_torque_apply(EPhysics_Body *body, double torque)
2657 2667
2658 ephysics_world_lock_take(body->world); 2668 ephysics_world_lock_take(body->world);
2659 ephysics_body_forces_apply(body); 2669 ephysics_body_forces_apply(body);
2660 body->rigid_body->applyTorque(btVector3(0, 0, -torque)); 2670 body->rigid_body->applyTorque(btVector3(-torque_x, -torque_y, -torque_z));
2661 _ephysics_body_forces_update(body); 2671 _ephysics_body_forces_update(body);
2662 ephysics_world_lock_release(body->world); 2672 ephysics_world_lock_release(body->world);
2663} 2673}
2664 2674
2665EAPI void 2675EAPI void
2666ephysics_body_forces_get(const EPhysics_Body *body, double *x, double *y, double *torque) 2676ephysics_body_forces_get(const EPhysics_Body *body, double *x, double *y, double *z)
2667{ 2677{
2668 double rate, gx, gy; 2678 double rate, gx, gy, gz;
2669 2679
2670 if (!body) 2680 if (!body)
2671 { 2681 {
@@ -2674,11 +2684,25 @@ ephysics_body_forces_get(const EPhysics_Body *body, double *x, double *y, double
2674 } 2684 }
2675 2685
2676 rate = ephysics_world_rate_get(body->world); 2686 rate = ephysics_world_rate_get(body->world);
2677 ephysics_world_gravity_get(body->world, &gx, &gy, NULL); 2687 ephysics_world_gravity_get(body->world, &gx, &gy, &gz);
2678 2688
2679 if (x) *x = body->force.x * rate + gx; 2689 if (x) *x = body->force.x * rate + gx;
2680 if (y) *y = -body->force.y * rate + gy; 2690 if (y) *y = -body->force.y * rate + gy;
2681 if (torque) *torque = -body->force.torque; 2691 if (z) *z = body->force.z * rate + gz;
2692}
2693
2694EAPI void
2695ephysics_body_torques_get(const EPhysics_Body *body, double *x, double *y, double *z)
2696{
2697 if (!body)
2698 {
2699 ERR("Can't get torques from a null body.");
2700 return;
2701 }
2702
2703 if (x) *x = -body->force.torque_x;
2704 if (y) *y = -body->force.torque_y;
2705 if (z) *z = -body->force.torque_z;
2682} 2706}
2683 2707
2684EAPI void 2708EAPI void
@@ -2692,7 +2716,10 @@ ephysics_body_forces_clear(EPhysics_Body *body)
2692 2716
2693 body->force.x = 0; 2717 body->force.x = 0;
2694 body->force.y = 0; 2718 body->force.y = 0;
2695 body->force.torque = 0; 2719 body->force.z = 0;
2720 body->force.torque_x = 0;
2721 body->force.torque_y = 0;
2722 body->force.torque_z = 0;
2696} 2723}
2697 2724
2698EAPI void 2725EAPI void
diff --git a/legacy/ephysics/src/lib/ephysics_private.h b/legacy/ephysics/src/lib/ephysics_private.h
index 1bdf50cd22..5d624fb16b 100644
--- a/legacy/ephysics/src/lib/ephysics_private.h
+++ b/legacy/ephysics/src/lib/ephysics_private.h
@@ -93,7 +93,10 @@ struct _EPhysics_Body {
93 struct { 93 struct {
94 double x; 94 double x;
95 double y; 95 double y;
96 double torque; 96 double z;
97 double torque_x;
98 double torque_y;
99 double torque_z;
97 } force; 100 } force;
98 struct { 101 struct {
99 double x; 102 double x;