aboutsummaryrefslogtreecommitdiffstats
path: root/legacy/ephysics/src/lib
diff options
context:
space:
mode:
authorLeandro Dorileo <dorileo@profusion.mobi>2012-11-23 21:43:32 +0000
committerBruno Dilly <bdilly@profusion.mobi>2012-11-23 21:43:32 +0000
commit900580095cf40066e6cad1f8f829f6871ed43f73 (patch)
tree4c272828314851d2b59e42a506e4b23693c63409 /legacy/ephysics/src/lib
parentfa05bab34341081ebc65d126fdfa54fc032c7469 (diff)
downloadefl-900580095cf40066e6cad1f8f829f6871ed43f73.tar.gz
efl-900580095cf40066e6cad1f8f829f6871ed43f73.tar.xz
efl-900580095cf40066e6cad1f8f829f6871ed43f73.zip
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 <dorileo@profusion.mobi> SVN revision: 79592
Diffstat (limited to 'legacy/ephysics/src/lib')
-rw-r--r--legacy/ephysics/src/lib/EPhysics.h22
-rw-r--r--legacy/ephysics/src/lib/ephysics_body.cpp45
-rw-r--r--legacy/ephysics/src/lib/ephysics_private.h3
-rw-r--r--legacy/ephysics/src/lib/ephysics_world.cpp3
4 files changed, 60 insertions, 13 deletions
diff --git a/legacy/ephysics/src/lib/EPhysics.h b/legacy/ephysics/src/lib/EPhysics.h
index 04179df1a..a9ac03d38 100644
--- a/legacy/ephysics/src/lib/EPhysics.h
+++ b/legacy/ephysics/src/lib/EPhysics.h
@@ -2425,6 +2425,28 @@ EAPI void ephysics_body_soft_body_triangle_move(EPhysics_Body *body, int idx, Ev
/**
* @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.
*
* Its collision shape will be a circle of diameter 1. To change it's size
diff --git a/legacy/ephysics/src/lib/ephysics_body.cpp b/legacy/ephysics/src/lib/ephysics_body.cpp
index 9508eca2a..5cc5f6ffa 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 85a41038e..f58e54210 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 15538feb8..a3b24863f 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();