ephysics: expose z-axis gravity

SVN revision: 77781
This commit is contained in:
Bruno Dilly 2012-10-10 19:17:44 +00:00
parent a1897ddf57
commit bdd5ba2115
7 changed files with 29 additions and 24 deletions

View File

@ -29,20 +29,22 @@ static void
_world_gravity_x_cb(void *data, Evas_Object *obj, void *event_info __UNUSED__)
{
EPhysics_World *world = data;
double gravity_y;
double gravity_y, gravity_z;
ephysics_world_gravity_get(world, NULL, &gravity_y);
ephysics_world_gravity_set(world, elm_spinner_value_get(obj), gravity_y);
ephysics_world_gravity_get(world, NULL, &gravity_y, &gravity_z);
ephysics_world_gravity_set(world, elm_spinner_value_get(obj), gravity_y,
gravity_z);
}
static void
_world_gravity_y_cb(void *data, Evas_Object *obj, void *event_info __UNUSED__)
{
EPhysics_World *world = data;
double gravity_x;
double gravity_x, gravity_z;
ephysics_world_gravity_get(world, &gravity_x, NULL);
ephysics_world_gravity_set(world, gravity_x, elm_spinner_value_get(obj));
ephysics_world_gravity_get(world, &gravity_x, NULL, &gravity_z);
ephysics_world_gravity_set(world, gravity_x, elm_spinner_value_get(obj),
gravity_z);
}
static void

View File

@ -107,5 +107,5 @@ test_forces(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info
ephysics_body_friction_set(boundary, 0);
_world_populate(test_data);
ephysics_world_gravity_set(world, 0, 0);
ephysics_world_gravity_set(world, 0, 0, 0);
}

View File

@ -128,5 +128,5 @@ test_no_gravity(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_
ephysics_body_friction_set(boundary, 0);
_world_populate(test_data);
ephysics_world_gravity_set(world, 0, 0);
ephysics_world_gravity_set(world, 0, 0, 0);
}

View File

@ -193,7 +193,7 @@ test_rotating_forever(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *
world = ephysics_world_new();
ephysics_world_render_geometry_set(world, 50, 40, WIDTH - 100, FLOOR_Y - 40);
test_data->world = world;
ephysics_world_gravity_set(world, 0, 0);
ephysics_world_gravity_set(world, 0, 0, 0);
_world_populate(test_data);
}

View File

