aboutsummaryrefslogtreecommitdiffstats
path: root/legacy/ephysics/src/lib
diff options
context:
space:
mode:
authorLeandro Dorileo <dorileo@profusion.mobi>2012-12-03 21:29:30 +0000
committerLeandro Dorileo <dorileo@profusion.mobi>2012-12-03 21:29:30 +0000
commitd449396bed3023de121a581397cc21ea0481e4e5 (patch)
treeb7b7cbaf50eb9b0d6780a022ac267b2c6d2cf2e6 /legacy/ephysics/src/lib
parentff57aea85321f9ec6411dcb5228162cf3801b51d (diff)
downloadefl-d449396bed3023de121a581397cc21ea0481e4e5.tar.gz
efl-d449396bed3023de121a581397cc21ea0481e4e5.tar.xz
efl-d449396bed3023de121a581397cc21ea0481e4e5.zip
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
Diffstat (limited to 'legacy/ephysics/src/lib')
-rw-r--r--legacy/ephysics/src/lib/EPhysics.h40
-rw-r--r--legacy/ephysics/src/lib/ephysics_body.cpp65
-rw-r--r--legacy/ephysics/src/lib/ephysics_private.h1
3 files changed, 101 insertions, 5 deletions
diff --git a/legacy/ephysics/src/lib/EPhysics.h b/legacy/ephysics/src/lib/EPhysics.h
index affac90c1..1675fe3da 100644
--- a/legacy/ephysics/src/lib/EPhysics.h
+++ b/legacy/ephysics/src/lib/EPhysics.h
@@ -2332,6 +2332,46 @@ 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.
*
* While dragging a soft body the user may want to freeze a specific trimesh
diff --git a/legacy/ephysics/src/lib/ephysics_body.cpp b/legacy/ephysics/src/lib/ephysics_body.cpp
index d85c52156..27f60792b 100644
--- a/legacy/ephysics/src/lib/ephysics_body.cpp
+++ b/legacy/ephysics/src/lib/ephysics_body.cpp
@@ -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)
diff --git a/legacy/ephysics/src/lib/ephysics_private.h b/legacy/ephysics/src/lib/ephysics_private.h
index 0b96a6c92..4acb00207 100644
--- a/legacy/ephysics/src/lib/ephysics_private.h
+++ b/legacy/ephysics/src/lib/ephysics_private.h
@@ -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;