From: Leandro Dorileo Date: Fri, 23 Nov 2012 21:43:49 +0000 (+0000) Subject: EPhysics: add soft body triangle impulse API X-Git-Tag: submit/devel/efl/20131022.203902~3258 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=cf2d140f8c3ef2b91d55e653188a48c4d5640a66;p=platform%2Fupstream%2Fefl.git EPhysics: add soft body triangle impulse API Patch by: Leandro Dorileo SVN revision: 79594 --- diff --git a/legacy/ephysics/src/lib/EPhysics.h b/legacy/ephysics/src/lib/EPhysics.h index a9ac03d..49e3f80 100644 --- a/legacy/ephysics/src/lib/EPhysics.h +++ b/legacy/ephysics/src/lib/EPhysics.h @@ -2370,6 +2370,33 @@ EAPI int ephysics_body_soft_body_triangle_index_get(EPhysics_Body *body, Evas_Co /** * @brief + * Apply an impulse on a given soft body triangle. + * + * The impulse is equal to the change of momentum of the body. + * Impulse is the product of the force over the time this force is applied. In + * ephysics case, it would be the time of a tick, so it behaves just summing + * current linear velocity to impulse per mass(per triangle mass). + * + * When a impulse is applied over a body, it will have its velocity changed. This + * impulse will be applied on body's specified triangle @p idx, so it won't + * imply in rotating the body. + * + * @note Impulse is measured in kg * p / s. + * + * @param body The body to apply impulse to. + * @param idx The soft body triangle index. + * @param x The axis @p x component of impulse. + * @param y The axis @p y component of impulse + * @param z The axis @p z component of impulse + * + * @see ephysics_body_soft_body_triangle_index_get(). + * + * @ingroup EPhysics_Body + */ +EAPI void ephysics_body_soft_body_triangle_impulse_apply(EPhysics_Body * body, int idx, double x, double y, double z); + +/** + * @brief * Set the soft body number of position iterations. * * Both soft body and cloth can have its number of position iterations changed. diff --git a/legacy/ephysics/src/lib/ephysics_body.cpp b/legacy/ephysics/src/lib/ephysics_body.cpp index 5cc5f6f..4dd6cd8 100644 --- a/legacy/ephysics/src/lib/ephysics_body.cpp +++ b/legacy/ephysics/src/lib/ephysics_body.cpp @@ -2078,6 +2078,41 @@ ephysics_body_soft_body_triangle_move(EPhysics_Body *body, int idx, Evas_Coord x ephysics_world_lock_release(body->world); } +EAPI void +ephysics_body_soft_body_triangle_impulse_apply(EPhysics_Body * body, int idx, double x, double y, double z) +{ + btSoftBody::Face face; + btSoftBody::Node *node; + double rate; + btVector3 impulse; + + if (body->type == EPHYSICS_BODY_TYPE_RIGID) + { + ERR("Can't apply impulse, operation not permited to rigid bodies."); + return; + } + + if (idx < 0 || idx >= body->soft_body->m_faces.size()) + { + ERR("Could not apply impulse, provided body triangle index ranges from" + " 0 to %d", body->soft_body->m_faces.size()); + return; + } + + rate = ephysics_world_rate_get(body->world); + impulse = btVector3(x / rate, y / rate, z / rate); + + ephysics_world_lock_take(body->world); + + face = body->soft_body->m_faces[idx]; + node = face.m_n[0]; + node->m_f += impulse * node->m_im; + + ephysics_world_lock_release(body->world); + DBG("Impulse applied to soft body node(%d): %lf, %lf, %lf", idx, impulse.x(), + impulse.y(), impulse.z()); +} + EAPI int ephysics_body_soft_body_triangle_index_get(EPhysics_Body *body, Evas_Coord x, Evas_Coord y) {