@codexo/exojs-physics 0.15.3 → 0.16.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 (201) hide show
  1. package/README.md +51 -23
  2. package/dist/esm/Aabb.d.ts +6 -10
  3. package/dist/esm/Aabb.d.ts.map +1 -0
  4. package/dist/esm/Aabb.js +9 -5
  5. package/dist/esm/Aabb.js.map +1 -1
  6. package/dist/esm/Collider.d.ts +62 -10
  7. package/dist/esm/Collider.d.ts.map +1 -0
  8. package/dist/esm/Collider.js +263 -157
  9. package/dist/esm/Collider.js.map +1 -1
  10. package/dist/esm/ContactGraph.d.ts +51 -5
  11. package/dist/esm/ContactGraph.d.ts.map +1 -0
  12. package/dist/esm/ContactGraph.js +282 -223
  13. package/dist/esm/ContactGraph.js.map +1 -1
  14. package/dist/esm/ContactModifier.d.ts +85 -0
  15. package/dist/esm/ContactModifier.d.ts.map +1 -0
  16. package/dist/esm/ContactModifier.js +49 -0
  17. package/dist/esm/ContactModifier.js.map +1 -0
  18. package/dist/esm/PhysicsBody.d.ts +56 -22
  19. package/dist/esm/PhysicsBody.d.ts.map +1 -0
  20. package/dist/esm/PhysicsBody.js +461 -443
  21. package/dist/esm/PhysicsBody.js.map +1 -1
  22. package/dist/esm/PhysicsWorld.d.ts +276 -43
  23. package/dist/esm/PhysicsWorld.d.ts.map +1 -0
  24. package/dist/esm/PhysicsWorld.js +890 -626
  25. package/dist/esm/PhysicsWorld.js.map +1 -1
  26. package/dist/esm/TimeStepper.d.ts +3 -2
  27. package/dist/esm/TimeStepper.d.ts.map +1 -0
  28. package/dist/esm/TimeStepper.js +56 -67
  29. package/dist/esm/TimeStepper.js.map +1 -1
  30. package/dist/esm/backend/NativePhysicsBackend.d.ts +8 -4
  31. package/dist/esm/backend/NativePhysicsBackend.d.ts.map +1 -0
  32. package/dist/esm/backend/NativePhysicsBackend.js +48 -41
  33. package/dist/esm/backend/NativePhysicsBackend.js.map +1 -1
  34. package/dist/esm/backend/PhysicsBackend.d.ts +9 -2
  35. package/dist/esm/backend/PhysicsBackend.d.ts.map +1 -0
  36. package/dist/esm/binding/BindingRegistry.d.ts +25 -4
  37. package/dist/esm/binding/BindingRegistry.d.ts.map +1 -0
  38. package/dist/esm/binding/BindingRegistry.js +70 -36
  39. package/dist/esm/binding/BindingRegistry.js.map +1 -1
  40. package/dist/esm/binding/PhysicsBinding.d.ts +22 -5
  41. package/dist/esm/binding/PhysicsBinding.d.ts.map +1 -0
  42. package/dist/esm/binding/PhysicsBinding.js +46 -21
  43. package/dist/esm/binding/PhysicsBinding.js.map +1 -1
  44. package/dist/esm/broadphase/AabbTreeBroadPhase.d.ts +68 -0
  45. package/dist/esm/broadphase/AabbTreeBroadPhase.d.ts.map +1 -0
  46. package/dist/esm/broadphase/AabbTreeBroadPhase.js +149 -0
  47. package/dist/esm/broadphase/AabbTreeBroadPhase.js.map +1 -0
  48. package/dist/esm/broadphase/BroadPhase.d.ts +7 -4
  49. package/dist/esm/broadphase/BroadPhase.d.ts.map +1 -0
  50. package/dist/esm/broadphase/index.d.ts +2 -1
  51. package/dist/esm/broadphase/index.d.ts.map +1 -0
  52. package/dist/esm/collision/CollisionProxy.d.ts +3 -2
  53. package/dist/esm/collision/CollisionProxy.d.ts.map +1 -0
  54. package/dist/esm/collision/Manifold.d.ts +5 -4
  55. package/dist/esm/collision/Manifold.d.ts.map +1 -0
  56. package/dist/esm/collision/Manifold.js +34 -25
  57. package/dist/esm/collision/Manifold.js.map +1 -1
  58. package/dist/esm/collision/chainAdjacency.d.ts +29 -0
  59. package/dist/esm/collision/chainAdjacency.d.ts.map +1 -0
  60. package/dist/esm/collision/chainAdjacency.js +44 -0
  61. package/dist/esm/collision/chainAdjacency.js.map +1 -0
  62. package/dist/esm/collision/dispatch.d.ts +35 -0
  63. package/dist/esm/collision/dispatch.d.ts.map +1 -0
  64. package/dist/esm/collision/dispatch.js +58 -0
  65. package/dist/esm/collision/dispatch.js.map +1 -0
  66. package/dist/esm/collision/index.d.ts +2 -0
  67. package/dist/esm/collision/index.d.ts.map +1 -0
  68. package/dist/esm/collision/narrowphase.d.ts +5 -2
  69. package/dist/esm/collision/narrowphase.d.ts.map +1 -0
  70. package/dist/esm/collision/narrowphase.js +524 -399
  71. package/dist/esm/collision/narrowphase.js.map +1 -1
  72. package/dist/esm/collision/segments.d.ts +19 -0
  73. package/dist/esm/collision/segments.d.ts.map +1 -0
  74. package/dist/esm/collision/segments.js +36 -0
  75. package/dist/esm/collision/segments.js.map +1 -0
  76. package/dist/esm/collision/sweep.d.ts +35 -0
  77. package/dist/esm/collision/sweep.d.ts.map +1 -0
  78. package/dist/esm/collision/sweep.js +437 -0
  79. package/dist/esm/collision/sweep.js.map +1 -0
  80. package/dist/esm/debug/PhysicsDebugDraw.d.ts +23 -4
  81. package/dist/esm/debug/PhysicsDebugDraw.d.ts.map +1 -0
  82. package/dist/esm/debug/PhysicsDebugDraw.js +230 -188
  83. package/dist/esm/debug/PhysicsDebugDraw.js.map +1 -1
  84. package/dist/esm/debug/index.d.ts +1 -0
  85. package/dist/esm/debug/index.d.ts.map +1 -0
  86. package/dist/esm/debug/index.js +3 -2
  87. package/dist/esm/events.d.ts +1 -0
  88. package/dist/esm/events.d.ts.map +1 -0
  89. package/dist/esm/index.d.ts +1 -0
  90. package/dist/esm/index.d.ts.map +1 -0
  91. package/dist/esm/index.js +24 -19
  92. package/dist/esm/joints/DistanceJoint.d.ts +4 -3
  93. package/dist/esm/joints/DistanceJoint.d.ts.map +1 -0
  94. package/dist/esm/joints/DistanceJoint.js +160 -172
  95. package/dist/esm/joints/DistanceJoint.js.map +1 -1
  96. package/dist/esm/joints/Joint.d.ts +5 -4
  97. package/dist/esm/joints/Joint.d.ts.map +1 -0
  98. package/dist/esm/joints/Joint.js +23 -21
  99. package/dist/esm/joints/Joint.js.map +1 -1
  100. package/dist/esm/joints/MouseJoint.d.ts +8 -7
  101. package/dist/esm/joints/MouseJoint.d.ts.map +1 -0
  102. package/dist/esm/joints/MouseJoint.js +132 -133
  103. package/dist/esm/joints/MouseJoint.js.map +1 -1
  104. package/dist/esm/joints/PrismaticJoint.d.ts +5 -4
  105. package/dist/esm/joints/PrismaticJoint.d.ts.map +1 -0
  106. package/dist/esm/joints/PrismaticJoint.js +211 -240
  107. package/dist/esm/joints/PrismaticJoint.js.map +1 -1
  108. package/dist/esm/joints/RevoluteJoint.d.ts +4 -3
  109. package/dist/esm/joints/RevoluteJoint.d.ts.map +1 -0
  110. package/dist/esm/joints/RevoluteJoint.js +191 -213
  111. package/dist/esm/joints/RevoluteJoint.js.map +1 -1
  112. package/dist/esm/joints/WeldJoint.d.ts +3 -2
  113. package/dist/esm/joints/WeldJoint.d.ts.map +1 -0
  114. package/dist/esm/joints/WeldJoint.js +156 -152
  115. package/dist/esm/joints/WeldJoint.js.map +1 -1
  116. package/dist/esm/joints/WheelJoint.d.ts +4 -3
  117. package/dist/esm/joints/WheelJoint.d.ts.map +1 -0
  118. package/dist/esm/joints/WheelJoint.js +228 -255
  119. package/dist/esm/joints/WheelJoint.js.map +1 -1
  120. package/dist/esm/math.d.ts +6 -9
  121. package/dist/esm/math.d.ts.map +1 -0
  122. package/dist/esm/math.js +37 -39
  123. package/dist/esm/math.js.map +1 -1
  124. package/dist/esm/physicsBuildInfo.d.ts +1 -0
  125. package/dist/esm/physicsBuildInfo.d.ts.map +1 -0
  126. package/dist/esm/physicsBuildInfo.js +6 -4
  127. package/dist/esm/physicsBuildInfo.js.map +1 -1
  128. package/dist/esm/public.d.ts +8 -3
  129. package/dist/esm/public.d.ts.map +1 -0
  130. package/dist/esm/query/QueryEngine.d.ts +56 -12
  131. package/dist/esm/query/QueryEngine.d.ts.map +1 -0
  132. package/dist/esm/query/QueryEngine.js +494 -237
  133. package/dist/esm/query/QueryEngine.js.map +1 -1
  134. package/dist/esm/query/SpatialIndex.d.ts +34 -0
  135. package/dist/esm/query/SpatialIndex.d.ts.map +1 -0
  136. package/dist/esm/shapes/AnyShape.d.ts +9 -4
  137. package/dist/esm/shapes/AnyShape.d.ts.map +1 -0
  138. package/dist/esm/shapes/BoxShape.d.ts +2 -1
  139. package/dist/esm/shapes/BoxShape.d.ts.map +1 -0
  140. package/dist/esm/shapes/BoxShape.js +37 -25
  141. package/dist/esm/shapes/BoxShape.js.map +1 -1
  142. package/dist/esm/shapes/CapsuleShape.d.ts +30 -0
  143. package/dist/esm/shapes/CapsuleShape.d.ts.map +1 -0
  144. package/dist/esm/shapes/CapsuleShape.js +88 -0
  145. package/dist/esm/shapes/CapsuleShape.js.map +1 -0
  146. package/dist/esm/shapes/ChainEdgeShape.d.ts +30 -0
  147. package/dist/esm/shapes/ChainEdgeShape.d.ts.map +1 -0
  148. package/dist/esm/shapes/ChainEdgeShape.js +66 -0
  149. package/dist/esm/shapes/ChainEdgeShape.js.map +1 -0
  150. package/dist/esm/shapes/ChainShape.d.ts +52 -0
  151. package/dist/esm/shapes/ChainShape.d.ts.map +1 -0
  152. package/dist/esm/shapes/ChainShape.js +85 -0
  153. package/dist/esm/shapes/ChainShape.js.map +1 -0
  154. package/dist/esm/shapes/CircleShape.d.ts +3 -4
  155. package/dist/esm/shapes/CircleShape.d.ts.map +1 -0
  156. package/dist/esm/shapes/CircleShape.js +27 -26
  157. package/dist/esm/shapes/CircleShape.js.map +1 -1
  158. package/dist/esm/shapes/PolygonShape.d.ts +7 -8
  159. package/dist/esm/shapes/PolygonShape.d.ts.map +1 -0
  160. package/dist/esm/shapes/PolygonShape.js +131 -162
  161. package/dist/esm/shapes/PolygonShape.js.map +1 -1
  162. package/dist/esm/shapes/SegmentShape.d.ts +31 -0
  163. package/dist/esm/shapes/SegmentShape.d.ts.map +1 -0
  164. package/dist/esm/shapes/SegmentShape.js +62 -0
  165. package/dist/esm/shapes/SegmentShape.js.map +1 -0
  166. package/dist/esm/shapes/Shape.d.ts +28 -17
  167. package/dist/esm/shapes/Shape.d.ts.map +1 -0
  168. package/dist/esm/shapes/Shape.js +12 -13
  169. package/dist/esm/shapes/Shape.js.map +1 -1
  170. package/dist/esm/shapes/convexParts.d.ts +21 -0
  171. package/dist/esm/shapes/convexParts.d.ts.map +1 -0
  172. package/dist/esm/shapes/convexParts.js +26 -0
  173. package/dist/esm/shapes/convexParts.js.map +1 -0
  174. package/dist/esm/shapes/decompose.d.ts +24 -0
  175. package/dist/esm/shapes/decompose.d.ts.map +1 -0
  176. package/dist/esm/shapes/decompose.js +272 -0
  177. package/dist/esm/shapes/decompose.js.map +1 -0
  178. package/dist/esm/shapes/index.d.ts +4 -0
  179. package/dist/esm/shapes/index.d.ts.map +1 -0
  180. package/dist/esm/solver/ContactSolver.d.ts +12 -5
  181. package/dist/esm/solver/ContactSolver.d.ts.map +1 -0
  182. package/dist/esm/solver/ContactSolver.js +425 -471
  183. package/dist/esm/solver/ContactSolver.js.map +1 -1
  184. package/dist/esm/solver/tolerances.d.ts +34 -0
  185. package/dist/esm/solver/tolerances.d.ts.map +1 -0
  186. package/dist/esm/solver/tolerances.js +38 -0
  187. package/dist/esm/solver/tolerances.js.map +1 -0
  188. package/dist/esm/sort.d.ts +5 -4
  189. package/dist/esm/sort.d.ts.map +1 -0
  190. package/dist/esm/sort.js +41 -51
  191. package/dist/esm/sort.js.map +1 -1
  192. package/dist/esm/types.d.ts +4 -8
  193. package/dist/esm/types.d.ts.map +1 -0
  194. package/dist/esm/types.js +15 -17
  195. package/dist/esm/types.js.map +1 -1
  196. package/package.json +6 -6
  197. package/dist/esm/broadphase/SweepAndPrune.d.ts +0 -15
  198. package/dist/esm/broadphase/SweepAndPrune.js +0 -77
  199. package/dist/esm/broadphase/SweepAndPrune.js.map +0 -1
  200. package/dist/esm/debug/index.js.map +0 -1
  201. package/dist/esm/index.js.map +0 -1
