diff --git a/legacy/ephysics/src/lib/EPhysics.h b/legacy/ephysics/src/lib/EPhysics.h index 2c40b7707b..5a7b2db9fe 100644 --- a/legacy/ephysics/src/lib/EPhysics.h +++ b/legacy/ephysics/src/lib/EPhysics.h @@ -1912,6 +1912,42 @@ EAPI void ephysics_body_soft_body_dragging_unset(EPhysics_Body *body); */ EAPI int ephysics_body_soft_body_triangle_index_get(EPhysics_Body *body, Evas_Coord x, Evas_Coord y); +/** + * @brief + * Set the soft body number of position iterations. + * + * Both soft body and cloth can have its number of position iterations changed. + * The number of position iterations will change how many time the physics engine + * will iterate the position solver, a greater value will change deformation + * behaves and how hard the soft body looks like. The greater position iterations + * the harder the soft body will be. + * + * @node For soft bodies the default value is set to 1, and for cloth it's set to + * the number of rows / 5; + * + * @param body The body to be set. + * @param iterations The number of iterations. + * + * @see ephysics_body_cloth_add() for more informations about cloth. + * @see ephysics_body_soft_body_position_iterations_get(). + * + * @ingroup EPhysics_Body + */ +EAPI void ephysics_body_soft_body_position_iterations_set(EPhysics_Body *body, int iterations); + +/** + * @brief + * Get the soft body number of position iterations. + * + * @param body The body to get the number os position iterations from. + * @return The number of position solver iterations of a soft @p body. + * + * @see ephysics_body_soft_body_position_iterations_set(). + * + * @ingroup EPhysics_Body + */ +EAPI int ephysics_body_soft_body_position_iterations_get(EPhysics_Body *body); + /** * @brief * Move a body's triangle. diff --git a/legacy/ephysics/src/lib/ephysics_body.cpp b/legacy/ephysics/src/lib/ephysics_body.cpp index 7441299894..c1ec7983c6 100644 --- a/legacy/ephysics/src/lib/ephysics_body.cpp +++ b/legacy/ephysics/src/lib/ephysics_body.cpp @@ -1571,6 +1571,47 @@ _ephysics_body_slices_add(EPhysics_Body *body, double delta, double max) return EINA_TRUE; } +EAPI void +ephysics_body_soft_body_position_iterations_set(EPhysics_Body *body, int iterations) +{ + if (!body) + { + ERR("Could not set the number of iterations for position solver, body " + "is null."); + return; + } + + if (body->type == EPHYSICS_BODY_TYPE_RIGID) + { + ERR("Could not set the number of iterations for position solver, body " + "must be a soft body or a cloth"); + return; + } + + body->soft_body->m_cfg.piterations = iterations; + DBG("Soft body position solver iterations set to: %d", iterations); +} + +EAPI int +ephysics_body_soft_body_position_iterations_get(EPhysics_Body *body) +{ + if (!body) + { + ERR("Could not get the number of iterations for position solver, body " + "is null."); + return 0; + } + + if (body->type == EPHYSICS_BODY_TYPE_RIGID) + { + ERR("Could not get the number of iterations for position solver, body " + "must be a soft body or a cloth"); + return 0; + } + + return body->soft_body->m_cfg.piterations; +} + EAPI EPhysics_Body * ephysics_body_cloth_add(EPhysics_World *world, unsigned short granularity) {