soft_body_forces_and_impulses
Forces and impulses can be applied to a soft-body as a whole
(r3SoftBody_AddForce, r3SoftBody_ApplyImpulse),
or to one particular particle
(r3SoftBody_AddParticleForce, r3SoftBody_ApplyParticleImpulse).
A force added to the whole body is added to each of its free particles and is persistent, i.e., it keeps being applied
at each step until the forces are reset (r3SoftBody_ResetForces), exactly like the forces of
a rigid-body. An impulse applied to the whole body is a velocity change
applied to each of its free particles, so the body is kicked as a whole without being deformed. Note that the pinned
particles ignore both.
Two additional methods are provided for the effects which magnitude depends on the distance to a point: an impulse
applied within a radius
(r3SoftBody_ApplyImpulseAtPoint), and a
radial blast pushing the particles away from its center
(r3SoftBody_ApplyRadialImpulse). In both
cases the impulse is scaled linearly down to zero at the given radius. Like for the rigid-bodies,
the last boolean argument of all these methods ensures the soft-body is
awake before the force or the impulse is applied:
- Example 2D
- Example 3D
// The last argument set to 1 makes sure the soft-body is awake.
r2SoftBody_ResetForces(sheet, 1); // Reset the forces to zero.
r2SoftBody_AddForce(sheet, r2Vector(0.0, 1.0), 1); // Added to the force of each particle.
r2SoftBody_AddParticleForce(sheet, 3, r2Vector(0.0, 1.0), 1);
r2SoftBody_ApplyImpulse(sheet, r2Vector(0.0, 0.1), 1);
r2SoftBody_ApplyParticleImpulse(sheet, 3, r2Vector(0.0, 0.1), 1);
// An impulse on the particles within 0.5 of a point, scaled down with the distance.
r2SoftBody_ApplyImpulseAtPoint(sheet, r2Vector(0.0, 0.1), r2Vector(-3.0, 3.0), 0.5, 1);
// A blast pushing the particles away from a center.
r2SoftBody_ApplyRadialImpulse(sheet, r2Vector(-3.0, 3.0), 0.1, 1.0, 1);
// The last argument set to 1 makes sure the soft-body is awake.
r3SoftBody_ResetForces(cloth, 1); // Reset the forces to zero.
r3SoftBody_AddForce(cloth, r3Vector(0.0, 1.0, 0.0), 1); // Added to the force of each particle.
r3SoftBody_AddParticleForce(cloth, 3, r3Vector(0.0, 1.0, 0.0), 1);
r3SoftBody_ApplyImpulse(cloth, r3Vector(0.0, 0.1, 0.0), 1);
r3SoftBody_ApplyParticleImpulse(cloth, 3, r3Vector(0.0, 0.1, 0.0), 1);
// An impulse on the particles within 0.5 of a point, scaled down with the distance.
r3SoftBody_ApplyImpulseAtPoint(cloth, r3Vector(0.0, 0.1, 0.0), r3Vector(0.0, 2.0, 0.0), 0.5, 1);
// A blast pushing the particles away from a center.
r3SoftBody_ApplyRadialImpulse(cloth, r3Vector(0.0, 2.0, 0.0), 0.1, 1.0, 1);