@@ -1,244 +1,215 @@
1
- import { applyInverseTransform, applyInverseRotation, applyRotation, applyTransform } from '../math.js';
2
- import { Joint } from './Joint.js';
1
+ import { applyInverseRotation, applyInverseTransform, applyRotation, applyTransform } from "../math.js";
2
+ import { Joint } from "./Joint.js";
3
3
 
4
- /** Reused output sink — physics steps single-threaded, so a shared scratch is safe. */
5
- const scratch = { x: 0, y: 0 };
4
+ //#region src/joints/PrismaticJoint.ts
5
+ /** Reused output sink - physics steps single-threaded, so a shared scratch is safe. */
6
+ const scratch = {
7
+ x: 0,
8
+ y: 0
9
+ };
6
10
  /**
7
- * Constrains a body to **slide along a single axis** relative to another: the
8
- * perpendicular translation and the relative rotation are locked (a 2×2 block);
9
- * only translation along the axis is free, optionally driven by a motor and/or
10
- * bounded by a translation limit. Solved in the sub-step loop, warm-started.
11
- */
12
- class PrismaticJoint extends Joint {
13
- /** When `true`, the motor drives the axis translation toward {@link motorSpeed}. */
14
- enableMotor;
15
- /** Target translation speed along the axis (px/s). */
16
- motorSpeed;
17
- /** Maximum motor force. */
18
- maxMotorForce;
19
- /** When `true`, the axis translation is constrained to `[lowerTranslation, upperTranslation]`. */
20
- enableLimit;
21
- /** Lower translation limit along the axis. */
22
- lowerTranslation;
23
- /** Upper translation limit along the axis. */
24
- upperTranslation;
25
- _localAnchorAx;
26
- _localAnchorAy;
27
- _localAnchorBx;
28
- _localAnchorBy;
29
- _localAxisAx;
30
- _localAxisAy;
31
- _referenceAngle;
32
- _axisX = 1;
33
- _axisY = 0;
34
- _perpX = 0;
35
- _perpY = 1;
36
- _a1 = 0;
37
- _a2 = 0;
38
- _s1 = 0;
39
- _s2 = 0;
40
- _k11 = 0;
41
- _k12 = 0;
42
- _k22 = 0;
43
- _cPerp = 0;
44
- _cAngle = 0;
45
- _translation = 0;
46
- _axialMass = 0;
47
- _h = 0;
48
- _invH = 0;
49
- _perpImpulse = 0;
50
- _angularImpulse = 0;
51
- _motorImpulse = 0;
52
- _lowerImpulse = 0;
53
- _upperImpulse = 0;
54
- constructor(options) {
55
- super(options.bodyA, options.bodyB);
56
- applyInverseTransform(options.bodyA.transform, options.anchor.x, options.anchor.y, scratch);
57
- this._localAnchorAx = scratch.x;
58
- this._localAnchorAy = scratch.y;
59
- applyInverseTransform(options.bodyB.transform, options.anchor.x, options.anchor.y, scratch);
60
- this._localAnchorBx = scratch.x;
61
- this._localAnchorBy = scratch.y;
62
- const axisLength = Math.hypot(options.axis.x, options.axis.y);
63
- if (!Number.isFinite(axisLength) || axisLength === 0) {
64
- throw new RangeError(`PrismaticJoint: axis must be a non-zero finite vector, received (${options.axis.x}, ${options.axis.y}).`);
65
- }
66
- applyInverseRotation(options.bodyA.transform, options.axis.x / axisLength, options.axis.y / axisLength, scratch);
67
- this._localAxisAx = scratch.x;
68
- this._localAxisAy = scratch.y;
69
- this._referenceAngle = options.bodyB.angle - options.bodyA.angle;
70
- this.enableMotor = options.enableMotor ?? false;
71
- this.motorSpeed = options.motorSpeed ?? 0;
72
- this.maxMotorForce = options.maxMotorForce ?? 0;
73
- this.enableLimit = options.enableLimit ?? false;
74
- this.lowerTranslation = options.lowerTranslation ?? 0;
75
- this.upperTranslation = options.upperTranslation ?? 0;
76
- }
77
- _prepare(h) {
78
- const bodyA = this.bodyA;
79
- const bodyB = this.bodyB;
80
- this._active = this.enabled && !bodyA.isSleeping && !bodyB.isSleeping && (bodyA.invMass > 0 || bodyB.invMass > 0);
81
- if (!this._active) {
82
- return;
83
- }
84
- // World axis + perpendicular (axis is local to body A).
85
- applyRotation(bodyA.transform, this._localAxisAx, this._localAxisAy, scratch);
86
- const axisX = scratch.x;
87
- const axisY = scratch.y;
88
- const perpX = -axisY;
89
- const perpY = axisX;
90
- this._axisX = axisX;
91
- this._axisY = axisY;
92
- this._perpX = perpX;
93
- this._perpY = perpY;
94
- applyTransform(bodyA.transform, this._localAnchorAx, this._localAnchorAy, scratch);
95
- const pAx = scratch.x;
96
- const pAy = scratch.y;
97
- applyTransform(bodyB.transform, this._localAnchorBx, this._localAnchorBy, scratch);
98
- const pBx = scratch.x;
99
- const pBy = scratch.y;
100
- const rAx = pAx - bodyA.worldCenterOfMassX;
101
- const rAy = pAy - bodyA.worldCenterOfMassY;
102
- const rBx = pBx - bodyB.worldCenterOfMassX;
103
- const rBy = pBy - bodyB.worldCenterOfMassY;
104
- const dx = pBx - pAx;
105
- const dy = pBy - pAy;
106
- // Jacobian cross terms for the axis (motor/limit) and the perpendicular (lock).
107
- this._a1 = (dx + rAx) * axisY - (dy + rAy) * axisX;
108
- this._a2 = rBx * axisY - rBy * axisX;
109
- this._s1 = (dx + rAx) * perpY - (dy + rAy) * perpX;
110
- this._s2 = rBx * perpY - rBy * perpX;
111
- const mA = bodyA.invMass;
112
- const mB = bodyB.invMass;
113
- const iA = bodyA.invInertia;
114
- const iB = bodyB.invInertia;
115
- const kAxial = mA + mB + iA * this._a1 * this._a1 + iB * this._a2 * this._a2;
116
- this._axialMass = kAxial > 0 ? 1 / kAxial : 0;
117
- // Perpendicular + angular 2×2 block.
118
- this._k11 = mA + mB + iA * this._s1 * this._s1 + iB * this._s2 * this._s2;
119
- this._k12 = iA * this._s1 + iB * this._s2;
120
- this._k22 = iA + iB;
121
- if (this._k22 === 0) {
122
- this._k22 = 1; // both bodies rotation-locked — keep the block invertible
123
- }
124
- this._cPerp = dx * perpX + dy * perpY;
125
- this._cAngle = bodyB.angle - bodyA.angle - this._referenceAngle;
126
- this._translation = dx * axisX + dy * axisY;
127
- this._h = h;
128
- this._invH = 1 / h;
129
- if (!this.enableMotor) {
130
- this._motorImpulse = 0;
131
- }
132
- if (!this.enableLimit) {
133
- this._lowerImpulse = 0;
134
- this._upperImpulse = 0;
135
- }
136
- }
137
- _warmStart() {
138
- if (!this._active) {
139
- return;
140
- }
141
- const axial = this._motorImpulse + this._lowerImpulse - this._upperImpulse;
142
- this._applyBlock(this._perpImpulse, this._angularImpulse);
143
- this._applyAxial(axial);
144
- }
145
- _solve(useBias) {
146
- if (!this._active) {
147
- return;
148
- }
149
- const bodyA = this.bodyA;
150
- const bodyB = this.bodyB;
151
- // Motor along the axis.
152
- if (this.enableMotor) {
153
- const cdot = this._axisVelocity() - this.motorSpeed;
154
- const max = this.maxMotorForce * this._h;
155
- const old = this._motorImpulse;
156
- this._motorImpulse = Math.min(max, Math.max(-max, old - this._axialMass * cdot));
157
- this._applyAxial(this._motorImpulse - old);
158
- }
159
- // Translation limits along the axis.
160
- if (this.enableLimit) {
161
- // Lower limit (translation lowerTranslation): positive impulse pushes along +axis.
162
- const cLower = this._translation - this.lowerTranslation;
163
- let biasLower = 0;
164
- if (cLower > 0) {
165
- biasLower = cLower * this._invH;
166
- }
167
- else if (useBias) {
168
- biasLower = 0.2 * this._invH * cLower;
169
- }
170
- const oldLower = this._lowerImpulse;
171
- this._lowerImpulse = Math.max(0, oldLower - this._axialMass * (this._axisVelocity() + biasLower));
172
- this._applyAxial(this._lowerImpulse - oldLower);
173
- // Upper limit (translation ≤ upperTranslation): impulse pushes along −axis.
174
- const cUpper = this.upperTranslation - this._translation;
175
- let biasUpper = 0;
176
- if (cUpper > 0) {
177
- biasUpper = cUpper * this._invH;
178
- }
179
- else if (useBias) {
180
- biasUpper = 0.2 * this._invH * cUpper;
181
- }
182
- const oldUpper = this._upperImpulse;
183
- this._upperImpulse = Math.max(0, oldUpper - this._axialMass * (-this._axisVelocity() + biasUpper));
184
- this._applyAxial(-(this._upperImpulse - oldUpper));
185
- }
186
- // Perpendicular + angular lock (2×2 block).
187
- const cdotPerp = this._perpVelocity();
188
- const cdotAngle = bodyB.angularVelocity - bodyA.angularVelocity;
189
- const rhs1 = -(cdotPerp + (useBias ? 0.2 * this._invH * this._cPerp : 0));
190
- const rhs2 = -(cdotAngle + (useBias ? 0.2 * this._invH * this._cAngle : 0));
191
- const det = this._k11 * this._k22 - this._k12 * this._k12;
192
- const invDet = det !== 0 ? 1 / det : 0;
193
- const dPerp = invDet * (this._k22 * rhs1 - this._k12 * rhs2);
194
- const dAngle = invDet * (-this._k12 * rhs1 + this._k11 * rhs2);
195
- this._perpImpulse += dPerp;
196
- this._angularImpulse += dAngle;
197
- this._applyBlock(dPerp, dAngle);
198
- }
199
- /** Relative velocity projected onto the axis (plus the rotation cross terms). */
200
- _axisVelocity() {
201
- const bodyA = this.bodyA;
202
- const bodyB = this.bodyB;
203
- return (this._axisX * (bodyB.linearVelocityX - bodyA.linearVelocityX) +
204
- this._axisY * (bodyB.linearVelocityY - bodyA.linearVelocityY) +
205
- this._a2 * bodyB.angularVelocity -
206
- this._a1 * bodyA.angularVelocity);
207
- }
208
- /** Relative velocity projected onto the perpendicular (plus the rotation cross terms). */
209
- _perpVelocity() {
210
- const bodyA = this.bodyA;
211
- const bodyB = this.bodyB;
212
- return (this._perpX * (bodyB.linearVelocityX - bodyA.linearVelocityX) +
213
- this._perpY * (bodyB.linearVelocityY - bodyA.linearVelocityY) +
214
- this._s2 * bodyB.angularVelocity -
215
- this._s1 * bodyA.angularVelocity);
216
- }
217
- _applyAxial(impulse) {
218
- const bodyA = this.bodyA;
219
- const bodyB = this.bodyB;
220
- const px = impulse * this._axisX;
221
- const py = impulse * this._axisY;
222
- bodyA.linearVelocityX -= bodyA.invMass * px;
223
- bodyA.linearVelocityY -= bodyA.invMass * py;
224
- bodyA.angularVelocity -= bodyA.invInertia * impulse * this._a1;
225
- bodyB.linearVelocityX += bodyB.invMass * px;
226
- bodyB.linearVelocityY += bodyB.invMass * py;
227
- bodyB.angularVelocity += bodyB.invInertia * impulse * this._a2;
228
- }
229
- _applyBlock(perpImpulse, angularImpulse) {
230
- const bodyA = this.bodyA;
231
- const bodyB = this.bodyB;
232
- const px = perpImpulse * this._perpX;
233
- const py = perpImpulse * this._perpY;
234
- bodyA.linearVelocityX -= bodyA.invMass * px;
235
- bodyA.linearVelocityY -= bodyA.invMass * py;
236
- bodyA.angularVelocity -= bodyA.invInertia * (perpImpulse * this._s1 + angularImpulse);
237
- bodyB.linearVelocityX += bodyB.invMass * px;
238
- bodyB.linearVelocityY += bodyB.invMass * py;
239
- bodyB.angularVelocity += bodyB.invInertia * (perpImpulse * this._s2 + angularImpulse);
240
- }
241
- }
11
+ * Constrains a body to **slide along a single axis** relative to another: the
12
+ * perpendicular translation and the relative rotation are locked (a 2×2 block);
13
+ * only translation along the axis is free, optionally driven by a motor and/or
14
+ * bounded by a translation limit. Solved in the sub-step loop, warm-started.
15
+ */
16
+ var PrismaticJoint = class extends Joint {
17
+ /** When `true`, the motor drives the axis translation toward {@link motorSpeed}. */
18
+ enableMotor;
19
+ /** Target translation speed along the axis (px/s). */
20
+ motorSpeed;
21
+ /** Maximum motor force. */
22
+ maxMotorForce;
23
+ /** When `true`, the axis translation is constrained to `[lowerTranslation, upperTranslation]`. */
24
+ enableLimit;
25
+ /** Lower translation limit along the axis. */
26
+ lowerTranslation;
27
+ /** Upper translation limit along the axis. */
28
+ upperTranslation;
29
+ _localAnchorAx;
30
+ _localAnchorAy;
31
+ _localAnchorBx;
32
+ _localAnchorBy;
33
+ _localAxisAx;
34
+ _localAxisAy;
35
+ _referenceAngle;
36
+ _axisX = 1;
37
+ _axisY = 0;
38
+ _perpX = 0;
39
+ _perpY = 1;
40
+ _a1 = 0;
41
+ _a2 = 0;
42
+ _s1 = 0;
43
+ _s2 = 0;
44
+ _k11 = 0;
45
+ _k12 = 0;
46
+ _k22 = 0;
47
+ _cPerp = 0;
48
+ _cAngle = 0;
49
+ _translation = 0;
50
+ _axialMass = 0;
51
+ _h = 0;
52
+ _invH = 0;
53
+ _perpImpulse = 0;
54
+ _angularImpulse = 0;
55
+ _motorImpulse = 0;
56
+ _lowerImpulse = 0;
57
+ _upperImpulse = 0;
58
+ constructor(options) {
59
+ super(options.bodyA, options.bodyB);
60
+ applyInverseTransform(options.bodyA.transform, options.anchor.x, options.anchor.y, scratch);
61
+ this._localAnchorAx = scratch.x;
62
+ this._localAnchorAy = scratch.y;
63
+ applyInverseTransform(options.bodyB.transform, options.anchor.x, options.anchor.y, scratch);
64
+ this._localAnchorBx = scratch.x;
65
+ this._localAnchorBy = scratch.y;
66
+ const axisLength = Math.hypot(options.axis.x, options.axis.y);
67
+ if (!Number.isFinite(axisLength) || axisLength === 0) throw new RangeError(`PrismaticJoint: axis must be a non-zero finite vector, received (${options.axis.x}, ${options.axis.y}).`);
68
+ applyInverseRotation(options.bodyA.transform, options.axis.x / axisLength, options.axis.y / axisLength, scratch);
69
+ this._localAxisAx = scratch.x;
70
+ this._localAxisAy = scratch.y;
71
+ this._referenceAngle = options.bodyB.angle - options.bodyA.angle;
72
+ this.enableMotor = options.enableMotor ?? false;
73
+ this.motorSpeed = options.motorSpeed ?? 0;
74
+ this.maxMotorForce = options.maxMotorForce ?? 0;
75
+ this.enableLimit = options.enableLimit ?? false;
76
+ this.lowerTranslation = options.lowerTranslation ?? 0;
77
+ this.upperTranslation = options.upperTranslation ?? 0;
78
+ }
79
+ _prepare(h) {
80
+ const bodyA = this.bodyA;
81
+ const bodyB = this.bodyB;
82
+ this._active = this.enabled && !bodyA.isSleeping && !bodyB.isSleeping && (bodyA.invMass > 0 || bodyB.invMass > 0);
83
+ if (!this._active) return;
84
+ applyRotation(bodyA.transform, this._localAxisAx, this._localAxisAy, scratch);
85
+ const axisX = scratch.x;
86
+ const axisY = scratch.y;
87
+ const perpX = -axisY;
88
+ const perpY = axisX;
89
+ this._axisX = axisX;
90
+ this._axisY = axisY;
91
+ this._perpX = perpX;
92
+ this._perpY = perpY;
93
+ applyTransform(bodyA.transform, this._localAnchorAx, this._localAnchorAy, scratch);
94
+ const pAx = scratch.x;
95
+ const pAy = scratch.y;
96
+ applyTransform(bodyB.transform, this._localAnchorBx, this._localAnchorBy, scratch);
97
+ const pBx = scratch.x;
98
+ const pBy = scratch.y;
99
+ const rAx = pAx - bodyA.worldCenterOfMassX;
100
+ const rAy = pAy - bodyA.worldCenterOfMassY;
101
+ const rBx = pBx - bodyB.worldCenterOfMassX;
102
+ const rBy = pBy - bodyB.worldCenterOfMassY;
103
+ const dx = pBx - pAx;
104
+ const dy = pBy - pAy;
105
+ this._a1 = (dx + rAx) * axisY - (dy + rAy) * axisX;
106
+ this._a2 = rBx * axisY - rBy * axisX;
107
+ this._s1 = (dx + rAx) * perpY - (dy + rAy) * perpX;
108
+ this._s2 = rBx * perpY - rBy * perpX;
109
+ const mA = bodyA.invMass;
110
+ const mB = bodyB.invMass;
111
+ const iA = bodyA.invInertia;
112
+ const iB = bodyB.invInertia;
113
+ const kAxial = mA + mB + iA * this._a1 * this._a1 + iB * this._a2 * this._a2;
114
+ this._axialMass = kAxial > 0 ? 1 / kAxial : 0;
115
+ this._k11 = mA + mB + iA * this._s1 * this._s1 + iB * this._s2 * this._s2;
116
+ this._k12 = iA * this._s1 + iB * this._s2;
117
+ this._k22 = iA + iB;
118
+ if (this._k22 === 0) this._k22 = 1;
119
+ this._cPerp = dx * perpX + dy * perpY;
120
+ this._cAngle = bodyB.angle - bodyA.angle - this._referenceAngle;
121
+ this._translation = dx * axisX + dy * axisY;
122
+ this._h = h;
123
+ this._invH = 1 / h;
124
+ if (!this.enableMotor) this._motorImpulse = 0;
125
+ if (!this.enableLimit) {
126
+ this._lowerImpulse = 0;
127
+ this._upperImpulse = 0;
128
+ }
129
+ }
130
+ _warmStart() {
131
+ if (!this._active) return;
132
+ const axial = this._motorImpulse + this._lowerImpulse - this._upperImpulse;
133
+ this._applyBlock(this._perpImpulse, this._angularImpulse);
134
+ this._applyAxial(axial);
135
+ }
136
+ _solve(useBias) {
137
+ if (!this._active) return;
138
+ const bodyA = this.bodyA;
139
+ const bodyB = this.bodyB;
140
+ if (this.enableMotor) {
141
+ const cdot = this._axisVelocity() - this.motorSpeed;
142
+ const max = this.maxMotorForce * this._h;
143
+ const old = this._motorImpulse;
144
+ this._motorImpulse = Math.min(max, Math.max(-max, old - this._axialMass * cdot));
145
+ this._applyAxial(this._motorImpulse - old);
146
+ }
147
+ if (this.enableLimit) {
148
+ const cLower = this._translation - this.lowerTranslation;
149
+ let biasLower = 0;
150
+ if (cLower > 0) biasLower = cLower * this._invH;
151
+ else if (useBias) biasLower = .2 * this._invH * cLower;
152
+ const oldLower = this._lowerImpulse;
153
+ this._lowerImpulse = Math.max(0, oldLower - this._axialMass * (this._axisVelocity() + biasLower));
154
+ this._applyAxial(this._lowerImpulse - oldLower);
155
+ const cUpper = this.upperTranslation - this._translation;
156
+ let biasUpper = 0;
157
+ if (cUpper > 0) biasUpper = cUpper * this._invH;
158
+ else if (useBias) biasUpper = .2 * this._invH * cUpper;
159
+ const oldUpper = this._upperImpulse;
160
+ this._upperImpulse = Math.max(0, oldUpper - this._axialMass * (-this._axisVelocity() + biasUpper));
161
+ this._applyAxial(-(this._upperImpulse - oldUpper));
162
+ }
163
+ const cdotPerp = this._perpVelocity();
164
+ const cdotAngle = bodyB.angularVelocity - bodyA.angularVelocity;
165
+ const rhs1 = -(cdotPerp + (useBias ? .2 * this._invH * this._cPerp : 0));
166
+ const rhs2 = -(cdotAngle + (useBias ? .2 * this._invH * this._cAngle : 0));
167
+ const det = this._k11 * this._k22 - this._k12 * this._k12;
168
+ const invDet = det !== 0 ? 1 / det : 0;
169
+ const dPerp = invDet * (this._k22 * rhs1 - this._k12 * rhs2);
170
+ const dAngle = invDet * (-this._k12 * rhs1 + this._k11 * rhs2);
171
+ this._perpImpulse += dPerp;
172
+ this._angularImpulse += dAngle;
173
+ this._applyBlock(dPerp, dAngle);
174
+ }
175
+ /** Relative velocity projected onto the axis (plus the rotation cross terms). */
176
+ _axisVelocity() {
177
+ const bodyA = this.bodyA;
178
+ const bodyB = this.bodyB;
179
+ return this._axisX * (bodyB.linearVelocityX - bodyA.linearVelocityX) + this._axisY * (bodyB.linearVelocityY - bodyA.linearVelocityY) + this._a2 * bodyB.angularVelocity - this._a1 * bodyA.angularVelocity;
180
+ }
181
+ /** Relative velocity projected onto the perpendicular (plus the rotation cross terms). */
182
+ _perpVelocity() {
183
+ const bodyA = this.bodyA;
184
+ const bodyB = this.bodyB;
185
+ return this._perpX * (bodyB.linearVelocityX - bodyA.linearVelocityX) + this._perpY * (bodyB.linearVelocityY - bodyA.linearVelocityY) + this._s2 * bodyB.angularVelocity - this._s1 * bodyA.angularVelocity;
186
+ }
187
+ _applyAxial(impulse) {
188
+ const bodyA = this.bodyA;
189
+ const bodyB = this.bodyB;
190
+ const px = impulse * this._axisX;
191
+ const py = impulse * this._axisY;
192
+ bodyA.linearVelocityX -= bodyA.invMass * px;
193
+ bodyA.linearVelocityY -= bodyA.invMass * py;
194
+ bodyA.angularVelocity -= bodyA.invInertia * impulse * this._a1;
195
+ bodyB.linearVelocityX += bodyB.invMass * px;
196
+ bodyB.linearVelocityY += bodyB.invMass * py;
197
+ bodyB.angularVelocity += bodyB.invInertia * impulse * this._a2;
198
+ }
199
+ _applyBlock(perpImpulse, angularImpulse) {
200
+ const bodyA = this.bodyA;
201
+ const bodyB = this.bodyB;
202
+ const px = perpImpulse * this._perpX;
203
+ const py = perpImpulse * this._perpY;
204
+ bodyA.linearVelocityX -= bodyA.invMass * px;
205
+ bodyA.linearVelocityY -= bodyA.invMass * py;
206
+ bodyA.angularVelocity -= bodyA.invInertia * (perpImpulse * this._s1 + angularImpulse);
207
+ bodyB.linearVelocityX += bodyB.invMass * px;
208
+ bodyB.linearVelocityY += bodyB.invMass * py;
209
+ bodyB.angularVelocity += bodyB.invInertia * (perpImpulse * this._s2 + angularImpulse);
210
+ }
211
+ };
242
212
 
