add

fun add(shape: SoftBodyShape, centerX: Float, baseY: Float, tuning: SoftBodyTuning = SoftBodyTuning(), particleMass: Float = 1.0f, material: Material = Material.DEFAULT): SoftBody(source)

Adds a body of shape with its middle at centerX and its bottom on baseY, at rest, and returns its handle. Each ring particle weighs particleMass; the core is SoftBodyShape.coreMass times that. Pass the arguments after baseY by name.

Throws

if particleMass is not more than 0, centerX or baseY is not finite, or any placed edge or spoke has length not finite and more than 0.

Samples

val world = PhysicsWorld()
// A floor of 16-unit tiles along row 9, its top at y = 144.
val grid = SolidGrid(columns = 20, rows = 10, tileSize = 16f)
for (column in 0 until 20) grid.fill(column, 9)
world.solids = grid
val slime = world.softBody(SoftBodyShape.semiDisc(13f, 14, 8, coreMass = 34f), centerX = 160f, baseY = 100f)

repeat(120) { world.step(1.seconds / 60) }

// It fell onto the floor and sits on it, its bottom at the floor's top.
assertTrue(world.softBodies.maxYOf(slime) in 140f..146f)
assertPrints(world.softBodies.isOnFloor(slime), "true")
assertPrints(world.softBodies.particlesOf(slime).size, "23")