summaryrefslogtreecommitdiff
path: root/legacy/ephysics
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
parentfa05bab34341081ebc65d126fdfa54fc032c7469 (diff)
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')
-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 04179df1ad..a9ac03d381 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
2425 2425
2426/** 2426/**
2427 * @brief 2427 * @brief
2428 * Add new bending constraints to some @p body.
2429 *
2430 * Bending constraints define how a soft body is to be deformeable. In fact a
2431 * bending constraints represents a link between a soft body mesh triangle and
2432 * other. The hardness property is used to define the bending constraint of
2433 * those new links.
2434 *
2435 * By default EPhysics create a new soft body or cloth with a single bending
2436 * constraint.
2437 *
2438 * @param body The body to add bending constraints to.
2439 * @param number The number of bending constraints to be added, it must be
2440 * greater than 0.
2441 *
2442 * @see ephysics_body_soft_body_hardness_set().
2443 *
2444 * @ingroup EPhysics_Body
2445 */
2446EAPI void ephysics_body_soft_body_bending_constraints_add(EPhysics_Body *body, int number);
2447
2448/**
2449 * @brief
2428 * Create a new circle physics body. 2450 * Create a new circle physics body.
2429 * 2451 *
2430 * Its collision shape will be a circle of diameter 1. To change it's size 2452 * 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 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
749 } 749 }
750} 750}
751 751
752void
753ephysics_body_soft_body_bending_constraints_generate(EPhysics_Body *body)
754{
755 btSoftBody *soft_body = body->soft_body;
756
757 for (; body->bending_constraints; body->bending_constraints--)
758 soft_body->generateBendingConstraints(2, soft_body->m_materials
759 [body->material_index]);
760}
761
752static void 762static void
753_ephysics_body_cloth_constraints_rebuild(EPhysics_Body *body) 763_ephysics_body_cloth_constraints_rebuild(EPhysics_Body *body)
754{ 764{
@@ -776,12 +786,7 @@ _ephysics_body_cloth_constraints_rebuild(EPhysics_Body *body)
776 } 786 }
777 } 787 }
778 soft_body->generateClusters(0); 788 soft_body->generateClusters(0);
779 if (!body->bending_constraints) 789 ephysics_body_soft_body_bending_constraints_generate(body);
780 {
781 soft_body->generateBendingConstraints(2, soft_body->
782 m_materials[body->material_index]);
783 body->bending_constraints = EINA_TRUE;
784 }
785} 790}
786 791
787static void 792static void
@@ -802,12 +807,7 @@ _ephysics_body_soft_body_constraints_rebuild(EPhysics_Body *body)
802 } 807 }
803 808
804 soft_body->generateClusters(0); 809 soft_body->generateClusters(0);
805 if (!body->bending_constraints) 810 ephysics_body_soft_body_bending_constraints_generate(body);
806 {
807 soft_body->generateBendingConstraints(10, soft_body->
808 m_materials[body->material_index]);
809 body->bending_constraints = EINA_TRUE;
810 }
811} 811}
812 812
813inline static double 813inline static double
@@ -1685,6 +1685,7 @@ ephysics_body_soft_body_hardness_get(const EPhysics_Body *body)
1685static void 1685static void
1686_ephysics_body_soft_body_default_config(EPhysics_Body *body, btSoftBody *soft_body) 1686_ephysics_body_soft_body_default_config(EPhysics_Body *body, btSoftBody *soft_body)
1687{ 1687{
1688 body->bending_constraints = 1;
1688 body->soft_body = soft_body; 1689 body->soft_body = soft_body;
1689 body->soft_body->getCollisionShape()->setMargin(btScalar(0.02)); 1690 body->soft_body->getCollisionShape()->setMargin(btScalar(0.02));
1690 body->soft_body->setUserPointer(body); 1691 body->soft_body->setUserPointer(body);
@@ -1892,6 +1893,26 @@ ephysics_body_soft_body_position_iterations_get(EPhysics_Body *body)
1892 return body->soft_body->m_cfg.piterations; 1893 return body->soft_body->m_cfg.piterations;
1893} 1894}
1894 1895
1896EAPI void
1897ephysics_body_soft_body_bending_constraints_add(EPhysics_Body *body, int number)
1898{
1899 if (!body)
1900 {
1901 ERR("Could add new bending constraint, body is null.");
1902 return;
1903 }
1904
1905 if (number <= 0)
1906 {
1907 ERR("Could not add new bending constraints, number must be greater"
1908 " than 0");
1909 return;
1910 }
1911
1912 body->bending_constraints += number;
1913 DBG("Added new bending constraints to body: %p", body);
1914}
1915
1895EAPI EPhysics_Body * 1916EAPI EPhysics_Body *
1896ephysics_body_cloth_add(EPhysics_World *world, unsigned short rows, unsigned short columns) 1917ephysics_body_cloth_add(EPhysics_World *world, unsigned short rows, unsigned short columns)
1897{ 1918{
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 {
151 Eina_Bool back_face_culling:1; 151 Eina_Bool back_face_culling:1;
152 Eina_Bool clockwise:1; 152 Eina_Bool clockwise:1;
153 Eina_Bool boundary:1; 153 Eina_Bool boundary:1;
154 Eina_Bool bending_constraints:1; 154 int bending_constraints;
155}; 155};
156 156
157extern int _ephysics_log_dom; 157extern int _ephysics_log_dom;
@@ -189,6 +189,7 @@ void ephysics_body_forces_apply(EPhysics_Body *body);
189void ephysics_body_activate(const EPhysics_Body *body, Eina_Bool activate); 189void ephysics_body_activate(const EPhysics_Body *body, Eina_Bool activate);
190void ephysics_body_evas_objects_restack(EPhysics_World *world); 190void ephysics_body_evas_objects_restack(EPhysics_World *world);
191void ephysics_body_soft_body_dragging_apply(EPhysics_Body *body); 191void ephysics_body_soft_body_dragging_apply(EPhysics_Body *body);
192void ephysics_body_soft_body_bending_constraints_generate(EPhysics_Body *body);
192 193
193/* Camera */ 194/* Camera */
194EPhysics_Camera *ephysics_camera_add(EPhysics_World *world); 195EPhysics_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)
590 ephysics_body_forces_apply(body); 590 ephysics_body_forces_apply(body);
591 if (body->dragging_data.dragging) 591 if (body->dragging_data.dragging)
592 ephysics_body_soft_body_dragging_apply(body); 592 ephysics_body_soft_body_dragging_apply(body);
593
594 if (body->bending_constraints)
595 ephysics_body_soft_body_bending_constraints_generate(body);
593 } 596 }
594 597
595 time_now = ecore_time_get(); 598 time_now = ecore_time_get();