summaryrefslogtreecommitdiff
path: root/legacy
diff options
context:
space:
mode:
authorBruno Dilly <bdilly@profusion.mobi>2012-08-16 21:35:04 +0000
committerBruno Dilly <bdilly@profusion.mobi>2012-08-16 21:35:04 +0000
commit44aeda07ae66f5007e4334b70b68b9755c457683 (patch)
tree254123bfb68ff0f5d7677953192468582727cd52 /legacy
parent13281200892292ee746eca1ded491130f2c357db (diff)
EPhysics: implement body recalc
SVN revision: 75332
Diffstat (limited to 'legacy')
-rw-r--r--legacy/ephysics/src/lib/ephysics_body.cpp56
-rw-r--r--legacy/ephysics/src/lib/ephysics_private.h1
2 files changed, 44 insertions, 13 deletions
diff --git a/legacy/ephysics/src/lib/ephysics_body.cpp b/legacy/ephysics/src/lib/ephysics_body.cpp
index 6fc1379f35..7677d5584e 100644
--- a/legacy/ephysics/src/lib/ephysics_body.cpp
+++ b/legacy/ephysics/src/lib/ephysics_body.cpp
@@ -26,6 +26,19 @@ struct _EPhysics_Body_Collision {
26 Evas_Coord y; 26 Evas_Coord y;
27}; 27};
28 28
29static inline void
30_ephysics_body_sleeping_threshold_set(EPhysics_Body *body, double linear_threshold, double angular_threshold, double rate)
31{
32 body->rigid_body->setSleepingThresholds(linear_threshold / rate,
33 angular_threshold / RAD_TO_DEG);
34}
35
36static inline void
37_ephysics_body_linear_velocity_set(EPhysics_Body *body, double x, double y, double rate)
38{
39 body->rigid_body->setLinearVelocity(btVector3(x / rate, y / rate, 0));
40}
41
29static void 42static void
30_ephysics_body_event_callback_del(EPhysics_Body *body, EPhysics_Body_Callback *cb) 43_ephysics_body_event_callback_del(EPhysics_Body *body, EPhysics_Body_Callback *cb)
31{ 44{
@@ -256,13 +269,12 @@ _ephysics_body_evas_obj_del_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj
256} 269}
257 270
258static void 271static void
259_ephysics_body_geometry_set(EPhysics_Body *body, Evas_Coord x, Evas_Coord y, Evas_Coord w, Evas_Coord h) 272_ephysics_body_geometry_set(EPhysics_Body *body, Evas_Coord x, Evas_Coord y, Evas_Coord w, Evas_Coord h, double rate)
260{ 273{
261 double rate, mx, my, sx, sy; 274 double mx, my, sx, sy;
262 btTransform trans; 275 btTransform trans;
263 int wy, height; 276 int wy, height;
264 277
265 rate = ephysics_world_rate_get(body->world);
266 ephysics_world_render_geometry_get(body->world, NULL, &wy, NULL, &height); 278 ephysics_world_render_geometry_get(body->world, NULL, &wy, NULL, &height);
267 height += wy; 279 height += wy;
268 280
@@ -285,6 +297,8 @@ _ephysics_body_geometry_set(EPhysics_Body *body, Evas_Coord x, Evas_Coord y, Eva
285 body->w = w; 297 body->w = w;
286 body->h = h; 298 body->h = h;
287 299
300 body->rigid_body->activate(1);
301
288 DBG("Body %p position changed to %lf, %lf.", body, mx, my); 302 DBG("Body %p position changed to %lf, %lf.", body, mx, my);
289 DBG("Body %p scale changed to %lf, %lf.", body, sx, sy); 303 DBG("Body %p scale changed to %lf, %lf.", body, sx, sy);
290} 304}
@@ -301,7 +315,8 @@ _ephysics_body_evas_obj_resize_cb(void *data, Evas *e __UNUSED__, Evas_Object *o
301 315
302 DBG("Resizing body %p to w=%i, h=%i", body, w, h); 316 DBG("Resizing body %p to w=%i, h=%i", body, w, h);
303 ephysics_body_geometry_get(body, &x, &y, NULL, NULL); 317 ephysics_body_geometry_get(body, &x, &y, NULL, NULL);
304 _ephysics_body_geometry_set(body, x, y, w, h); 318 _ephysics_body_geometry_set(body, x, y, w, h,
319 ephysics_world_rate_get(body->world));
305} 320}
306 321
307static void 322static void
@@ -405,6 +420,21 @@ _ephysics_body_outside_render_area_check(EPhysics_Body *body)
405} 420}
406 421
407void 422void
423ephysics_body_recalc(EPhysics_Body *body, double rate)
424{
425 Evas_Coord x, y, w, h;
426 double vx, vy, lt, at;
427
428 ephysics_body_geometry_get(body, &x, &y, &w, &h);
429 ephysics_body_linear_velocity_get(body, &vx, &vy);
430 ephysics_body_sleeping_threshold_get(body, &lt, &at);
431
432 _ephysics_body_geometry_set(body, x, y, w, h, rate);
433 _ephysics_body_linear_velocity_set(body, vx, vy, rate);
434 _ephysics_body_sleeping_threshold_set(body, lt, at, rate);
435}
436
437void
408ephysics_body_evas_object_update_select(EPhysics_Body *body) 438ephysics_body_evas_object_update_select(EPhysics_Body *body)
409{ 439{
410 Eina_Bool callback_called = EINA_FALSE; 440 Eina_Bool callback_called = EINA_FALSE;
@@ -707,7 +737,8 @@ ephysics_body_evas_object_set(EPhysics_Body *body, Evas_Object *evas_obj, Eina_B
707 evas_object_event_callback_add(evas_obj, EVAS_CALLBACK_RESIZE, 737 evas_object_event_callback_add(evas_obj, EVAS_CALLBACK_RESIZE,
708 _ephysics_body_evas_obj_resize_cb, body); 738 _ephysics_body_evas_obj_resize_cb, body);
709 evas_object_geometry_get(body->evas_obj, &obj_x, &obj_y, &obj_w, &obj_h); 739 evas_object_geometry_get(body->evas_obj, &obj_x, &obj_y, &obj_w, &obj_h);
710 _ephysics_body_geometry_set(body, obj_x, obj_y, obj_w, obj_h); 740 _ephysics_body_geometry_set(body, obj_x, obj_y, obj_w, obj_h,
741 ephysics_world_rate_get(body->world));
711} 742}
712 743
713EAPI Evas_Object * 744EAPI Evas_Object *
@@ -761,7 +792,8 @@ ephysics_body_geometry_set(EPhysics_Body *body, Evas_Coord x, Evas_Coord y, Evas
761 return; 792 return;
762 } 793 }
763 794
764 _ephysics_body_geometry_set(body, x, y, w, h); 795 _ephysics_body_geometry_set(body, x, y, w, h,
796 ephysics_world_rate_get(body->world));
765} 797}
766 798
767EAPI void 799EAPI void
@@ -833,8 +865,8 @@ ephysics_body_linear_velocity_set(EPhysics_Body *body, double x, double y)
833 return; 865 return;
834 } 866 }
835 867
836 rate = ephysics_world_rate_get(body->world); 868 _ephysics_body_linear_velocity_set(body, x, y,
837 body->rigid_body->setLinearVelocity(btVector3(x / rate, y / rate, 0)); 869 ephysics_world_rate_get(body->world));
838 DBG("Linear velocity of body %p set to %lf, %lf", body, x, y); 870 DBG("Linear velocity of body %p set to %lf, %lf", body, x, y);
839} 871}
840 872
@@ -882,17 +914,15 @@ ephysics_body_angular_velocity_get(const EPhysics_Body *body)
882EAPI void 914EAPI void
883ephysics_body_sleeping_threshold_set(EPhysics_Body *body, double linear_threshold, double angular_threshold) 915ephysics_body_sleeping_threshold_set(EPhysics_Body *body, double linear_threshold, double angular_threshold)
884{ 916{
885 double rate;
886
887 if (!body) 917 if (!body)
888 { 918 {
889 ERR("Can't set sleeping thresholds, body is null."); 919 ERR("Can't set sleeping thresholds, body is null.");
890 return; 920 return;
891 } 921 }
892 922
893 rate = ephysics_world_rate_get(body->world); 923 _ephysics_body_sleeping_threshold_set(body, linear_threshold,
894 body->rigid_body->setSleepingThresholds(linear_threshold / rate, 924 angular_threshold,
895 angular_threshold / RAD_TO_DEG); 925 ephysics_world_rate_get(body->world));
896} 926}
897 927
898EAPI void 928EAPI void
diff --git a/legacy/ephysics/src/lib/ephysics_private.h b/legacy/ephysics/src/lib/ephysics_private.h
index 4c0b10ab5f..b8c3527f82 100644
--- a/legacy/ephysics/src/lib/ephysics_private.h
+++ b/legacy/ephysics/src/lib/ephysics_private.h
@@ -99,6 +99,7 @@ void ephysics_orphan_body_del(EPhysics_Body *body);
99void ephysics_body_contact_processed(EPhysics_Body *body, EPhysics_Body *contact_body, btVector3 position); 99void ephysics_body_contact_processed(EPhysics_Body *body, EPhysics_Body *contact_body, btVector3 position);
100btRigidBody *ephysics_body_rigid_body_get(const EPhysics_Body *body); 100btRigidBody *ephysics_body_rigid_body_get(const EPhysics_Body *body);
101void ephysics_body_active_set(EPhysics_Body *body, Eina_Bool active); 101void ephysics_body_active_set(EPhysics_Body *body, Eina_Bool active);
102void ephysics_body_recalc(EPhysics_Body *body, double rate);
102 103
103EPhysics_Camera *ephysics_camera_add(EPhysics_World *world); 104EPhysics_Camera *ephysics_camera_add(EPhysics_World *world);
104void ephysics_camera_del(EPhysics_Camera *camera); 105void ephysics_camera_del(EPhysics_Camera *camera);