@ -678,11 +678,11 @@ EAPI double ephysics_world_max_sleeping_time_get(const EPhysics_World *world);
/**
* @brief
* Set world gravity in 2 axes (x, y).
* Set world gravity in the 3 axes (x, y, z).
*
* Gravity will act over bodies with mass over all the time.
*
* By default values are 0, 294 Evas Coordinates per second ^ 2
* By default values are 0, 294, 0 Evas Coordinates per second ^ 2
* (9.8 m/s^2, since we've a default rate of 30 pixels).
*
* 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);
* @param world The world object.
* @param gx Gravity on x axis.
* @param gy Gravity on y axis.
* @param gz Gravity on z axis.
*
* @note The unit used for acceleration is Evas coordinates per second ^ 2.
*
@ -699,7 +700,7 @@ EAPI double ephysics_world_max_sleeping_time_get(const EPhysics_World *world);
*
* @ingroup EPhysics_World
*/
EAPI void ephysics_world_gravity_set(EPhysics_World *world, double gx, double gy);
EAPI void ephysics_world_gravity_set(EPhysics_World *world, double gx, double gy, double gz);
/**
* @brief
@ -794,17 +795,18 @@ EAPI Eina_Bool ephysics_world_constraint_solver_mode_enable_get(const EPhysics_W
/**
* @brief
* Get world gravity values for axis x and y.
* Get world gravity values for axis x, y and z.
*
* @param world The world object.
* @param gx Gravity on x axis.
* @param gy Gravity on y axis.
* @param gz Gravity on y axis.
*
* @see ephysics_world_gravity_set().
*
* @ingroup EPhysics_World
*/
EAPI void ephysics_world_gravity_get(const EPhysics_World *world, double *gx, double *gy);
EAPI void ephysics_world_gravity_get(const EPhysics_World *world, double *gx, double *gy, double *gz);
/**
* @brief

View File

@ -2674,7 +2674,7 @@ ephysics_body_forces_get(const EPhysics_Body *body, double *x, double *y, double
}
rate = ephysics_world_rate_get(body->world);
ephysics_world_gravity_get(body->world, &gx, &gy);
ephysics_world_gravity_get(body->world, &gx, &gy, NULL);
if (x) *x = body->force.x * rate + gx;
if (y) *y = -body->force.y * rate + gy;

View File

@ -107,11 +107,11 @@ struct _ephysics_world_ovelap_filter_cb : public btOverlapFilterCallback
};
static inline void
_ephysics_world_gravity_set(EPhysics_World *world, double gx, double gy, double rate)
_ephysics_world_gravity_set(EPhysics_World *world, double gx, double gy, double gz, double rate)
{
btVector3 gravity;
gravity = btVector3(gx / rate, -gy / rate, 0);
gravity = btVector3(gx / rate, -gy / rate, gz / rate);
world->dynamics_world->setGravity(gravity);
world->world_info->m_gravity = gravity;
}
@ -919,7 +919,7 @@ ephysics_world_max_sleeping_time_get(const EPhysics_World *world)
}
EAPI void
ephysics_world_gravity_set(EPhysics_World *world, double gx, double gy)
ephysics_world_gravity_set(EPhysics_World *world, double gx, double gy, double gz)
{
EPhysics_Body *bd;
@ -932,8 +932,8 @@ ephysics_world_gravity_set(EPhysics_World *world, double gx, double gy)
eina_lock_take(&world->mutex);
EINA_INLIST_FOREACH(world->bodies, bd)
ephysics_body_activate(bd, EINA_TRUE);
_ephysics_world_gravity_set(world, gx, gy, world->rate);
DBG("World %p gravity set to X:%lf, Y:%lf.", world, gx, gy);
_ephysics_world_gravity_set(world, gx, gy, gz, world->rate);
DBG("World %p gravity set to X:%lf, Y:%lf, Z: %lf.", world, gx, gy, gz);
eina_lock_release(&world->mutex);
}
@ -994,7 +994,7 @@ ephysics_world_constraint_solver_mode_enable_get(const EPhysics_World *world, EP
}
EAPI void
ephysics_world_gravity_get(const EPhysics_World *world, double *gx, double *gy)
ephysics_world_gravity_get(const EPhysics_World *world, double *gx, double *gy, double *gz)
{
btVector3 vector;
@ -1008,14 +1008,15 @@ ephysics_world_gravity_get(const EPhysics_World *world, double *gx, double *gy)
if (gx) *gx = vector.x() * world->rate;
if (gy) *gy = -vector.y() * world->rate;
if (gz) *gz = vector.z() * world->rate;
}
EAPI void
ephysics_world_rate_set(EPhysics_World *world, double rate)
{
EPhysics_Body *body;
double gx, gy, gz;
void *constraint;
double gx, gy;
Eina_List *l;
if (!world)
@ -1033,8 +1034,8 @@ ephysics_world_rate_set(EPhysics_World *world, double rate)
eina_lock_take(&world->mutex);
/* Force to recalculate sizes, velocities and accelerations with new rate */
ephysics_world_gravity_get(world, &gx, &gy);
_ephysics_world_gravity_set(world, gx, gy, rate);
ephysics_world_gravity_get(world, &gx, &gy, &gz);
_ephysics_world_gravity_set(world, gx, gy, gz, rate);
EINA_INLIST_FOREACH(world->bodies, body)
ephysics_body_recalc(body, rate);