/**
* @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.
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)
{