From 900580095cf40066e6cad1f8f829f6871ed43f73 Mon Sep 17 00:00:00 2001 From: Leandro Dorileo Date: Fri, 23 Nov 2012 21:43:32 +0000 Subject: [PATCH] EPhysics: add soft body bending constraints API This patch introduces the API ephysics_body_soft_body_bending_constraints_add used define how deformeable a soft body is supposed to be. Patch by: Leandro Dorileo SVN revision: 79592 --- legacy/ephysics/src/lib/EPhysics.h | 22 +++++++++++ legacy/ephysics/src/lib/ephysics_body.cpp | 45 ++++++++++++++++------ legacy/ephysics/src/lib/ephysics_private.h | 3 +- legacy/ephysics/src/lib/ephysics_world.cpp | 3 ++ 4 files changed, 60 insertions(+), 13 deletions(-) diff --git a/legacy/ephysics/src/lib/EPhysics.h b/legacy/ephysics/src/lib/EPhysics.h index 04179df1ad..a9ac03d381 100644 --- a/legacy/ephysics/src/lib/EPhysics.h +++ b/legacy/ephysics/src/lib/EPhysics.h @@ -2423,6 +2423,28 @@ EAPI int ephysics_body_soft_body_position_iterations_get(EPhysics_Body *body); */ EAPI void ephysics_body_soft_body_triangle_move(EPhysics_Body *body, int idx, Evas_Coord x, Evas_Coord y, Evas_Coord z); +/** + * @brief + * Add new bending constraints to some @p body. + * + * Bending constraints define how a soft body is to be deformeable. In fact a + * bending constraints represents a link between a soft body mesh triangle and + * other. The hardness property is used to define the bending constraint of + * those new links. + * + * By default EPhysics create a new soft body or cloth with a single bending + * constraint. + * + * @param body The body to add bending constraints to. + * @param number The number of bending constraints to be added, it must be + * greater than 0. + * + * @see ephysics_body_soft_body_hardness_set(). + * + * @ingroup EPhysics_Body + */ +EAPI void ephysics_body_soft_body_bending_constraints_add(EPhysics_Body *body, int number); + /** * @brief * Create a new circle physics body. diff --git a/legacy/ephysics/src/lib/ephysics_body.cpp b/legacy/ephysics/src/lib/ephysics_body.cpp index 9508eca2a8..5cc5f6ffad 100644 --- a/legacy/ephysics/src/lib/ephysics_body.cpp +++ b/legacy/ephysics/src/lib/ephysics_body.cpp @@ -749,6 +749,16 @@ _ephysics_body_soft_body_anchors_rebuild(int node, btRigidBody *rigid_body, btSo } } +void +ephysics_body_soft_body_bending_constraints_generate(EPhysics_Body *body) +{ + btSoftBody *soft_body = body->soft_body; + + for (; body->bending_constraints; body->bending_constraints--) + soft_body->generateBendingConstraints(2, soft_body->m_materials + [body->material_index]); +} + static void _ephysics_body_cloth_constraints_rebuild(EPhysics_Body *body) { @@ -776,12 +786,7 @@ _ephysics_body_cloth_constraints_rebuild(EPhysics_Body *body) } } soft_body->generateClusters(0); - if (!body->bending_constraints) - { - soft_body->generateBendingConstraints(2, soft_body-> - m_materials[body->material_index]); - body->bending_constraints = EINA_TRUE; - } + ephysics_body_soft_body_bending_constraints_generate(body); } static void @@ -802,12 +807,7 @@ _ephysics_body_soft_body_constraints_rebuild(EPhysics_Body *body) } soft_body->generateClusters(0); - if (!body->bending_constraints) - { - soft_body->generateBendingConstraints(10, soft_body-> - m_materials[body->material_index]); - body->bending_constraints = EINA_TRUE; - } + ephysics_body_soft_body_bending_constraints_generate(body); } inline static double @@ -1685,6 +1685,7 @@ ephysics_body_soft_body_hardness_get(const EPhysics_Body *body) static void _ephysics_body_soft_body_default_config(EPhysics_Body *body, btSoftBody *soft_body) { + body->bending_constraints = 1; body->soft_body = soft_body; body->soft_body->getCollisionShape()->setMargin(btScalar(0.02)); body->soft_body->setUserPointer(body); @@ -1892,6 +1893,26 @@ ephysics_body_soft_body_position_iterations_get(EPhysics_Body *body) return body->soft_body->m_cfg.piterations; } +EAPI void +ephysics_body_soft_body_bending_constraints_add(EPhysics_Body *body, int number) +{ + if (!body) + { + ERR("Could add new bending constraint, body is null."); + return; + } + + if (number <= 0) + { + ERR("Could not add new bending constraints, number must be greater" + " than 0"); + return; + } + + body->bending_constraints += number; + DBG("Added new bending constraints to body: %p", body); +} + EAPI EPhysics_Body * ephysics_body_cloth_add(EPhysics_World *world, unsigned short rows, unsigned short columns) { diff --git a/legacy/ephysics/src/lib/ephysics_private.h b/legacy/ephysics/src/lib/ephysics_private.h index 85a41038e6..f58e542106 100644 --- a/legacy/ephysics/src/lib/ephysics_private.h +++ b/legacy/ephysics/src/lib/ephysics_private.h @@ -151,7 +151,7 @@ struct _EPhysics_Body { Eina_Bool back_face_culling:1; Eina_Bool clockwise:1; Eina_Bool boundary:1; - Eina_Bool bending_constraints:1; + int bending_constraints; }; extern int _ephysics_log_dom; @@ -189,6 +189,7 @@ void ephysics_body_forces_apply(EPhysics_Body *body); void ephysics_body_activate(const EPhysics_Body *body, Eina_Bool activate); void ephysics_body_evas_objects_restack(EPhysics_World *world); void ephysics_body_soft_body_dragging_apply(EPhysics_Body *body); +void ephysics_body_soft_body_bending_constraints_generate(EPhysics_Body *body); /* Camera */ EPhysics_Camera *ephysics_camera_add(EPhysics_World *world); diff --git a/legacy/ephysics/src/lib/ephysics_world.cpp b/legacy/ephysics/src/lib/ephysics_world.cpp index 15538feb82..a3b24863fd 100644 --- a/legacy/ephysics/src/lib/ephysics_world.cpp +++ b/legacy/ephysics/src/lib/ephysics_world.cpp @@ -590,6 +590,9 @@ _th_simulate(void *data, Ecore_Thread *th) ephysics_body_forces_apply(body); if (body->dragging_data.dragging) ephysics_body_soft_body_dragging_apply(body); + + if (body->bending_constraints) + ephysics_body_soft_body_bending_constraints_generate(body); } time_now = ecore_time_get();