Attachments

Particles held to points on rigid bodies: a rope tied to a crate, a blob glued to a wheel. Each one pulls its particle and the point of its body together, the XPBD way, as softly as its compliance says, so the particle is dragged along by the body and the body is tugged by the particle, moving and turning it. 0 is a firm hold. Each is an Attachment handle; a removed one's slot is reused, and removing its particle or body removes the attachment.

toString gives how many there are, for example Attachments(size=2).

Samples

val world = PhysicsWorld()
val crate = world.rigidBody(Shape.box(20f, 20f), x = 100f, y = 0f)
val rope = world.rope(fromX = 0f, fromY = 0f, toX = 90f, toY = 0f, segments = 9)
// Ties the rope's free end to the crate's left face: the crate swings on the rope.
val knot = world.attach(rope.last, crate)
repeat(60) { world.step(1.seconds / 60) }
assertPrints(world.attachments.bodyOf(knot) == crate, "true")
assertTrue(world.rigidBodies.yOf(crate) > 20f)

Properties

Link copied to clipboard
val size: Int

Number of attachments.

Functions

Link copied to clipboard
fun attach(particle: Particle, body: RigidBody, compliance: Float = 0.0f): Attachment

Holds particle to body at the point where the particle is now, as softly as compliance, and returns the attachment's handle.

Link copied to clipboard
fun bodyOf(attachment: Attachment): RigidBody

Returns the rigid body attachment ties its particle to.

Link copied to clipboard
inline fun forEach(action: (Attachment) -> Unit)

Calls action with every attachment, in slot order. action may remove the one it is given.

Link copied to clipboard
fun isAlive(attachment: Attachment): Boolean

Returns true if attachment is still there.

Link copied to clipboard
fun particleOf(attachment: Attachment): Particle

Returns the particle attachment holds.

Link copied to clipboard
fun pointXOf(attachment: Attachment): Float

Returns where attachment holds its particle, the point on its body, in the world now, across.

Link copied to clipboard
fun pointYOf(attachment: Attachment): Float

Returns where attachment holds its particle in the world now, down.

Link copied to clipboard
fun remove(attachment: Attachment)

Lets go: attachment no longer holds its particle. Removing one that is gone does nothing.

Link copied to clipboard
open override fun toString(): String