From d1ba36f4bafef5d6b5e3b63f01fe1d950637df51 Mon Sep 17 00:00:00 2001 From: Bruno Dilly Date: Tue, 3 Jul 2012 23:24:27 +0000 Subject: [PATCH] EPhysics: constraint solver iterations Functions to get and set the constraint solver number of iterations. Patch by Leandro Dorileo SVN revision: 73249 --- legacy/ephysics/src/lib/EPhysics.h | 36 ++++++++++++++++++++++ legacy/ephysics/src/lib/ephysics_world.cpp | 24 +++++++++++++++ 2 files changed, 60 insertions(+) diff --git a/legacy/ephysics/src/lib/EPhysics.h b/legacy/ephysics/src/lib/EPhysics.h index 5b48fffdef..748dab279c 100644 --- a/legacy/ephysics/src/lib/EPhysics.h +++ b/legacy/ephysics/src/lib/EPhysics.h @@ -442,6 +442,42 @@ EAPI Eina_Bool ephysics_world_running_get(const EPhysics_World *world); */ EAPI void ephysics_world_gravity_set(EPhysics_World *world, double gx, double gy); +/** + * @brief + * Set the number of iterations the constraint solver will have for contact and + * joint constraints. + * + * The default value is set to 10. The greater number of iterations more + * quality and precise the result but with performance penalty. + * + * By default, the Projected Gauss Seidel constraint solver is used for contact + * and joint constraints. The algorithm is an iterative LCP solver, informally + * known as 'sequential impulse'. + * + * A reasonable range of iterations is from 4 (low quality, good performance) + * to 20 (good quality, less but still reasonable performance). + * + * @param world The world to be set. + * @param iterations The number of iterations to be set. + * + * @see ephysics_world_constraint_solver_iterations_get(). + * @ingroup EPhysics_World + */ +EAPI void ephysics_world_constraint_solver_iterations_set(EPhysics_World *world, int iterations); + +/** + * @brief + * Get the number of iterations the constraint solver will have for contact and + * joint constraints. + * + * @param world The world to get number of iterations from. + * @return the number of iterations set to @p world, or 0 on failure. + * + * @see ephysics_world_constraint_solver_iterations_set() for its meaning. + * @ingroup EPhysics_World + */ +EAPI int ephysics_world_constraint_solver_iterations_get(EPhysics_World *world); + /** * @brief * Get world gravity values for axis x and y. diff --git a/legacy/ephysics/src/lib/ephysics_world.cpp b/legacy/ephysics/src/lib/ephysics_world.cpp index ee74844806..235f60e15d 100644 --- a/legacy/ephysics/src/lib/ephysics_world.cpp +++ b/legacy/ephysics/src/lib/ephysics_world.cpp @@ -471,6 +471,30 @@ ephysics_world_gravity_set(EPhysics_World *world, double gx, double gy) DBG("World %p gravity set to X:%lf, Y:%lf.", world, gx, gy); } +EAPI void +ephysics_world_constraint_solver_iterations_set(EPhysics_World *world, int iterations) +{ + if (!world) + { + ERR("Can't set constraint solver iterations, world is null."); + return; + } + + world->dynamics_world->getSolverInfo().m_numIterations = iterations; +} + +EAPI int +ephysics_world_constraint_solver_iterations_get(EPhysics_World *world) +{ + if (!world) + { + ERR("Can't get constraint solver iterations, world is null."); + return 0; + } + + return world->dynamics_world->getSolverInfo().m_numIterations; +} + EAPI void ephysics_world_gravity_get(const EPhysics_World *world, double *gx, double *gy) {