@codexo/exojs-physics 0.19.1 → 0.20.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 (207) hide show
  1. package/README.md +8 -73
  2. package/{dist/esm/debug/index.d.ts → debug.d.ts} +1 -2
  3. package/debug.js +1 -0
  4. package/index.d.ts +1 -0
  5. package/index.js +1 -0
  6. package/package.json +17 -23
  7. package/dist/esm/Aabb.d.ts +0 -10
  8. package/dist/esm/Aabb.d.ts.map +0 -1
  9. package/dist/esm/Aabb.js +0 -16
  10. package/dist/esm/Aabb.js.map +0 -1
  11. package/dist/esm/Collider.d.ts +0 -107
  12. package/dist/esm/Collider.d.ts.map +0 -1
  13. package/dist/esm/Collider.js +0 -284
  14. package/dist/esm/Collider.js.map +0 -1
  15. package/dist/esm/ContactGraph.d.ts +0 -154
  16. package/dist/esm/ContactGraph.d.ts.map +0 -1
  17. package/dist/esm/ContactGraph.js +0 -383
  18. package/dist/esm/ContactGraph.js.map +0 -1
  19. package/dist/esm/ContactModifier.d.ts +0 -62
  20. package/dist/esm/ContactModifier.d.ts.map +0 -1
  21. package/dist/esm/ContactModifier.js +0 -49
  22. package/dist/esm/ContactModifier.js.map +0 -1
  23. package/dist/esm/PhysicsBody.d.ts +0 -186
  24. package/dist/esm/PhysicsBody.d.ts.map +0 -1
  25. package/dist/esm/PhysicsBody.js +0 -526
  26. package/dist/esm/PhysicsBody.js.map +0 -1
  27. package/dist/esm/PhysicsBodyComponent.d.ts +0 -45
  28. package/dist/esm/PhysicsBodyComponent.d.ts.map +0 -1
  29. package/dist/esm/PhysicsBodyComponent.js +0 -77
  30. package/dist/esm/PhysicsBodyComponent.js.map +0 -1
  31. package/dist/esm/PhysicsWorld.d.ts +0 -567
  32. package/dist/esm/PhysicsWorld.d.ts.map +0 -1
  33. package/dist/esm/PhysicsWorld.js +0 -1096
  34. package/dist/esm/PhysicsWorld.js.map +0 -1
  35. package/dist/esm/TimeStepper.d.ts +0 -40
  36. package/dist/esm/TimeStepper.d.ts.map +0 -1
  37. package/dist/esm/TimeStepper.js +0 -59
  38. package/dist/esm/TimeStepper.js.map +0 -1
  39. package/dist/esm/backend/NativePhysicsBackend.d.ts +0 -28
  40. package/dist/esm/backend/NativePhysicsBackend.d.ts.map +0 -1
  41. package/dist/esm/backend/NativePhysicsBackend.js +0 -52
  42. package/dist/esm/backend/NativePhysicsBackend.js.map +0 -1
  43. package/dist/esm/backend/PhysicsBackend.d.ts +0 -38
  44. package/dist/esm/backend/PhysicsBackend.d.ts.map +0 -1
  45. package/dist/esm/binding/BindingRegistry.d.ts +0 -48
  46. package/dist/esm/binding/BindingRegistry.d.ts.map +0 -1
  47. package/dist/esm/binding/BindingRegistry.js +0 -81
  48. package/dist/esm/binding/BindingRegistry.js.map +0 -1
  49. package/dist/esm/binding/PhysicsBinding.d.ts +0 -37
  50. package/dist/esm/binding/PhysicsBinding.d.ts.map +0 -1
  51. package/dist/esm/binding/PhysicsBinding.js +0 -54
  52. package/dist/esm/binding/PhysicsBinding.js.map +0 -1
  53. package/dist/esm/binding/nodeWorldTransform.d.ts +0 -18
  54. package/dist/esm/binding/nodeWorldTransform.d.ts.map +0 -1
  55. package/dist/esm/binding/nodeWorldTransform.js +0 -41
  56. package/dist/esm/binding/nodeWorldTransform.js.map +0 -1
  57. package/dist/esm/broadphase/AabbTreeBroadPhase.d.ts +0 -84
  58. package/dist/esm/broadphase/AabbTreeBroadPhase.d.ts.map +0 -1
  59. package/dist/esm/broadphase/AabbTreeBroadPhase.js +0 -183
  60. package/dist/esm/broadphase/AabbTreeBroadPhase.js.map +0 -1
  61. package/dist/esm/broadphase/BroadPhase.d.ts +0 -25
  62. package/dist/esm/broadphase/BroadPhase.d.ts.map +0 -1
  63. package/dist/esm/broadphase/index.d.ts +0 -3
  64. package/dist/esm/broadphase/index.d.ts.map +0 -1
  65. package/dist/esm/collision/CollisionProxy.d.ts +0 -15
  66. package/dist/esm/collision/CollisionProxy.d.ts.map +0 -1
  67. package/dist/esm/collision/Manifold.d.ts +0 -34
  68. package/dist/esm/collision/Manifold.d.ts.map +0 -1
  69. package/dist/esm/collision/Manifold.js +0 -37
  70. package/dist/esm/collision/Manifold.js.map +0 -1
  71. package/dist/esm/collision/chainAdjacency.d.ts +0 -2
  72. package/dist/esm/collision/chainAdjacency.d.ts.map +0 -1
  73. package/dist/esm/collision/chainAdjacency.js +0 -44
  74. package/dist/esm/collision/chainAdjacency.js.map +0 -1
  75. package/dist/esm/collision/dispatch.d.ts +0 -35
  76. package/dist/esm/collision/dispatch.d.ts.map +0 -1
  77. package/dist/esm/collision/dispatch.js +0 -58
  78. package/dist/esm/collision/dispatch.js.map +0 -1
  79. package/dist/esm/collision/index.d.ts +0 -5
  80. package/dist/esm/collision/index.d.ts.map +0 -1
  81. package/dist/esm/collision/narrowphase.d.ts +0 -17
  82. package/dist/esm/collision/narrowphase.d.ts.map +0 -1
  83. package/dist/esm/collision/narrowphase.js +0 -555
  84. package/dist/esm/collision/narrowphase.js.map +0 -1
  85. package/dist/esm/collision/segments.d.ts +0 -19
  86. package/dist/esm/collision/segments.d.ts.map +0 -1
  87. package/dist/esm/collision/segments.js +0 -36
  88. package/dist/esm/collision/segments.js.map +0 -1
  89. package/dist/esm/collision/sweep.d.ts +0 -35
  90. package/dist/esm/collision/sweep.d.ts.map +0 -1
  91. package/dist/esm/collision/sweep.js +0 -437
  92. package/dist/esm/collision/sweep.js.map +0 -1
  93. package/dist/esm/debug/PhysicsDebugDraw.d.ts +0 -72
  94. package/dist/esm/debug/PhysicsDebugDraw.d.ts.map +0 -1
  95. package/dist/esm/debug/PhysicsDebugDraw.js +0 -239
  96. package/dist/esm/debug/PhysicsDebugDraw.js.map +0 -1
  97. package/dist/esm/debug/index.d.ts.map +0 -1
  98. package/dist/esm/debug/index.js +0 -3
  99. package/dist/esm/events.d.ts +0 -36
  100. package/dist/esm/events.d.ts.map +0 -1
  101. package/dist/esm/index.d.ts +0 -2
  102. package/dist/esm/index.d.ts.map +0 -1
  103. package/dist/esm/index.js +0 -25
  104. package/dist/esm/joints/DistanceJoint.d.ts +0 -70
  105. package/dist/esm/joints/DistanceJoint.d.ts.map +0 -1
  106. package/dist/esm/joints/DistanceJoint.js +0 -167
  107. package/dist/esm/joints/DistanceJoint.js.map +0 -1
  108. package/dist/esm/joints/Joint.d.ts +0 -76
  109. package/dist/esm/joints/Joint.d.ts.map +0 -1
  110. package/dist/esm/joints/Joint.js +0 -62
  111. package/dist/esm/joints/Joint.js.map +0 -1
  112. package/dist/esm/joints/MouseJoint.d.ts +0 -55
  113. package/dist/esm/joints/MouseJoint.d.ts.map +0 -1
  114. package/dist/esm/joints/MouseJoint.js +0 -139
  115. package/dist/esm/joints/MouseJoint.js.map +0 -1
  116. package/dist/esm/joints/PrismaticJoint.d.ts +0 -84
  117. package/dist/esm/joints/PrismaticJoint.d.ts.map +0 -1
  118. package/dist/esm/joints/PrismaticJoint.js +0 -218
  119. package/dist/esm/joints/PrismaticJoint.js.map +0 -1
  120. package/dist/esm/joints/RevoluteJoint.d.ts +0 -77
  121. package/dist/esm/joints/RevoluteJoint.d.ts.map +0 -1
  122. package/dist/esm/joints/RevoluteJoint.js +0 -204
  123. package/dist/esm/joints/RevoluteJoint.js.map +0 -1
  124. package/dist/esm/joints/WeldJoint.d.ts +0 -60
  125. package/dist/esm/joints/WeldJoint.d.ts.map +0 -1
  126. package/dist/esm/joints/WeldJoint.js +0 -166
  127. package/dist/esm/joints/WeldJoint.js.map +0 -1
  128. package/dist/esm/joints/WheelJoint.d.ts +0 -91
  129. package/dist/esm/joints/WheelJoint.d.ts.map +0 -1
  130. package/dist/esm/joints/WheelJoint.js +0 -235
  131. package/dist/esm/joints/WheelJoint.js.map +0 -1
  132. package/dist/esm/math.d.ts +0 -29
  133. package/dist/esm/math.d.ts.map +0 -1
  134. package/dist/esm/math.js +0 -60
  135. package/dist/esm/math.js.map +0 -1
  136. package/dist/esm/physicsBuildInfo.d.ts +0 -16
  137. package/dist/esm/physicsBuildInfo.d.ts.map +0 -1
  138. package/dist/esm/physicsBuildInfo.js +0 -10
  139. package/dist/esm/physicsBuildInfo.js.map +0 -1
  140. package/dist/esm/public.d.ts +0 -34
  141. package/dist/esm/public.d.ts.map +0 -1
  142. package/dist/esm/query/QueryEngine.d.ts +0 -95
  143. package/dist/esm/query/QueryEngine.d.ts.map +0 -1
  144. package/dist/esm/query/QueryEngine.js +0 -512
  145. package/dist/esm/query/QueryEngine.js.map +0 -1
  146. package/dist/esm/query/SpatialIndex.d.ts +0 -34
  147. package/dist/esm/query/SpatialIndex.d.ts.map +0 -1
  148. package/dist/esm/shapes/AnyShape.d.ts +0 -14
  149. package/dist/esm/shapes/AnyShape.d.ts.map +0 -1
  150. package/dist/esm/shapes/BoxShape.d.ts +0 -12
  151. package/dist/esm/shapes/BoxShape.d.ts.map +0 -1
  152. package/dist/esm/shapes/BoxShape.js +0 -41
  153. package/dist/esm/shapes/BoxShape.js.map +0 -1
  154. package/dist/esm/shapes/CapsuleShape.d.ts +0 -30
  155. package/dist/esm/shapes/CapsuleShape.d.ts.map +0 -1
  156. package/dist/esm/shapes/CapsuleShape.js +0 -88
  157. package/dist/esm/shapes/CapsuleShape.js.map +0 -1
  158. package/dist/esm/shapes/ChainEdgeShape.d.ts +0 -2
  159. package/dist/esm/shapes/ChainEdgeShape.d.ts.map +0 -1
  160. package/dist/esm/shapes/ChainEdgeShape.js +0 -66
  161. package/dist/esm/shapes/ChainEdgeShape.js.map +0 -1
  162. package/dist/esm/shapes/ChainShape.d.ts +0 -46
  163. package/dist/esm/shapes/ChainShape.d.ts.map +0 -1
  164. package/dist/esm/shapes/ChainShape.js +0 -85
  165. package/dist/esm/shapes/ChainShape.js.map +0 -1
  166. package/dist/esm/shapes/CircleShape.d.ts +0 -14
  167. package/dist/esm/shapes/CircleShape.d.ts.map +0 -1
  168. package/dist/esm/shapes/CircleShape.js +0 -31
  169. package/dist/esm/shapes/CircleShape.js.map +0 -1
  170. package/dist/esm/shapes/PolygonShape.d.ts +0 -24
  171. package/dist/esm/shapes/PolygonShape.d.ts.map +0 -1
  172. package/dist/esm/shapes/PolygonShape.js +0 -153
  173. package/dist/esm/shapes/PolygonShape.js.map +0 -1
  174. package/dist/esm/shapes/SegmentShape.d.ts +0 -31
  175. package/dist/esm/shapes/SegmentShape.d.ts.map +0 -1
  176. package/dist/esm/shapes/SegmentShape.js +0 -62
  177. package/dist/esm/shapes/SegmentShape.js.map +0 -1
  178. package/dist/esm/shapes/Shape.d.ts +0 -37
  179. package/dist/esm/shapes/Shape.d.ts.map +0 -1
  180. package/dist/esm/shapes/Shape.js +0 -15
  181. package/dist/esm/shapes/Shape.js.map +0 -1
  182. package/dist/esm/shapes/convexParts.d.ts +0 -21
  183. package/dist/esm/shapes/convexParts.d.ts.map +0 -1
  184. package/dist/esm/shapes/convexParts.js +0 -26
  185. package/dist/esm/shapes/convexParts.js.map +0 -1
  186. package/dist/esm/shapes/decompose.d.ts +0 -2
  187. package/dist/esm/shapes/decompose.d.ts.map +0 -1
  188. package/dist/esm/shapes/decompose.js +0 -272
  189. package/dist/esm/shapes/decompose.js.map +0 -1
  190. package/dist/esm/shapes/index.d.ts +0 -9
  191. package/dist/esm/shapes/index.d.ts.map +0 -1
  192. package/dist/esm/solver/ContactSolver.d.ts +0 -94
  193. package/dist/esm/solver/ContactSolver.d.ts.map +0 -1
  194. package/dist/esm/solver/ContactSolver.js +0 -457
  195. package/dist/esm/solver/ContactSolver.js.map +0 -1
  196. package/dist/esm/solver/tolerances.d.ts +0 -2
  197. package/dist/esm/solver/tolerances.d.ts.map +0 -1
  198. package/dist/esm/solver/tolerances.js +0 -36
  199. package/dist/esm/solver/tolerances.js.map +0 -1
  200. package/dist/esm/sort.d.ts +0 -2
  201. package/dist/esm/sort.d.ts.map +0 -1
  202. package/dist/esm/sort.js +0 -44
  203. package/dist/esm/sort.js.map +0 -1
  204. package/dist/esm/types.d.ts +0 -35
  205. package/dist/esm/types.d.ts.map +0 -1
  206. package/dist/esm/types.js +0 -26
  207. package/dist/esm/types.js.map +0 -1
