aboutsummaryrefslogtreecommitdiffstats
path: root/legacy/ephysics/src/lib
diff options
context:
space:
mode:
authorLeandro Dorileo <dorileo@profusion.mobi>2012-12-10 17:15:18 +0000
committerLeandro Dorileo <dorileo@profusion.mobi>2012-12-10 17:15:18 +0000
commit0941fad05f8bded47634e2c3917018e15f95bbf4 (patch)
treef640564e047cf7e15c696fce98b479dbf6d79279 /legacy/ephysics/src/lib
parentd56bd9c189357d117fea631a5dc4e7465ea8fdfa (diff)
downloadefl-0941fad05f8bded47634e2c3917018e15f95bbf4.tar.gz
efl-0941fad05f8bded47634e2c3917018e15f95bbf4.tar.xz
efl-0941fad05f8bded47634e2c3917018e15f95bbf4.zip
EPhysics: fix issues with resizing cloth
--This line, and those below, will be ignored-- SVN revision: 80614
Diffstat (limited to 'legacy/ephysics/src/lib')
-rw-r--r--legacy/ephysics/src/lib/ephysics_body.cpp71
1 files changed, 43 insertions, 28 deletions
diff --git a/legacy/ephysics/src/lib/ephysics_body.cpp b/legacy/ephysics/src/lib/ephysics_body.cpp
index 608c259db..7c3b3d278 100644
--- a/legacy/ephysics/src/lib/ephysics_body.cpp
+++ b/legacy/ephysics/src/lib/ephysics_body.cpp
@@ -60,6 +60,18 @@ struct _EPhysics_Body_Face_Obj {
};
static void
+_ephysics_body_cloth_anchor_mass_reset(EPhysics_Body *body)
+{
+ double anchor_mass;
+ anchor_mass = 1 / (body->soft_body->m_nodes.size() * 0.025);
+
+ for (int i = 0; i < body->soft_body->m_anchors.size(); i++)
+ body->soft_body->m_anchors[i].m_node->m_im = anchor_mass;
+
+ DBG("Cloth anchors mass reset.");
+}
+
+static void
_ephysics_body_soft_body_slices_apply(EPhysics_Body *body, Evas_Object *evas_obj, Eina_List *slices)
{
double rate;
@@ -994,10 +1006,13 @@ _ephysics_body_geometry_set(EPhysics_Body *body, Evas_Coord x, Evas_Coord y, Eva
}
else if (body->type == EPHYSICS_BODY_TYPE_CLOTH)
{
+ body->soft_body->setTotalMass(body->mass, true);
body->soft_body->scale(btVector3(1, 1, 1) / body->scale);
body->soft_body->scale(body_scale);
_ephysics_body_transform_set(body, trans);
_ephysics_body_cloth_constraints_rebuild(body);
+ body->soft_body->setTotalMass(body->mass, false);
+ _ephysics_body_cloth_anchor_mass_reset(body);
}
else
{
@@ -1023,6 +1038,7 @@ _ephysics_body_geometry_set(EPhysics_Body *body, Evas_Coord x, Evas_Coord y, Eva
static void
_ephysics_body_resize(EPhysics_Body *body, Evas_Coord w, Evas_Coord h, Evas_Coord d)
{
+ Evas_Coord bx, by, bz;
double rate, sx, sy, sz;
btVector3 body_scale, center;
btTransform trans;
@@ -1032,6 +1048,8 @@ _ephysics_body_resize(EPhysics_Body *body, Evas_Coord w, Evas_Coord h, Evas_Coor
sy = h / rate;
sz = d / rate;
+ DBG("Body %p scale changed to (%lf, %lf, %lf).", body, sx, sy, sz);
+
body_scale = btVector3(sx, sy, sz);
if (body->type == EPHYSICS_BODY_TYPE_SOFT)
{
@@ -1047,9 +1065,9 @@ _ephysics_body_resize(EPhysics_Body *body, Evas_Coord w, Evas_Coord h, Evas_Coor
}
else if (body->type == EPHYSICS_BODY_TYPE_CLOTH)
{
- body->soft_body->scale(btVector3(1, 1, 1) / body->scale);
- body->soft_body->scale(body_scale);
- _ephysics_body_cloth_constraints_rebuild(body);
+ ephysics_body_geometry_get(body, &bx, &by, &bz, NULL, NULL, NULL);
+ _ephysics_body_geometry_set(body, bx, by, bz, w, h, d, rate);
+ return;
}
else
{
@@ -1065,8 +1083,6 @@ _ephysics_body_resize(EPhysics_Body *body, Evas_Coord w, Evas_Coord h, Evas_Coor
body->scale = body_scale;
ephysics_body_activate(body, EINA_TRUE);
-
- DBG("Body %p scale changed to (%lf, %lf, %lf).", body, sx, sy, sz);
}
static void
@@ -1122,6 +1138,14 @@ _ephysics_body_evas_obj_resize_cb(void *data, Evas *e __UNUSED__, Evas_Object *o
ephysics_world_lock_take(body->world);
_ephysics_body_resize(body, w, h, body->size.d);
+
+ if (body->type == EPHYSICS_BODY_TYPE_CLOTH)
+ {
+ _ephysics_body_soft_body_slices_clean(body->default_face->slices);
+ _ephysics_body_soft_body_slices_init(body, body->evas_obj,
+ body->default_face->slices);
+ }
+
ephysics_world_lock_release(body->world);
}
@@ -2029,7 +2053,6 @@ ephysics_body_cloth_anchor_full_add(EPhysics_Body *body1, EPhysics_Body *body2,
{
int rows;
int columns;
- double anchor_mass;
if (!body1 || !body2)
{
@@ -2052,48 +2075,38 @@ ephysics_body_cloth_anchor_full_add(EPhysics_Body *body1, EPhysics_Body *body2,
rows = body1->cloth_rows + 1;
columns = body1->cloth_columns + 1;
- anchor_mass = body1->soft_body->m_nodes.size() * 0.025;
if (side == EPHYSICS_BODY_CLOTH_ANCHOR_SIDE_RIGHT)
{
for (int i = 0; i < rows; i++)
- {
- body1->soft_body->setMass(i, anchor_mass);
- body1->soft_body->appendAnchor(i, body2->rigid_body);
- }
- return;
+ body1->soft_body->appendAnchor(i, body2->rigid_body);
+ goto mass_reset;
}
if (side == EPHYSICS_BODY_CLOTH_ANCHOR_SIDE_LEFT)
{
for (int i = 1; i <= rows; i++)
- {
- body1->soft_body->setMass((rows * columns) - i, anchor_mass);
- body1->soft_body->appendAnchor((rows * columns) - i,
- body2->rigid_body);
- }
- return;
+ body1->soft_body->appendAnchor((rows * columns) - i,
+ body2->rigid_body);
+ goto mass_reset;
}
if (side == EPHYSICS_BODY_CLOTH_ANCHOR_SIDE_BOTTOM)
{
for (int i = 0; i <= rows; i++)
- {
- body1->soft_body->setMass((i * rows), anchor_mass);
- body1->soft_body->appendAnchor(i * rows, body2->rigid_body);
- }
- return;
+ body1->soft_body->appendAnchor(i * rows, body2->rigid_body);
+ goto mass_reset;
}
if (side == EPHYSICS_BODY_CLOTH_ANCHOR_SIDE_TOP)
{
for (int i = 0; i < columns; i++)
- {
- body1->soft_body->setMass((rows - 1) + rows * i, anchor_mass);
- body1->soft_body->appendAnchor((rows - 1) + rows * i,
- body2->rigid_body);
- }
+ body1->soft_body->appendAnchor((rows - 1) + rows * i,
+ body2->rigid_body);
}
+
+ mass_reset:
+ _ephysics_body_cloth_anchor_mass_reset(body1);
}
EAPI void
@@ -2113,6 +2126,7 @@ ephysics_body_cloth_anchor_add(EPhysics_Body *body1, EPhysics_Body *body2, int n
}
body1->soft_body->appendAnchor(node, body2->rigid_body);
+ _ephysics_body_cloth_anchor_mass_reset(body1);
}
EAPI void
@@ -2131,6 +2145,7 @@ ephysics_body_cloth_anchor_del(EPhysics_Body *body)
}
body->soft_body->m_anchors.resize(0);
+ body->soft_body->setTotalMass(body->mass);
}
static Eina_List *