forked from enlightenment/efl
EPhysics: implement generic apply impulse for bodies
It results in central and torque impulses. SVN revision: 75474
This commit is contained in:
parent
1ef5ae1a2d
commit
d3e74fce50
|
@ -14,7 +14,7 @@ _update_object_cb(void *data __UNUSED__, EPhysics_Body *body, void *event_info _
|
||||||
vrot = ephysics_body_angular_velocity_get(body);
|
vrot = ephysics_body_angular_velocity_get(body);
|
||||||
ephysics_body_evas_object_update(body);
|
ephysics_body_evas_object_update(body);
|
||||||
|
|
||||||
DBG("rot: %lf, vrot :%lf", rot, vrot);
|
DBG("body: %p, rot: %lf, vrot :%lf", body, rot, vrot);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -39,6 +39,23 @@ _world_populate(Test_Data *test_data)
|
||||||
_update_object_cb, NULL);
|
_update_object_cb, NULL);
|
||||||
|
|
||||||
ephysics_body_torque_impulse_apply(body, 1);
|
ephysics_body_torque_impulse_apply(body, 1);
|
||||||
|
|
||||||
|
cube = elm_image_add(test_data->win);
|
||||||
|
elm_image_file_set(
|
||||||
|
cube, PACKAGE_DATA_DIR "/" EPHYSICS_TEST_THEME ".edj", "purple-cube");
|
||||||
|
evas_object_move(cube, WIDTH / 3, FLOOR_Y - 70);
|
||||||
|
evas_object_resize(cube, 70, 70);
|
||||||
|
evas_object_show(cube);
|
||||||
|
test_data->evas_objs = eina_list_append(test_data->evas_objs, cube);
|
||||||
|
|
||||||
|
body = ephysics_body_box_add(test_data->world);
|
||||||
|
ephysics_body_evas_object_set(body, cube, EINA_TRUE);
|
||||||
|
test_data->bodies = eina_list_append(test_data->bodies, body);
|
||||||
|
ephysics_body_event_callback_add(body,
|
||||||
|
EPHYSICS_CALLBACK_BODY_UPDATE,
|
||||||
|
_update_object_cb, NULL);
|
||||||
|
|
||||||
|
ephysics_body_impulse_apply(body, 30, 0, 0, -10);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|
|
@ -2143,6 +2143,9 @@ EAPI double ephysics_body_friction_get(const EPhysics_Body *body);
|
||||||
* @param x The axis x component of impulse.
|
* @param x The axis x component of impulse.
|
||||||
* @param y The axis y component of impulse.
|
* @param y The axis y component of impulse.
|
||||||
*
|
*
|
||||||
|
* @see ephysics_body_torque_impulse_apply().
|
||||||
|
* @see ephysics_body_impulse_apply().
|
||||||
|
*
|
||||||
* @ingroup EPhysics_Body
|
* @ingroup EPhysics_Body
|
||||||
*/
|
*/
|
||||||
EAPI void ephysics_body_central_impulse_apply(EPhysics_Body *body, double x, double y);
|
EAPI void ephysics_body_central_impulse_apply(EPhysics_Body *body, double x, double y);
|
||||||
|
@ -2162,11 +2165,46 @@ EAPI void ephysics_body_central_impulse_apply(EPhysics_Body *body, double x, dou
|
||||||
* Negative values will impulse body on anti clock rotation.
|
* Negative values will impulse body on anti clock rotation.
|
||||||
*
|
*
|
||||||
* @see ephysics_body_central_impulse_apply().
|
* @see ephysics_body_central_impulse_apply().
|
||||||
|
* @see ephysics_body_impulse_apply().
|
||||||
*
|
*
|
||||||
* @ingroup EPhysics_Body
|
* @ingroup EPhysics_Body
|
||||||
*/
|
*/
|
||||||
EAPI void ephysics_body_torque_impulse_apply(EPhysics_Body *body, double roll);
|
EAPI void ephysics_body_torque_impulse_apply(EPhysics_Body *body, double roll);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief
|
||||||
|
* Apply an impulse over a body.
|
||||||
|
*
|
||||||
|
* An impulse will be applied over the body to make it move and rotate around
|
||||||
|
* Z axis.
|
||||||
|
*
|
||||||
|
* Impulse is the product of the force over the time this force is applied.
|
||||||
|
* It can be applied in the center of the body, avoiding rotating it,
|
||||||
|
* with @ref ephysics_body_central_impulse_apply(), it can be applied only
|
||||||
|
* to make a body rotate, with @ref ephysics_body_torque_impulse_apply(),
|
||||||
|
* or can be used to lead to both behaviors with
|
||||||
|
* @ref ephysics_body_impulse_apply().
|
||||||
|
*
|
||||||
|
* It will resulte in a central impulse with impulse (@p x, @p y) and a
|
||||||
|
* torque impulse that will be calculated as a cross product on impulse
|
||||||
|
* and relative position.
|
||||||
|
*
|
||||||
|
* @param body The physics body that will receive the impulse.
|
||||||
|
* @param x The axis x component of impulse.
|
||||||
|
* @param y The axis y component of impulse.
|
||||||
|
* @param pos_x The axis x component of the relative position to apply impulse.
|
||||||
|
* @param pos_y The axis y component of the relative position to apply impulse.
|
||||||
|
*
|
||||||
|
* @note Impulse is measured in kg * p / s and position in pixels
|
||||||
|
* (Evas coordinates).
|
||||||
|
*
|
||||||
|
* @see ephysics_body_central_impulse_apply().
|
||||||
|
* @see ephysics_body_torque_impulse_apply().
|
||||||
|
*
|
||||||
|
* @ingroup EPhysics_Body
|
||||||
|
*/
|
||||||
|
EAPI void ephysics_body_impulse_apply(EPhysics_Body *body, double x, double y, Evas_Coord pos_x, Evas_Coord pos_y);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief
|
* @brief
|
||||||
* Enable or disable body's rotation on z axis.
|
* Enable or disable body's rotation on z axis.
|
||||||
|
|
|
@ -1237,6 +1237,25 @@ ephysics_body_central_impulse_apply(EPhysics_Body *body, double x, double y)
|
||||||
body->rigid_body->applyCentralImpulse(btVector3(x / rate, y / rate, 0));
|
body->rigid_body->applyCentralImpulse(btVector3(x / rate, y / rate, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
EAPI void
|
||||||
|
ephysics_body_impulse_apply(EPhysics_Body *body, double x, double y, Evas_Coord pos_x, Evas_Coord pos_y)
|
||||||
|
{
|
||||||
|
double rate;
|
||||||
|
|
||||||
|
if (!body)
|
||||||
|
{
|
||||||
|
ERR("Can't apply impulse to a null body.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
rate = ephysics_world_rate_get(body->world);
|
||||||
|
|
||||||
|
body->rigid_body->activate(1);
|
||||||
|
body->rigid_body->applyImpulse(btVector3(x / rate, y / rate, 0),
|
||||||
|
btVector3((double) pos_x / rate,
|
||||||
|
(double) pos_y / rate, 0));
|
||||||
|
}
|
||||||
|
|
||||||
EAPI void
|
EAPI void
|
||||||
ephysics_body_linear_movement_enable_set(EPhysics_Body *body, Eina_Bool enable_x, Eina_Bool enable_y)
|
ephysics_body_linear_movement_enable_set(EPhysics_Body *body, Eina_Bool enable_x, Eina_Bool enable_y)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue