Grab

class Grab(source)

A hand in the world, like a mouse's: it takes hold of one thing at a time and pulls it towards a point with a soft pin. That's a particle, or a rigid body by the point of it that was grabbed, so a crate picked up by its corner hangs from that corner. Use it through PhysicsWorld.grab, PhysicsWorld.moveGrab and PhysicsWorld.release.

However far the point jumps, the pin never pulls from further than maxPull away: at the start of every step its target is put back within maxPull of what it holds. So a mouse flung across the screen in one frame drags a body along quickly, but never yanks one particle out of it.

toString gives what it holds and where the hand is, for example Grab(particle=Particle(4), target=(120.0, 80.0)).

Samples

val world = PhysicsWorld()
val crate = world.rigidBody(Shape.box(20f, 20f), x = 100f, y = 100f)

// Take the crate by its corner and drag it to the right.
world.grab(108f, 92f)
assertPrints(world.hand.bodyOrNull == crate, "true")
repeat(30) {
    world.moveGrab(200f, 92f)
    world.step(1.seconds / 60)
}
assertTrue(world.rigidBodies.xOf(crate) > 150f)

world.release()
assertPrints(world.hand.isHolding, "false")

Types

Link copied to clipboard
object Companion

Holds the hand's defaults.

Properties

Link copied to clipboard

The rigid body held, or null when the hand holds no body.

Link copied to clipboard

Where the point held is in the world: the particle, or the grabbed point of the body.

Link copied to clipboard

Where the point held is in the world, down: see heldX.

Link copied to clipboard

Whether the hand holds something: a particle or a body.

Link copied to clipboard

Furthest from the point held that the pin pulls from, in world units, more than 0.

Link copied to clipboard

The particle held, or null when the hand holds no particle.

Link copied to clipboard

Where the hand is: the point the particle is pulled towards.

Link copied to clipboard

Where the hand is, down: see targetX.

Functions

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