@codexo/exojs-physics 0.16.2 → 0.18.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (72) hide show
  1. package/README.md +13 -45
  2. package/dist/esm/Collider.d.ts +0 -33
  3. package/dist/esm/Collider.d.ts.map +1 -1
  4. package/dist/esm/Collider.js +10 -1
  5. package/dist/esm/Collider.js.map +1 -1
  6. package/dist/esm/ContactGraph.d.ts +22 -14
  7. package/dist/esm/ContactGraph.d.ts.map +1 -1
  8. package/dist/esm/ContactGraph.js +43 -5
  9. package/dist/esm/ContactGraph.js.map +1 -1
  10. package/dist/esm/ContactModifier.d.ts +0 -23
  11. package/dist/esm/ContactModifier.d.ts.map +1 -1
  12. package/dist/esm/PhysicsBody.d.ts +0 -81
  13. package/dist/esm/PhysicsBody.d.ts.map +1 -1
  14. package/dist/esm/PhysicsBody.js +37 -8
  15. package/dist/esm/PhysicsBody.js.map +1 -1
  16. package/dist/esm/PhysicsWorld.d.ts +63 -41
  17. package/dist/esm/PhysicsWorld.d.ts.map +1 -1
  18. package/dist/esm/PhysicsWorld.js +162 -36
  19. package/dist/esm/PhysicsWorld.js.map +1 -1
  20. package/dist/esm/broadphase/AabbTreeBroadPhase.d.ts +22 -6
  21. package/dist/esm/broadphase/AabbTreeBroadPhase.d.ts.map +1 -1
  22. package/dist/esm/broadphase/AabbTreeBroadPhase.js +45 -11
  23. package/dist/esm/broadphase/AabbTreeBroadPhase.js.map +1 -1
  24. package/dist/esm/collision/chainAdjacency.d.ts +1 -28
  25. package/dist/esm/collision/chainAdjacency.d.ts.map +1 -1
  26. package/dist/esm/joints/DistanceJoint.d.ts +2 -4
  27. package/dist/esm/joints/DistanceJoint.d.ts.map +1 -1
  28. package/dist/esm/joints/DistanceJoint.js +8 -5
  29. package/dist/esm/joints/DistanceJoint.js.map +1 -1
  30. package/dist/esm/joints/Joint.d.ts +59 -9
  31. package/dist/esm/joints/Joint.d.ts.map +1 -1
  32. package/dist/esm/joints/Joint.js +39 -3
  33. package/dist/esm/joints/Joint.js.map +1 -1
  34. package/dist/esm/joints/MouseJoint.d.ts +0 -3
  35. package/dist/esm/joints/MouseJoint.d.ts.map +1 -1
  36. package/dist/esm/joints/MouseJoint.js +4 -1
  37. package/dist/esm/joints/MouseJoint.js.map +1 -1
  38. package/dist/esm/joints/PrismaticJoint.d.ts +2 -4
  39. package/dist/esm/joints/PrismaticJoint.d.ts.map +1 -1
  40. package/dist/esm/joints/PrismaticJoint.js +5 -2
  41. package/dist/esm/joints/PrismaticJoint.js.map +1 -1
  42. package/dist/esm/joints/RevoluteJoint.d.ts +4 -9
  43. package/dist/esm/joints/RevoluteJoint.d.ts.map +1 -1
  44. package/dist/esm/joints/RevoluteJoint.js +42 -33
  45. package/dist/esm/joints/RevoluteJoint.js.map +1 -1
  46. package/dist/esm/joints/WeldJoint.d.ts +2 -4
  47. package/dist/esm/joints/WeldJoint.d.ts.map +1 -1
  48. package/dist/esm/joints/WeldJoint.js +12 -9
  49. package/dist/esm/joints/WeldJoint.js.map +1 -1
  50. package/dist/esm/joints/WheelJoint.d.ts +2 -4
  51. package/dist/esm/joints/WheelJoint.d.ts.map +1 -1
  52. package/dist/esm/joints/WheelJoint.js +8 -5
  53. package/dist/esm/joints/WheelJoint.js.map +1 -1
  54. package/dist/esm/physicsBuildInfo.js +2 -2
  55. package/dist/esm/public.d.ts +1 -1
  56. package/dist/esm/public.d.ts.map +1 -1
  57. package/dist/esm/shapes/ChainEdgeShape.d.ts +1 -29
  58. package/dist/esm/shapes/ChainEdgeShape.d.ts.map +1 -1
  59. package/dist/esm/shapes/ChainShape.d.ts +0 -6
  60. package/dist/esm/shapes/ChainShape.d.ts.map +1 -1
  61. package/dist/esm/shapes/decompose.d.ts +1 -23
  62. package/dist/esm/shapes/decompose.d.ts.map +1 -1
  63. package/dist/esm/solver/ContactSolver.d.ts.map +1 -1
  64. package/dist/esm/solver/ContactSolver.js +16 -3
  65. package/dist/esm/solver/ContactSolver.js.map +1 -1
  66. package/dist/esm/solver/tolerances.d.ts +1 -33
  67. package/dist/esm/solver/tolerances.d.ts.map +1 -1
  68. package/dist/esm/solver/tolerances.js +14 -16
  69. package/dist/esm/solver/tolerances.js.map +1 -1
  70. package/dist/esm/sort.d.ts +1 -17
  71. package/dist/esm/sort.d.ts.map +1 -1
  72. package/package.json +3 -3
