Package-level declarations
Types
Identifies one area constraint, which keeps a ring of particles covering the same area, as returned by Constraints.area.
Identifies one attachment, which ties a particle to a point on a rigid body, as returned by PhysicsWorld.attach.
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.
Identifies one bend, which keeps the angle at the middle of three particles, as returned by Constraints.bend.
Whether a particle collides with bodies and other particles: see Particles.add.
A sheet made by PhysicsWorld.cloth: a grid of columns by rows particles, held by structural links along its rows and columns, shear links across each square, and bends along its rows and columns.
The rules that hold particles together, solved the XPBD way. Each one has a compliance: how far it gives per unit of force, in world units. 0 is rigid. Because each constraint also remembers how hard it has pushed this substep (its lambda), a compliance means the same softness however many substeps and iterations the world runs.
What a rigid body does to what it overlaps: see RigidBodies.setResponse.
Draws what the physics sees, in world space, on a klyph Canvas: soft bodies filled from their outlines, and the solids they collide with. Its view adds more, a level at a time: every particle and tile edge, then every constraint coloured by its stress, then every contact and its normal (see DebugView). showBroadphase adds the broadphase's cells on top. What isn't shown costs nothing.
What happened in the last PhysicsWorld.step.
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.
What a ray hit: see RayHit.kind.
Identifies one joint between rigid bodies, as returned by Joints.hinge, Joints.slider, Joints.weld and Joints.distance.
What the second end of a joint holds on to: another RigidBody, a Particle, or the world itself, JointEnd.WORLD, which never moves.
Identifies one distance constraint between two particles, a stick or a rope, as returned by Constraints.distance and Constraints.rope.
What a surface is like to touch: how much it grips and how much it bounces. Solids and particles each have one, and a contact mixes the two: grip by the geometric mean, so ice on anything slides, and bounce by the larger, so a rubber ball bounces on a stone floor. Pass the values by name.
How a particle or a rigid body moves each substep: see Particles.setMotion and RigidBodies.setMotion.
What a point or box query found, filled in by PhysicsWorld.queryPoint and PhysicsWorld.queryBox. Make one and keep it: it only allocates when it has to grow, the first few times.
Identifies one particle of a PhysicsWorld, as returned by Particles.add. Pass it to the world's stores, such as Particles.xOf and Constraints.distance.
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.
A PhysicsWorld run by a klyph app: App.addPhysics makes one and steps it every fixed step. After each step, every entity with a PhysicsBody and a Transform is moved to where its body is.
Links an entity to a body in the Physics' world: after each step its Transform is put where the body is, and turned as the body is. Make one with PhysicsBody.of, and add it as world.add(entity, PhysicsBody, PhysicsBody.of(box)).
How a PhysicsWorld moves time. Every value is in world units and seconds, so a world behaves the same however finely it is stepped, except where a value says otherwise. Pass the values by name.
How physics reads klyph's CollisionLayers. Everything that collides is on some layers and has a mask of the layers it collides with, and two things collide only when each one's mask holds a layer of the other, so either one can refuse the other. By default everything is on CollisionLayers.DEFAULT with the mask CollisionLayers.ALL, so everything collides with everything. All 32 layers are the game's own.
Everything that moves, and the one way to move time: step. The world owns its stores; bodies, particles and constraints are value-class handles into them, such as Particle and RigidBody, so a step touches plain arrays and allocates nothing. The same calls in the same order give the same results, to the bit.
Identifies one pin, which holds a particle at a point of the world, as returned by Constraints.pin.
Which ends of a rope or a chain are pinned where they start, so it hangs from them.
What a query looks at: RIGID_BODIES, SOFT_BODIES and SOLIDS, joined with plus, or EVERYTHING. Two are equal when they look at the same things.
Where a ray first hit something, filled in by PhysicsWorld.raycast. Make one and keep it, so a raycast allocates nothing.
Every rigid body in a PhysicsWorld, as parallel arrays that a RigidBody handle indexes: bodies that keep their shape and turn. A removed body's slot is handed out again by the next add.
Identifies one rigid body of a PhysicsWorld, as returned by PhysicsWorld.rigidBody. Pass it to RigidBodies, such as RigidBodies.xOf and RigidBodies.setVelocity, and to Joints.
A closed outline of points, in order, such as a soft body's skin: see SoftBodies.ringOf. It reads the points where they are now, so the same one serves every frame.
Whether a soft body's skin is kept from passing through itself: see SoftBodies.setSelfCollision.
The soft bodies in a PhysicsWorld. A SoftBody handle names a group of the world's particles, a ring and a core, held together by the world's constraints:
Identifies one soft body of a PhysicsWorld, as returned by PhysicsWorld.softBody. Pass it to SoftBodies, such as SoftBodies.centerXOf and SoftBodies.addVelocity.
The rest shape of a soft body: a ring of points in order, and a core inside it coreMass times heavier than a ring point. The coordinates are the shape's own, with y growing down; PhysicsWorld.softBody places it. Make one with semiDisc, circle or box.
How soft a body is. The compliances say how far each kind of constraint gives per unit of force (0 is rigid): the ring's edges, the spokes from the ring to the core, and the area. Soft spokes let a body stretch and squash, a soft area lets it sag and be squeezed, and stiff edges keep the skin from tearing. How fast it moves, how damped and how often it is solved is the world's PhysicsConfig. Pass the values by name.
Something a particle cannot enter: a rectangle with the given edges (y grows down) filled as shape says. A tile's solid knows its grid cell, so the grid can tell which faces are buried against a neighbour; a moving one has none. Make a tile's solid with SolidGrid.fill.
Whether a body or a particle is kept out of the level, the SolidGrid and its moving solids: see RigidBodies.setSolidCollision, SoftBodies.setSolidCollision and Particles.setSolidCollision.
A level's solids: at most one per cell of a grid of columns by rows cells, each tileSize wide, plus moving ones. Set it as PhysicsWorld.solids and every particle is pushed out of it: a point particle can only be inside the one tile it is in, so only that tile and the moving solids are checked; a round one checks the tiles its radius reaches.
How a Solid fills its rectangle: all of it, or the half under a diagonal surface.
A set of up to 32 tags a game gives its solids, such as "bounce pad" or "ice", one bit each. Events.floorTagsOf reports the tags of the floors a particle stood on.
A rope or a chain made by PhysicsWorld.rope or PhysicsWorld.chain: its particles in order from one end to the other, the links between neighbours, and the bends at every particle but the ends (empty when it has none). They are ordinary world particles and constraints; this just remembers which ones.
Properties
The Physics that addPhysics added to this app, or null if it has not been called.
Functions
Runs world in this app and returns its Physics: steps it in Phase.FIXED_UPDATE by the fixed step, unless paused, then moves every entity with a PhysicsBody and a Transform to its body. The Physics is also kept as a resource: physics finds it again.
Holds particle to body at the point where the particle is now, as softly as compliance, so each drags the other, as a rope tied to a crate does. Returns the handle in PhysicsWorld.attachments.
Returns how many particles of body stood on a floor during the last step.
Returns the tags of every floor a particle of body stood on during the last step, together; SolidTags.NONE for none.
Returns the longest edge of body's ring as a multiple of its rest length: 1 at rest, large when it is tearing.
Returns the mean velocity of body's ring particles across, in units per second.
Returns the mean velocity of body's ring particles down, in units per second.
Returns how long this strand is at rest in world: the sum of its links' rest lengths.
Adds a rigid body the shape and size of collider where transform puts it, and returns its handle in PhysicsWorld.rigidBodies, so a crate that tumbles and that bullets hit through app.collisions is described once.
Adds a rigid body made of shape with the shape's origin at (x, y), turned by angle radians, and returns its handle in PhysicsWorld.rigidBodies. Its mass and inertia come from the shape's size and density.
Adds a rigid body made of several shapes, such as a hammer of two boxes, and returns its handle: see RigidBodies.add.
Adds a soft body of shape with its middle at centerX and its bottom on baseY, and returns its handle in PhysicsWorld.softBodies.