213
+ //#endregion
243
214
  export { PrismaticJoint };
244
- //# sourceMappingURL=PrismaticJoint.js.map
215
+ //# sourceMappingURL=PrismaticJoint.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"PrismaticJoint.js","sources":["../../../../src/joints/PrismaticJoint.ts"],"sourcesContent":[null],"names":[],"mappings":";;;AA6BA;AACA,MAAM,OAAO,GAAc,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE;AAEzC;;;;;AAKG;AACG,MAAO,cAAe,SAAQ,KAAK,CAAA;;AAEhC,IAAA,WAAW;;AAEX,IAAA,UAAU;;AAEV,IAAA,aAAa;;AAEb,IAAA,WAAW;;AAEX,IAAA,gBAAgB;;AAEhB,IAAA,gBAAgB;AAEN,IAAA,cAAc;AACd,IAAA,cAAc;AACd,IAAA,cAAc;AACd,IAAA,cAAc;AACd,IAAA,YAAY;AACZ,IAA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,GAAG,GAAG,cAAc,CAAC;IACvF;AACD;;;;"}
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,SAAgC;EACjD,MAAM,QAAQ,OAAO,QAAQ,KAAK;EAElC,sBAAsB,QAAQ,MAAM,WAAW,QAAQ,OAAO,GAAG,QAAQ,OAAO,GAAG,OAAO;EAC1F,KAAK,iBAAiB,QAAQ;EAC9B,KAAK,iBAAiB,QAAQ;EAC9B,sBAAsB,QAAQ,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Y,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,5 +1,5 @@
1
+ import type { PointLike } from '@codexo/exojs';
1
2
  import type { PhysicsBody } from '../PhysicsBody';