@@ -1,218 +0,0 @@
1
- import { applyInverseRotation, applyInverseTransform, applyRotation, applyTransform } from "../math.js";
2
- import { Joint } from "./Joint.js";
3
-
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
- };
10
- /**
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, options.collideConnected);
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
- /** @internal */
80
- _prepare(h, _rigid) {
81
- const bodyA = this.bodyA;
82
- const bodyB = this.bodyB;
83
- this._active = this.enabled && !bodyA.isSleeping && !bodyB.isSleeping && (bodyA.invMass > 0 || bodyB.invMass > 0);
84
- if (!this._active) return;
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
- this._a1 = (dx + rAx) * axisY - (dy + rAy) * axisX;
107
- this._a2 = rBx * axisY - rBy * axisX;
108
- this._s1 = (dx + rAx) * perpY - (dy + rAy) * perpX;
109
- this._s2 = rBx * perpY - rBy * perpX;
110
- const mA = bodyA.invMass;
111
- const mB = bodyB.invMass;
112
- const iA = bodyA.invInertia;
113
- const iB = bodyB.invInertia;
114
- const kAxial = mA + mB + iA * this._a1 * this._a1 + iB * this._a2 * this._a2;
115
- this._axialMass = kAxial > 0 ? 1 / kAxial : 0;
116
- this._k11 = mA + mB + iA * this._s1 * this._s1 + iB * this._s2 * this._s2;
117
- this._k12 = iA * this._s1 + iB * this._s2;
118
- this._k22 = iA + iB;
119
- if (this._k22 === 0) this._k22 = 1;
120
- this._cPerp = dx * perpX + dy * perpY;
121
- this._cAngle = bodyB.angle - bodyA.angle - this._referenceAngle;
122
- this._translation = dx * axisX + dy * axisY;
123
- this._h = h;
124
- this._invH = 1 / h;
125
- if (!this.enableMotor) this._motorImpulse = 0;
126
- if (!this.enableLimit) {
127
- this._lowerImpulse = 0;
128
- this._upperImpulse = 0;
129
- }
130
- }
131
- /** @internal */
132
- _warmStart() {
133
- if (!this._active) return;
134
- const axial = this._motorImpulse + this._lowerImpulse - this._upperImpulse;
135
- this._applyBlock(this._perpImpulse, this._angularImpulse);
136
- this._applyAxial(axial);
137
- }
138
- /** @internal */
139
- _solve(useBias) {
140
- if (!this._active) return;
141
- const bodyA = this.bodyA;
142
- const bodyB = this.bodyB;
143
- if (this.enableMotor) {
144
- const cdot = this._axisVelocity() - this.motorSpeed;
145
- const max = this.maxMotorForce * this._h;
146
- const old = this._motorImpulse;
147
- this._motorImpulse = Math.min(max, Math.max(-max, old - this._axialMass * cdot));
148
- this._applyAxial(this._motorImpulse - old);
149
- }
150
- if (this.enableLimit) {
151
- const cLower = this._translation - this.lowerTranslation;
152
- let biasLower = 0;
153
- if (cLower > 0) biasLower = cLower * this._invH;
154
- else if (useBias) biasLower = .2 * this._invH * cLower;
155
- const oldLower = this._lowerImpulse;
156
- this._lowerImpulse = Math.max(0, oldLower - this._axialMass * (this._axisVelocity() + biasLower));
157
- this._applyAxial(this._lowerImpulse - oldLower);
158
- const cUpper = this.upperTranslation - this._translation;
159
- let biasUpper = 0;
160
- if (cUpper > 0) biasUpper = cUpper * this._invH;
161
- else if (useBias) biasUpper = .2 * this._invH * cUpper;
162
- const oldUpper = this._upperImpulse;
163
- this._upperImpulse = Math.max(0, oldUpper - this._axialMass * (-this._axisVelocity() + biasUpper));
164
- this._applyAxial(-(this._upperImpulse - oldUpper));
165
- }
166
- const cdotPerp = this._perpVelocity();
167
- const cdotAngle = bodyB.angularVelocity - bodyA.angularVelocity;
168
- const rhs1 = -(cdotPerp + (useBias ? .2 * this._invH * this._cPerp : 0));
169
- const rhs2 = -(cdotAngle + (useBias ? .2 * this._invH * this._cAngle : 0));
170
- const det = this._k11 * this._k22 - this._k12 * this._k12;
171
- const invDet = det !== 0 ? 1 / det : 0;
172
- const dPerp = invDet * (this._k22 * rhs1 - this._k12 * rhs2);
173
- const dAngle = invDet * (-this._k12 * rhs1 + this._k11 * rhs2);
174
- this._perpImpulse += dPerp;
175
- this._angularImpulse += dAngle;
176
- this._applyBlock(dPerp, dAngle);
177
- }
178
- /** Relative velocity projected onto the axis (plus the rotation cross terms). */
179
- _axisVelocity() {
180
- const bodyA = this.bodyA;
181
- const bodyB = this.bodyB;
182
- return this._axisX * (bodyB.linearVelocityX - bodyA.linearVelocityX) + this._axisY * (bodyB.linearVelocityY - bodyA.linearVelocityY) + this._a2 * bodyB.angularVelocity - this._a1 * bodyA.angularVelocity;
183
- }
184
- /** Relative velocity projected onto the perpendicular (plus the rotation cross terms). */
185
- _perpVelocity() {
186
- const bodyA = this.bodyA;
187
- const bodyB = this.bodyB;
188
- return this._perpX * (bodyB.linearVelocityX - bodyA.linearVelocityX) + this._perpY * (bodyB.linearVelocityY - bodyA.linearVelocityY) + this._s2 * bodyB.angularVelocity - this._s1 * bodyA.angularVelocity;
189
- }
190
- _applyAxial(impulse) {
191
- const bodyA = this.bodyA;
192
- const bodyB = this.bodyB;
193
- const px = impulse * this._axisX;
194
- const py = impulse * this._axisY;
195
- bodyA.linearVelocityX -= bodyA.invMass * px;
196
- bodyA.linearVelocityY -= bodyA.invMass * py;
197
- bodyA.angularVelocity -= bodyA.invInertia * impulse * this._a1;
198
- bodyB.linearVelocityX += bodyB.invMass * px;
199
- bodyB.linearVelocityY += bodyB.invMass * py;
200
- bodyB.angularVelocity += bodyB.invInertia * impulse * this._a2;
201
- }
202
- _applyBlock(perpImpulse, angularImpulse) {
203
- const bodyA = this.bodyA;
204
- const bodyB = this.bodyB;
205
- const px = perpImpulse * this._perpX;
206
- const py = perpImpulse * this._perpY;
207
- bodyA.linearVelocityX -= bodyA.invMass * px;
208
- bodyA.linearVelocityY -= bodyA.invMass * py;
209
- bodyA.angularVelocity -= bodyA.invInertia * (perpImpulse * this._s1 + angularImpulse);
210
- bodyB.linearVelocityX += bodyB.invMass * px;
211
- bodyB.linearVelocityY += bodyB.invMass * py;
212
- bodyB.angularVelocity += bodyB.invInertia * (perpImpulse * this._s2 + angularImpulse);
213
- }
214
- };
215
-
216
- //#endregion
217
- export { PrismaticJoint };
218
- //# sourceMappingURL=PrismaticJoint.js.map
@@ -1 +0,0 @@
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 *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,MAAM,mBAAmB,MAAM,UAAU;EACzC,MAAM,mBAAmB,MAAM,UAAU;EACzC,MAAM,mBAAmB,MAAM,cAAc,cAAc,KAAK,MAAM;CACxE;AACF"}
@@ -1,77 +0,0 @@
1
- import type { PointLike } from '@codexo/exojs';
2
- import type { PhysicsBody } from '../PhysicsBody';
3
- import type { JointOptions } from './Joint';
4
- import { Joint } from './Joint';
5
- /** Construction options for a {@link RevoluteJoint}. */
6
- export interface RevoluteJointOptions extends JointOptions {
7
- /** First body (often a static anchor). */
8
- bodyA: PhysicsBody;
9
- /** Second body. */
10
- bodyB: PhysicsBody;
11
- /** Shared world-space pivot point at creation. The two bodies are pinned here and may rotate freely about it. */
12
- anchor: Readonly<PointLike>;
13
- /** Soft-spring frequency in Hz; `0` (default) makes it a rigid pin. */
14
- hertz?: number;
15
- /** Soft-spring damping ratio (used when `hertz > 0`). Default `1`. */
16
- dampingRatio?: number;
17
- /** Enable the angular motor (drives `ωB − ωA` toward {@link motorSpeed}). Default `false`. */
18
- enableMotor?: boolean;
19
- /** Target relative angular velocity in rad/s when the motor is enabled. Default `0`. */
20
- motorSpeed?: number;
21
- /** Maximum motor torque - clamps the per-step motor impulse. Default `0`. */
22
- maxMotorTorque?: number;
23
- /** Enable the angle limit (keeps the relative angle in `[lowerAngle, upperAngle]`). Default `false`. */
24
- enableLimit?: boolean;
25
- /** Lower relative-angle limit in radians (relative to the angle at creation). Default `0`. */
26
- lowerAngle?: number;
27
- /** Upper relative-angle limit in radians. Default `0`. */
28
- upperAngle?: number;
29
- }
30
- /**
31
- * Pins a shared anchor point on two bodies (a hinge): the bodies may rotate
32
- * freely about the pivot but the anchor points stay coincident. Solved as a
33
- * 2-DOF point constraint (a 2×2 block) in the sub-step loop, warm-started.
34
- */
35
- export declare class RevoluteJoint extends Joint {
36
- /** Soft-spring frequency in Hz (`0` = rigid). */
37
- hertz: number;
38
- /** Soft-spring damping ratio. */
39
- dampingRatio: number;
40
- /** When `true`, the motor drives `ωB − ωA` toward {@link motorSpeed}. */
41
- enableMotor: boolean;
42
- /** Target relative angular velocity (rad/s) for the motor. */
43
- motorSpeed: number;
44
- /** Maximum motor torque. */
45
- maxMotorTorque: number;
46
- /** When `true`, the relative angle is constrained to `[lowerAngle, upperAngle]`. */
47
- enableLimit: boolean;
48
- /** Lower relative-angle limit (radians, relative to the creation angle). */
49
- lowerAngle: number;
50
- /** Upper relative-angle limit (radians). */
51
- upperAngle: number;
52
- private readonly _localAnchorAx;
53
- private readonly _localAnchorAy;
54
- private readonly _localAnchorBx;
55
- private readonly _localAnchorBy;
56
- private _rAx;
57
- private _rAy;
58
- private _rBx;
59
- private _rBy;
60
- private _c0x;
61
- private _c0y;
62
- private _biasRate;
63
- private _massScale;
64
- private _impulseScale;
65
- private _impulseX;
66
- private _impulseY;
67
- private readonly _referenceAngle;
68
- private _axialMass;
69
- private _h;
70
- private _invH;
71
- private _motorImpulse;
72
- private _lowerImpulse;
73
- private _upperImpulse;
74
- constructor(options: RevoluteJointOptions);
75
- private _applyImpulse;
76
- }
77
- //# sourceMappingURL=RevoluteJoint.d.ts.map
@@ -1 +0,0 @@
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,KAAK,EAAE,YAAY,EAAiB,MAAM,SAAS,CAAC;AAC3D,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAEhC,wDAAwD;AACxD,MAAM,WAAW,oBAAqB,SAAQ,YAAY;IACxD,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,K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,CAAC,aAAa,CAAK;IAC1B,OAAO,CAAC,SAAS,CAAK;IACtB,OAAO,CAAC,SAAS,CAAK;IACtB,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAS;IACzC,OAAO,CAAC,UAAU,CAAK;IACvB,OAAO,CAAC,EAAE,CAAK;IACf,OAAO,CAAC,KAAK,CAAK;IAClB,OAAO,CAAC,aAAa,CAAK;IAC1B,OAAO,CAAC,aAAa,CAAK;IAC1B,OAAO,CAAC,aAAa,CAAK;IAE1B,YAAmB,OAAO,EAAE,oBAAoB,EAmB/C;IA4MD,OAAO,CAAC,aAAa;CAWtB"}
@@ -1,204 +0,0 @@
1
- import { applyInverseTransform, applyTransform } from "../math.js";
2
- import { Joint } from "./Joint.js";
3
-
4
- //#region src/joints/RevoluteJoint.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
- };
10
- /**
11
- * Pins a shared anchor point on two bodies (a hinge): the bodies may rotate
12
- * freely about the pivot but the anchor points stay coincident. Solved as a
13
- * 2-DOF point constraint (a 2×2 block) in the sub-step loop, warm-started.
14
- */
15
- var RevoluteJoint = class extends Joint {
16
- /** Soft-spring frequency in Hz (`0` = rigid). */
17
- hertz;
18
- /** Soft-spring damping ratio. */
19
- dampingRatio;
20
- /** When `true`, the motor drives `ωB − ωA` toward {@link motorSpeed}. */
21
- enableMotor;
22
- /** Target relative angular velocity (rad/s) for the motor. */
23
- motorSpeed;
24
- /** Maximum motor torque. */
25
- maxMotorTorque;
26
- /** When `true`, the relative angle is constrained to `[lowerAngle, upperAngle]`. */
27
- enableLimit;
28
- /** Lower relative-angle limit (radians, relative to the creation angle). */
29
- lowerAngle;
30
- /** Upper relative-angle limit (radians). */
31
- upperAngle;
32
- _localAnchorAx;
33
- _localAnchorAy;
34
- _localAnchorBx;
35
- _localAnchorBy;
36
- _rAx = 0;
37
- _rAy = 0;
38
- _rBx = 0;
39
- _rBy = 0;
40
- _c0x = 0;
41
- _c0y = 0;
42
- _biasRate = 0;
43
- _massScale = 1;
44
- _impulseScale = 0;
45
- _impulseX = 0;
46
- _impulseY = 0;
47
- _referenceAngle;
48
- _axialMass = 0;
49
- _h = 0;
50
- _invH = 0;
51
- _motorImpulse = 0;
52
- _lowerImpulse = 0;
53
- _upperImpulse = 0;
54
- constructor(options) {
55
- super(options.bodyA, options.bodyB, options.collideConnected);
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
- this.hertz = options.hertz ?? 0;
63
- this.dampingRatio = options.dampingRatio ?? 1;
64
- this.enableMotor = options.enableMotor ?? false;
65
- this.motorSpeed = options.motorSpeed ?? 0;
66
- this.maxMotorTorque = options.maxMotorTorque ?? 0;
67
- this.enableLimit = options.enableLimit ?? false;
68
- this.lowerAngle = options.lowerAngle ?? 0;
69
- this.upperAngle = options.upperAngle ?? 0;
70
- this._referenceAngle = options.bodyB.angle - options.bodyA.angle;
71
- }
72
- /** @internal */
73
- _prepare(h, rigid) {
74
- const bodyA = this.bodyA;
75
- const bodyB = this.bodyB;
76
- this._active = this.enabled && !bodyA.isSleeping && !bodyB.isSleeping && (bodyA.invMass > 0 || bodyB.invMass > 0);
77
- if (!this._active) return;
78
- applyTransform(bodyA.transform, this._localAnchorAx, this._localAnchorAy, scratch);
79
- const pAx = scratch.x;
80
- const pAy = scratch.y;
81
- applyTransform(bodyB.transform, this._localAnchorBx, this._localAnchorBy, scratch);
82
- const pBx = scratch.x;
83
- const pBy = scratch.y;
84
- this._rAx = pAx - bodyA.worldCenterOfMassX;
85
- this._rAy = pAy - bodyA.worldCenterOfMassY;
86
- this._rBx = pBx - bodyB.worldCenterOfMassX;
87
- this._rBy = pBy - bodyB.worldCenterOfMassY;
88
- this._c0x = pBx - pAx;
89
- this._c0y = pBy - pAy;
90
- const iA = bodyA.invInertia;
91
- const iB = bodyB.invInertia;
92
- this._axialMass = iA + iB > 0 ? 1 / (iA + iB) : 0;
93
- this._h = h;
94
- this._invH = 1 / h;
95
- if (!this.enableMotor) this._motorImpulse = 0;
96
- if (!this.enableLimit) {
97
- this._lowerImpulse = 0;
98
- this._upperImpulse = 0;
99
- }
100
- if (this.hertz > 0) {
101
- const omega = 2 * Math.PI * this.hertz;
102
- const a1 = 2 * this.dampingRatio + h * omega;
103
- const a2 = h * omega * a1;
104
- const a3 = 1 / (1 + a2);
105
- this._biasRate = omega / a1;
106
- this._massScale = a2 * a3;
107
- this._impulseScale = a3;
108
- } else {
109
- this._biasRate = rigid.biasRate;
110
- this._massScale = rigid.massScale;
111
- this._impulseScale = rigid.impulseScale;
112
- }
113
- }
114
- /** @internal */
115
- _warmStart() {
116
- if (!this._active) return;
117
- const axial = this._motorImpulse + this._lowerImpulse - this._upperImpulse;
118
- this.bodyA.angularVelocity -= this.bodyA.invInertia * axial;
119
- this.bodyB.angularVelocity += this.bodyB.invInertia * axial;
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);
127
- }
128
- /** @internal */
129
- _solve(useBias) {
130
- if (!this._active) return;
131
- const bodyA = this.bodyA;
132
- const bodyB = this.bodyB;
133
- const iA = bodyA.invInertia;
134
- const iB = bodyB.invInertia;
135
- if (this.enableMotor) {
136
- const cdot = bodyB.angularVelocity - bodyA.angularVelocity - this.motorSpeed;
137
- const max = this.maxMotorTorque * this._h;
138
- const old = this._motorImpulse;
139
- this._motorImpulse = Math.min(max, Math.max(-max, old - this._axialMass * cdot));
140
- const applied = this._motorImpulse - old;
141
- bodyA.angularVelocity -= iA * applied;
142
- bodyB.angularVelocity += iB * applied;
143
- }
144
- if (this.enableLimit) {
145
- const angle = bodyB.angle + bodyB._deltaAngle - (bodyA.angle + bodyA._deltaAngle) - this._referenceAngle;
146
- const cLower = angle - this.lowerAngle;
147
- let biasLower = 0;
148
- if (cLower > 0) biasLower = cLower * this._invH;
149
- else if (useBias) biasLower = .2 * this._invH * cLower;
150
- const oldLower = this._lowerImpulse;
151
- this._lowerImpulse = Math.max(0, oldLower - this._axialMass * (bodyB.angularVelocity - bodyA.angularVelocity + biasLower));
152
- const appliedLower = this._lowerImpulse - oldLower;
153
- bodyA.angularVelocity -= iA * appliedLower;
154
- bodyB.angularVelocity += iB * appliedLower;
155
- const cUpper = this.upperAngle - angle;
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 * (bodyA.angularVelocity - bodyB.angularVelocity + biasUpper));
161
- const appliedUpper = this._upperImpulse - oldUpper;
162
- bodyA.angularVelocity += iA * appliedUpper;
163
- bodyB.angularVelocity -= iB * appliedUpper;
164
- }
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);
184
- const impulseX = -this._massScale * solvedX - this._impulseScale * this._impulseX;
185
- const impulseY = -this._massScale * solvedY - this._impulseScale * this._impulseY;
186
- this._impulseX += impulseX;
187
- this._impulseY += impulseY;
188
- this._applyImpulse(impulseX, impulseY, rotAx, rotAy, rotBx, rotBy);
189
- }
190
- _applyImpulse(jx, jy, rAx, rAy, rBx, rBy) {
191
- const bodyA = this.bodyA;
192
- const bodyB = this.bodyB;
193
- bodyA.linearVelocityX -= bodyA.invMass * jx;
194
- bodyA.linearVelocityY -= bodyA.invMass * jy;
195
- bodyA.angularVelocity -= bodyA.invInertia * (rAx * jy - rAy * jx);
196
- bodyB.linearVelocityX += bodyB.invMass * jx;
197
- bodyB.linearVelocityY += bodyB.invMass * jy;
198
- bodyB.angularVelocity += bodyB.invInertia * (rBx * jy - rBy * jx);
199
- }
200
- };
201
-
202
- //#endregion
203
- export { RevoluteJoint };
204
- //# sourceMappingURL=RevoluteJoint.js.map
@@ -1 +0,0 @@
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 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,AAAiB;CACjB,AAA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B;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,60 +0,0 @@
1
- import type { PointLike } from '@codexo/exojs';
2
- import type { PhysicsBody } from '../PhysicsBody';
3
- import type { JointOptions } from './Joint';
4
- import { Joint } from './Joint';
5
- /** Construction options for a {@link WeldJoint}. */
6
- export interface WeldJointOptions extends JointOptions {
7
- /** First body. */
8
- bodyA: PhysicsBody;
9
- /** Second body. */
10
- bodyB: PhysicsBody;
11
- /** World-space anchor the linear constraint acts at. Default: the midpoint of the two bodies. */
12
- anchor?: Readonly<PointLike>;
13
- /** Locked relative angle `angleB − angleA`. Default: the current relative angle at creation. */
14
- referenceAngle?: number;
15
- /** Soft frequency (Hz) for the position lock; `0` (default) is rigid. */
16
- linearHertz?: number;
17
- /** Soft frequency (Hz) for the angle lock; `0` (default) is rigid. */
18
- angularHertz?: number;
19
- /** Soft damping ratio (used when a hertz is `> 0`). Default `1`. */
20
- dampingRatio?: number;
21
- }
22
- /**
23
- * Rigidly fixes the relative position and orientation of two bodies (they move
24
- * as one rigid body). A 2-DOF point constraint (like {@link RevoluteJoint}) plus
25
- * a 1-DOF angular constraint, solved in the sub-step loop. Both locks default to
26
- * rigid; set `linearHertz`/`angularHertz` for a springy weld.
27
- */
28
- export declare class WeldJoint extends Joint {
29
- /** Locked relative angle `angleB − angleA`. */
30
- referenceAngle: number;
31
- /** Soft frequency for the position lock (`0` = rigid). */
32
- linearHertz: number;
33
- /** Soft frequency for the angle lock (`0` = rigid). */
34
- angularHertz: number;
35
- /** Soft damping ratio. */
36
- dampingRatio: number;
37
- private readonly _localAnchorAx;
38
- private readonly _localAnchorAy;
39
- private readonly _localAnchorBx;
40
- private readonly _localAnchorBy;
41
- private _rAx;
42
- private _rAy;
43
- private _rBx;
44
- private _rBy;
45
- private _cx;
46
- private _cy;
47
- private _invK11;
48
- private _invK12;
49
- private _invK22;
50
- private _angleError;
51
- private _effMassAngle;
52
- private readonly _linear;
53
- private readonly _angular;
54
- private _impulseX;
55
- private _impulseY;
56
- private _impulseAngle;
57
- constructor(options: WeldJointOptions);
58
- private _applyLinearImpulse;
59
- }
60
- //# sourceMappingURL=WeldJoint.d.ts.map
@@ -1 +0,0 @@
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,KAAK,EAAE,YAAY,EAAiB,MAAM,SAAS,CAAC;AAC3D,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAE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