rope

fun PhysicsWorld.rope(fromX: Float, fromY: Float, toX: Float, toY: Float, segments: Int, mass: Float = 1.0f, compliance: Float = 0.0f, bendCompliance: Float = Float.NaN, pinned: PinnedEnds = PinnedEnds.START, tearAt: Float = 0.0f, radius: Float = 0.0f, bodyCollision: BodyCollision = BodyCollision.PASS, material: Material = Material.DEFAULT): Strand(source)

Adds a rope from (fromX, fromY) to (toX, toY), cut into segments links, and returns it.

It has segments + 1 particles of mass, held by rope constraints that pull but go slack when pushed. With a bendCompliance it also resists folding (see Constraints.bend); without, it folds anywhere. pinned says which ends are static, so it hangs from there. A link stretched past tearAt times its rest length breaks (0, the default, never). Its particles are as round as radius, and collide as bodyCollision says. Pass the arguments after the ends by name.

Throws

if segments is less than 1, either end is not finite, the two ends are the same point, any segment has length not finite and more than 0, mass is not more than 0, radius is negative, compliance or a non-NaN bendCompliance is negative or not finite, or tearAt is neither 0 nor more than 1.

Samples

val world = PhysicsWorld()
val rope = world.rope(fromX = 0f, fromY = 0f, toX = 100f, toY = 0f, segments = 10)
assertPrints(rope, "Strand(particles=11, links=10, bends=0)")
// Its start is pinned where it was made; the rest falls and hangs.
assertPrints(world.particles.inverseMassOf(rope.first), "0.0")
assertPrints(rope.restLength(world), "100.0")