EPhysics: anchor hardness api and small fixes

This patch introduces a separeted API for handling with anchor hardness,
and fixes small problems with pose and soft body impulses.

--This line, and those below, will be ignored--


SVN revision: 80107
This commit is contained in:
Leandro Dorileo 2012-12-03 21:29:30 +00:00
parent ff57aea853
commit d449396bed
3 changed files with 101 additions and 5 deletions

View File

@ -2330,6 +2330,46 @@ EAPI void ephysics_body_soft_body_hardness_set(EPhysics_Body *body, double hardn
*/
EAPI double ephysics_body_soft_body_hardness_get(const EPhysics_Body *body);
/**
* @brief
* Set the soft body anchor hardness percentage.
*
* The anchor hardness percentage(together with general hardness settings
* set with ephysics_body_soft_body_hardness_set()) will define how the soft
* body is supposed to deform.
*
* By default EPhysics will calculate the anchor hardness depending on the
* general hardness settings, by default it`s set to 70% of general hardness on
* soft body and a fixed 80% for cloths.
*
* Anchor hardness will result on a contrary force to impulse and velocities
* applied to soft bodies. So it implies on force reduction.
*
* @note Since it`s a percentage value @p hardness will range from 0 - 100.
*
* @param body The body to be set.
* @param hardness The hardness to be set to @p body.
*
* @see ephysics_body_soft_body_hardness_set() for general hardness.
* @see ephysics_body_soft_body_anchor_hardness_get().
*
* @ingroup EPhysics_Body
*/
EAPI void ephysics_body_soft_body_anchor_hardness_set(EPhysics_Body *body, double hardness);
/**
* @brief
* Get the soft body anchor hardnees percentage.
*
* @param body The body to get the anchor hardness percentage from.
* @return The anchor hardness percentage on success -1 on failure.
*
* @see ephysics_body_soft_body_anchor_hardness_set().
*
* @ingroup EPhysics_Body
*/
EAPI double ephysics_body_soft_body_anchor_hardness_get(EPhysics_Body *body);
/**
* @brief
* Set the soft body dragging status.

View File

@ -1749,20 +1749,73 @@ ephysics_body_soft_body_get(const EPhysics_Body *body)
return body->soft_body;
}
EAPI void
ephysics_body_soft_body_anchor_hardness_set(EPhysics_Body *body, double hardness)
{
if (!body)
{
ERR("Can't set soft body's anchor hardness, body is null.");
return;
}
if (!body->soft_body)
{
ERR("Can't set soft body's anchor hardness, body seems not to be a soft"
" body.");
return;
}
if (hardness < 0 || hardness > 100)
{
ERR("Can't set soft body's anchor hardness, it must be between 0 and"
" 100.");
return;
}
ephysics_world_lock_take(body->world);
body->anchor_hardness = EINA_TRUE;
body->soft_body->m_cfg.kAHR = 1 - (hardness / 100);
ephysics_world_lock_release(body->world);
DBG("Soft body anchor hardness set to: %lf", hardness);
}
EAPI double
ephysics_body_soft_body_anchor_hardness_get(EPhysics_Body *body)
{
if (!body)
{
ERR("Can't get soft body's anchor hardness, body is null.");
return -1;
}
if (!body->soft_body)
{
ERR("Can't get soft body's anchor hardness, body seems not to be a soft"
" body.");
return -1;
}
return body->soft_body->m_cfg.kAHR * 100;
}
static void
_ephysics_body_soft_body_hardness_set(EPhysics_Body *body, double hardness)
{
int m = body->material_index;
btSoftBody *soft_body = body->soft_body;
if (body->type == EPHYSICS_BODY_TYPE_CLOTH)
soft_body->m_cfg.kAHR = 0.8;
else
soft_body->m_cfg.kAHR = (hardness / 1000) * 0.6;
if (!body->anchor_hardness)
{
if (body->type == EPHYSICS_BODY_TYPE_CLOTH)
soft_body->m_cfg.kAHR = 0.8;
else
soft_body->m_cfg.kAHR = (hardness / 1000) * 0.6;
}
soft_body->m_materials[m]->m_kVST = (hardness / 1000);
soft_body->m_materials[m]->m_kLST = (hardness / 1000);
soft_body->m_materials[m]->m_kAST = (hardness / 1000);
DBG("Soft body %p hardness set to %lf.", body, hardness);
}
@ -2365,7 +2418,7 @@ _ephysics_body_soft_body_triangle_impulse_apply(EPhysics_Body *body, int idx, do
for (int i = 0; i < 3; i++)
{
node = face.m_n[i];
node->m_v += impulse * node->m_im;
node->m_v = impulse * node->m_im;
}
DBG("Impulse applied to soft body node(%d): %lf, %lf, %lf", idx, impulse.x(),
@ -2574,6 +2627,8 @@ ephysics_body_soft_ellipsoid_add(EPhysics_World *world, int granularity)
if (!body)
goto no_body;
body->soft_body->setPose(false, true);
front_face = _ephysics_body_soft_ellipsoid_face_slices_add(body,
EPHYSICS_BODY_SOFT_ELLIPSOID_FACE_FRONT, center);
if (!front_face)

View File

@ -161,6 +161,7 @@ struct _EPhysics_Body {
Eina_Bool clockwise:1;
Eina_Bool boundary:1;
int bending_constraints;
Eina_Bool anchor_hardness;
};
extern int _ephysics_log_dom;