diff --git a/legacy/ephysics/src/lib/EPhysics.h b/legacy/ephysics/src/lib/EPhysics.h index 4870c2373d..1c966ce43e 100644 --- a/legacy/ephysics/src/lib/EPhysics.h +++ b/legacy/ephysics/src/lib/EPhysics.h @@ -1520,6 +1520,42 @@ EAPI void ephysics_body_rotation_on_z_axis_enable_set(EPhysics_Body *body, Eina_ */ EAPI Eina_Bool ephysics_body_rotation_on_z_axis_enable_get(EPhysics_Body *body); +/** + * @brief + * Enable or disable body's movement on x and y axises. + * + * Enabled by default on both axises. + * + * @param body The physics body. + * @param enable_x If @c EINA_TRUE allow movement on x axis, if @c EINA_FALSE + * disallow it. + * @param enable_y If @c EINA_TRUE allow movement on y axis, if @c EINA_FALSE + * disallow it. + * + * @see ephysics_body_linear_movement_enable_set(). + * @see ephysics_body_rotation_on_z_axis_enable_set(). + * + * @ingroup EPhysics_Body + */ +EAPI void ephysics_body_linear_movement_enable_set(EPhysics_Body *body, Eina_Bool enable_x, Eina_Bool enable_y); + +/** + * @brief + * Get body's movement on x and y axises behavior. + * + * @param body The physics body. + * @param enable_x @c EINA_TRUE if movement on x axis is allowed, or + * @c EINA_FALSE if it's not. + * @param enable_y @c EINA_TRUE if movement on y axis is allowed, or + * @c EINA_FALSE if it's not. + * + * @see ephysics_body_linear_movement_enable_get(). + * @see ephysics_body_rotation_on_z_axis_enable_get(). + * + * @ingroup EPhysics_Body + */ +EAPI void ephysics_body_linear_movement_enable_get(EPhysics_Body *body, Eina_Bool *enable_x, Eina_Bool *enable_y); + /** * @brief * Return body's rotation on z axis. diff --git a/legacy/ephysics/src/lib/ephysics_body.cpp b/legacy/ephysics/src/lib/ephysics_body.cpp index 41ef18620b..0353212f8f 100644 --- a/legacy/ephysics/src/lib/ephysics_body.cpp +++ b/legacy/ephysics/src/lib/ephysics_body.cpp @@ -820,6 +820,31 @@ ephysics_body_central_impulse_apply(EPhysics_Body *body, double x, double y) body->rigid_body->applyCentralImpulse(btVector3(x, y, 0)); } +EAPI void +ephysics_body_linear_movement_enable_set(EPhysics_Body *body, Eina_Bool enable_x, Eina_Bool enable_y) +{ + if (!body) + { + ERR("Can't set linear factor on a null body."); + return; + } + + body->rigid_body->setLinearFactor(btVector3(!!enable_x, !!enable_y, 0)); +} + +EAPI void +ephysics_body_linear_movement_enable_get(EPhysics_Body *body, Eina_Bool *enable_x, Eina_Bool *enable_y) +{ + if (!body) + { + ERR("Can't check if linear factor is enabled, body is null."); + return; + } + + if (enable_x) *enable_x = !!body->rigid_body->getLinearFactor().x(); + if (enable_y) *enable_y = !!body->rigid_body->getLinearFactor().y(); +} + EAPI void ephysics_body_torque_impulse_apply(EPhysics_Body *body, double roll) {