ephysics: allow to enable angular movement on all the

planes




SVN revision: 77775
This commit is contained in:
Bruno Dilly 2012-10-10 19:16:48 +00:00
parent 4ef1a74d4c
commit 290a7d8821
4 changed files with 33 additions and 24 deletions

View File

@ -143,7 +143,8 @@ _letter_body_setup_common(EPhysics_Body *body, Evas_Object *view)
ephysics_body_evas_object_set(body, view, EINA_TRUE);
ephysics_body_mass_set(body, 1.2);
ephysics_body_restitution_set(body, 0.6);
ephysics_body_rotation_on_z_axis_enable_set(body, EINA_FALSE);
ephysics_body_angular_movement_enable_set(body, EINA_FALSE, EINA_FALSE,
EINA_FALSE);
}
static EPhysics_Body *
@ -260,7 +261,8 @@ elm_main(int argc __UNUSED__, char **argv __UNUSED__)
letter_body = _letter_body_circle_add(world, image);
ephysics_body_friction_set(letter_body, 1);
ephysics_body_mass_set(letter_body, 1);
ephysics_body_rotation_on_z_axis_enable_set(letter_body, EINA_TRUE);
ephysics_body_angular_movement_enable_set(letter_body, EINA_FALSE,
EINA_FALSE, EINA_TRUE);
/* make the "E" logo get into the viewport by applying an horizontal force */
ephysics_body_central_impulse_apply(letter_body, 390, 0);

View File

@ -60,6 +60,7 @@ _add_sphere(Test_Data *test_data, int i)
test_data->evas_objs = eina_list_append(test_data->evas_objs, sphere);
fall_body = ephysics_body_circle_add(test_data->world);
ephysics_body_linear_movement_enable_set(fall_body, EINA_TRUE, EINA_TRUE, EINA_TRUE);
ephysics_body_evas_object_set(fall_body, sphere, EINA_TRUE);
ephysics_body_event_callback_add(fall_body, EPHYSICS_CALLBACK_BODY_UPDATE,
update_object_cb, shadow);

View File

@ -2693,33 +2693,39 @@ EAPI void ephysics_body_impulse_apply(EPhysics_Body *body, double x, double y, E
* @brief
* Enable or disable body's rotation on z axis.
*
* Enabled by default.
*
* If disabled, body won't rotate on x-y plane.
* Enabled by default for z axis, so the body only will rotate on x-y plane.
*
* @param body The physics body.
* @param enable If @c EINA_TRUE enable rotation on z axis, if @c EINA_FALSE
* disable it.
* @param enable_x If @c EINA_TRUE allow rotation on x axis (y-z plane),
* if @c EINA_FALSE disallow it.
* @param enable_y If @c EINA_TRUE allow rotation on y axis (x-z plane),
*if @c EINA_FALSE disallow it.
* @param enable_z If @c EINA_TRUE allow rotation on z axis (x-y plane),
* if @c EINA_FALSE disallow it.
*
* @see ephysics_body_rotation_on_z_axis_enable_get().
* @see ephysics_body_angular_movement_enable_get().
*
* @ingroup EPhysics_Body
*/
EAPI void ephysics_body_rotation_on_z_axis_enable_set(EPhysics_Body *body, Eina_Bool enable);
EAPI void ephysics_body_angular_movement_enable_set(EPhysics_Body *body, Eina_Bool enable_x, Eina_Bool enable_y, Eina_Bool enable_z);
/**
* @brief
* Return body's rotation on z axis state.
*
* @param body The physics body.
* @return @c EINA_TRUE if rotation on z axis is enabled, or @c EINA_FALSE
* if disabled (or on error).
* @param enable_x @c EINA_TRUE if rotation on x axis (y-z plane) is allowed, or
* @c EINA_FALSE if it's not.
* @param enable_y @c EINA_TRUE if rotation on y axis (x-z plane) is allowed, or
* @c EINA_FALSE if it's not.
* @param enable_z @c EINA_TRUE if rotation on z axis (x-y plane) is allowed, or
* @c EINA_FALSE if it's not.
*
* @see ephysics_body_rotation_on_z_axis_enable_set() for more details.
* @see ephysics_body_angular_movement_enable_set() for more details.
*
* @ingroup EPhysics_Body
*/
EAPI Eina_Bool ephysics_body_rotation_on_z_axis_enable_get(const EPhysics_Body *body);
EAPI void ephysics_body_angular_movement_enable_get(const EPhysics_Body *body, Eina_Bool *enable_x, Eina_Bool *enable_y, Eina_Bool *enable_z);
/**
* @brief
@ -2736,7 +2742,7 @@ EAPI Eina_Bool ephysics_body_rotation_on_z_axis_enable_get(const EPhysics_Body *
* disallow it.
*
* @see ephysics_body_linear_movement_enable_get().
* @see ephysics_body_rotation_on_z_axis_enable_set().
* @see ephysics_body_angular_movement_enable_set().
*
* @ingroup EPhysics_Body
*/
@ -2755,7 +2761,7 @@ EAPI void ephysics_body_linear_movement_enable_set(EPhysics_Body *body, Eina_Boo
* @c EINA_FALSE if it's not.
*
* @see ephysics_body_linear_movement_enable_set().
* @see ephysics_body_rotation_on_z_axis_enable_get().
* @see ephysics_body_angular_movement_enable_get().
*
* @ingroup EPhysics_Body
*/

View File

@ -2483,7 +2483,7 @@ ephysics_body_torque_impulse_apply(EPhysics_Body *body, double roll)
}
EAPI void
ephysics_body_rotation_on_z_axis_enable_set(EPhysics_Body *body, Eina_Bool enable)
ephysics_body_angular_movement_enable_set(EPhysics_Body *body, Eina_Bool enable_x, Eina_Bool enable_y, Eina_Bool enable_z)
{
if (!body)
{
@ -2492,23 +2492,23 @@ ephysics_body_rotation_on_z_axis_enable_set(EPhysics_Body *body, Eina_Bool enabl
}
ephysics_world_lock_take(body->world);
if (!enable)
body->rigid_body->setAngularFactor(btVector3(0, 0, 0));
else
body->rigid_body->setAngularFactor(btVector3(0, 0, 1));
body->rigid_body->setAngularFactor(btVector3(!!enable_x, !!enable_y,
!!enable_z));
ephysics_world_lock_release(body->world);
}
EAPI Eina_Bool
ephysics_body_rotation_on_z_axis_enable_get(const EPhysics_Body *body)
EAPI void
ephysics_body_angular_movement_enable_get(const EPhysics_Body *body, Eina_Bool *enable_x, Eina_Bool *enable_y, Eina_Bool *enable_z)
{
if (!body)
{
ERR("Can't check if rotation is enabled, body is null.");
return EINA_FALSE;
return;
}
return !!body->rigid_body->getAngularFactor().z();
if (enable_x) *enable_x = !!body->rigid_body->getAngularFactor().x();
if (enable_y) *enable_y = !!body->rigid_body->getAngularFactor().y();
if (enable_z) *enable_z = !!body->rigid_body->getAngularFactor().z();
}
EAPI double