Particles

Every particle in a PhysicsWorld, as parallel arrays that a Particle handle indexes. A removed particle's slot is handed out again by the next add, so hold on to handles only while their particles are alive.

Velocity is implicit, as in Verlet integration: the difference between where a particle is and where it was a substep ago. That's why the velocity setters move the previous position.

The arrays grow by doubling when a particle is added, never during a step.

toString gives how many particles are alive, for example Particles(size=120).

Types

Link copied to clipboard
object Companion

Holds the mass of a particle nothing moves.

Properties

Link copied to clipboard
val size: Int

Number of particles alive.

Functions

Link copied to clipboard
fun add(x: Float, y: Float, mass: Float = 1.0f, radius: Float = 0.0f, bodyCollision: BodyCollision = BodyCollision.PASS, material: Material = Material.DEFAULT): Particle

Adds a particle at (x, y) at rest and returns its handle.

Link copied to clipboard

Returns whether particle collides with bodies and other particles: see add.

Link copied to clipboard
fun clear()

Removes every particle and everything that holds them. Slots start from 0 again.

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

Calls action with every particle alive, in slot order. action may remove the particle it is given, but must not add any.

Link copied to clipboard
fun inverseMassOf(particle: Particle): Float

Returns one over particle's mass: 0 for a STATIC particle.

Link copied to clipboard
fun isAlive(particle: Particle): Boolean

Returns true if particle is still in the world.

Link copied to clipboard

Returns the layers particle is on: see setLayers.

Link copied to clipboard

Returns the layers particle collides with: see setLayers.

Link copied to clipboard
fun motionOf(particle: Particle): Motion

Returns how particle moves: see setMotion.

Link copied to clipboard
fun movedXOf(particle: Particle): Float

Returns how far particle moved across in the last substep: its velocity per substep.

Link copied to clipboard
fun movedYOf(particle: Particle): Float

Returns how far particle moved down in the last substep: its velocity per substep.

Link copied to clipboard
fun moveTo(particle: Particle, x: Float, y: Float)

Moves particle to (x, y) and keeps its velocity.

Link copied to clipboard
fun radiusOf(particle: Particle): Float

Returns how far particle keeps out of things: 0 for a point.

Link copied to clipboard
fun remove(particle: Particle)

Removes particle and every constraint that holds it, so that the particle that takes its slot, which may be handed out again, inherits none. Removing a particle that is gone does nothing. A particle of a soft body is removed with it instead, by SoftBodies.remove.

Link copied to clipboard
fun setLayers(particle: Particle, layers: CollisionLayers, mask: CollisionLayers)

Puts particle on layers and has it collide with what is on a layer of mask and holds a layer of particle's in its own mask; see PhysicsLayers. The layers say nothing about the solids: see setSolidCollision. For a soft body's particles, set the whole body's with SoftBodies.setLayers.

Link copied to clipboard
fun setMaterial(particle: Particle, material: Material)

Makes particle grip and bounce like material.

Link copied to clipboard
fun setMotion(particle: Particle, motion: Motion)

Sets how particle moves. A Motion.BULLET is not held to PhysicsConfig.maxStep a substep: it goes as fast as it is thrown, and every substep it is swept from where it was to where it went and stopped where it first meets a solid, so it cannot pass through a thin one.

Link copied to clipboard
fun setSolidCollision(particle: Particle, solidCollision: SolidCollision)

Sets whether particle is kept out of the solids, the SolidGrid and its moving solids. It is SolidCollision.COLLIDE by default; a SolidCollision.PASS particle falls through the level. For a soft body's particles, set the whole body's with SoftBodies.setSolidCollision.

Link copied to clipboard

Returns whether particle is kept out of the solids: see setSolidCollision.

Link copied to clipboard
open override fun toString(): String
Link copied to clipboard
fun xOf(particle: Particle): Float

Returns where particle is, across.

Link copied to clipboard
fun yOf(particle: Particle): Float

Returns where particle is, down.