ephysics: add define to infinite mass

Also check for invalid values on mass set.



SVN revision: 77459
This commit is contained in:
Bruno Dilly 2012-10-04 22:39:10 +00:00
parent 7b7bef6087
commit b52d2ed85e
3 changed files with 24 additions and 4 deletions

View File

@ -6,9 +6,6 @@
#include <EPhysics.h>
#include <Evas.h>
/* TODO: move to EPhysics.h */
#define EPHYSICS_BODY_MASS_IMMUTABLE (0.0)
#define WIDTH (512)
#define HEIGHT (384)
#define FLOOR_Y (HEIGHT - 80)
@ -219,7 +216,7 @@ elm_main(int argc __UNUSED__, char **argv __UNUSED__)
ephysics_world_render_geometry_set(world, 0, 0, WIDTH, HEIGHT);
ground_body = ephysics_body_box_add(world);
ephysics_body_mass_set(ground_body, EPHYSICS_BODY_MASS_IMMUTABLE);
ephysics_body_mass_set(ground_body, EPHYSICS_BODY_MASS_STATIC);
ephysics_body_geometry_set(ground_body, -100, FLOOR_Y, WIDTH + 800, 10);
ephysics_body_restitution_set(ground_body, 0.65);
ephysics_body_friction_set(ground_body, 0.8);

View File

@ -1287,6 +1287,16 @@ EAPI void ephysics_world_simulation_get(const EPhysics_World *world, double *fix
* moved or rotated.
*/
/**
* @def EPHYSICS_BODY_MASS_STATIC
* @brief Mass amount used to makes a body static.
*
* Body will be set with infinite mass, so it will be immovable.
*
* @see ephysics_body_mass_set() for details.
*/
#define EPHYSICS_BODY_MASS_STATIC (0.0)
/**
* @typedef EPhysics_Body_Collision
*
@ -1770,6 +1780,13 @@ EAPI void ephysics_body_geometry_get(const EPhysics_Body *body, Evas_Coord *x, E
* an object's resistance to the change of its speed. It's required to apply
* more force on objects with more mass to increase its speed.
*
* If mass is set to 0 the body will have infinite mass, so it will be
* immovable, static. @ref EPHYSICS_BODY_MASS_STATIC can be used too.
*
* Negative mass is not allowed.
*
* By default, a body is created with 1 kg.
*
* @note The unit used for mass is kilograms.
*
* @param body The body to has its mass set.

View File

@ -1401,6 +1401,12 @@ ephysics_body_mass_set(EPhysics_Body *body, double mass)
return;
}
if (mass < 0)
{
ERR("Can't set body's mass, it must to be non-negative.");
return;
}
ephysics_world_lock_take(body->world);
_ephysics_body_mass_set(body, mass);
ephysics_world_lock_release(body->world);