summaryrefslogtreecommitdiff
path: root/legacy/ephysics
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
parentd56bd9c189357d117fea631a5dc4e7465ea8fdfa (diff)
EPhysics: fix issues with resizing cloth
--This line, and those below, will be ignored-- SVN revision: 80614
Diffstat (limited to 'legacy/ephysics')
-rw-r--r--legacy/ephysics/src/bin/test_flag.c3
-rw-r--r--legacy/ephysics/src/lib/ephysics_body.cpp71
2 files changed, 45 insertions, 29 deletions
diff --git a/legacy/ephysics/src/bin/test_flag.c b/legacy/ephysics/src/bin/test_flag.c
index 33e431c4f2..d87c05d5da 100644
--- a/legacy/ephysics/src/bin/test_flag.c
+++ b/legacy/ephysics/src/bin/test_flag.c
@@ -105,7 +105,6 @@ _world_populate(Test_Data *test_data)
105 elm_image_file_set( 105 elm_image_file_set(
106 evas_obj, PACKAGE_DATA_DIR "/" EPHYSICS_TEST_THEME ".edj", "green-flag"); 106 evas_obj, PACKAGE_DATA_DIR "/" EPHYSICS_TEST_THEME ".edj", "green-flag");
107 evas_object_move(evas_obj, 150 + 12, FLOOR_Y - 280 + 14); 107 evas_object_move(evas_obj, 150 + 12, FLOOR_Y - 280 + 14);
108 evas_object_resize(evas_obj, 180, 126);
109 evas_object_show(evas_obj); 108 evas_object_show(evas_obj);
110 test_data->evas_objs = eina_list_append(test_data->evas_objs, evas_obj); 109 test_data->evas_objs = eina_list_append(test_data->evas_objs, evas_obj);
111 110
@@ -121,6 +120,8 @@ _world_populate(Test_Data *test_data)
121 ephysics_body_cloth_anchor_full_add(flag_body, pole_body, 120 ephysics_body_cloth_anchor_full_add(flag_body, pole_body,
122 EPHYSICS_BODY_CLOTH_ANCHOR_SIDE_LEFT); 121 EPHYSICS_BODY_CLOTH_ANCHOR_SIDE_LEFT);
123 122
123 evas_object_resize(evas_obj, 180, 126);
124
124 dragging->body = flag_body; 125 dragging->body = flag_body;
125 ephysics_body_data_set(flag_body, dragging); 126 ephysics_body_data_set(flag_body, dragging);
126 127
diff --git a/legacy/ephysics/src/lib/ephysics_body.cpp b/legacy/ephysics/src/lib/ephysics_body.cpp
index 608c259db5..7c3b3d2782 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 {
60}; 60};
61 61
62static void 62static void
63_ephysics_body_cloth_anchor_mass_reset(EPhysics_Body *body)
64{
65 double anchor_mass;
66 anchor_mass = 1 / (body->soft_body->m_nodes.size() * 0.025);
67
68 for (int i = 0; i < body->soft_body->m_anchors.size(); i++)
69 body->soft_body->m_anchors[i].m_node->m_im = anchor_mass;
70
71 DBG("Cloth anchors mass reset.");
72}
73
74static void
63_ephysics_body_soft_body_slices_apply(EPhysics_Body *body, Evas_Object *evas_obj, Eina_List *slices) 75_ephysics_body_soft_body_slices_apply(EPhysics_Body *body, Evas_Object *evas_obj, Eina_List *slices)
64{ 76{
65 double rate; 77 double rate;
@@ -994,10 +1006,13 @@ _ephysics_body_geometry_set(EPhysics_Body *body, Evas_Coord x, Evas_Coord y, Eva
994 } 1006 }
995 else if (body->type == EPHYSICS_BODY_TYPE_CLOTH) 1007 else if (body->type == EPHYSICS_BODY_TYPE_CLOTH)
996 { 1008 {
1009 body->soft_body->setTotalMass(body->mass, true);
997 body->soft_body->scale(btVector3(1, 1, 1) / body->scale); 1010 body->soft_body->scale(btVector3(1, 1, 1) / body->scale);
998 body->soft_body->scale(body_scale); 1011 body->soft_body->scale(body_scale);
999 _ephysics_body_transform_set(body, trans); 1012 _ephysics_body_transform_set(body, trans);
1000 _ephysics_body_cloth_constraints_rebuild(body); 1013 _ephysics_body_cloth_constraints_rebuild(body);
1014 body->soft_body->setTotalMass(body->mass, false);
1015 _ephysics_body_cloth_anchor_mass_reset(body);
1001 } 1016 }
1002 else 1017 else
1003 { 1018 {
@@ -1023,6 +1038,7 @@ _ephysics_body_geometry_set(EPhysics_Body *body, Evas_Coord x, Evas_Coord y, Eva
1023static void 1038static void
1024_ephysics_body_resize(EPhysics_Body *body, Evas_Coord w, Evas_Coord h, Evas_Coord d) 1039_ephysics_body_resize(EPhysics_Body *body, Evas_Coord w, Evas_Coord h, Evas_Coord d)
1025{ 1040{
1041 Evas_Coord bx, by, bz;
1026 double rate, sx, sy, sz; 1042 double rate, sx, sy, sz;
1027 btVector3 body_scale, center; 1043 btVector3 body_scale, center;
1028 btTransform trans; 1044 btTransform trans;
@@ -1032,6 +1048,8 @@ _ephysics_body_resize(EPhysics_Body *body, Evas_Coord w, Evas_Coord h, Evas_Coor
1032 sy = h / rate; 1048 sy = h / rate;
1033 sz = d / rate; 1049 sz = d / rate;
1034 1050
1051 DBG("Body %p scale changed to (%lf, %lf, %lf).", body, sx, sy, sz);
1052
1035 body_scale = btVector3(sx, sy, sz); 1053 body_scale = btVector3(sx, sy, sz);
1036 if (body->type == EPHYSICS_BODY_TYPE_SOFT) 1054 if (body->type == EPHYSICS_BODY_TYPE_SOFT)
1037 { 1055 {
@@ -1047,9 +1065,9 @@ _ephysics_body_resize(EPhysics_Body *body, Evas_Coord w, Evas_Coord h, Evas_Coor
1047 } 1065 }
1048 else if (body->type == EPHYSICS_BODY_TYPE_CLOTH) 1066 else if (body->type == EPHYSICS_BODY_TYPE_CLOTH)
1049 { 1067 {
1050 body->soft_body->scale(btVector3(1, 1, 1) / body->scale); 1068 ephysics_body_geometry_get(body, &bx, &by, &bz, NULL, NULL, NULL);
1051 body->soft_body->scale(body_scale); 1069 _ephysics_body_geometry_set(body, bx, by, bz, w, h, d, rate);
1052 _ephysics_body_cloth_constraints_rebuild(body); 1070 return;
1053 } 1071 }
1054 else 1072 else
1055 { 1073 {
@@ -1065,8 +1083,6 @@ _ephysics_body_resize(EPhysics_Body *body, Evas_Coord w, Evas_Coord h, Evas_Coor
1065 body->scale = body_scale; 1083 body->scale = body_scale;
1066 1084
1067 ephysics_body_activate(body, EINA_TRUE); 1085 ephysics_body_activate(body, EINA_TRUE);
1068
1069 DBG("Body %p scale changed to (%lf, %lf, %lf).", body, sx, sy, sz);
1070} 1086}
1071 1087
1072static void 1088static void
@@ -1122,6 +1138,14 @@ _ephysics_body_evas_obj_resize_cb(void *data, Evas *e __UNUSED__, Evas_Object *o
1122 1138
1123 ephysics_world_lock_take(body->world); 1139 ephysics_world_lock_take(body->world);
1124 _ephysics_body_resize(body, w, h, body->size.d); 1140 _ephysics_body_resize(body, w, h, body->size.d);
1141
1142 if (body->type == EPHYSICS_BODY_TYPE_CLOTH)
1143 {
1144 _ephysics_body_soft_body_slices_clean(body->default_face->slices);
1145 _ephysics_body_soft_body_slices_init(body, body->evas_obj,
1146 body->default_face->slices);
1147 }
1148
1125 ephysics_world_lock_release(body->world); 1149 ephysics_world_lock_release(body->world);
1126} 1150}
1127 1151
@@ -2029,7 +2053,6 @@ ephysics_body_cloth_anchor_full_add(EPhysics_Body *body1, EPhysics_Body *body2,
2029{ 2053{
2030 int rows; 2054 int rows;
2031 int columns; 2055 int columns;
2032 double anchor_mass;
2033 2056
2034 if (!body1 || !body2) 2057 if (!body1 || !body2)
2035 { 2058 {
@@ -2052,48 +2075,38 @@ ephysics_body_cloth_anchor_full_add(EPhysics_Body *body1, EPhysics_Body *body2,
2052 2075
2053 rows = body1->cloth_rows + 1; 2076 rows = body1->cloth_rows + 1;
2054 columns = body1->cloth_columns + 1; 2077 columns = body1->cloth_columns + 1;
2055 anchor_mass = body1->soft_body->m_nodes.size() * 0.025;
2056 2078
2057 if (side == EPHYSICS_BODY_CLOTH_ANCHOR_SIDE_RIGHT) 2079 if (side == EPHYSICS_BODY_CLOTH_ANCHOR_SIDE_RIGHT)
2058 { 2080 {
2059 for (int i = 0; i < rows; i++) 2081 for (int i = 0; i < rows; i++)
2060 { 2082 body1->soft_body->appendAnchor(i, body2->rigid_body);
2061 body1->soft_body->setMass(i, anchor_mass); 2083 goto mass_reset;
2062 body1->soft_body->appendAnchor(i, body2->rigid_body);
2063 }
2064 return;
2065 } 2084 }
2066 2085
2067 if (side == EPHYSICS_BODY_CLOTH_ANCHOR_SIDE_LEFT) 2086 if (side == EPHYSICS_BODY_CLOTH_ANCHOR_SIDE_LEFT)
2068 { 2087 {
2069 for (int i = 1; i <= rows; i++) 2088 for (int i = 1; i <= rows; i++)
2070 { 2089 body1->soft_body->appendAnchor((rows * columns) - i,
2071 body1->soft_body->setMass((rows * columns) - i, anchor_mass); 2090 body2->rigid_body);
2072 body1->soft_body->appendAnchor((rows * columns) - i, 2091 goto mass_reset;
2073 body2->rigid_body);
2074 }
2075 return;
2076 } 2092 }
2077 2093
2078 if (side == EPHYSICS_BODY_CLOTH_ANCHOR_SIDE_BOTTOM) 2094 if (side == EPHYSICS_BODY_CLOTH_ANCHOR_SIDE_BOTTOM)
2079 { 2095 {
2080 for (int i = 0; i <= rows; i++) 2096 for (int i = 0; i <= rows; i++)
2081 { 2097 body1->soft_body->appendAnchor(i * rows, body2->rigid_body);
2082 body1->soft_body->setMass((i * rows), anchor_mass); 2098 goto mass_reset;
2083 body1->soft_body->appendAnchor(i * rows, body2->rigid_body);
2084 }
2085 return;
2086 } 2099 }
2087 2100
2088 if (side == EPHYSICS_BODY_CLOTH_ANCHOR_SIDE_TOP) 2101 if (side == EPHYSICS_BODY_CLOTH_ANCHOR_SIDE_TOP)
2089 { 2102 {
2090 for (int i = 0; i < columns; i++) 2103 for (int i = 0; i < columns; i++)
2091 { 2104 body1->soft_body->appendAnchor((rows - 1) + rows * i,
2092 body1->soft_body->setMass((rows - 1) + rows * i, anchor_mass); 2105 body2->rigid_body);
2093 body1->soft_body->appendAnchor((rows - 1) + rows * i,
2094 body2->rigid_body);
2095 }
2096 } 2106 }
2107
2108 mass_reset:
2109 _ephysics_body_cloth_anchor_mass_reset(body1);
2097} 2110}
2098 2111
2099EAPI void 2112EAPI void
@@ -2113,6 +2126,7 @@ ephysics_body_cloth_anchor_add(EPhysics_Body *body1, EPhysics_Body *body2, int n
2113 } 2126 }
2114 2127
2115 body1->soft_body->appendAnchor(node, body2->rigid_body); 2128 body1->soft_body->appendAnchor(node, body2->rigid_body);
2129 _ephysics_body_cloth_anchor_mass_reset(body1);
2116} 2130}
2117 2131
2118EAPI void 2132EAPI void
@@ -2131,6 +2145,7 @@ ephysics_body_cloth_anchor_del(EPhysics_Body *body)
2131 } 2145 }
2132 2146
2133 body->soft_body->m_anchors.resize(0); 2147 body->soft_body->m_anchors.resize(0);
2148 body->soft_body->setTotalMass(body->mass);
2134} 2149}
2135 2150
2136static Eina_List * 2151static Eina_List *