summaryrefslogtreecommitdiff
path: root/legacy/ephysics
diff options
context:
space:
mode:
authorLeandro Dorileo <dorileo@profusion.mobi>2012-12-05 13:50:08 +0000
committerLeandro Dorileo <dorileo@profusion.mobi>2012-12-05 13:50:08 +0000
commitd435db293105f9319fc8865558bd0edac104d318 (patch)
treee07bfe6b86f8d9cabcbc2e6c64ae85efcfe3e256 /legacy/ephysics
parentac6cadd8dc2535478675f455baeb8807d44a9d96 (diff)
EPhysics: fix soft body velocity and stop implementation
+ velocity Handle cloth cases on velocity functions and consider both rigid and soft body whenever touching velocities + stoping a body. + activation Activate the body when setting angular velocity. --This line, and those below, will be ignored-- SVN revision: 80248
Diffstat (limited to 'legacy/ephysics')
-rw-r--r--legacy/ephysics/src/lib/EPhysics.h2
-rw-r--r--legacy/ephysics/src/lib/ephysics_body.cpp68
2 files changed, 63 insertions, 7 deletions
diff --git a/legacy/ephysics/src/lib/EPhysics.h b/legacy/ephysics/src/lib/EPhysics.h
index 1675fe3da4..5a3f9b124f 100644
--- a/legacy/ephysics/src/lib/EPhysics.h
+++ b/legacy/ephysics/src/lib/EPhysics.h
@@ -3282,6 +3282,8 @@ EAPI void ephysics_body_linear_velocity_set(EPhysics_Body *body, double x, doubl
3282 * @param z The linear velocity on axis z. 3282 * @param z The linear velocity on axis z.
3283 * 3283 *
3284 * @note EPhysics unit for linear velocity is Evas coordinates per second. 3284 * @note EPhysics unit for linear velocity is Evas coordinates per second.
3285 * @note For cloth bodies the returned value is a velocity average of nodes
3286 * velocities.
3285 * 3287 *
3286 * @see ephysics_body_linear_velocity_set(). 3288 * @see ephysics_body_linear_velocity_set().
3287 * @see ephysics_body_angular_velocity_get(). 3289 * @see ephysics_body_angular_velocity_get().
diff --git a/legacy/ephysics/src/lib/ephysics_body.cpp b/legacy/ephysics/src/lib/ephysics_body.cpp
index 27f60792b7..f6b63e8ecf 100644
--- a/legacy/ephysics/src/lib/ephysics_body.cpp
+++ b/legacy/ephysics/src/lib/ephysics_body.cpp
@@ -534,9 +534,17 @@ _ephysics_body_sleeping_threshold_set(EPhysics_Body *body, double linear_thresho
534static inline void 534static inline void
535_ephysics_body_linear_velocity_set(EPhysics_Body *body, double x, double y, double z, double rate) 535_ephysics_body_linear_velocity_set(EPhysics_Body *body, double x, double y, double z, double rate)
536{ 536{
537 btVector3 linear_velocity = btVector3(x / rate, -y / rate, z / rate);
538
537 ephysics_body_activate(body, EINA_TRUE); 539 ephysics_body_activate(body, EINA_TRUE);
538 body->rigid_body->setLinearVelocity(btVector3(x / rate, -y / rate, 540 if (body->rigid_body)
539 z / rate)); 541 body->rigid_body->setLinearVelocity(linear_velocity);
542
543 if (body->soft_body)
544 {
545 for (int i = 0; i < body->soft_body->m_nodes.size(); i++)
546 body->soft_body->m_nodes[i].m_v = linear_velocity;
547 }
540} 548}
541 549
542static void 550static void
@@ -3425,6 +3433,21 @@ ephysics_body_linear_velocity_set(EPhysics_Body *body, double x, double y, doubl
3425 DBG("Linear velocity of body %p set to (%lf, %lf, %lf).", body, x, y, z); 3433 DBG("Linear velocity of body %p set to (%lf, %lf, %lf).", body, x, y, z);
3426} 3434}
3427 3435
3436static void
3437_ephysics_body_soft_body_linear_velocity_get(const EPhysics_Body *body, double *x, double *y, double *z, double rate)
3438{
3439 btVector3 total_velocity = btVector3(0, 0, 0);
3440 int nodes_size = body->soft_body->m_nodes.size();
3441
3442 for (int i = 0; i < nodes_size; i++)
3443 total_velocity += body->soft_body->m_nodes[i].m_v;
3444
3445 total_velocity /= nodes_size;
3446 if (x) *x = total_velocity.getX() * rate;
3447 if (y) *y = -total_velocity.getY() * rate;
3448 if (z) *z = total_velocity.getZ() * rate;
3449}
3450
3428EAPI void 3451EAPI void
3429ephysics_body_linear_velocity_get(const EPhysics_Body *body, double *x, double *y, double *z) 3452ephysics_body_linear_velocity_get(const EPhysics_Body *body, double *x, double *y, double *z)
3430{ 3453{
@@ -3437,9 +3460,14 @@ ephysics_body_linear_velocity_get(const EPhysics_Body *body, double *x, double *
3437 } 3460 }
3438 3461
3439 rate = ephysics_world_rate_get(body->world); 3462 rate = ephysics_world_rate_get(body->world);
3440 if (x) *x = body->rigid_body->getLinearVelocity().getX() * rate; 3463 if (body->rigid_body)
3441 if (y) *y = -body->rigid_body->getLinearVelocity().getY() * rate; 3464 {
3442 if (z) *z = body->rigid_body->getLinearVelocity().getZ() * rate; 3465 if (x) *x = body->rigid_body->getLinearVelocity().getX() * rate;
3466 if (y) *y = -body->rigid_body->getLinearVelocity().getY() * rate;
3467 if (z) *z = body->rigid_body->getLinearVelocity().getZ() * rate;
3468 return;
3469 }
3470 _ephysics_body_soft_body_linear_velocity_get(body, x, y, z, rate);
3443} 3471}
3444 3472
3445EAPI void 3473EAPI void
@@ -3451,10 +3479,18 @@ ephysics_body_angular_velocity_set(EPhysics_Body *body, double x, double y, doub
3451 return; 3479 return;
3452 } 3480 }
3453 3481
3482 if (body->type == EPHYSICS_BODY_TYPE_CLOTH)
3483 {
3484 ERR("Can't set angular velocity, not implemented for cloth.");
3485 return;
3486 }
3487
3454 ephysics_world_lock_take(body->world); 3488 ephysics_world_lock_take(body->world);
3489 ephysics_body_activate(body, EINA_TRUE);
3455 body->rigid_body->setAngularVelocity(btVector3(-x / RAD_TO_DEG, 3490 body->rigid_body->setAngularVelocity(btVector3(-x / RAD_TO_DEG,
3456 -y / RAD_TO_DEG, 3491 -y / RAD_TO_DEG,
3457 -z/RAD_TO_DEG)); 3492 -z/RAD_TO_DEG));
3493
3458 DBG("Angular velocity of body %p set to (%lf, %lf, %lf).", body, x, y, z); 3494 DBG("Angular velocity of body %p set to (%lf, %lf, %lf).", body, x, y, z);
3459 ephysics_world_lock_release(body->world); 3495 ephysics_world_lock_release(body->world);
3460} 3496}
@@ -3468,6 +3504,12 @@ ephysics_body_angular_velocity_get(const EPhysics_Body *body, double *x, double
3468 return; 3504 return;
3469 } 3505 }
3470 3506
3507 if (body->type == EPHYSICS_BODY_TYPE_CLOTH)
3508 {
3509 ERR("Can't get angular velocity, not implemented for cloth.");
3510 return;
3511 }
3512
3471 if (x) *x = -body->rigid_body->getAngularVelocity().getX() * RAD_TO_DEG; 3513 if (x) *x = -body->rigid_body->getAngularVelocity().getX() * RAD_TO_DEG;
3472 if (y) *y = -body->rigid_body->getAngularVelocity().getY() * RAD_TO_DEG; 3514 if (y) *y = -body->rigid_body->getAngularVelocity().getY() * RAD_TO_DEG;
3473 if (z) *z = -body->rigid_body->getAngularVelocity().getZ() * RAD_TO_DEG; 3515 if (z) *z = -body->rigid_body->getAngularVelocity().getZ() * RAD_TO_DEG;
@@ -3518,8 +3560,20 @@ ephysics_body_stop(EPhysics_Body *body)
3518 } 3560 }
3519 3561
3520 ephysics_world_lock_take(body->world); 3562 ephysics_world_lock_take(body->world);
3521 body->rigid_body->setLinearVelocity(btVector3(0, 0, 0)); 3563 if (body->rigid_body)
3522 body->rigid_body->setAngularVelocity(btVector3(0, 0, 0)); 3564 {
3565 body->rigid_body->setLinearVelocity(btVector3(0, 0, 0));
3566 body->rigid_body->setAngularVelocity(btVector3(0, 0, 0));
3567 }
3568
3569 if (body->soft_body)
3570 {
3571 for (int i = 0; i < body->soft_body->m_nodes.size(); i++)
3572 {
3573 body->soft_body->m_nodes[i].m_v *= 0;
3574 body->soft_body->m_nodes[i].m_f *= 0;
3575 }
3576 }
3523 ephysics_world_lock_release(body->world); 3577 ephysics_world_lock_release(body->world);
3524 3578
3525 DBG("Body %p stopped", body); 3579 DBG("Body %p stopped", body);