summaryrefslogtreecommitdiff
path: root/legacy
diff options
context:
space:
mode:
authorBruno Dilly <bdilly@profusion.mobi>2012-10-04 22:39:10 +0000
committerBruno Dilly <bdilly@profusion.mobi>2012-10-04 22:39:10 +0000
commitb52d2ed85e8fb878588279faf0723fb1fd7b99a2 (patch)
tree9d3c4b708339915015bf5fe9c326f9c6b31e3be0 /legacy
parent7b7bef60879a813f453b6d4ee031cd7aa9a1579a (diff)
ephysics: add define to infinite mass
Also check for invalid values on mass set. SVN revision: 77459
Diffstat (limited to 'legacy')
-rw-r--r--legacy/ephysics/src/bin/ephysics_logo.c5
-rw-r--r--legacy/ephysics/src/lib/EPhysics.h17
-rw-r--r--legacy/ephysics/src/lib/ephysics_body.cpp6
3 files changed, 24 insertions, 4 deletions
diff --git a/legacy/ephysics/src/bin/ephysics_logo.c b/legacy/ephysics/src/bin/ephysics_logo.c
index aa8f996..faaff4e 100644
--- a/legacy/ephysics/src/bin/ephysics_logo.c
+++ b/legacy/ephysics/src/bin/ephysics_logo.c
@@ -6,9 +6,6 @@
6#include <EPhysics.h> 6#include <EPhysics.h>
7#include <Evas.h> 7#include <Evas.h>
8 8
9/* TODO: move to EPhysics.h */
10#define EPHYSICS_BODY_MASS_IMMUTABLE (0.0)
11
12#define WIDTH (512) 9#define WIDTH (512)
13#define HEIGHT (384) 10#define HEIGHT (384)
14#define FLOOR_Y (HEIGHT - 80) 11#define FLOOR_Y (HEIGHT - 80)
@@ -219,7 +216,7 @@ elm_main(int argc __UNUSED__, char **argv __UNUSED__)
219 ephysics_world_render_geometry_set(world, 0, 0, WIDTH, HEIGHT); 216 ephysics_world_render_geometry_set(world, 0, 0, WIDTH, HEIGHT);
220 217
221 ground_body = ephysics_body_box_add(world); 218 ground_body = ephysics_body_box_add(world);
222 ephysics_body_mass_set(ground_body, EPHYSICS_BODY_MASS_IMMUTABLE); 219 ephysics_body_mass_set(ground_body, EPHYSICS_BODY_MASS_STATIC);
223 ephysics_body_geometry_set(ground_body, -100, FLOOR_Y, WIDTH + 800, 10); 220 ephysics_body_geometry_set(ground_body, -100, FLOOR_Y, WIDTH + 800, 10);
224 ephysics_body_restitution_set(ground_body, 0.65); 221 ephysics_body_restitution_set(ground_body, 0.65);
225 ephysics_body_friction_set(ground_body, 0.8); 222 ephysics_body_friction_set(ground_body, 0.8);
diff --git a/legacy/ephysics/src/lib/EPhysics.h b/legacy/ephysics/src/lib/EPhysics.h
index 2d07668..52d6ec8 100644
--- a/legacy/ephysics/src/lib/EPhysics.h
+++ b/legacy/ephysics/src/lib/EPhysics.h
@@ -1288,6 +1288,16 @@ EAPI void ephysics_world_simulation_get(const EPhysics_World *world, double *fix
1288 */ 1288 */
1289 1289
1290/** 1290/**
1291 * @def EPHYSICS_BODY_MASS_STATIC
1292 * @brief Mass amount used to makes a body static.
1293 *
1294 * Body will be set with infinite mass, so it will be immovable.
1295 *
1296 * @see ephysics_body_mass_set() for details.
1297 */
1298#define EPHYSICS_BODY_MASS_STATIC (0.0)
1299
1300/**
1291 * @typedef EPhysics_Body_Collision 1301 * @typedef EPhysics_Body_Collision
1292 * 1302 *
1293 * Body collision wraps collision informations. 1303 * Body collision wraps collision informations.
@@ -1770,6 +1780,13 @@ EAPI void ephysics_body_geometry_get(const EPhysics_Body *body, Evas_Coord *x, E
1770 * an object's resistance to the change of its speed. It's required to apply 1780 * an object's resistance to the change of its speed. It's required to apply
1771 * more force on objects with more mass to increase its speed. 1781 * more force on objects with more mass to increase its speed.
1772 * 1782 *
1783 * If mass is set to 0 the body will have infinite mass, so it will be
1784 * immovable, static. @ref EPHYSICS_BODY_MASS_STATIC can be used too.
1785 *
1786 * Negative mass is not allowed.
1787 *
1788 * By default, a body is created with 1 kg.
1789 *
1773 * @note The unit used for mass is kilograms. 1790 * @note The unit used for mass is kilograms.
1774 * 1791 *
1775 * @param body The body to has its mass set. 1792 * @param body The body to has its mass set.
diff --git a/legacy/ephysics/src/lib/ephysics_body.cpp b/legacy/ephysics/src/lib/ephysics_body.cpp
index 35bf24f..2d1a163 100644
--- a/legacy/ephysics/src/lib/ephysics_body.cpp
+++ b/legacy/ephysics/src/lib/ephysics_body.cpp
@@ -1401,6 +1401,12 @@ ephysics_body_mass_set(EPhysics_Body *body, double mass)
1401 return; 1401 return;
1402 } 1402 }
1403 1403
1404 if (mass < 0)
1405 {
1406 ERR("Can't set body's mass, it must to be non-negative.");
1407 return;
1408 }
1409
1404 ephysics_world_lock_take(body->world); 1410 ephysics_world_lock_take(body->world);
1405 _ephysics_body_mass_set(body, mass); 1411 _ephysics_body_mass_set(body, mass);
1406 ephysics_world_lock_release(body->world); 1412 ephysics_world_lock_release(body->world);