soft_body_sets
The soft-bodies are owned by the world, next to the rigid-bodies and the colliders, and are identified by their
R3SoftBodyHandle. There is no separate set to manage: r3InsertSoftBody creates the soft-body as well as the
rigid-body standing for it and the colliders of its surface, and r3FreeWorld frees all of them. The number of
soft-bodies of the world is given by r3SoftBodyCount, and their handles by r3SoftBodyHandles. A handle becomes
invalid once its soft-body is removed, which is checked by r3SoftBody_Contains. Conversely, the soft-body a
rigid-body stands for (its root body, or the proxy of one of its
clusters) is given by r3RigidBody_SoftBody, which returns an invalid handle for any
other rigid-body:
- Example 2D
- Example 3D
// The world owns every soft-body: their number and their handles can be read at any time.
R2SoftBodyDesc rope_desc = r2RopeSoftBodyDesc(r2Vector(0.0, 3.0), r2Vector(2.0, 3.0), 20);
R2SoftBodyHandle rope_handle = r2InsertSoftBody(world, &rope_desc);
size_t num_soft_bodies = r2SoftBodyCount(world);
R2SoftBodyHandle *soft_bodies = malloc(num_soft_bodies * sizeof(R2SoftBodyHandle));
r2SoftBodyHandles(world, soft_bodies, num_soft_bodies);
for (size_t i = 0; i < num_soft_bodies; i++) {
printf("Soft-body %u has %zu particles.\n", soft_bodies[i].index,
r2SoftBody_NumParticles(soft_bodies[i]));
}
free(soft_bodies);
// Whether a handle still refers to a soft-body of the world.
assert(r2SoftBody_Contains(rope_handle));
// The soft-body a rigid-body stands for (its root body, or the proxy of one of its clusters).
R2SoftBodyHandle owner = r2RigidBody_SoftBody(r2SoftBody_RootBody(rope_handle));
assert(owner.index == rope_handle.index && owner.generation == rope_handle.generation);
// The world owns every soft-body: their number and their handles can be read at any time.
R3SoftBodyDesc rope_desc = r3RopeSoftBodyDesc(r3Vector(0.0, 3.0, 0.0), r3Vector(2.0, 3.0, 0.0), 20);
R3SoftBodyHandle rope_handle = r3InsertSoftBody(world, &rope_desc);
size_t num_soft_bodies = r3SoftBodyCount(world);
R3SoftBodyHandle *soft_bodies = malloc(num_soft_bodies * sizeof(R3SoftBodyHandle));
r3SoftBodyHandles(world, soft_bodies, num_soft_bodies);
for (size_t i = 0; i < num_soft_bodies; i++) {
printf("Soft-body %u has %zu particles.\n", soft_bodies[i].index,
r3SoftBody_NumParticles(soft_bodies[i]));
}
free(soft_bodies);
// Whether a handle still refers to a soft-body of the world.
assert(r3SoftBody_Contains(rope_handle));
// The soft-body a rigid-body stands for (its root body, or the proxy of one of its clusters).
R3SoftBodyHandle owner = r3RigidBody_SoftBody(r3SoftBody_RootBody(rope_handle));
assert(owner.index == rope_handle.index && owner.generation == rope_handle.generation);
The state of the body as a whole can be read at any time as well: its number of particles (r3SoftBody_NumParticles),
its total mass (r3SoftBody_Mass), its mass-weighted center of mass (r3SoftBody_CenterOfMass), the area (2D) or the
volume (3D) it currently encloses and its rest value (r3SoftBody_Volume, r3SoftBody_RestVolume), and whether it is
sleeping (r3SoftBody_IsSleeping, see also r3SoftBody_WakeUp). Finally, a soft-body can be disabled until it is
enabled again with r3SoftBody_SetEnabled.