2
- import type { VectorLike } from '../types';
3
3
  import { Joint } from './Joint';
4
4
  /** Construction options for a {@link RevoluteJoint}. */
5
5
  export interface RevoluteJointOptions {
@@ -8,7 +8,7 @@ export interface RevoluteJointOptions {
8
8
  /** Second body. */
9
9
  bodyB: PhysicsBody;
10
10
  /** Shared world-space pivot point at creation. The two bodies are pinned here and may rotate freely about it. */
11
- anchor: VectorLike;
11
+ anchor: Readonly<PointLike>;
12
12
  /** Soft-spring frequency in Hz; `0` (default) makes it a rigid pin. */
13
13
  hertz?: number;
14
14
  /** Soft-spring damping ratio (used when `hertz > 0`). Default `1`. */
@@ -17,7 +17,7 @@ export interface RevoluteJointOptions {
17
17
  enableMotor?: boolean;
18
18
  /** Target relative angular velocity in rad/s when the motor is enabled. Default `0`. */
19
19
  motorSpeed?: number;
20
- /** Maximum motor torque clamps the per-step motor impulse. Default `0`. */
20
+ /** Maximum motor torque - clamps the per-step motor impulse. Default `0`. */
21
21
  maxMotorTorque?: number;
22
22
  /** Enable the angle limit (keeps the relative angle in `[lowerAngle, upperAngle]`). Default `false`. */
23
23
  enableLimit?: boolean;
@@ -79,3 +79,4 @@ export declare class RevoluteJoint extends Joint {
79
79
  _solve(useBias: boolean): void;
80
80
  private _applyImpulse;
81
81
  }
82
+ //# sourceMappingURL=RevoluteJoint.d.ts.map
@@ -0,0 +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;IACxB,wGAAwG;IACxG,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,8FAA8F;IAC9F,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,0DAA0D;IAC1D,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAKD;;;;GAIG;AACH,qBAAa,aAAc,SAAQ,KAAK;IACtC,iDAAiD;IAC1C,KAAK,EAAE,MAAM,CAAC;IACrB,iCAAiC;IAC1B,YAAY,EAAE,MAAM,CAAC;IAC5B,yEAAyE;IAClE,WAAW,EAAE,OAAO,CAAC;IAC5B,8DAA8D;IACvD,UAAU,EAAE,MAAM,CAAC;IAC1B,4BAA4B;IACrB,cAAc,EAAE,MAAM,CAAC;IAC9B,oFAAoF;IAC7E,WAAW,EAAE,OAA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