@@ -1 +1 @@
1
- {"version":3,"file":"PrismaticJoint.js","names":[],"sources":["../../../src/joints/PrismaticJoint.ts"],"sourcesContent":["import type { PointLike } from '@codexo/exojs';\n\nimport { applyInverseRotation, applyInverseTransform, applyRotation, applyTransform } from '../math';\nimport type { PhysicsBody } from '../PhysicsBody';\nimport { Joint } from './Joint';\n\n/** Construction options for a {@link PrismaticJoint}. */\nexport interface PrismaticJointOptions {\n /** First body (often a static rail anchor). */\n bodyA: PhysicsBody;\n /** Second body (the slider). */\n bodyB: PhysicsBody;\n /** Shared world-space anchor at creation. */\n anchor: Readonly<PointLike>;\n /** Slide axis in world space at creation (normalised internally). The body may only translate along this axis. */\n axis: Readonly<PointLike>;\n /** Enable the linear motor (drives translation along the axis toward {@link motorSpeed}). Default `false`. */\n enableMotor?: boolean;\n /** Target translation speed along the axis (px/s). Default `0`. */\n motorSpeed?: number;\n /** Maximum motor force - clamps the per-step motor impulse. Default `0`. */\n maxMotorForce?: number;\n /** Enable the translation limit (keeps the axis translation in `[lowerTranslation, upperTranslation]`). Default `false`. */\n enableLimit?: boolean;\n /** Lower translation limit along the axis (relative to the creation position). Default `0`. */\n lowerTranslation?: number;\n /** Upper translation limit along the axis. Default `0`. */\n upperTranslation?: number;\n}\n\n/** Reused output sink - physics steps single-threaded, so a shared scratch is safe. */\nconst scratch: PointLike = { x: 0, y: 0 };\n\n/**\n * Constrains a body to **slide along a single axis** relative to another: the\n * perpendicular translation and the relative rotation are locked (a 2×2 block);\n * only translation along the axis is free, optionally driven by a motor and/or\n * bounded by a translation limit. Solved in the sub-step loop, warm-started.\n */\nexport class PrismaticJoint extends Joint {\n /** When `true`, the motor drives the axis translation toward {@link motorSpeed}. */\n public enableMotor: boolean;\n /** Target translation speed along the axis (px/s). */\n public motorSpeed: number;\n /** Maximum motor force. */\n public maxMotorForce: number;\n /** When `true`, the axis translation is constrained to `[lowerTranslation, upperTranslation]`. */\n public enableLimit: boolean;\n /** Lower translation limit along the axis. */\n public lowerTranslation: number;\n /** Upper translation limit along the axis. */\n public upperTranslation: number;\n\n private readonly _localAnchorAx: number;\n private readonly _localAnchorAy: number;\n private readonly _localAnchorBx: number;\n private readonly _localAnchorBy: number;\n private readonly _localAxisAx: number;\n private readonly _localAxisAy: number;\n private readonly _referenceAngle: number;\n\n private _axisX = 1;\n private _axisY = 0;\n private _perpX = 0;\n private _perpY = 1;\n private _a1 = 0;\n private _a2 = 0;\n private _s1 = 0;\n private _s2 = 0;\n private _k11 = 0;\n private _k12 = 0;\n private _k22 = 0;\n private _cPerp = 0;\n private _cAngle = 0;\n private _translation = 0;\n private _axialMass = 0;\n private _h = 0;\n private _invH = 0;\n private _perpImpulse = 0;\n private _angularImpulse = 0;\n private _motorImpulse = 0;\n private _lowerImpulse = 0;\n private _upperImpulse = 0;\n\n public constructor(options: PrismaticJointOptions) {\n super(options.bodyA, options.bodyB);\n\n applyInverseTransform(options.bodyA.transform, options.anchor.x, options.anchor.y, scratch);\n this._localAnchorAx = scratch.x;\n this._localAnchorAy = scratch.y;\n applyInverseTransform(options.bodyB.transform, options.anchor.x, options.anchor.y, scratch);\n this._localAnchorBx = scratch.x;\n this._localAnchorBy = scratch.y;\n\n const axisLength = Math.hypot(options.axis.x, options.axis.y);\n\n if (!Number.isFinite(axisLength) || axisLength === 0) {\n throw new RangeError(`PrismaticJoint: axis must be a non-zero finite vector, received (${options.axis.x}, ${options.axis.y}).`);\n }\n\n applyInverseRotation(options.bodyA.transform, options.axis.x / axisLength, options.axis.y / axisLength, scratch);\n this._localAxisAx = scratch.x;\n this._localAxisAy = scratch.y;\n\n this._referenceAngle = options.bodyB.angle - options.bodyA.angle;\n this.enableMotor = options.enableMotor ?? false;\n this.motorSpeed = options.motorSpeed ?? 0;\n this.maxMotorForce = options.maxMotorForce ?? 0;\n this.enableLimit = options.enableLimit ?? false;\n this.lowerTranslation = options.lowerTranslation ?? 0;\n this.upperTranslation = options.upperTranslation ?? 0;\n }\n\n public override _prepare(h: number): void {\n const bodyA = this.bodyA;\n const bodyB = this.bodyB;\n\n this._active = this.enabled && !bodyA.isSleeping && !bodyB.isSleeping && (bodyA.invMass > 0 || bodyB.invMass > 0);\n\n if (!this._active) {\n return;\n }\n\n // World axis + perpendicular (axis is local to body A).\n applyRotation(bodyA.transform, this._localAxisAx, this._localAxisAy, scratch);\n const axisX = scratch.x;\n const axisY = scratch.y;\n const perpX = -axisY;\n const perpY = axisX;\n\n this._axisX = axisX;\n this._axisY = axisY;\n this._perpX = perpX;\n this._perpY = perpY;\n\n applyTransform(bodyA.transform, this._localAnchorAx, this._localAnchorAy, scratch);\n const pAx = scratch.x;\n const pAy = scratch.y;\n applyTransform(bodyB.transform, this._localAnchorBx, this._localAnchorBy, scratch);\n const pBx = scratch.x;\n const pBy = scratch.y;\n\n const rAx = pAx - bodyA.worldCenterOfMassX;\n const rAy = pAy - bodyA.worldCenterOfMassY;\n const rBx = pBx - bodyB.worldCenterOfMassX;\n const rBy = pBy - bodyB.worldCenterOfMassY;\n const dx = pBx - pAx;\n const dy = pBy - pAy;\n\n // Jacobian cross terms for the axis (motor/limit) and the perpendicular (lock).\n this._a1 = (dx + rAx) * axisY - (dy + rAy) * axisX;\n this._a2 = rBx * axisY - rBy * axisX;\n this._s1 = (dx + rAx) * perpY - (dy + rAy) * perpX;\n this._s2 = rBx * perpY - rBy * perpX;\n\n const mA = bodyA.invMass;\n const mB = bodyB.invMass;\n const iA = bodyA.invInertia;\n const iB = bodyB.invInertia;\n\n const kAxial = mA + mB + iA * this._a1 * this._a1 + iB * this._a2 * this._a2;\n this._axialMass = kAxial > 0 ? 1 / kAxial : 0;\n\n // Perpendicular + angular 2×2 block.\n this._k11 = mA + mB + iA * this._s1 * this._s1 + iB * this._s2 * this._s2;\n this._k12 = iA * this._s1 + iB * this._s2;\n this._k22 = iA + iB;\n\n if (this._k22 === 0) {\n this._k22 = 1; // both bodies rotation-locked — keep the block invertible\n }\n\n this._cPerp = dx * perpX + dy * perpY;\n this._cAngle = bodyB.angle - bodyA.angle - this._referenceAngle;\n this._translation = dx * axisX + dy * axisY;\n this._h = h;\n this._invH = 1 / h;\n\n if (!this.enableMotor) {\n this._motorImpulse = 0;\n }\n\n if (!this.enableLimit) {\n this._lowerImpulse = 0;\n this._upperImpulse = 0;\n }\n }\n\n public override _warmStart(): void {\n if (!this._active) {\n return;\n }\n\n const axial = this._motorImpulse + this._lowerImpulse - this._upperImpulse;\n this._applyBlock(this._perpImpulse, this._angularImpulse);\n this._applyAxial(axial);\n }\n\n public override _solve(useBias: boolean): void {\n if (!this._active) {\n return;\n }\n\n const bodyA = this.bodyA;\n const bodyB = this.bodyB;\n\n // Motor along the axis.\n if (this.enableMotor) {\n const cdot = this._axisVelocity() - this.motorSpeed;\n const max = this.maxMotorForce * this._h;\n const old = this._motorImpulse;\n\n this._motorImpulse = Math.min(max, Math.max(-max, old - this._axialMass * cdot));\n this._applyAxial(this._motorImpulse - old);\n }\n\n // Translation limits along the axis.\n if (this.enableLimit) {\n // Lower limit (translation ≥ lowerTranslation): positive impulse pushes along +axis.\n const cLower = this._translation - this.lowerTranslation;\n let biasLower = 0;\n\n if (cLower > 0) {\n biasLower = cLower * this._invH;\n } else if (useBias) {\n biasLower = 0.2 * this._invH * cLower;\n }\n\n const oldLower = this._lowerImpulse;\n this._lowerImpulse = Math.max(0, oldLower - this._axialMass * (this._axisVelocity() + biasLower));\n this._applyAxial(this._lowerImpulse - oldLower);\n\n // Upper limit (translation ≤ upperTranslation): impulse pushes along −axis.\n const cUpper = this.upperTranslation - this._translation;\n let biasUpper = 0;\n\n if (cUpper > 0) {\n biasUpper = cUpper * this._invH;\n } else if (useBias) {\n biasUpper = 0.2 * this._invH * cUpper;\n }\n\n const oldUpper = this._upperImpulse;\n this._upperImpulse = Math.max(0, oldUpper - this._axialMass * (-this._axisVelocity() + biasUpper));\n this._applyAxial(-(this._upperImpulse - oldUpper));\n }\n\n // Perpendicular + angular lock (2×2 block).\n const cdotPerp = this._perpVelocity();\n const cdotAngle = bodyB.angularVelocity - bodyA.angularVelocity;\n const rhs1 = -(cdotPerp + (useBias ? 0.2 * this._invH * this._cPerp : 0));\n const rhs2 = -(cdotAngle + (useBias ? 0.2 * this._invH * this._cAngle : 0));\n const det = this._k11 * this._k22 - this._k12 * this._k12;\n const invDet = det !== 0 ? 1 / det : 0;\n const dPerp = invDet * (this._k22 * rhs1 - this._k12 * rhs2);\n const dAngle = invDet * (-this._k12 * rhs1 + this._k11 * rhs2);\n\n this._perpImpulse += dPerp;\n this._angularImpulse += dAngle;\n this._applyBlock(dPerp, dAngle);\n }\n\n /** Relative velocity projected onto the axis (plus the rotation cross terms). */\n private _axisVelocity(): number {\n const bodyA = this.bodyA;\n const bodyB = this.bodyB;\n\n return (\n this._axisX * (bodyB.linearVelocityX - bodyA.linearVelocityX) +\n this._axisY * (bodyB.linearVelocityY - bodyA.linearVelocityY) +\n this._a2 * bodyB.angularVelocity -\n this._a1 * bodyA.angularVelocity\n );\n }\n\n /** Relative velocity projected onto the perpendicular (plus the rotation cross terms). */\n private _perpVelocity(): number {\n const bodyA = this.bodyA;\n const bodyB = this.bodyB;\n\n return (\n this._perpX * (bodyB.linearVelocityX - bodyA.linearVelocityX) +\n this._perpY * (bodyB.linearVelocityY - bodyA.linearVelocityY) +\n this._s2 * bodyB.angularVelocity -\n this._s1 * bodyA.angularVelocity\n );\n }\n\n private _applyAxial(impulse: number): void {\n const bodyA = this.bodyA;\n const bodyB = this.bodyB;\n const px = impulse * this._axisX;\n const py = impulse * this._axisY;\n\n bodyA.linearVelocityX -= bodyA.invMass * px;\n bodyA.linearVelocityY -= bodyA.invMass * py;\n bodyA.angularVelocity -= bodyA.invInertia * impulse * this._a1;\n bodyB.linearVelocityX += bodyB.invMass * px;\n bodyB.linearVelocityY += bodyB.invMass * py;\n bodyB.angularVelocity += bodyB.invInertia * impulse * this._a2;\n }\n\n private _applyBlock(perpImpulse: number, angularImpulse: number): void {\n const bodyA = this.bodyA;\n const bodyB = this.bodyB;\n const px = perpImpulse * this._perpX;\n const py = perpImpulse * this._perpY;\n\n bodyA.linearVelocityX -= bodyA.invMass * px;\n bodyA.linearVelocityY -= bodyA.invMass * py;\n bodyA.angularVelocity -= bodyA.invInertia * (perpImpulse * this._s1 + angularImpulse);\n bodyB.linearVelocityX += bodyB.invMass * px;\n bodyB.linearVelocityY += bodyB.invMass * py;\n bodyB.angularVelocity += bodyB.invInertia * (perpImpulse * this._s2 + angularImpulse);\n }\n}\n"],"mappings":";;;;;AA+BA,MAAM,UAAqB;CAAE,GAAG;CAAG,GAAG;AAAE;;;;;;;AAQxC,IAAa,iBAAb,cAAoC,MAAM;;CAExC,AAAO;;CAEP,AAAO;;CAEP,AAAO;;CAEP,AAAO;;CAEP,AAAO;;CAEP,AAAO;CAEP,AAAiB;CACjB,AAAiB;CACjB,AAAiB;CACjB,AAAiB;CACjB,AAAiB;CACjB,AAAiB;CACjB,AAAiB;CAEjB,AAAQ,SAAS;CACjB,AAAQ,SAAS;CACjB,AAAQ,SAAS;CACjB,AAAQ,SAAS;CACjB,AAAQ,MAAM;CACd,AAAQ,MAAM;CACd,AAAQ,MAAM;CACd,AAAQ,MAAM;CACd,AAAQ,OAAO;CACf,AAAQ,OAAO;CACf,AAAQ,OAAO;CACf,AAAQ,SAAS;CACjB,AAAQ,UAAU;CAClB,AAAQ,eAAe;CACvB,AAAQ,aAAa;CACrB,AAAQ,KAAK;CACb,AAAQ,QAAQ;CAChB,AAAQ,eAAe;CACvB,AAAQ,kBAAkB;CAC1B,AAAQ,gBAAgB;CACxB,AAAQ,gBAAgB;CACxB,AAAQ,gBAAgB;CAExB,AAAO,YAAY,SA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M,mBAAmB,MAAM,UAAU;EACzC,MAAM,mBAAmB,MAAM,aAAa,UAAU,KAAK;EAC3D,MAAM,mBAAmB,MAAM,UAAU;EACzC,MAAM,mBAAmB,MAAM,UAAU;EACzC,MAAM,mBAAmB,MAAM,aAAa,UAAU,KAAK;CAC7D;CAEA,AAAQ,YAAY,aAAqB,gBAA8B;EACrE,MAAM,QAAQ,KAAK;EACnB,MAAM,QAAQ,KAAK;EACnB,MAAM,KAAK,cAAc,KAAK;EAC9B,MAAM,KAAK,cAAc,KAAK;EAE9B,MAAM,mBAAmB,MAAM,UAAU;EACzC,MAAM,mBAAmB,MAAM,UAAU;EACzC,MAAM,mBAAmB,MAAM,cAAc,cAAc,KAAK,MAAM;EACtE,MAAM,mBAAmB,MAAM,UAAU;EACzC,MAAM,mBAAmB,MAAM,UAAU;EACzC,MAAM,mBAAmB,MAAM,cAAc,cAAc,KAAK,MAAM;CACxE;AACF"}
1
+ {"version":3,"file":"PrismaticJoint.js","names":[],"sources":["../../../src/joints/PrismaticJoint.ts"],"sourcesContent":["import type { PointLike } from '@codexo/exojs';\n\nimport { applyInverseRotation, applyInverseTransform, applyRotation, applyTransform } from '../math';\nimport type { PhysicsBody } from '../PhysicsBody';\nimport type { JointOptions, JointSoftness } from './Joint';\nimport { Joint } from './Joint';\n\n/** Construction options for a {@link PrismaticJoint}. */\nexport interface PrismaticJointOptions extends JointOptions {\n /** First body (often a static rail anchor). */\n bodyA: PhysicsBody;\n /** Second body (the slider). */\n bodyB: PhysicsBody;\n /** Shared world-space anchor at creation. */\n anchor: Readonly<PointLike>;\n /** Slide axis in world space at creation (normalised internally). The body may only translate along this axis. */\n axis: Readonly<PointLike>;\n /** Enable the linear motor (drives translation along the axis toward {@link motorSpeed}). Default `false`. */\n enableMotor?: boolean;\n /** Target translation speed along the axis (px/s). Default `0`. */\n motorSpeed?: number;\n /** Maximum motor force - clamps the per-step motor impulse. Default `0`. */\n maxMotorForce?: number;\n /** Enable the translation limit (keeps the axis translation in `[lowerTranslation, upperTranslation]`). Default `false`. */\n enableLimit?: boolean;\n /** Lower translation limit along the axis (relative to the creation position). Default `0`. */\n lowerTranslation?: number;\n /** Upper translation limit along the axis. Default `0`. */\n upperTranslation?: number;\n}\n\n/** Reused output sink - physics steps single-threaded, so a shared scratch is safe. */\nconst scratch: PointLike = { x: 0, y: 0 };\n\n/**\n * Constrains a body to **slide along a single axis** relative to another: the\n * perpendicular translation and the relative rotation are locked (a 2×2 block);\n * only translation along the axis is free, optionally driven by a motor and/or\n * bounded by a translation limit. Solved in the sub-step loop, warm-started.\n */\nexport class PrismaticJoint extends Joint {\n /** When `true`, the motor drives the axis translation toward {@link motorSpeed}. */\n public enableMotor: boolean;\n /** Target translation speed along the axis (px/s). */\n public motorSpeed: number;\n /** Maximum motor force. */\n public maxMotorForce: number;\n /** When `true`, the axis translation is constrained to `[lowerTranslation, upperTranslation]`. */\n public enableLimit: boolean;\n /** Lower translation limit along the axis. */\n public lowerTranslation: number;\n /** Upper translation limit along the axis. */\n public upperTranslation: number;\n\n private readonly _localAnchorAx: number;\n private readonly _localAnchorAy: number;\n private readonly _localAnchorBx: number;\n private readonly _localAnchorBy: number;\n private readonly _localAxisAx: number;\n private readonly _localAxisAy: number;\n private readonly _referenceAngle: number;\n\n private _axisX = 1;\n private _axisY = 0;\n private _perpX = 0;\n private _perpY = 1;\n private _a1 = 0;\n private _a2 = 0;\n private _s1 = 0;\n private _s2 = 0;\n private _k11 = 0;\n private _k12 = 0;\n private _k22 = 0;\n private _cPerp = 0;\n private _cAngle = 0;\n private _translation = 0;\n private _axialMass = 0;\n private _h = 0;\n private _invH = 0;\n private _perpImpulse = 0;\n private _angularImpulse = 0;\n private _motorImpulse = 0;\n private _lowerImpulse = 0;\n private _upperImpulse = 0;\n\n public constructor(options: PrismaticJointOptions) {\n super(options.bodyA, options.bodyB, options.collideConnected);\n\n applyInverseTransform(options.bodyA.transform, options.anchor.x, options.anchor.y, scratch);\n this._localAnchorAx = scratch.x;\n this._localAnchorAy = scratch.y;\n applyInverseTransform(options.bodyB.transform, options.anchor.x, options.anchor.y, scratch);\n this._localAnchorBx = scratch.x;\n this._localAnchorBy = scratch.y;\n\n const axisLength = Math.hypot(options.axis.x, options.axis.y);\n\n if (!Number.isFinite(axisLength) || axisLength === 0) {\n throw new RangeError(`PrismaticJoint: axis must be a non-zero finite vector, received (${options.axis.x}, ${options.axis.y}).`);\n }\n\n applyInverseRotation(options.bodyA.transform, options.axis.x / axisLength, options.axis.y / axisLength, scratch);\n this._localAxisAx = scratch.x;\n this._localAxisAy = scratch.y;\n\n this._referenceAngle = options.bodyB.angle - options.bodyA.angle;\n this.enableMotor = options.enableMotor ?? false;\n this.motorSpeed = options.motorSpeed ?? 0;\n this.maxMotorForce = options.maxMotorForce ?? 0;\n this.enableLimit = options.enableLimit ?? false;\n this.lowerTranslation = options.lowerTranslation ?? 0;\n this.upperTranslation = options.upperTranslation ?? 0;\n }\n\n /** @internal */\n public override _prepare(h: number, _rigid: JointSoftness): void {\n const bodyA = this.bodyA;\n const bodyB = this.bodyB;\n\n this._active = this.enabled && !bodyA.isSleeping && !bodyB.isSleeping && (bodyA.invMass > 0 || bodyB.invMass > 0);\n\n if (!this._active) {\n return;\n }\n\n // World axis + perpendicular (axis is local to body A).\n applyRotation(bodyA.transform, this._localAxisAx, this._localAxisAy, scratch);\n const axisX = scratch.x;\n const axisY = scratch.y;\n const perpX = -axisY;\n const perpY = axisX;\n\n this._axisX = axisX;\n this._axisY = axisY;\n this._perpX = perpX;\n this._perpY = perpY;\n\n applyTransform(bodyA.transform, this._localAnchorAx, this._localAnchorAy, scratch);\n const pAx = scratch.x;\n const pAy = scratch.y;\n applyTransform(bodyB.transform, this._localAnchorBx, this._localAnchorBy, scratch);\n const pBx = scratch.x;\n const pBy = scratch.y;\n\n const rAx = pAx - bodyA.worldCenterOfMassX;\n const rAy = pAy - bodyA.worldCenterOfMassY;\n const rBx = pBx - bodyB.worldCenterOfMassX;\n const rBy = pBy - bodyB.worldCenterOfMassY;\n const dx = pBx - pAx;\n const dy = pBy - pAy;\n\n // Jacobian cross terms for the axis (motor/limit) and the perpendicular (lock).\n this._a1 = (dx + rAx) * axisY - (dy + rAy) * axisX;\n this._a2 = rBx * axisY - rBy * axisX;\n this._s1 = (dx + rAx) * perpY - (dy + rAy) * perpX;\n this._s2 = rBx * perpY - rBy * perpX;\n\n const mA = bodyA.invMass;\n const mB = bodyB.invMass;\n const iA = bodyA.invInertia;\n const iB = bodyB.invInertia;\n\n const kAxial = mA + mB + iA * this._a1 * this._a1 + iB * this._a2 * this._a2;\n this._axialMass = kAxial > 0 ? 1 / kAxial : 0;\n\n // Perpendicular + angular 2×2 block.\n this._k11 = mA + mB + iA * this._s1 * this._s1 + iB * this._s2 * this._s2;\n this._k12 = iA * this._s1 + iB * this._s2;\n this._k22 = iA + iB;\n\n if (this._k22 === 0) {\n this._k22 = 1; // both bodies rotation-locked — keep the block invertible\n }\n\n this._cPerp = dx * perpX + dy * perpY;\n this._cAngle = bodyB.angle - bodyA.angle - this._referenceAngle;\n this._translation = dx * axisX + dy * axisY;\n this._h = h;\n this._invH = 1 / h;\n\n if (!this.enableMotor) {\n this._motorImpulse = 0;\n }\n\n if (!this.enableLimit) {\n this._lowerImpulse = 0;\n this._upperImpulse = 0;\n }\n }\n\n /** @internal */\n public override _warmStart(): void {\n if (!this._active) {\n return;\n }\n\n const axial = this._motorImpulse + this._lowerImpulse - this._upperImpulse;\n this._applyBlock(this._perpImpulse, this._angularImpulse);\n this._applyAxial(axial);\n }\n\n /** @internal */\n public override _solve(useBias: boolean): void {\n if (!this._active) {\n return;\n }\n\n const bodyA = this.bodyA;\n const bodyB = this.bodyB;\n\n // Motor along the axis.\n if (this.enableMotor) {\n const cdot = this._axisVelocity() - this.motorSpeed;\n const max = this.maxMotorForce * this._h;\n const old = this._motorImpulse;\n\n this._motorImpulse = Math.min(max, Math.max(-max, old - this._axialMass * cdot));\n this._applyAxial(this._motorImpulse - old);\n }\n\n // Translation limits along the axis.\n if (this.enableLimit) {\n // Lower limit (translation ≥ lowerTranslation): positive impulse pushes along +axis.\n const cLower = this._translation - this.lowerTranslation;\n let biasLower = 0;\n\n if (cLower > 0) {\n biasLower = cLower * this._invH;\n } else if (useBias) {\n biasLower = 0.2 * this._invH * cLower;\n }\n\n const oldLower = this._lowerImpulse;\n this._lowerImpulse = Math.max(0, oldLower - this._axialMass * (this._axisVelocity() + biasLower));\n this._applyAxial(this._lowerImpulse - oldLower);\n\n // Upper limit (translation ≤ upperTranslation): impulse pushes along −axis.\n const cUpper = this.upperTranslation - this._translation;\n let biasUpper = 0;\n\n if (cUpper > 0) {\n biasUpper = cUpper * this._invH;\n } else if (useBias) {\n biasUpper = 0.2 * this._invH * cUpper;\n }\n\n const oldUpper = this._upperImpulse;\n this._upperImpulse = Math.max(0, oldUpper - this._axialMass * (-this._axisVelocity() + biasUpper));\n this._applyAxial(-(this._upperImpulse - oldUpper));\n }\n\n // Perpendicular + angular lock (2×2 block).\n const cdotPerp = this._perpVelocity();\n const cdotAngle = bodyB.angularVelocity - bodyA.angularVelocity;\n const rhs1 = -(cdotPerp + (useBias ? 0.2 * this._invH * this._cPerp : 0));\n const rhs2 = -(cdotAngle + (useBias ? 0.2 * this._invH * this._cAngle : 0));\n const det = this._k11 * this._k22 - this._k12 * this._k12;\n const invDet = det !== 0 ? 1 / det : 0;\n const dPerp = invDet * (this._k22 * rhs1 - this._k12 * rhs2);\n const dAngle = invDet * (-this._k12 * rhs1 + this._k11 * rhs2);\n\n this._perpImpulse += dPerp;\n this._angularImpulse += dAngle;\n this._applyBlock(dPerp, dAngle);\n }\n\n /** Relative velocity projected onto the axis (plus the rotation cross terms). */\n private _axisVelocity(): number {\n const bodyA = this.bodyA;\n const bodyB = this.bodyB;\n\n return (\n this._axisX * (bodyB.linearVelocityX - bodyA.linearVelocityX) +\n this._axisY * (bodyB.linearVelocityY - bodyA.linearVelocityY) +\n this._a2 * bodyB.angularVelocity -\n this._a1 * bodyA.angularVelocity\n );\n }\n\n /** Relative velocity projected onto the perpendicular (plus the rotation cross terms). */\n private _perpVelocity(): number {\n const bodyA = this.bodyA;\n const bodyB = this.bodyB;\n\n return (\n this._perpX * (bodyB.linearVelocityX - bodyA.linearVelocityX) +\n this._perpY * (bodyB.linearVelocityY - bodyA.linearVelocityY) +\n this._s2 * bodyB.angularVelocity -\n this._s1 * bodyA.angularVelocity\n );\n }\n\n private _applyAxial(impulse: number): void {\n const bodyA = this.bodyA;\n const bodyB = this.bodyB;\n const px = impulse * this._axisX;\n const py = impulse * this._axisY;\n\n bodyA.linearVelocityX -= bodyA.invMass * px;\n bodyA.linearVelocityY -= bodyA.invMass * py;\n bodyA.angularVelocity -= bodyA.invInertia * impulse * this._a1;\n bodyB.linearVelocityX += bodyB.invMass * px;\n bodyB.linearVelocityY += bodyB.invMass * py;\n bodyB.angularVelocity += bodyB.invInertia * impulse * this._a2;\n }\n\n private _applyBlock(perpImpulse: number, angularImpulse: number): void {\n const bodyA = this.bodyA;\n const bodyB = this.bodyB;\n const px = perpImpulse * this._perpX;\n const py = perpImpulse * this._perpY;\n\n bodyA.linearVelocityX -= bodyA.invMass * px;\n bodyA.linearVelocityY -= bodyA.invMass * py;\n bodyA.angularVelocity -= bodyA.invInertia * (perpImpulse * this._s1 + angularImpulse);\n bodyB.linearVelocityX += bodyB.invMass * px;\n bodyB.linearVelocityY += bodyB.invMass * py;\n bodyB.angularVelocity += bodyB.invInertia * (perpImpulse * this._s2 + angularImpulse);\n }\n}\n"],"mappings":";;;;;AAgCA,MAAM,UAAqB;CAAE,GAAG;CAAG,GAAG;AAAE;;;;;;;AAQxC,IAAa,iBAAb,cAAoC,MAAM;;CAExC,AAAO;;CAEP,AAAO;;CAEP,AAAO;;CAEP,AAAO;;CAEP,AAAO;;CAEP,AAAO;CAEP,AAAiB;CACjB,AAAiB;CACjB,AAAiB;CACjB,AAAiB;CACjB,AAAiB;CACjB,AAAiB;CACjB,AAAiB;CAEjB,AAAQ,SAAS;CACj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C,KAAK,MAAM,MAAM,kBACjB,KAAK,MAAM,MAAM;CAErB;;CAGA,AAAQ,gBAAwB;EAC9B,MAAM,QAAQ,KAAK;EACnB,MAAM,QAAQ,KAAK;EAEnB,OACE,KAAK,UAAU,MAAM,kBAAkB,MAAM,mBAC7C,KAAK,UAAU,MAAM,kBAAkB,MAAM,mBAC7C,KAAK,MAAM,MAAM,kBACjB,KAAK,MAAM,MAAM;CAErB;CAEA,AAAQ,YAAY,SAAuB;EACzC,MAAM,QAAQ,KAAK;EACnB,MAAM,QAAQ,KAAK;EACnB,MAAM,KAAK,UAAU,KAAK;EAC1B,MAAM,KAAK,UAAU,KAAK;EAE1B,MAAM,mBAAmB,MAAM,UAAU;EACzC,MAAM,mBAAmB,MAAM,UAAU;EACzC,MAAM,mBAAmB,MAAM,aAAa,UAAU,KAAK;EAC3D,MAAM,mBAAmB,MAAM,UAAU;EACzC,MAAM,mBAAmB,MAAM,UAAU;EACzC,MAAM,mBAAmB,MAAM,aAAa,UAAU,KAAK;CAC7D;CAEA,AAAQ,YAAY,aAAqB,gBAA8B;EACrE,MAAM,QAAQ,KAAK;EACnB,MAAM,QAAQ,KAAK;EACnB,MAAM,KAAK,cAAc,KAAK;EAC9B,MAAM,KAAK,cAAc,KAAK;EAE9B,MAAM,mBAAmB,MAAM,UAAU;EACzC,MAAM,mBAAmB,MAAM,UAAU;EACzC,MAAM,mBAAmB,MAAM,cAAc,cAAc,KAAK,MAAM;EACtE,MAAM,mBAAmB,MAAM,UAAU;EACzC,MAAM,mBAAmB,MAAM,UAAU;EACzC,MAAM,mBAAmB,MAAM,cAAc,cAAc,KAAK,MAAM;CACxE;AACF"}
@@ -1,8 +1,9 @@
1
1
  import type { PointLike } from '@codexo/exojs';
