summaryrefslogtreecommitdiff
path: root/legacy/ephysics/src/lib/ephysics_body.cpp
diff options
context:
space:
mode:
authorLeandro Dorileo <dorileo@profusion.mobi>2012-11-23 21:52:08 +0000
committerBruno Dilly <bdilly@profusion.mobi>2012-11-23 21:52:08 +0000
commit1a1adc1a5fd0ff1b8c289da72a685692af5d1874 (patch)
treef8abc514a00fb25ef2cd7b5440945af8a6a0f02f /legacy/ephysics/src/lib/ephysics_body.cpp
parent889ba8d30705a22fd15aa23a5a5f87ce9fc3455a (diff)
EPhysics: soft body operations on triangles list
This patch introduces API to get a list of triangles inside an area and another to apply impulse - also - in a list of triangles. Patch by: Leandro Dorileo <dorileo@profusion.mobi> SVN revision: 79607
Diffstat (limited to '')
-rw-r--r--legacy/ephysics/src/lib/ephysics_body.cpp118
1 files changed, 108 insertions, 10 deletions
diff --git a/legacy/ephysics/src/lib/ephysics_body.cpp b/legacy/ephysics/src/lib/ephysics_body.cpp
index 1869a3b9bd..a636dc43cd 100644
--- a/legacy/ephysics/src/lib/ephysics_body.cpp
+++ b/legacy/ephysics/src/lib/ephysics_body.cpp
@@ -2290,14 +2290,90 @@ ephysics_body_soft_body_triangle_move(EPhysics_Body *body, int idx, Evas_Coord x
2290 ephysics_world_lock_release(body->world); 2290 ephysics_world_lock_release(body->world);
2291} 2291}
2292 2292
2293EAPI void 2293EAPI Eina_List *
2294ephysics_body_soft_body_triangle_impulse_apply(EPhysics_Body * body, int idx, double x, double y, double z) 2294ephysics_body_soft_body_triangles_inside_get(const EPhysics_Body *body, Evas_Coord x, Evas_Coord y, Evas_Coord z, Evas_Coord w, Evas_Coord h, Evas_Coord d)
2295{
2296 Eina_List *face_list = NULL;
2297 btSoftBody::Face *bt_face;
2298 btSoftBody::Node *node;
2299 int out, *idx;
2300 btScalar nx, ny, nz, xx, yy, zz, dd, ww, hh;
2301 Evas_Coord wy, wh;
2302 double rate;
2303
2304 if (body->type == EPHYSICS_BODY_TYPE_RIGID)
2305 {
2306 ERR("Can't get triangle indexes, operation not permited to rigid"
2307 " bodies.");
2308 return NULL;
2309 }
2310
2311 ephysics_world_lock_take(body->world);
2312 rate = ephysics_world_rate_get(body->world);
2313 ephysics_world_render_geometry_get(body->world, NULL, &wy, NULL, NULL, &wh,
2314 NULL);
2315 xx = x / rate;
2316 yy = ((wh + wy) - y) / rate;
2317 zz = z / rate;
2318 dd = d / rate;
2319 ww = w / rate;
2320 hh = h / rate;
2321
2322 for (int m = 0; m < body->soft_body->m_faces.size(); m++)
2323 {
2324 out = 0;
2325 bt_face = &body->soft_body->m_faces[m];
2326 for (int n = 0; n < 3; n++)
2327 {
2328 node = bt_face->m_n[n];
2329 nx = node->m_x.x();
2330 ny = node->m_x.y();
2331 nz = node->m_x.z();
2332
2333 if ((nz > zz || nz < dd) || (nx < xx || nx > xx + ww) ||
2334 (ny > yy || ny < ny - hh))
2335 out++;
2336 }
2337
2338 if (!out)
2339 {
2340 idx = (int *)malloc(sizeof(int));
2341 *idx = m;
2342 face_list = eina_list_append(face_list, idx);
2343 }
2344 }
2345
2346 ephysics_world_lock_release(body->world);
2347
2348 return face_list;
2349}
2350
2351static void
2352_ephysics_body_soft_body_triangle_impulse_apply(EPhysics_Body *body, int idx, double x, double y, double z)
2295{ 2353{
2296 btSoftBody::Face face; 2354 btSoftBody::Face face;
2297 btSoftBody::Node *node; 2355 btSoftBody::Node *node;
2298 double rate; 2356 double rate;
2299 btVector3 impulse; 2357 btVector3 impulse;
2300 2358
2359 rate = ephysics_world_rate_get(body->world);
2360 impulse = btVector3(x / rate, y / rate, z / rate);
2361
2362 face = body->soft_body->m_faces[idx];
2363 for (int i = 0; i < 3; i++)
2364 {
2365 node = face.m_n[i];
2366 node->m_v += impulse * node->m_im;
2367 }
2368
2369 DBG("Impulse applied to soft body node(%d): %lf, %lf, %lf", idx, impulse.x(),
2370 impulse.y(), impulse.z());
2371}
2372
2373EAPI void
2374ephysics_body_soft_body_triangle_impulse_apply(EPhysics_Body * body, int idx, double x, double y, double z)
2375{
2376
2301 if (body->type == EPHYSICS_BODY_TYPE_RIGID) 2377 if (body->type == EPHYSICS_BODY_TYPE_RIGID)
2302 { 2378 {
2303 ERR("Can't apply impulse, operation not permited to rigid bodies."); 2379 ERR("Can't apply impulse, operation not permited to rigid bodies.");
@@ -2311,18 +2387,40 @@ ephysics_body_soft_body_triangle_impulse_apply(EPhysics_Body * body, int idx, do
2311 return; 2387 return;
2312 } 2388 }
2313 2389
2314 rate = ephysics_world_rate_get(body->world);
2315 impulse = btVector3(x / rate, y / rate, z / rate);
2316
2317 ephysics_world_lock_take(body->world); 2390 ephysics_world_lock_take(body->world);
2391 _ephysics_body_soft_body_triangle_impulse_apply(body, idx, x, y, z);
2392 ephysics_world_lock_release(body->world);
2393}
2318 2394
2319 face = body->soft_body->m_faces[idx]; 2395EAPI void
2320 node = face.m_n[0]; 2396ephysics_body_soft_body_triangle_list_impulse_apply(EPhysics_Body *body, Eina_List *triangles, double x, double y, double z)
2321 node->m_f += impulse * node->m_im; 2397{
2398 Eina_List *l;
2399 void *ldata;
2400 int idx, faces_cnt;
2322 2401
2402 if (body->type == EPHYSICS_BODY_TYPE_RIGID)
2403 {
2404 ERR("Can't apply impulse, operation not permited to rigid bodies.");
2405 return;
2406 }
2407
2408 faces_cnt = body->soft_body->m_faces.size();
2409 ephysics_world_lock_take(body->world);
2410 EINA_LIST_FOREACH(triangles, l, ldata)
2411 {
2412 idx = *(int *)ldata;
2413 if (idx < 0 || idx >= faces_cnt)
2414 {
2415 INF("Could not apply impulse to triangle %d, provided body"
2416 " triangle index ranges from 0 to %d", idx, faces_cnt);
2417 continue;
2418 }
2419
2420 _ephysics_body_soft_body_triangle_impulse_apply(body, idx, x, y, z);
2421 DBG("Applied impulse on body %p, triangle: %d", body, idx);
2422 }
2323 ephysics_world_lock_release(body->world); 2423 ephysics_world_lock_release(body->world);
2324 DBG("Impulse applied to soft body node(%d): %lf, %lf, %lf", idx, impulse.x(),
2325 impulse.y(), impulse.z());
2326} 2424}
2327 2425
2328EAPI int 2426EAPI int