summaryrefslogtreecommitdiff
path: root/legacy/ephysics
diff options
context:
space:
mode:
authorBruno Dilly <bdilly@profusion.mobi>2012-10-10 19:17:44 +0000
committerBruno Dilly <bdilly@profusion.mobi>2012-10-10 19:17:44 +0000
commitbdd5ba211551a4f93d64e886509ce25836f27161 (patch)
tree8db04366d921a2fc48eea6eb69029a010ff14b4d /legacy/ephysics
parenta1897ddf578417e6bca3a193b1839a0355c91b67 (diff)
ephysics: expose z-axis gravity
SVN revision: 77781
Diffstat (limited to 'legacy/ephysics')
-rw-r--r--legacy/ephysics/src/bin/ephysics_sandbox.c14
-rw-r--r--legacy/ephysics/src/bin/test_forces.c2
-rw-r--r--legacy/ephysics/src/bin/test_no_gravity.c2
-rw-r--r--legacy/ephysics/src/bin/test_rotating_forever.c2
-rw-r--r--legacy/ephysics/src/lib/EPhysics.h12
-rw-r--r--legacy/ephysics/src/lib/ephysics_body.cpp2
-rw-r--r--legacy/ephysics/src/lib/ephysics_world.cpp19
7 files changed, 29 insertions, 24 deletions
diff --git a/legacy/ephysics/src/bin/ephysics_sandbox.c b/legacy/ephysics/src/bin/ephysics_sandbox.c
index b3fbcab43f..232b2cf976 100644
--- a/legacy/ephysics/src/bin/ephysics_sandbox.c
+++ b/legacy/ephysics/src/bin/ephysics_sandbox.c
@@ -29,20 +29,22 @@ static void
29_world_gravity_x_cb(void *data, Evas_Object *obj, void *event_info __UNUSED__) 29_world_gravity_x_cb(void *data, Evas_Object *obj, void *event_info __UNUSED__)
30{ 30{
31 EPhysics_World *world = data; 31 EPhysics_World *world = data;
32 double gravity_y; 32 double gravity_y, gravity_z;
33 33
34 ephysics_world_gravity_get(world, NULL, &gravity_y); 34 ephysics_world_gravity_get(world, NULL, &gravity_y, &gravity_z);
35 ephysics_world_gravity_set(world, elm_spinner_value_get(obj), gravity_y); 35 ephysics_world_gravity_set(world, elm_spinner_value_get(obj), gravity_y,
36 gravity_z);
36} 37}
37 38
38static void 39static void
39_world_gravity_y_cb(void *data, Evas_Object *obj, void *event_info __UNUSED__) 40_world_gravity_y_cb(void *data, Evas_Object *obj, void *event_info __UNUSED__)
40{ 41{
41 EPhysics_World *world = data; 42 EPhysics_World *world = data;
42 double gravity_x; 43 double gravity_x, gravity_z;
43 44
44 ephysics_world_gravity_get(world, &gravity_x, NULL); 45 ephysics_world_gravity_get(world, &gravity_x, NULL, &gravity_z);
45 ephysics_world_gravity_set(world, gravity_x, elm_spinner_value_get(obj)); 46 ephysics_world_gravity_set(world, gravity_x, elm_spinner_value_get(obj),
47 gravity_z);
46} 48}
47 49
48static void 50static void
diff --git a/legacy/ephysics/src/bin/test_forces.c b/legacy/ephysics/src/bin/test_forces.c
index a2377dc5a1..85ac312f89 100644
--- a/legacy/ephysics/src/bin/test_forces.c
+++ b/legacy/ephysics/src/bin/test_forces.c
@@ -107,5 +107,5 @@ test_forces(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info
107 ephysics_body_friction_set(boundary, 0); 107 ephysics_body_friction_set(boundary, 0);
108 108
109 _world_populate(test_data); 109 _world_populate(test_data);
110 ephysics_world_gravity_set(world, 0, 0); 110 ephysics_world_gravity_set(world, 0, 0, 0);
111} 111}
diff --git a/legacy/ephysics/src/bin/test_no_gravity.c b/legacy/ephysics/src/bin/test_no_gravity.c
index 32e5569e36..b659ea0963 100644
--- a/legacy/ephysics/src/bin/test_no_gravity.c
+++ b/legacy/ephysics/src/bin/test_no_gravity.c
@@ -128,5 +128,5 @@ test_no_gravity(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_
128 ephysics_body_friction_set(boundary, 0); 128 ephysics_body_friction_set(boundary, 0);
129 129
130 _world_populate(test_data); 130 _world_populate(test_data);
131 ephysics_world_gravity_set(world, 0, 0); 131 ephysics_world_gravity_set(world, 0, 0, 0);
132} 132}
diff --git a/legacy/ephysics/src/bin/test_rotating_forever.c b/legacy/ephysics/src/bin/test_rotating_forever.c
index 11cc77158d..d3674e730c 100644
--- a/legacy/ephysics/src/bin/test_rotating_forever.c
+++ b/legacy/ephysics/src/bin/test_rotating_forever.c
@@ -193,7 +193,7 @@ test_rotating_forever(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *
193 world = ephysics_world_new(); 193 world = ephysics_world_new();
194 ephysics_world_render_geometry_set(world, 50, 40, WIDTH - 100, FLOOR_Y - 40); 194 ephysics_world_render_geometry_set(world, 50, 40, WIDTH - 100, FLOOR_Y - 40);
195 test_data->world = world; 195 test_data->world = world;
196 ephysics_world_gravity_set(world, 0, 0); 196 ephysics_world_gravity_set(world, 0, 0, 0);
197 197
198 _world_populate(test_data); 198 _world_populate(test_data);
199} 199}
diff --git a/legacy/ephysics/src/lib/EPhysics.h b/legacy/ephysics/src/lib/EPhysics.h
index 63526c28e9..e99fdf28e1 100644
--- a/legacy/ephysics/src/lib/EPhysics.h
+++ b/legacy/ephysics/src/lib/EPhysics.h
@@ -678,11 +678,11 @@ EAPI double ephysics_world_max_sleeping_time_get(const EPhysics_World *world);
678 678
679/** 679/**
680 * @brief 680 * @brief
681 * Set world gravity in 2 axes (x, y). 681 * Set world gravity in the 3 axes (x, y, z).
682 * 682 *
683 * Gravity will act over bodies with mass over all the time. 683 * Gravity will act over bodies with mass over all the time.
684 * 684 *
685 * By default values are 0, 294 Evas Coordinates per second ^ 2 685 * By default values are 0, 294, 0 Evas Coordinates per second ^ 2
686 * (9.8 m/s^2, since we've a default rate of 30 pixels). 686 * (9.8 m/s^2, since we've a default rate of 30 pixels).
687 * 687 *
688 * If you change the rate but wants to keep 9.8 m/s^2, you well need 688 * If you change the rate but wants to keep 9.8 m/s^2, you well need
@@ -691,6 +691,7 @@ EAPI double ephysics_world_max_sleeping_time_get(const EPhysics_World *world);
691 * @param world The world object. 691 * @param world The world object.
692 * @param gx Gravity on x axis. 692 * @param gx Gravity on x axis.
693 * @param gy Gravity on y axis. 693 * @param gy Gravity on y axis.
694 * @param gz Gravity on z axis.
694 * 695 *
695 * @note The unit used for acceleration is Evas coordinates per second ^ 2. 696 * @note The unit used for acceleration is Evas coordinates per second ^ 2.
696 * 697 *
@@ -699,7 +700,7 @@ EAPI double ephysics_world_max_sleeping_time_get(const EPhysics_World *world);
699 * 700 *
700 * @ingroup EPhysics_World 701 * @ingroup EPhysics_World
701 */ 702 */
702EAPI void ephysics_world_gravity_set(EPhysics_World *world, double gx, double gy); 703EAPI void ephysics_world_gravity_set(EPhysics_World *world, double gx, double gy, double gz);
703 704
704/** 705/**
705 * @brief 706 * @brief
@@ -794,17 +795,18 @@ EAPI Eina_Bool ephysics_world_constraint_solver_mode_enable_get(const EPhysics_W
794 795
795/** 796/**
796 * @brief 797 * @brief
797 * Get world gravity values for axis x and y. 798 * Get world gravity values for axis x, y and z.
798 * 799 *
799 * @param world The world object. 800 * @param world The world object.
800 * @param gx Gravity on x axis. 801 * @param gx Gravity on x axis.
801 * @param gy Gravity on y axis. 802 * @param gy Gravity on y axis.
803 * @param gz Gravity on y axis.
802 * 804 *
803 * @see ephysics_world_gravity_set(). 805 * @see ephysics_world_gravity_set().
804 * 806 *
805 * @ingroup EPhysics_World 807 * @ingroup EPhysics_World
806 */ 808 */
807EAPI void ephysics_world_gravity_get(const EPhysics_World *world, double *gx, double *gy); 809EAPI void ephysics_world_gravity_get(const EPhysics_World *world, double *gx, double *gy, double *gz);
808 810
809/** 811/**
810 * @brief 812 * @brief
diff --git a/legacy/ephysics/src/lib/ephysics_body.cpp b/legacy/ephysics/src/lib/ephysics_body.cpp
index a88c073100..8779a6dabb 100644
--- a/legacy/ephysics/src/lib/ephysics_body.cpp
+++ b/legacy/ephysics/src/lib/ephysics_body.cpp
@@ -2674,7 +2674,7 @@ ephysics_body_forces_get(const EPhysics_Body *body, double *x, double *y, double
2674 } 2674 }
2675 2675
2676 rate = ephysics_world_rate_get(body->world); 2676 rate = ephysics_world_rate_get(body->world);
2677 ephysics_world_gravity_get(body->world, &gx, &gy); 2677 ephysics_world_gravity_get(body->world, &gx, &gy, NULL);
2678 2678
2679 if (x) *x = body->force.x * rate + gx; 2679 if (x) *x = body->force.x * rate + gx;
2680 if (y) *y = -body->force.y * rate + gy; 2680 if (y) *y = -body->force.y * rate + gy;
diff --git a/legacy/ephysics/src/lib/ephysics_world.cpp b/legacy/ephysics/src/lib/ephysics_world.cpp
index 94604f5af4..937478664f 100644
--- a/legacy/ephysics/src/lib/ephysics_world.cpp
+++ b/legacy/ephysics/src/lib/ephysics_world.cpp
@@ -107,11 +107,11 @@ struct _ephysics_world_ovelap_filter_cb : public btOverlapFilterCallback
107}; 107};
108 108
109static inline void 109static inline void
110_ephysics_world_gravity_set(EPhysics_World *world, double gx, double gy, double rate) 110_ephysics_world_gravity_set(EPhysics_World *world, double gx, double gy, double gz, double rate)
111{ 111{
112 btVector3 gravity; 112 btVector3 gravity;
113 113
114 gravity = btVector3(gx / rate, -gy / rate, 0); 114 gravity = btVector3(gx / rate, -gy / rate, gz / rate);
115 world->dynamics_world->setGravity(gravity); 115 world->dynamics_world->setGravity(gravity);
116 world->world_info->m_gravity = gravity; 116 world->world_info->m_gravity = gravity;
117} 117}
@@ -919,7 +919,7 @@ ephysics_world_max_sleeping_time_get(const EPhysics_World *world)
919} 919}
920 920
921EAPI void 921EAPI void
922ephysics_world_gravity_set(EPhysics_World *world, double gx, double gy) 922ephysics_world_gravity_set(EPhysics_World *world, double gx, double gy, double gz)
923{ 923{
924 EPhysics_Body *bd; 924 EPhysics_Body *bd;
925 925
@@ -932,8 +932,8 @@ ephysics_world_gravity_set(EPhysics_World *world, double gx, double gy)
932 eina_lock_take(&world->mutex); 932 eina_lock_take(&world->mutex);
933 EINA_INLIST_FOREACH(world->bodies, bd) 933 EINA_INLIST_FOREACH(world->bodies, bd)
934 ephysics_body_activate(bd, EINA_TRUE); 934 ephysics_body_activate(bd, EINA_TRUE);
935 _ephysics_world_gravity_set(world, gx, gy, world->rate); 935 _ephysics_world_gravity_set(world, gx, gy, gz, world->rate);
936 DBG("World %p gravity set to X:%lf, Y:%lf.", world, gx, gy); 936 DBG("World %p gravity set to X:%lf, Y:%lf, Z: %lf.", world, gx, gy, gz);
937 eina_lock_release(&world->mutex); 937 eina_lock_release(&world->mutex);
938} 938}
939 939
@@ -994,7 +994,7 @@ ephysics_world_constraint_solver_mode_enable_get(const EPhysics_World *world, EP
994} 994}
995 995
996EAPI void 996EAPI void
997ephysics_world_gravity_get(const EPhysics_World *world, double *gx, double *gy) 997ephysics_world_gravity_get(const EPhysics_World *world, double *gx, double *gy, double *gz)
998{ 998{
999 btVector3 vector; 999 btVector3 vector;
1000 1000
@@ -1008,14 +1008,15 @@ ephysics_world_gravity_get(const EPhysics_World *world, double *gx, double *gy)
1008 1008
1009 if (gx) *gx = vector.x() * world->rate; 1009 if (gx) *gx = vector.x() * world->rate;
1010 if (gy) *gy = -vector.y() * world->rate; 1010 if (gy) *gy = -vector.y() * world->rate;
1011 if (gz) *gz = vector.z() * world->rate;
1011} 1012}
1012 1013
1013EAPI void 1014EAPI void
1014ephysics_world_rate_set(EPhysics_World *world, double rate) 1015ephysics_world_rate_set(EPhysics_World *world, double rate)
1015{ 1016{
1016 EPhysics_Body *body; 1017 EPhysics_Body *body;
1018 double gx, gy, gz;
1017 void *constraint; 1019 void *constraint;
1018 double gx, gy;
1019 Eina_List *l; 1020 Eina_List *l;
1020 1021
1021 if (!world) 1022 if (!world)
@@ -1033,8 +1034,8 @@ ephysics_world_rate_set(EPhysics_World *world, double rate)
1033 1034
1034 eina_lock_take(&world->mutex); 1035 eina_lock_take(&world->mutex);
1035 /* Force to recalculate sizes, velocities and accelerations with new rate */ 1036 /* Force to recalculate sizes, velocities and accelerations with new rate */
1036 ephysics_world_gravity_get(world, &gx, &gy); 1037 ephysics_world_gravity_get(world, &gx, &gy, &gz);
1037 _ephysics_world_gravity_set(world, gx, gy, rate); 1038 _ephysics_world_gravity_set(world, gx, gy, gz, rate);
1038 1039
1039 EINA_INLIST_FOREACH(world->bodies, body) 1040 EINA_INLIST_FOREACH(world->bodies, body)
1040 ephysics_body_recalc(body, rate); 1041 ephysics_body_recalc(body, rate);