2
2
  import type { PhysicsBody } from '../PhysicsBody';
3
+ import type { JointOptions } from './Joint';
3
4
  import { Joint } from './Joint';
4
5
  /** Construction options for a {@link RevoluteJoint}. */
5
- export interface RevoluteJointOptions {
6
+ export interface RevoluteJointOptions extends JointOptions {
6
7
  /** First body (often a static anchor). */
7
8
  bodyA: PhysicsBody;
8
9
  /** Second body. */
@@ -56,11 +57,8 @@ export declare class RevoluteJoint extends Joint {
56
57
  private _rAy;
57
58
  private _rBx;
58
59
  private _rBy;
59
- private _cx;
60
- private _cy;
61
- private _invK11;
62
- private _invK12;
63
- private _invK22;
60
+ private _c0x;
61
+ private _c0y;
64
62
  private _biasRate;
65
63
  private _massScale;
66
64
  private _impulseScale;
@@ -74,9 +72,6 @@ export declare class RevoluteJoint extends Joint {
74
72
  private _lowerImpulse;
75
73
  private _upperImpulse;
76
74
  constructor(options: RevoluteJointOptions);
77
- _prepare(h: number): void;
78
- _warmStart(): void;
79
- _solve(useBias: boolean): void;
80
75
  private _applyImpulse;
81
76
  }
82
77
  //# sourceMappingURL=RevoluteJoint.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"RevoluteJoint.d.ts","sourceRoot":"","sources":["../../../src/joints/RevoluteJoint.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAG/C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAClD,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAEhC,wDAAwD;AACxD,MAAM,WAAW,oBAAoB;IACnC,0CAA0C;IAC1C,KAAK,EAAE,WAAW,CAAC;IACnB,mBAAmB;IACnB,KAAK,EAAE,WAAW,CAAC;IACnB,iHAAiH;IACjH,MAAM,EAAE,QAAQ,CAAC,SAAS,CAAC,CAAC;IAC5B,uEAAuE;IACvE,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,sEAAsE;IACtE,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,8FAA8F;IAC9F,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,wFAAwF;IACxF,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,6EAA6E;IAC7E,cAAc,CAAC,EAAE,MAAM,CAAC;IAC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AO,CAAC,aAAa;CAWtB"}
@@ -37,11 +37,8 @@ var RevoluteJoint = class extends Joint {
37
37
  _rAy = 0;
38
38
  _rBx = 0;
39
39
  _rBy = 0;
40
- _cx = 0;
41
- _cy = 0;
42
- _invK11 = 0;
43
- _invK12 = 0;
44
- _invK22 = 0;
40
+ _c0x = 0;
41
+ _c0y = 0;
45
42
  _biasRate = 0;
46
43
  _massScale = 1;
47
44
  _impulseScale = 0;
@@ -55,7 +52,7 @@ var RevoluteJoint = class extends Joint {
55
52
  _lowerImpulse = 0;
56
53
  _upperImpulse = 0;
57
54
  constructor(options) {
58
- super(options.bodyA, options.bodyB);
55
+ super(options.bodyA, options.bodyB, options.collideConnected);
59
56
  applyInverseTransform(options.bodyA.transform, options.anchor.x, options.anchor.y, scratch);
60
57
  this._localAnchorAx = scratch.x;
61
58
  this._localAnchorAy = scratch.y;
@@ -72,7 +69,8 @@ var RevoluteJoint = class extends Joint {
72
69
  this.upperAngle = options.upperAngle ?? 0;
73
70
  this._referenceAngle = options.bodyB.angle - options.bodyA.angle;
74
71
  }
75
- _prepare(h) {
72
+ /** @internal */
73
+ _prepare(h, rigid) {
76
74
  const bodyA = this.bodyA;
77
75
  const bodyB = this.bodyB;
78
76
  this._active = this.enabled && !bodyA.isSleeping && !bodyB.isSleeping && (bodyA.invMass > 0 || bodyB.invMass > 0);
@@ -87,20 +85,10 @@ var RevoluteJoint = class extends Joint {
87
85
  this._rAy = pAy - bodyA.worldCenterOfMassY;
88
86
  this._rBx = pBx - bodyB.worldCenterOfMassX;
89
87
  this._rBy = pBy - bodyB.worldCenterOfMassY;
90
- this._cx = pBx - pAx;
91
- this._cy = pBy - pAy;
92
- const mA = bodyA.invMass;
93
- const mB = bodyB.invMass;
88
+ this._c0x = pBx - pAx;
89
+ this._c0y = pBy - pAy;
94
90
  const iA = bodyA.invInertia;
95
91
  const iB = bodyB.invInertia;
96
- const k11 = mA + mB + iA * this._rAy * this._rAy + iB * this._rBy * this._rBy;
97
- const k12 = -iA * this._rAx * this._rAy - iB * this._rBx * this._rBy;
98
- const k22 = mA + mB + iA * this._rAx * this._rAx + iB * this._rBx * this._rBx;
99
- const det = k11 * k22 - k12 * k12;
100
- const invDet = det !== 0 ? 1 / det : 0;
101
- this._invK11 = invDet * k22;
102
- this._invK12 = -invDet * k12;
103
- this._invK22 = invDet * k11;
104
92
  this._axialMass = iA + iB > 0 ? 1 / (iA + iB) : 0;
105
93
  this._h = h;
106
94
  this._invH = 1 / h;
@@ -118,18 +106,26 @@ var RevoluteJoint = class extends Joint {
118
106
  this._massScale = a2 * a3;
119
107
  this._impulseScale = a3;
120
108
  } else {
121
- this._biasRate = .2 / h;
122
- this._massScale = 1;
123
- this._impulseScale = 0;
109
+ this._biasRate = rigid.biasRate;
110
+ this._massScale = rigid.massScale;
111
+ this._impulseScale = rigid.impulseScale;
124
112
  }
125
113
  }
114
+ /** @internal */
126
115
  _warmStart() {
127
116
  if (!this._active) return;
128
117
  const axial = this._motorImpulse + this._lowerImpulse - this._upperImpulse;
129
118
  this.bodyA.angularVelocity -= this.bodyA.invInertia * axial;
130
119
  this.bodyB.angularVelocity += this.bodyB.invInertia * axial;
131
- this._applyImpulse(this._impulseX, this._impulseY);
120
+ const bodyA = this.bodyA;
121
+ const bodyB = this.bodyB;
122
+ const rotAx = this._rAx * bodyA._deltaCos - this._rAy * bodyA._deltaSin;
123
+ const rotAy = this._rAx * bodyA._deltaSin + this._rAy * bodyA._deltaCos;
124
+ const rotBx = this._rBx * bodyB._deltaCos - this._rBy * bodyB._deltaSin;
125
+ const rotBy = this._rBx * bodyB._deltaSin + this._rBy * bodyB._deltaCos;
126
+ this._applyImpulse(this._impulseX, this._impulseY, rotAx, rotAy, rotBx, rotBy);
132
127
  }
128
+ /** @internal */
133
129
  _solve(useBias) {
134
130
  if (!this._active) return;
135
131
  const bodyA = this.bodyA;
@@ -166,27 +162,40 @@ var RevoluteJoint = class extends Joint {
166
162
  bodyA.angularVelocity += iA * appliedUpper;
167
163
  bodyB.angularVelocity -= iB * appliedUpper;
168
164
  }
169
- const cdotX = bodyB.linearVelocityX - bodyB.angularVelocity * this._rBy - (bodyA.linearVelocityX - bodyA.angularVelocity * this._rAy);
170
- const cdotY = bodyB.linearVelocityY + bodyB.angularVelocity * this._rBx - (bodyA.linearVelocityY + bodyA.angularVelocity * this._rAx);
171
- const rhsX = cdotX + (useBias ? this._biasRate * this._cx : 0);
172
- const rhsY = cdotY + (useBias ? this._biasRate * this._cy : 0);
173
- const solvedX = this._invK11 * rhsX + this._invK12 * rhsY;
174
- const solvedY = this._invK12 * rhsX + this._invK22 * rhsY;
165
+ const rotAx = this._rAx * bodyA._deltaCos - this._rAy * bodyA._deltaSin;
166
+ const rotAy = this._rAx * bodyA._deltaSin + this._rAy * bodyA._deltaCos;
167
+ const rotBx = this._rBx * bodyB._deltaCos - this._rBy * bodyB._deltaSin;
168
+ const rotBy = this._rBx * bodyB._deltaSin + this._rBy * bodyB._deltaCos;
169
+ const cx = this._c0x + (bodyB._deltaPosX + rotBx - this._rBx) - (bodyA._deltaPosX + rotAx - this._rAx);
170
+ const cy = this._c0y + (bodyB._deltaPosY + rotBy - this._rBy) - (bodyA._deltaPosY + rotAy - this._rAy);
171
+ const mA = bodyA.invMass;
172
+ const mB = bodyB.invMass;
173
+ const k11 = mA + mB + iA * rotAy * rotAy + iB * rotBy * rotBy;
174
+ const k12 = -iA * rotAx * rotAy - iB * rotBx * rotBy;
175
+ const k22 = mA + mB + iA * rotAx * rotAx + iB * rotBx * rotBx;
176
+ const det = k11 * k22 - k12 * k12;
177
+ const invDet = det !== 0 ? 1 / det : 0;
178
+ const cdotX = bodyB.linearVelocityX - bodyB.angularVelocity * rotBy - (bodyA.linearVelocityX - bodyA.angularVelocity * rotAy);
179
+ const cdotY = bodyB.linearVelocityY + bodyB.angularVelocity * rotBx - (bodyA.linearVelocityY + bodyA.angularVelocity * rotAx);
180
+ const rhsX = cdotX + (useBias ? this._biasRate * cx : 0);
181
+ const rhsY = cdotY + (useBias ? this._biasRate * cy : 0);
182
+ const solvedX = invDet * (k22 * rhsX - k12 * rhsY);
183
+ const solvedY = invDet * (k11 * rhsY - k12 * rhsX);
175
184
  const impulseX = -this._massScale * solvedX - this._impulseScale * this._impulseX;
176
185
  const impulseY = -this._massScale * solvedY - this._impulseScale * this._impulseY;
177
186
  this._impulseX += impulseX;
178
187
  this._impulseY += impulseY;
179
- this._applyImpulse(impulseX, impulseY);
188
+ this._applyImpulse(impulseX, impulseY, rotAx, rotAy, rotBx, rotBy);
180
189
  }
181
- _applyImpulse(jx, jy) {
190
+ _applyImpulse(jx, jy, rAx, rAy, rBx, rBy) {
182
191
  const bodyA = this.bodyA;
183
192
  const bodyB = this.bodyB;
184
193
  bodyA.linearVelocityX -= bodyA.invMass * jx;
185
194
  bodyA.linearVelocityY -= bodyA.invMass * jy;
186
- bodyA.angularVelocity -= bodyA.invInertia * (this._rAx * jy - this._rAy * jx);
195
+ bodyA.angularVelocity -= bodyA.invInertia * (rAx * jy - rAy * jx);
187
196
  bodyB.linearVelocityX += bodyB.invMass * jx;
188
197
  bodyB.linearVelocityY += bodyB.invMass * jy;
189
- bodyB.angularVelocity += bodyB.invInertia * (this._rBx * jy - this._rBy * jx);
198
+ bodyB.angularVelocity += bodyB.invInertia * (rBx * jy - rBy * jx);
190
199
  }
191
200
  };
192
201
 
@@ -1 +1 @@
1
- {"version":3,"file":"RevoluteJoint.js","names":[],"sources":["../../../src/joints/RevoluteJoint.ts"],"sourcesContent":["import type { PointLike } from '@codexo/exojs';\n\nimport { applyInverseTransform, applyTransform } from '../math';\nimport type { PhysicsBody } from '../PhysicsBody';\nimport { Joint } from './Joint';\n\n/** Construction options for a {@link RevoluteJoint}. */\nexport interface RevoluteJointOptions {\n /** First body (often a static anchor). */\n bodyA: PhysicsBody;\n /** Second body. */\n bodyB: PhysicsBody;\n /** Shared world-space pivot point at creation. The two bodies are pinned here and may rotate freely about it. */\n anchor: Readonly<PointLike>;\n /** Soft-spring frequency in Hz; `0` (default) makes it a rigid pin. */\n hertz?: number;\n /** Soft-spring damping ratio (used when `hertz > 0`). Default `1`. */\n dampingRatio?: number;\n /** Enable the angular motor (drives `ωB − ωA` toward {@link motorSpeed}). Default `false`. */\n enableMotor?: boolean;\n /** Target relative angular velocity in rad/s when the motor is enabled. Default `0`. */\n motorSpeed?: number;\n /** Maximum motor torque - clamps the per-step motor impulse. Default `0`. */\n maxMotorTorque?: number;\n /** Enable the angle limit (keeps the relative angle in `[lowerAngle, upperAngle]`). Default `false`. */\n enableLimit?: boolean;\n /** Lower relative-angle limit in radians (relative to the angle at creation). Default `0`. */\n lowerAngle?: number;\n /** Upper relative-angle limit in radians. Default `0`. */\n upperAngle?: number;\n}\n\n/** Reused output sink - physics steps single-threaded, so a shared scratch is safe. */\nconst scratch: PointLike = { x: 0, y: 0 };\n\n/**\n * Pins a shared anchor point on two bodies (a hinge): the bodies may rotate\n * freely about the pivot but the anchor points stay coincident. Solved as a\n * 2-DOF point constraint (a 2×2 block) in the sub-step loop, warm-started.\n */\nexport class RevoluteJoint extends Joint {\n /** Soft-spring frequency in Hz (`0` = rigid). */\n public hertz: number;\n /** Soft-spring damping ratio. */\n public dampingRatio: number;\n /** When `true`, the motor drives `ωB − ωA` toward {@link motorSpeed}. */\n public enableMotor: boolean;\n /** Target relative angular velocity (rad/s) for the motor. */\n public motorSpeed: number;\n /** Maximum motor torque. */\n public maxMotorTorque: number;\n /** When `true`, the relative angle is constrained to `[lowerAngle, upperAngle]`. */\n public enableLimit: boolean;\n /** Lower relative-angle limit (radians, relative to the creation angle). */\n public lowerAngle: number;\n /** Upper relative-angle limit (radians). */\n public upperAngle: number;\n\n private readonly _localAnchorAx: number;\n private readonly _localAnchorAy: number;\n private readonly _localAnchorBx: number;\n private readonly _localAnchorBy: number;\n\n private _rAx = 0;\n private _rAy = 0;\n private _rBx = 0;\n private _rBy = 0;\n private _cx = 0;\n private _cy = 0;\n private _invK11 = 0;\n private _invK12 = 0;\n private _invK22 = 0;\n private _biasRate = 0;\n private _massScale = 1;\n private _impulseScale = 0;\n private _impulseX = 0;\n private _impulseY = 0;\n private readonly _referenceAngle: number;\n private _axialMass = 0;\n private _h = 0;\n private _invH = 0;\n private _motorImpulse = 0;\n private _lowerImpulse = 0;\n private _upperImpulse = 0;\n\n public constructor(options: RevoluteJointOptions) {\n super(options.bodyA, options.bodyB);\n\n applyInverseTransform(options.bodyA.transform, options.anchor.x, options.anchor.y, scratch);\n this._localAnchorAx = scratch.x;\n this._localAnchorAy = scratch.y;\n applyInverseTransform(options.bodyB.transform, options.anchor.x, options.anchor.y, scratch);\n this._localAnchorBx = scratch.x;\n this._localAnchorBy = scratch.y;\n\n this.hertz = options.hertz ?? 0;\n this.dampingRatio = options.dampingRatio ?? 1;\n this.enableMotor = options.enableMotor ?? false;\n this.motorSpeed = options.motorSpeed ?? 0;\n this.maxMotorTorque = options.maxMotorTorque ?? 0;\n this.enableLimit = options.enableLimit ?? false;\n this.lowerAngle = options.lowerAngle ?? 0;\n this.upperAngle = options.upperAngle ?? 0;\n this._referenceAngle = options.bodyB.angle - options.bodyA.angle;\n }\n\n public override _prepare(h: number): void {\n const bodyA = this.bodyA;\n const bodyB = this.bodyB;\n\n this._active = this.enabled && !bodyA.isSleeping && !bodyB.isSleeping && (bodyA.invMass > 0 || bodyB.invMass > 0);\n\n if (!this._active) {\n return;\n }\n\n applyTransform(bodyA.transform, this._localAnchorAx, this._localAnchorAy, scratch);\n const pAx = scratch.x;\n const pAy = scratch.y;\n applyTransform(bodyB.transform, this._localAnchorBx, this._localAnchorBy, scratch);\n const pBx = scratch.x;\n const pBy = scratch.y;\n\n this._rAx = pAx - bodyA.worldCenterOfMassX;\n this._rAy = pAy - bodyA.worldCenterOfMassY;\n this._rBx = pBx - bodyB.worldCenterOfMassX;\n this._rBy = pBy - bodyB.worldCenterOfMassY;\n\n // Position error (the anchors should coincide).\n this._cx = pBx - pAx;\n this._cy = pBy - pAy;\n\n const mA = bodyA.invMass;\n const mB = bodyB.invMass;\n const iA = bodyA.invInertia;\n const iB = bodyB.invInertia;\n\n // 2×2 effective-mass matrix K and its inverse.\n const k11 = mA + mB + iA * this._rAy * this._rAy + iB * this._rBy * this._rBy;\n const k12 = -iA * this._rAx * this._rAy - iB * this._rBx * this._rBy;\n const k22 = mA + mB + iA * this._rAx * this._rAx + iB * this._rBx * this._rBx;\n const det = k11 * k22 - k12 * k12;\n const invDet = det !== 0 ? 1 / det : 0;\n\n this._invK11 = invDet * k22;\n this._invK12 = -invDet * k12;\n this._invK22 = invDet * k11;\n\n // Angular (motor/limit) effective mass + sub-step rate.\n this._axialMass = iA + iB > 0 ? 1 / (iA + iB) : 0;\n this._h = h;\n this._invH = 1 / h;\n\n if (!this.enableMotor) {\n this._motorImpulse = 0;\n }\n\n if (!this.enableLimit) {\n this._lowerImpulse = 0;\n this._upperImpulse = 0;\n }\n\n if (this.hertz > 0) {\n const omega = 2 * Math.PI * this.hertz;\n const a1 = 2 * this.dampingRatio + h * omega;\n const a2 = h * omega * a1;\n const a3 = 1 / (1 + a2);\n\n this._biasRate = omega / a1;\n this._massScale = a2 * a3;\n this._impulseScale = a3;\n } else {\n this._biasRate = 0.2 / h;\n this._massScale = 1;\n this._impulseScale = 0;\n }\n }\n\n public override _warmStart(): void {\n if (!this._active) {\n return;\n }\n\n // Angular warm-start: motor + limits (lower pushes +, upper pushes −).\n const axial = this._motorImpulse + this._lowerImpulse - this._upperImpulse;\n this.bodyA.angularVelocity -= this.bodyA.invInertia * axial;\n this.bodyB.angularVelocity += this.bodyB.invInertia * axial;\n\n this._applyImpulse(this._impulseX, this._impulseY);\n }\n\n public override _solve(useBias: boolean): void {\n if (!this._active) {\n return;\n }\n\n const bodyA = this.bodyA;\n const bodyB = this.bodyB;\n const iA = bodyA.invInertia;\n const iB = bodyB.invInertia;\n\n // Angular motor: drive ωB − ωA toward motorSpeed, clamped to ±maxMotorTorque·h.\n if (this.enableMotor) {\n const cdot = bodyB.angularVelocity - bodyA.angularVelocity - this.motorSpeed;\n const max = this.maxMotorTorque * this._h;\n const old = this._motorImpulse;\n\n this._motorImpulse = Math.min(max, Math.max(-max, old - this._axialMass * cdot));\n\n const applied = this._motorImpulse - old;\n bodyA.angularVelocity -= iA * applied;\n bodyB.angularVelocity += iB * applied;\n }\n\n // Angle limits: one-sided constraints keeping the relative angle in [lower, upper].\n if (this.enableLimit) {\n const angle = bodyB.angle + bodyB._deltaAngle - (bodyA.angle + bodyA._deltaAngle) - this._referenceAngle;\n\n // Lower limit (angle ≥ lowerAngle): a positive impulse increases the angle.\n const cLower = angle - this.lowerAngle;\n let biasLower = 0;\n\n if (cLower > 0) {\n biasLower = cLower * this._invH; // speculative: allow approach, engage at the surface\n } else if (useBias) {\n biasLower = 0.2 * this._invH * cLower; // Baumgarte push-back when violated\n }\n\n const oldLower = this._lowerImpulse;\n this._lowerImpulse = Math.max(0, oldLower - this._axialMass * (bodyB.angularVelocity - bodyA.angularVelocity + biasLower));\n\n const appliedLower = this._lowerImpulse - oldLower;\n bodyA.angularVelocity -= iA * appliedLower;\n bodyB.angularVelocity += iB * appliedLower;\n\n // Upper limit (angle ≤ upperAngle): a positive impulse decreases the angle.\n const cUpper = this.upperAngle - angle;\n let biasUpper = 0;\n\n if (cUpper > 0) {\n biasUpper = cUpper * this._invH;\n } else if (useBias) {\n biasUpper = 0.2 * this._invH * cUpper;\n }\n\n const oldUpper = this._upperImpulse;\n this._upperImpulse = Math.max(0, oldUpper - this._axialMass * (bodyA.angularVelocity - bodyB.angularVelocity + biasUpper));\n\n const appliedUpper = this._upperImpulse - oldUpper;\n bodyA.angularVelocity += iA * appliedUpper;\n bodyB.angularVelocity -= iB * appliedUpper;\n }\n\n // Relative velocity of the anchors.\n const cdotX = bodyB.linearVelocityX - bodyB.angularVelocity * this._rBy - (bodyA.linearVelocityX - bodyA.angularVelocity * this._rAy);\n const cdotY = bodyB.linearVelocityY + bodyB.angularVelocity * this._rBx - (bodyA.linearVelocityY + bodyA.angularVelocity * this._rAx);\n\n const rhsX = cdotX + (useBias ? this._biasRate * this._cx : 0);\n const rhsY = cdotY + (useBias ? this._biasRate * this._cy : 0);\n\n // Solve K·λ = −rhs, then apply the soft mass/impulse scaling.\n const solvedX = this._invK11 * rhsX + this._invK12 * rhsY;\n const solvedY = this._invK12 * rhsX + this._invK22 * rhsY;\n const impulseX = -this._massScale * solvedX - this._impulseScale * this._impulseX;\n const impulseY = -this._massScale * solvedY - this._impulseScale * this._impulseY;\n\n this._impulseX += impulseX;\n this._impulseY += impulseY;\n this._applyImpulse(impulseX, impulseY);\n }\n\n private _applyImpulse(jx: number, jy: number): void {\n const bodyA = this.bodyA;\n const bodyB = this.bodyB;\n\n bodyA.linearVelocityX -= bodyA.invMass * jx;\n bodyA.linearVelocityY -= bodyA.invMass * jy;\n bodyA.angularVelocity -= bodyA.invInertia * (this._rAx * jy - this._rAy * jx);\n bodyB.linearVelocityX += bodyB.invMass * jx;\n bodyB.linearVelocityY += bodyB.invMass * jy;\n bodyB.angularVelocity += bodyB.invInertia * (this._rBx * jy - this._rBy * jx);\n }\n}\n"],"mappings":";;;;;AAiCA,MAAM,UAAqB;CAAE,GAAG;CAAG,GAAG;AAAE;;;;;;AAOxC,IAAa,gBAAb,cAAmC,MAAM;;CAEvC,AAAO;;CAEP,AAAO;;CAEP,AAAO;;CAEP,AAAO;;CAEP,AAAO;;CAEP,AAAO;;CAEP,AAAO;;CAEP,AAAO;CAEP,AAAiB;CACjB,AAAiB;CACjB,AAAiB;CACjB,AAAiB;CAEjB,AAAQ,OAAO;CACf,AAAQ,OAAO;CACf,AAAQ,OAAO;CACf,AAAQ,OAAO;CACf,AAAQ,MAAM;CACd,AAAQ,MAAM;CACd,AAAQ,UAAU;CAClB,AAAQ,UAAU;CAClB,AAAQ,UAAU;CAClB,AAAQ,YAAY;CACpB,AAAQ,aAAa;CACrB,AAAQ,gBAAgB;CACxB,AAAQ,YAAY;CACpB,AAAQ,YAAY;CACpB,AAAiB;CACjB,AAAQ,aAAa;CACrB,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ints/RevoluteJoint.ts"],"sourcesContent":["import type { PointLike } from '@codexo/exojs';\n\nimport { applyInverseTransform, applyTransform } from '../math';\nimport type { PhysicsBody } from '../PhysicsBody';\nimport type { JointOptions, JointSoftness } from './Joint';\nimport { Joint } from './Joint';\n\n/** Construction options for a {@link RevoluteJoint}. */\nexport interface RevoluteJointOptions extends JointOptions {\n /** First body (often a static anchor). */\n bodyA: PhysicsBody;\n /** Second body. */\n bodyB: PhysicsBody;\n /** Shared world-space pivot point at creation. The two bodies are pinned here and may rotate freely about it. */\n anchor: Readonly<PointLike>;\n /** Soft-spring frequency in Hz; `0` (default) makes it a rigid pin. */\n hertz?: number;\n /** Soft-spring damping ratio (used when `hertz > 0`). Default `1`. */\n dampingRatio?: number;\n /** Enable the angular motor (drives `ωB − ωA` toward {@link motorSpeed}). Default `false`. */\n enableMotor?: boolean;\n /** Target relative angular velocity in rad/s when the motor is enabled. Default `0`. */\n motorSpeed?: number;\n /** Maximum motor torque - clamps the per-step motor impulse. Default `0`. */\n maxMotorTorque?: number;\n /** Enable the angle limit (keeps the relative angle in `[lowerAngle, upperAngle]`). Default `false`. */\n enableLimit?: boolean;\n /** Lower relative-angle limit in radians (relative to the angle at creation). Default `0`. */\n lowerAngle?: number;\n /** Upper relative-angle limit in radians. Default `0`. */\n upperAngle?: number;\n}\n\n/** Reused output sink - physics steps single-threaded, so a shared scratch is safe. */\nconst scratch: PointLike = { x: 0, y: 0 };\n\n/**\n * Pins a shared anchor point on two bodies (a hinge): the bodies may rotate\n * freely about the pivot but the anchor points stay coincident. Solved as a\n * 2-DOF point constraint (a 2×2 block) in the sub-step loop, warm-started.\n */\nexport class RevoluteJoint extends Joint {\n /** Soft-spring frequency in Hz (`0` = rigid). */\n public hertz: number;\n /** Soft-spring damping ratio. */\n public dampingRatio: number;\n /** When `true`, the motor drives `ωB − ωA` toward {@link motorSpeed}. */\n public enableMotor: boolean;\n /** Target relative angular velocity (rad/s) for the motor. */\n public motorSpeed: number;\n /** Maximum motor torque. */\n public maxMotorTorque: number;\n /** When `true`, the relative angle is constrained to `[lowerAngle, upperAngle]`. */\n public enableLimit: boolean;\n /** Lower relative-angle limit (radians, relative to the creation angle). */\n public lowerAngle: number;\n /** Upper relative-angle limit (radians). */\n public upperAngle: number;\n\n private readonly _localAnchorAx: number;\n private readonly _localAnchorAy: number;\n private readonly _localAnchorBx: number;\n private readonly _localAnchorBy: number;\n\n private _rAx = 0;\n private _rAy = 0;\n private _rBx = 0;\n private _rBy = 0;\n private _c0x = 0;\n private _c0y = 0;\n private _biasRate = 0;\n private _massScale = 1;\n private _impulseScale = 0;\n private _impulseX = 0;\n private _impulseY = 0;\n private readonly _referenceAngle: number;\n private _axialMass = 0;\n private _h = 0;\n private _invH = 0;\n private _motorImpulse = 0;\n private _lowerImpulse = 0;\n private _upperImpulse = 0;\n\n public constructor(options: RevoluteJointOptions) {\n super(options.bodyA, options.bodyB, options.collideConnected);\n\n applyInverseTransform(options.bodyA.transform, options.anchor.x, options.anchor.y, scratch);\n this._localAnchorAx = scratch.x;\n this._localAnchorAy = scratch.y;\n applyInverseTransform(options.bodyB.transform, options.anchor.x, options.anchor.y, scratch);\n this._localAnchorBx = scratch.x;\n this._localAnchorBy = scratch.y;\n\n this.hertz = options.hertz ?? 0;\n this.dampingRatio = options.dampingRatio ?? 1;\n this.enableMotor = options.enableMotor ?? false;\n this.motorSpeed = options.motorSpeed ?? 0;\n this.maxMotorTorque = options.maxMotorTorque ?? 0;\n this.enableLimit = options.enableLimit ?? false;\n this.lowerAngle = options.lowerAngle ?? 0;\n this.upperAngle = options.upperAngle ?? 0;\n this._referenceAngle = options.bodyB.angle - options.bodyA.angle;\n }\n\n /** @internal */\n public override _prepare(h: number, rigid: JointSoftness): void {\n const bodyA = this.bodyA;\n const bodyB = this.bodyB;\n\n this._active = this.enabled && !bodyA.isSleeping && !bodyB.isSleeping && (bodyA.invMass > 0 || bodyB.invMass > 0);\n\n if (!this._active) {\n return;\n }\n\n applyTransform(bodyA.transform, this._localAnchorAx, this._localAnchorAy, scratch);\n const pAx = scratch.x;\n const pAy = scratch.y;\n applyTransform(bodyB.transform, this._localAnchorBx, this._localAnchorBy, scratch);\n const pBx = scratch.x;\n const pBy = scratch.y;\n\n // Frame-start arms and anchor error. Both are the BASE the sub-step solve\n // advances from; neither is used directly as the constraint's current state.\n this._rAx = pAx - bodyA.worldCenterOfMassX;\n this._rAy = pAy - bodyA.worldCenterOfMassY;\n this._rBx = pBx - bodyB.worldCenterOfMassX;\n this._rBy = pBy - bodyB.worldCenterOfMassY;\n this._c0x = pBx - pAx;\n this._c0y = pBy - pAy;\n\n // Angular (motor/limit) effective mass + sub-step rate.\n const iA = bodyA.invInertia;\n const iB = bodyB.invInertia;\n\n this._axialMass = iA + iB > 0 ? 1 / (iA + iB) : 0;\n this._h = h;\n this._invH = 1 / h;\n\n if (!this.enableMotor) {\n this._motorImpulse = 0;\n }\n\n if (!this.enableLimit) {\n this._lowerImpulse = 0;\n this._upperImpulse = 0;\n }\n\n if (this.hertz > 0) {\n const omega = 2 * Math.PI * this.hertz;\n const a1 = 2 * this.dampingRatio + h * omega;\n const a2 = h * omega * a1;\n const a3 = 1 / (1 + a2);\n\n this._biasRate = omega / a1;\n this._massScale = a2 * a3;\n this._impulseScale = a3;\n } else {\n // The solver's own softness, not a raw Baumgarte term. `0.2 / h` turns\n // the whole position error into a bias velocity every sub-step and\n // relaxes none of the impulse behind it; a hanging chain of seven or more\n // links then gains speed without bound along its own axis.\n this._biasRate = rigid.biasRate;\n this._massScale = rigid.massScale;\n this._impulseScale = rigid.impulseScale;\n }\n }\n\n /** @internal */\n public override _warmStart(): void {\n if (!this._active) {\n return;\n }\n\n // Angular warm-start: motor + limits (lower pushes +, upper pushes −).\n const axial = this._motorImpulse + this._lowerImpulse - this._upperImpulse;\n this.bodyA.angularVelocity -= this.bodyA.invInertia * axial;\n this.bodyB.angularVelocity += this.bodyB.invInertia * axial;\n\n const bodyA = this.bodyA;\n const bodyB = this.bodyB;\n const rotAx = this._rAx * bodyA._deltaCos - this._rAy * bodyA._deltaSin;\n const rotAy = this._rAx * bodyA._deltaSin + this._rAy * bodyA._deltaCos;\n const rotBx = this._rBx * bodyB._deltaCos - this._rBy * bodyB._deltaSin;\n const rotBy = this._rBx * bodyB._deltaSin + this._rBy * bodyB._deltaCos;\n\n this._applyImpulse(this._impulseX, this._impulseY, rotAx, rotAy, rotBx, rotBy);\n }\n\n /** @internal */\n public override _solve(useBias: boolean): void {\n if (!this._active) {\n return;\n }\n\n const bodyA = this.bodyA;\n const bodyB = this.bodyB;\n const iA = bodyA.invInertia;\n const iB = bodyB.invInertia;\n\n // Angular motor: drive ωB − ωA toward motorSpeed, clamped to ±maxMotorTorque·h.\n if (this.enableMotor) {\n const cdot = bodyB.angularVelocity - bodyA.angularVelocity - this.motorSpeed;\n const max = this.maxMotorTorque * this._h;\n const old = this._motorImpulse;\n\n this._motorImpulse = Math.min(max, Math.max(-max, old - this._axialMass * cdot));\n\n const applied = this._motorImpulse - old;\n bodyA.angularVelocity -= iA * applied;\n bodyB.angularVelocity += iB * applied;\n }\n\n // Angle limits: one-sided constraints keeping the relative angle in [lower, upper].\n if (this.enableLimit) {\n const angle = bodyB.angle + bodyB._deltaAngle - (bodyA.angle + bodyA._deltaAngle) - this._referenceAngle;\n\n // Lower limit (angle ≥ lowerAngle): a positive impulse increases the angle.\n const cLower = angle - this.lowerAngle;\n let biasLower = 0;\n\n if (cLower > 0) {\n biasLower = cLower * this._invH; // speculative: allow approach, engage at the surface\n } else if (useBias) {\n biasLower = 0.2 * this._invH * cLower; // Baumgarte push-back when violated\n }\n\n const oldLower = this._lowerImpulse;\n this._lowerImpulse = Math.max(0, oldLower - this._axialMass * (bodyB.angularVelocity - bodyA.angularVelocity + biasLower));\n\n const appliedLower = this._lowerImpulse - oldLower;\n bodyA.angularVelocity -= iA * appliedLower;\n bodyB.angularVelocity += iB * appliedLower;\n\n // Upper limit (angle ≤ upperAngle): a positive impulse decreases the angle.\n const cUpper = this.upperAngle - angle;\n let biasUpper = 0;\n\n if (cUpper > 0) {\n biasUpper = cUpper * this._invH;\n } else if (useBias) {\n biasUpper = 0.2 * this._invH * cUpper;\n }\n\n const oldUpper = this._upperImpulse;\n this._upperImpulse = Math.max(0, oldUpper - this._axialMass * (bodyA.angularVelocity - bodyB.angularVelocity + biasUpper));\n\n const appliedUpper = this._upperImpulse - oldUpper;\n bodyA.angularVelocity += iA * appliedUpper;\n bodyB.angularVelocity -= iB * appliedUpper;\n }\n\n /*\n * The point constraint is solved against the geometry as it stands NOW, not\n * as it stood at frame start.\n *\n * Each sub-step moves the bodies, so the arms have rotated and the anchors\n * have separated by a different amount than `_prepare` measured. Applying\n * the frame-start error as the bias in every sub-step re-corrects an error\n * the earlier sub-steps already took out - and with a rigid bias rate of\n * `0.2 / h` that over-correction is an impulse the chain has no way to\n * dissipate. In a serial chain it compounds link by link: a hanging chain\n * of seven or more equal links left to itself gained velocity without\n * bound, purely along its own axis, until it diverged. The contact solver\n * has always advanced its separation this way; the joint now does too.\n */\n const rotAx = this._rAx * bodyA._deltaCos - this._rAy * bodyA._deltaSin;\n const rotAy = this._rAx * bodyA._deltaSin + this._rAy * bodyA._deltaCos;\n const rotBx = this._rBx * bodyB._deltaCos - this._rBy * bodyB._deltaSin;\n const rotBy = this._rBx * bodyB._deltaSin + this._rBy * bodyB._deltaCos;\n\n // Anchor displacement since frame start: linear delta plus the shift the\n // body's own rotation gave the arm.\n const cx = this._c0x + (bodyB._deltaPosX + rotBx - this._rBx) - (bodyA._deltaPosX + rotAx - this._rAx);\n const cy = this._c0y + (bodyB._deltaPosY + rotBy - this._rBy) - (bodyA._deltaPosY + rotAy - this._rAy);\n\n const mA = bodyA.invMass;\n const mB = bodyB.invMass;\n\n // K follows the live arms for the same reason the bias does: an effective\n // mass built from the frame-start geometry solves a different constraint\n // than the one the bias is now asking for.\n const k11 = mA + mB + iA * rotAy * rotAy + iB * rotBy * rotBy;\n const k12 = -iA * rotAx * rotAy - iB * rotBx * rotBy;\n const k22 = mA + mB + iA * rotAx * rotAx + iB * rotBx * rotBx;\n const det = k11 * k22 - k12 * k12;\n const invDet = det !== 0 ? 1 / det : 0;\n\n // Relative velocity of the anchors.\n const cdotX = bodyB.linearVelocityX - bodyB.angularVelocity * rotBy - (bodyA.linearVelocityX - bodyA.angularVelocity * rotAy);\n const cdotY = bodyB.linearVelocityY + bodyB.angularVelocity * rotBx - (bodyA.linearVelocityY + bodyA.angularVelocity * rotAx);\n\n const rhsX = cdotX + (useBias ? this._biasRate * cx : 0);\n const rhsY = cdotY + (useBias ? this._biasRate * cy : 0);\n\n // Solve K·λ = −rhs, then apply the soft mass/impulse scaling.\n const solvedX = invDet * (k22 * rhsX - k12 * rhsY);\n const solvedY = invDet * (k11 * rhsY - k12 * rhsX);\n const impulseX = -this._massScale * solvedX - this._impulseScale * this._impulseX;\n const impulseY = -this._massScale * solvedY - this._impulseScale * this._impulseY;\n\n this._impulseX += impulseX;\n this._impulseY += impulseY;\n this._applyImpulse(impulseX, impulseY, rotAx, rotAy, rotBx, rotBy);\n }\n\n private _applyImpulse(jx: number, jy: number, rAx: number, rAy: number, rBx: number, rBy: number): void {\n const bodyA = this.bodyA;\n const bodyB = this.bodyB;\n\n bodyA.linearVelocityX -= bodyA.invMass * jx;\n bodyA.linearVelocityY -= bodyA.invMass * jy;\n bodyA.angularVelocity -= bodyA.invInertia * (rAx * jy - rAy * jx);\n bodyB.linearVelocityX += bodyB.invMass * jx;\n bodyB.linearVelocityY += bodyB.invMass * jy;\n bodyB.angularVelocity += bodyB.invInertia * (rBx * jy - rBy * jx);\n }\n}\n"],"mappings":";;;;;AAkCA,MAAM,UAAqB;CAAE,GAAG;CAAG,GAAG;AAAE;;;;;;AAOxC,IAAa,gBAAb,cAAmC,MAAM;;CAEvC,AAAO;;CAEP,AAAO;;CAEP,AAAO;;CAEP,AAAO;;CAEP,AAAO;;CAEP,AAAO;;CAEP,AAAO;;CAEP,AAAO;CAEP,AAAiB;CACjB,AA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B,MAAM,kBAAkB;EACvH,MAAM,QAAQ,MAAM,kBAAkB,MAAM,kBAAkB,SAAS,MAAM,kBAAkB,MAAM,kBAAkB;EAEvH,MAAM,OAAO,SAAS,UAAU,KAAK,YAAY,KAAK;EACtD,MAAM,OAAO,SAAS,UAAU,KAAK,YAAY,KAAK;EAGtD,MAAM,UAAU,UAAU,MAAM,OAAO,MAAM;EAC7C,MAAM,UAAU,UAAU,MAAM,OAAO,MAAM;EAC7C,MAAM,WAAW,CAAC,KAAK,aAAa,UAAU,KAAK,gBAAgB,KAAK;EACxE,MAAM,WAAW,CAAC,KAAK,aAAa,UAAU,KAAK,gBAAgB,KAAK;EAExE,KAAK,aAAa;EAClB,KAAK,aAAa;EAClB,KAAK,cAAc,UAAU,UAAU,OAAO,OAAO,OAAO,KAAK;CACnE;CAEA,AAAQ,cAAc,IAAY,IAAY,KAAa,KAAa,KAAa,KAAmB;EACtG,MAAM,QAAQ,KAAK;EACnB,MAAM,QAAQ,KAAK;EAEnB,MAAM,mBAAmB,MAAM,UAAU;EACzC,MAAM,mBAAmB,MAAM,UAAU;EACzC,MAAM,mBAAmB,MAAM,cAAc,MAAM,KAAK,MAAM;EAC9D,MAAM,mBAAmB,MAAM,UAAU;EACzC,MAAM,mBAAmB,MAAM,UAAU;EACzC,MAAM,mBAAmB,MAAM,cAAc,MAAM,KAAK,MAAM;CAChE;AACF"}
@@ -1,8 +1,9 @@
1
1
  import type { PointLike } from '@codexo/exojs';
2
2
  import type { PhysicsBody } from '../PhysicsBody';
3
+ import type { JointOptions } from './Joint';
3
4
  import { Joint } from './Joint';
4
5
  /** Construction options for a {@link WeldJoint}. */
5
- export interface WeldJointOptions {
6
+ export interface WeldJointOptions extends JointOptions {
6
7
  /** First body. */
7
8
  bodyA: PhysicsBody;
8
9
  /** Second body. */
@@ -54,9 +55,6 @@ export declare class WeldJoint extends Joint {
54
55
  private _impulseY;
55
56
  private _impulseAngle;
56
57
  constructor(options: WeldJointOptions);
57
- _prepare(h: number): void;
58
- _warmStart(): void;
59
- _solve(useBias: boolean): void;
60
58
  private _applyLinearImpulse;
61
59
  }
62
60
  //# sourceMappingURL=WeldJoint.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"WeldJoint.d.ts","sourceRoot":"","sources":["../../../src/joints/WeldJoint.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAG/C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAClD,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAEhC,oDAAoD;AACpD,MAAM,WAAW,gBAAgB;IAC/B,kBAAkB;IAClB,KAAK,EAAE,WAAW,CAAC;IACnB,mBAAmB;IACnB,KAAK,EAAE,WAAW,CAAC;IACnB,iGAAiG;IACjG,MAAM,CAAC,EAAE,QAAQ,CAAC,SAAS,CAAC,CAAC;IAC7B,gGAAgG;IAChG,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,yEAAyE;IACzE,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,sEAAsE;IACtE,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,oEAAoE;IACpE,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AA6BD;;;;;GAKG;AACH,qBAAa,SAAU,SAAQ,KAAK;IAClC,+CAA+C;IACxC,cAAc,EAAE,MAAM,CAAC;IAC9B,0DAA0D;IACnD,WAAW,EAAE,MAAM,CAAC;IAC3B,uDAAuD;IAChD,YAAY,EAAE,MAAM,CAAC;IAC5B,0BAA0B;IACnB,YAAY,EAAE,MAAM,CAAC;IAE5B,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAS;IACxC,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAS;IACxC,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAS;IACxC,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAS;IAExC,OAAO,CAAC,IAAI,CAAK;IACjB,OAAO,CAAC,I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id Baumgarte when `hertz === 0`. */
11
- const computeSoftFactors = (hertz, dampingRatio, h, out) => {
10
+ /** Soft-constraint factors at sub-step `h`, or the solver's own rigid factors when `hertz === 0`. */
11
+ const computeSoftFactors = (hertz, dampingRatio, h, rigid, out) => {
12
12
  if (hertz > 0) {
13
13
  const omega = 2 * Math.PI * hertz;
14
14
  const a1 = 2 * dampingRatio + h * omega;
@@ -18,9 +18,9 @@ const computeSoftFactors = (hertz, dampingRatio, h, out) => {
18
18
  out.massScale = a2 * a3;
19
19
  out.impulseScale = a3;
20
20
  } else {
21
- out.biasRate = .2 / h;
22
- out.massScale = 1;
23
- out.impulseScale = 0;
21
+ out.biasRate = rigid.biasRate;
22
+ out.massScale = rigid.massScale;
23
+ out.impulseScale = rigid.impulseScale;
24
24
  }
25
25
  };
26
26
  /**
@@ -67,7 +67,7 @@ var WeldJoint = class extends Joint {
67
67
  _impulseY = 0;
68
68
  _impulseAngle = 0;
69
69
  constructor(options) {
70
- super(options.bodyA, options.bodyB);
70
+ super(options.bodyA, options.bodyB, options.collideConnected);
71
71
  const ax = options.anchor?.x ?? (options.bodyA.x + options.bodyB.x) / 2;
72
72
  const ay = options.anchor?.y ?? (options.bodyA.y + options.bodyB.y) / 2;
73
73
  applyInverseTransform(options.bodyA.transform, ax, ay, scratch);
@@ -81,7 +81,8 @@ var WeldJoint = class extends Joint {
81
81
  this.angularHertz = options.angularHertz ?? 0;
82
82
  this.dampingRatio = options.dampingRatio ?? 1;
83
83
  }
84
- _prepare(h) {
84
+ /** @internal */
85
+ _prepare(h, rigid) {
85
86
  const bodyA = this.bodyA;
86
87
  const bodyB = this.bodyB;
87
88
  this._active = this.enabled && !bodyA.isSleeping && !bodyB.isSleeping && (bodyA.invMass > 0 || bodyB.invMass > 0);
@@ -113,9 +114,10 @@ var WeldJoint = class extends Joint {
113
114
  this._angleError = bodyB.angle - bodyA.angle - this.referenceAngle;
114
115
  const kAngle = iA + iB;
115
116
  this._effMassAngle = kAngle > 0 ? 1 / kAngle : 0;
116
- computeSoftFactors(this.linearHertz, this.dampingRatio, h, this._linear);
117
- computeSoftFactors(this.angularHertz, this.dampingRatio, h, this._angular);
117
+ computeSoftFactors(this.linearHertz, this.dampingRatio, h, rigid, this._linear);
118
+ computeSoftFactors(this.angularHertz, this.dampingRatio, h, rigid, this._angular);
118
119
  }
120
+ /** @internal */
119
121
  _warmStart() {
120
122
  if (!this._active) return;
121
123
  const bodyA = this.bodyA;
@@ -124,6 +126,7 @@ var WeldJoint = class extends Joint {
124
126
  bodyB.angularVelocity += bodyB.invInertia * this._impulseAngle;
125
127
  this._applyLinearImpulse(this._impulseX, this._impulseY);
126
128
  }
129
+ /** @internal */
127
130
  _solve(useBias) {
128
131
  if (!this._active) return;
129
132
  const bodyA = this.bodyA;
@@ -1 +1 @@
1
- {"version":3,"file":"WeldJoint.js","names":[],"sources":["../../../src/joints/WeldJoint.ts"],"sourcesContent":["import type { PointLike } from '@codexo/exojs';\n\nimport { applyInverseTransform, applyTransform } from '../math';\nimport type { PhysicsBody } from '../PhysicsBody';\nimport { Joint } from './Joint';\n\n/** Construction options for a {@link WeldJoint}. */\nexport interface WeldJointOptions {\n /** First body. */\n bodyA: PhysicsBody;\n /** Second body. */\n bodyB: PhysicsBody;\n /** World-space anchor the linear constraint acts at. Default: the midpoint of the two bodies. */\n anchor?: Readonly<PointLike>;\n /** Locked relative angle `angleB − angleA`. Default: the current relative angle at creation. */\n referenceAngle?: number;\n /** Soft frequency (Hz) for the position lock; `0` (default) is rigid. */\n linearHertz?: number;\n /** Soft frequency (Hz) for the angle lock; `0` (default) is rigid. */\n angularHertz?: number;\n /** Soft damping ratio (used when a hertz is `> 0`). Default `1`. */\n dampingRatio?: number;\n}\n\n/** Reused output sink - physics steps single-threaded, so a shared scratch is safe. */\nconst scratch: PointLike = { x: 0, y: 0 };\n\ninterface SoftFactors {\n biasRate: number;\n massScale: number;\n impulseScale: number;\n}\n\n/** Box2D-v3 soft-constraint factors at sub-step `h`, or rigid Baumgarte when `hertz === 0`. */\nconst computeSoftFactors = (hertz: number, dampingRatio: number, h: number, out: SoftFactors): void => {\n if (hertz > 0) {\n const omega = 2 * Math.PI * hertz;\n const a1 = 2 * dampingRatio + h * omega;\n const a2 = h * omega * a1;\n const a3 = 1 / (1 + a2);\n\n out.biasRate = omega / a1;\n out.massScale = a2 * a3;\n out.impulseScale = a3;\n } else {\n out.biasRate = 0.2 / h;\n out.massScale = 1;\n out.impulseScale = 0;\n }\n};\n\n/**\n * Rigidly fixes the relative position and orientation of two bodies (they move\n * as one rigid body). A 2-DOF point constraint (like {@link RevoluteJoint}) plus\n * a 1-DOF angular constraint, solved in the sub-step loop. Both locks default to\n * rigid; set `linearHertz`/`angularHertz` for a springy weld.\n */\nexport class WeldJoint extends Joint {\n /** Locked relative angle `angleB − angleA`. */\n public referenceAngle: number;\n /** Soft frequency for the position lock (`0` = rigid). */\n public linearHertz: number;\n /** Soft frequency for the angle lock (`0` = rigid). */\n public angularHertz: number;\n /** Soft damping ratio. */\n public dampingRatio: number;\n\n private readonly _localAnchorAx: number;\n private readonly _localAnchorAy: number;\n private readonly _localAnchorBx: number;\n private readonly _localAnchorBy: number;\n\n private _rAx = 0;\n private _rAy = 0;\n private _rBx = 0;\n private _rBy = 0;\n private _cx = 0;\n private _cy = 0;\n private _invK11 = 0;\n private _invK12 = 0;\n private _invK22 = 0;\n private _angleError = 0;\n private _effMassAngle = 0;\n private readonly _linear: SoftFactors = { biasRate: 0, massScale: 1, impulseScale: 0 };\n private readonly _angular: SoftFactors = { biasRate: 0, massScale: 1, impulseScale: 0 };\n private _impulseX = 0;\n private _impulseY = 0;\n private _impulseAngle = 0;\n\n public constructor(options: WeldJointOptions) {\n super(options.bodyA, options.bodyB);\n\n const ax = options.anchor?.x ?? (options.bodyA.x + options.bodyB.x) / 2;\n const ay = options.anchor?.y ?? (options.bodyA.y + options.bodyB.y) / 2;\n\n applyInverseTransform(options.bodyA.transform, ax, ay, scratch);\n this._localAnchorAx = scratch.x;\n this._localAnchorAy = scratch.y;\n applyInverseTransform(options.bodyB.transform, ax, ay, scratch);\n this._localAnchorBx = scratch.x;\n this._localAnchorBy = scratch.y;\n\n this.referenceAngle = options.referenceAngle ?? options.bodyB.angle - options.bodyA.angle;\n this.linearHertz = options.linearHertz ?? 0;\n this.angularHertz = options.angularHertz ?? 0;\n this.dampingRatio = options.dampingRatio ?? 1;\n }\n\n public override _prepare(h: number): void {\n const bodyA = this.bodyA;\n const bodyB = this.bodyB;\n\n this._active = this.enabled && !bodyA.isSleeping && !bodyB.isSleeping && (bodyA.invMass > 0 || bodyB.invMass > 0);\n\n if (!this._active) {\n return;\n }\n\n applyTransform(bodyA.transform, this._localAnchorAx, this._localAnchorAy, scratch);\n const pAx = scratch.x;\n const pAy = scratch.y;\n applyTransform(bodyB.transform, this._localAnchorBx, this._localAnchorBy, scratch);\n const pBx = scratch.x;\n const pBy = scratch.y;\n\n this._rAx = pAx - bodyA.worldCenterOfMassX;\n this._rAy = pAy - bodyA.worldCenterOfMassY;\n this._rBx = pBx - bodyB.worldCenterOfMassX;\n this._rBy = pBy - bodyB.worldCenterOfMassY;\n this._cx = pBx - pAx;\n this._cy = pBy - pAy;\n\n const mA = bodyA.invMass;\n const mB = bodyB.invMass;\n const iA = bodyA.invInertia;\n const iB = bodyB.invInertia;\n\n const k11 = mA + mB + iA * this._rAy * this._rAy + iB * this._rBy * this._rBy;\n const k12 = -iA * this._rAx * this._rAy - iB * this._rBx * this._rBy;\n const k22 = mA + mB + iA * this._rAx * this._rAx + iB * this._rBx * this._rBx;\n const det = k11 * k22 - k12 * k12;\n const invDet = det !== 0 ? 1 / det : 0;\n\n this._invK11 = invDet * k22;\n this._invK12 = -invDet * k12;\n this._invK22 = invDet * k11;\n\n this._angleError = bodyB.angle - bodyA.angle - this.referenceAngle;\n const kAngle = iA + iB;\n this._effMassAngle = kAngle > 0 ? 1 / kAngle : 0;\n\n computeSoftFactors(this.linearHertz, this.dampingRatio, h, this._linear);\n computeSoftFactors(this.angularHertz, this.dampingRatio, h, this._angular);\n }\n\n public override _warmStart(): void {\n if (!this._active) {\n return;\n }\n\n const bodyA = this.bodyA;\n const bodyB = this.bodyB;\n\n bodyA.angularVelocity -= bodyA.invInertia * this._impulseAngle;\n bodyB.angularVelocity += bodyB.invInertia * this._impulseAngle;\n this._applyLinearImpulse(this._impulseX, this._impulseY);\n }\n\n public override _solve(useBias: boolean): void {\n if (!this._active) {\n return;\n }\n\n const bodyA = this.bodyA;\n const bodyB = this.bodyB;\n\n // Angular lock first.\n const cdotAngle = bodyB.angularVelocity - bodyA.angularVelocity;\n const biasAngle = useBias ? this._angular.biasRate * this._angleError : 0;\n const impulseAngle = -this._effMassAngle * this._angular.massScale * (cdotAngle + biasAngle) - this._angular.impulseScale * this._impulseAngle;\n\n this._impulseAngle += impulseAngle;\n bodyA.angularVelocity -= bodyA.invInertia * impulseAngle;\n bodyB.angularVelocity += bodyB.invInertia * impulseAngle;\n\n // Linear (point) lock.\n const cdotX = bodyB.linearVelocityX - bodyB.angularVelocity * this._rBy - (bodyA.linearVelocityX - bodyA.angularVelocity * this._rAy);\n const cdotY = bodyB.linearVelocityY + bodyB.angularVelocity * this._rBx - (bodyA.linearVelocityY + bodyA.angularVelocity * this._rAx);\n const rhsX = cdotX + (useBias ? this._linear.biasRate * this._cx : 0);\n const rhsY = cdotY + (useBias ? this._linear.biasRate * this._cy : 0);\n const solvedX = this._invK11 * rhsX + this._invK12 * rhsY;\n const solvedY = this._invK12 * rhsX + this._invK22 * rhsY;\n const impulseX = -this._linear.massScale * solvedX - this._linear.impulseScale * this._impulseX;\n const impulseY = -this._linear.massScale * solvedY - this._linear.impulseScale * this._impulseY;\n\n this._impulseX += impulseX;\n this._impulseY += impulseY;\n this._applyLinearImpulse(impulseX, impulseY);\n }\n\n private _applyLinearImpulse(jx: number, jy: number): void {\n const bodyA = this.bodyA;\n const bodyB = this.bodyB;\n\n bodyA.linearVelocityX -= bodyA.invMass * jx;\n bodyA.linearVelocityY -= bodyA.invMass * jy;\n bodyA.angularVelocity -= bodyA.invInertia * (this._rAx * jy - this._rAy * jx);\n bodyB.linearVelocityX += bodyB.invMass * jx;\n bodyB.linearVelocityY += bodyB.invMass * jy;\n bodyB.angularVelocity += bodyB.invInertia * (this._rBx * jy - this._rBy * jx);\n }\n}\n"],"mappings":";;;;;AAyBA,MAAM,UAAqB;CAAE,GAAG;CAAG,GAAG;AAAE;;AASxC,MAAM,sBAAsB,OAAe,cAAsB,GAAW,QAA2B;CACrG,IAAI,QAAQ,GAAG;EACb,MAAM,QAAQ,IAAI,KAAK,KAAK;EAC5B,MAAM,KAAK,IAAI,eAAe,IAAI;EAClC,MAAM,KAAK,IAAI,QAAQ;EACvB,MAAM,KAAK,KAAK,IAAI;EAEpB,IAAI,WAAW,QAAQ;EACvB,IAAI,YAAY,KAAK;EACrB,IAAI,eAAe;CACrB,OAAO;EACL,IAAI,WAAW,KAAM;EACrB,IAAI,YAAY;EAChB,IAAI,eAAe;CACrB;AACF;;;;;;;AAQA,IAAa,YAAb,cAA+B,MAAM;;CAEnC,AAAO;;CAEP,AAAO;;CAEP,AAAO;;CAEP,AAAO;CAEP,AAAiB;CACjB,AAAiB;CACjB,AAAiB;CACjB,AAAiB;CAEjB,AAAQ,OAAO;CACf,AAAQ,OAAO;CACf,AAAQ,OAAO;CACf,AAAQ,OAAO;CACf,AAAQ,MAAM;CACd,AAAQ,MAAM;CACd,AAAQ,UAAU;CAClB,AAAQ,UAAU;CAClB,AAAQ,UAAU;CAClB,AAAQ,cAAc;CACtB,AAAQ,gBAAgB;CACxB,AAAiB,UAAuB;EAAE,UAAU;EAAG,WAAW;EAAG,cAAc;CAAE;CACrF,AAAiB,WAAwB;EAAE,UAAU;EAAG,WAAW;EAAG,cAAc;CAAE;CACtF,AAAQ,YAAY;CACpB,AAAQ,YAAY;CACpB,AAAQ,gBAAgB;CAExB,AAAO,YAAY,SAA2B;EAC5C,MAAM,QAAQ,OAAO,QAAQ,KAAK;EAElC,MAA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5C,MAAM,mBAAmB,MAAM,aAAa;EAG5C,MAAM,QAAQ,MAAM,kBAAkB,MAAM,kBAAkB,KAAK,QAAQ,MAAM,kBAAkB,MAAM,kBAAkB,KAAK;EAChI,MAAM,QAAQ,MAAM,kBAAkB,MAAM,kBAAkB,KAAK,QAAQ,MAAM,kBAAkB,MAAM,kBAAkB,KAAK;EAChI,MAAM,OAAO,SAAS,UAAU,KAAK,QAAQ,WAAW,KAAK,MAAM;EACnE,MAAM,OAAO,SAAS,UAAU,KAAK,QAAQ,WAAW,KAAK,MAAM;EACnE,MAAM,UAAU,KAAK,UAAU,OAAO,KAAK,UAAU;EACrD,MAAM,UAAU,KAAK,UAAU,OAAO,KAAK,UAAU;EACrD,MAAM,WAAW,CAAC,KAAK,QAAQ,YAAY,UAAU,KAAK,QAAQ,eAAe,KAAK;EACtF,MAAM,WAAW,CAAC,KAAK,QAAQ,YAAY,UAAU,KAAK,QAAQ,eAAe,KAAK;EAEtF,KAAK,aAAa;EAClB,KAAK,aAAa;EAClB,KAAK,oBAAoB,UAAU,QAAQ;CAC7C;CAEA,AAAQ,oBAAoB,IAAY,IAAkB;EACxD,MAAM,QAAQ,KAAK;EACnB,MAAM,QAAQ,KAAK;EAEnB,MAAM,mBAAmB,MAAM,UAAU;EACzC,MAAM,mBAAmB,MAAM,UAAU;EACzC,MAAM,mBAAmB,MAAM,cAAc,KAAK,OAAO,KAAK,KAAK,OAAO;EAC1E,MAAM,mBAAmB,MAAM,UAAU;EACzC,MAAM,mBAAmB,MAAM,UAAU;EACzC,MAAM,mBAAmB,MAAM,cAAc,KAAK,OAAO,KAAK,KAAK,OAAO;CAC5E;AACF"}
1
+ {"version":3,"file":"WeldJoint.js","names":[],"sources":["../../../src/joints/WeldJoint.ts"],"sourcesContent":["import type { PointLike } from '@codexo/exojs';\n\nimport { applyInverseTransform, applyTransform } from '../math';\nimport type { PhysicsBody } from '../PhysicsBody';\nimport type { JointOptions, JointSoftness } from './Joint';\nimport { Joint } from './Joint';\n\n/** Construction options for a {@link WeldJoint}. */\nexport interface WeldJointOptions extends JointOptions {\n /** First body. */\n bodyA: PhysicsBody;\n /** Second body. */\n bodyB: PhysicsBody;\n /** World-space anchor the linear constraint acts at. Default: the midpoint of the two bodies. */\n anchor?: Readonly<PointLike>;\n /** Locked relative angle `angleB − angleA`. Default: the current relative angle at creation. */\n referenceAngle?: number;\n /** Soft frequency (Hz) for the position lock; `0` (default) is rigid. */\n linearHertz?: number;\n /** Soft frequency (Hz) for the angle lock; `0` (default) is rigid. */\n angularHertz?: number;\n /** Soft damping ratio (used when a hertz is `> 0`). Default `1`. */\n dampingRatio?: number;\n}\n\n/** Reused output sink - physics steps single-threaded, so a shared scratch is safe. */\nconst scratch: PointLike = { x: 0, y: 0 };\n\ninterface SoftFactors {\n biasRate: number;\n massScale: number;\n impulseScale: number;\n}\n\n/** Soft-constraint factors at sub-step `h`, or the solver's own rigid factors when `hertz === 0`. */\nconst computeSoftFactors = (hertz: number, dampingRatio: number, h: number, rigid: JointSoftness, out: SoftFactors): void => {\n if (hertz > 0) {\n const omega = 2 * Math.PI * hertz;\n const a1 = 2 * dampingRatio + h * omega;\n const a2 = h * omega * a1;\n const a3 = 1 / (1 + a2);\n\n out.biasRate = omega / a1;\n out.massScale = a2 * a3;\n out.impulseScale = a3;\n } else {\n out.biasRate = rigid.biasRate;\n out.massScale = rigid.massScale;\n out.impulseScale = rigid.impulseScale;\n }\n};\n\n/**\n * Rigidly fixes the relative position and orientation of two bodies (they move\n * as one rigid body). A 2-DOF point constraint (like {@link RevoluteJoint}) plus\n * a 1-DOF angular constraint, solved in the sub-step loop. Both locks default to\n * rigid; set `linearHertz`/`angularHertz` for a springy weld.\n */\nexport class WeldJoint extends Joint {\n /** Locked relative angle `angleB − angleA`. */\n public referenceAngle: number;\n /** Soft frequency for the position lock (`0` = rigid). */\n public linearHertz: number;\n /** Soft frequency for the angle lock (`0` = rigid). */\n public angularHertz: number;\n /** Soft damping ratio. */\n public dampingRatio: number;\n\n private readonly _localAnchorAx: number;\n private readonly _localAnchorAy: number;\n private readonly _localAnchorBx: number;\n private readonly _localAnchorBy: number;\n\n private _rAx = 0;\n private _rAy = 0;\n private _rBx = 0;\n private _rBy = 0;\n private _cx = 0;\n private _cy = 0;\n private _invK11 = 0;\n private _invK12 = 0;\n private _invK22 = 0;\n private _angleError = 0;\n private _effMassAngle = 0;\n private readonly _linear: SoftFactors = { biasRate: 0, massScale: 1, impulseScale: 0 };\n private readonly _angular: SoftFactors = { biasRate: 0, massScale: 1, impulseScale: 0 };\n private _impulseX = 0;\n private _impulseY = 0;\n private _impulseAngle = 0;\n\n public constructor(options: WeldJointOptions) {\n super(options.bodyA, options.bodyB, options.collideConnected);\n\n const ax = options.anchor?.x ?? (options.bodyA.x + options.bodyB.x) / 2;\n const ay = options.anchor?.y ?? (options.bodyA.y + options.bodyB.y) / 2;\n\n applyInverseTransform(options.bodyA.transform, ax, ay, scratch);\n this._localAnchorAx = scratch.x;\n this._localAnchorAy = scratch.y;\n applyInverseTransform(options.bodyB.transform, ax, ay, scratch);\n this._localAnchorBx = scratch.x;\n this._localAnchorBy = scratch.y;\n\n this.referenceAngle = options.referenceAngle ?? options.bodyB.angle - options.bodyA.angle;\n this.linearHertz = options.linearHertz ?? 0;\n this.angularHertz = options.angularHertz ?? 0;\n this.dampingRatio = options.dampingRatio ?? 1;\n }\n\n /** @internal */\n public override _prepare(h: number, rigid: JointSoftness): void {\n const bodyA = this.bodyA;\n const bodyB = this.bodyB;\n\n this._active = this.enabled && !bodyA.isSleeping && !bodyB.isSleeping && (bodyA.invMass > 0 || bodyB.invMass > 0);\n\n if (!this._active) {\n return;\n }\n\n applyTransform(bodyA.transform, this._localAnchorAx, this._localAnchorAy, scratch);\n const pAx = scratch.x;\n const pAy = scratch.y;\n applyTransform(bodyB.transform, this._localAnchorBx, this._localAnchorBy, scratch);\n const pBx = scratch.x;\n const pBy = scratch.y;\n\n this._rAx = pAx - bodyA.worldCenterOfMassX;\n this._rAy = pAy - bodyA.worldCenterOfMassY;\n this._rBx = pBx - bodyB.worldCenterOfMassX;\n this._rBy = pBy - bodyB.worldCenterOfMassY;\n this._cx = pBx - pAx;\n this._cy = pBy - pAy;\n\n const mA = bodyA.invMass;\n const mB = bodyB.invMass;\n const iA = bodyA.invInertia;\n const iB = bodyB.invInertia;\n\n const k11 = mA + mB + iA * this._rAy * this._rAy + iB * this._rBy * this._rBy;\n const k12 = -iA * this._rAx * this._rAy - iB * this._rBx * this._rBy;\n const k22 = mA + mB + iA * this._rAx * this._rAx + iB * this._rBx * this._rBx;\n const det = k11 * k22 - k12 * k12;\n const invDet = det !== 0 ? 1 / det : 0;\n\n this._invK11 = invDet * k22;\n this._invK12 = -invDet * k12;\n this._invK22 = invDet * k11;\n\n this._angleError = bodyB.angle - bodyA.angle - this.referenceAngle;\n const kAngle = iA + iB;\n this._effMassAngle = kAngle > 0 ? 1 / kAngle : 0;\n\n computeSoftFactors(this.linearHertz, this.dampingRatio, h, rigid, this._linear);\n computeSoftFactors(this.angularHertz, this.dampingRatio, h, rigid, this._angular);\n }\n\n /** @internal */\n public override _warmStart(): void {\n if (!this._active) {\n return;\n }\n\n const bodyA = this.bodyA;\n const bodyB = this.bodyB;\n\n bodyA.angularVelocity -= bodyA.invInertia * this._impulseAngle;\n bodyB.angularVelocity += bodyB.invInertia * this._impulseAngle;\n this._applyLinearImpulse(this._impulseX, this._impulseY);\n }\n\n /** @internal */\n public override _solve(useBias: boolean): void {\n if (!this._active) {\n return;\n }\n\n const bodyA = this.bodyA;\n const bodyB = this.bodyB;\n\n // Angular lock first.\n const cdotAngle = bodyB.angularVelocity - bodyA.angularVelocity;\n const biasAngle = useBias ? this._angular.biasRate * this._angleError : 0;\n const impulseAngle = -this._effMassAngle * this._angular.massScale * (cdotAngle + biasAngle) - this._angular.impulseScale * this._impulseAngle;\n\n this._impulseAngle += impulseAngle;\n bodyA.angularVelocity -= bodyA.invInertia * impulseAngle;\n bodyB.angularVelocity += bodyB.invInertia * impulseAngle;\n\n // Linear (point) lock.\n const cdotX = bodyB.linearVelocityX - bodyB.angularVelocity * this._rBy - (bodyA.linearVelocityX - bodyA.angularVelocity * this._rAy);\n const cdotY = bodyB.linearVelocityY + bodyB.angularVelocity * this._rBx - (bodyA.linearVelocityY + bodyA.angularVelocity * this._rAx);\n const rhsX = cdotX + (useBias ? this._linear.biasRate * this._cx : 0);\n const rhsY = cdotY + (useBias ? this._linear.biasRate * this._cy : 0);\n const solvedX = this._invK11 * rhsX + this._invK12 * rhsY;\n const solvedY = this._invK12 * rhsX + this._invK22 * rhsY;\n const impulseX = -this._linear.massScale * solvedX - this._linear.impulseScale * this._impulseX;\n const impulseY = -this._linear.massScale * solvedY - this._linear.impulseScale * this._impulseY;\n\n this._impulseX += impulseX;\n this._impulseY += impulseY;\n this._applyLinearImpulse(impulseX, impulseY);\n }\n\n private _applyLinearImpulse(jx: number, jy: number): void {\n const bodyA = this.bodyA;\n const bodyB = this.bodyB;\n\n bodyA.linearVelocityX -= bodyA.invMass * jx;\n bodyA.linearVelocityY -= bodyA.invMass * jy;\n bodyA.angularVelocity -= bodyA.invInertia * (this._rAx * jy - this._rAy * jx);\n bodyB.linearVelocityX += bodyB.invMass * jx;\n bodyB.linearVelocityY += bodyB.invMass * jy;\n bodyB.angularVelocity += bodyB.invInertia * (this._rBx * jy - this._rBy * jx);\n }\n}\n"],"mappings":";;;;;AA0BA,MAAM,UAAqB;CAAE,GAAG;CAAG,GAAG;AAAE;;AASxC,MAAM,sBAAsB,OAAe,cAAsB,GAAW,OAAsB,QAA2B;CAC3H,IAAI,QAAQ,GAAG;EACb,MAAM,QAAQ,IAAI,KAAK,KAAK;EAC5B,MAAM,KAAK,IAAI,eAAe,IAAI;EAClC,MAAM,KAAK,IAAI,QAAQ;EACvB,MAAM,KAAK,KAAK,IAAI;EAEpB,IAAI,WAAW,QAAQ;EACvB,IAAI,YAAY,KAAK;EACrB,IAAI,eAAe;CACrB,OAAO;EACL,IAAI,WAAW,MAAM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EACtF,MAAM,WAAW,CAAC,KAAK,QAAQ,YAAY,UAAU,KAAK,QAAQ,eAAe,KAAK;EAEtF,KAAK,aAAa;EAClB,KAAK,aAAa;EAClB,KAAK,oBAAoB,UAAU,QAAQ;CAC7C;CAEA,AAAQ,oBAAoB,IAAY,IAAkB;EACxD,MAAM,QAAQ,KAAK;EACnB,MAAM,QAAQ,KAAK;EAEnB,MAAM,mBAAmB,MAAM,UAAU;EACzC,MAAM,mBAAmB,MAAM,UAAU;EACzC,MAAM,mBAAmB,MAAM,cAAc,KAAK,OAAO,KAAK,KAAK,OAAO;EAC1E,MAAM,mBAAmB,MAAM,UAAU;EACzC,MAAM,mBAAmB,MAAM,UAAU;EACzC,MAAM,mBAAmB,MAAM,cAAc,KAAK,OAAO,KAAK,KAAK,OAAO;CAC5E;AACF"}
@@ -1,8 +1,9 @@
1
1
  import type { PointLike } from '@codexo/exojs';
2
2
  import type { PhysicsBody } from '../PhysicsBody';
3
+ import type { JointOptions } from './Joint';
3
4
  import { Joint } from './Joint';
4
5
  /** Construction options for a {@link WheelJoint}. */
5
- export interface WheelJointOptions {
6
+ export interface WheelJointOptions extends JointOptions {
6
7
  /** First body (the chassis). */
7
8
  bodyA: PhysicsBody;
8
9
  /** Second body (the wheel). */
@@ -82,9 +83,6 @@ export declare class WheelJoint extends Joint {
82
83
  private _lowerImpulse;
83
84
  private _upperImpulse;
84
85
  constructor(options: WheelJointOptions);
85
- _prepare(h: number): void;
86
- _warmStart(): void;
87
- _solve(useBias: boolean): void;
88
86
  private _axisVelocity;
89
87
  private _perpVelocity;
90
88
  private _applyAxial;
@@ -1 +1 @@
1
- {"version":3,"file":"WheelJoint.d.ts","sourceRoot":"","sources":["../../../src/joints/WheelJoint.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAG/C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAClD,OAAO,EAAE,KAAK,EAAE,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;
62
62
  _upperImpulse = 0;
63
63
  constructor(options) {
64
- super(options.bodyA, options.bodyB);
64
+ super(options.bodyA, options.bodyB, options.collideConnected);
65
65
  applyInverseTransform(options.bodyA.transform, options.anchor.x, options.anchor.y, scratch);
66
66
  this._localAnchorAx = scratch.x;
67
67
  this._localAnchorAy = scratch.y;
@@ -82,7 +82,8 @@ var WheelJoint = class extends Joint {
82
82
  this.lowerTranslation = options.lowerTranslation ?? 0;
83
83
  this.upperTranslation = options.upperTranslation ?? 0;
84
84
  }
85
- _prepare(h) {
85
+ /** @internal */
86
+ _prepare(h, rigid) {
86
87
  const bodyA = this.bodyA;
87
88
  const bodyB = this.bodyB;
88
89
  this._active = this.enabled && !bodyA.isSleeping && !bodyB.isSleeping && (bodyA.invMass > 0 || bodyB.invMass > 0);
@@ -134,9 +135,9 @@ var WheelJoint = class extends Joint {
134
135
  this._springMassScale = a2 * a3;
135
136
  this._springImpulseScale = a3;
136
137
  } else {
137
- this._springBiasRate = .2 / h;
138
- this._springMassScale = 1;
139
- this._springImpulseScale = 0;
138
+ this._springBiasRate = rigid.biasRate;
139
+ this._springMassScale = rigid.massScale;
140
+ this._springImpulseScale = rigid.impulseScale;
140
141
  }
141
142
  if (!this.enableMotor) this._motorImpulse = 0;
142
143
  if (!this.enableLimit) {
@@ -144,6 +145,7 @@ var WheelJoint = class extends Joint {
144
145
  this._upperImpulse = 0;
145
146
  }
146
147
  }
148
+ /** @internal */
147
149
  _warmStart() {
148
150
  if (!this._active) return;
149
151
  const bodyA = this.bodyA;
@@ -153,6 +155,7 @@ var WheelJoint = class extends Joint {
153
155
  this._applyAxial(this._springImpulse + this._lowerImpulse - this._upperImpulse);
154
156
  this._applyPerp(this._perpImpulse);
155
157
  }
158
+ /** @internal */
156
159
  _solve(useBias) {
157
160
  if (!this._active) return;
158
161
  const bodyA = this.bodyA;