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
This commit is contained in:
Leandro Dorileo 2012-11-23 21:43:32 +00:00 committed by Bruno Dilly
parent fa05bab343
commit 900580095c
4 changed files with 60 additions and 13 deletions

View File

@ -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.

View File

@ -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)
{

View File

@ -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);

View File

@ -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();