Joints
Joints between rigid bodies, the way machines connect them: hinge, slider, weld and distance, solved the XPBD way, as in Müller et al. 2020.
A joint's first end is a RigidBody. Its second, a JointEnd, is another body, the world (JointEnd.WORLD: a fixed point in it), or a Particle. Each holds a point of each end, its anchor, where it was when the joint was made. A particle can't turn, so a joint to one holds its position only.
Every pass, a joint pulls its anchors where they should be, split by how hard each end is to move there, as for a contact, and turns the two ends to the angle they should have. Its compliance says how soft that is: 0 is rigid. A hinge and a slider can have limits (setLimits), past which they're pushed back, and a motor (setMotor), which drives them at a speed with at most a torque or a force. A weld breaks, and is removed, when the force holding it passes its breakForce.
Two bodies joined to each other don't collide with each other: a wheel can sit inside its axle box.
Each joint is a Joint handle; a removed one's slot is reused. Removing a body or particle removes every joint that holds it.
toString gives how many joints there are, for example Joints(size=12).
Samples
val world = PhysicsWorld()
val door = world.rigidBody(Shape.box(40f, 4f), x = 20f, y = 0f)
// Hinged to the world at its left end: it swings down about that point.
val hinge = world.joints.hinge(door, JointEnd.WORLD, x = 0f, y = 0f)
repeat(60) { world.step(1.seconds / 60) }
assertTrue(world.rigidBodies.angleOf(door) > 0.5f)
assertPrints(world.joints.kindOf(hinge), "HINGE")Functions
Takes away joint's limits, so it turns or slides as far as it likes.
Returns where joint holds its first end in the world now, across.
Returns where joint holds its first end in the world now, down.
Returns joint's first end.
Returns joint's lower limit: an angle in radians for a hinge, a distance for a slider.
Returns how fast joint's motor drives it: radians a second for a hinge, units a second for a slider.
Returns how far slider joint's second end has slid along its axis since it was made, in units.
Returns the angle hinge joint's two ends had when it was made: its second end's less its first's.
Returns where joint holds its second end in the world now, across.
Returns where joint holds its second end in the world now, down.
Returns joint's second end: a body, JointEnd.WORLD, or a particle.
Drives hinge joint at speed radians a second, with at most maxTorque, or slider joint at speed units a second, with at most maxTorque as a force. A maxTorque of 0 turns the motor off. The speed is the second end's against the first, clockwise on screen, as angleOf counts: a wheel hinged to JointEnd.WORLD turns at -speed, since the world turns against the wheel.
Returns joint's upper limit: an angle in radians for a hinge, a distance for a slider.
Holds a and b together at the world point (x, y), and at the angle they have now, as softly as compliance, and returns the joint's handle. Pulled harder than breakForce, it breaks: it is removed, and Events.brokenJointAt reports it.