|
21 | 21 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
22 | 22 | * POSSIBILITY OF SUCH DAMAGE. |
23 | 23 | */ |
24 | | -/* |
25 | | - * JBox2D - A Java Port of Erin Catto's Box2D |
26 | | - * |
27 | | - * JBox2D homepage: http://jbox2d.sourceforge.net/ |
28 | | - * Box2D homepage: http://www.box2d.org |
29 | | - * |
30 | | - * This software is provided 'as-is', without any express or implied |
31 | | - * warranty. In no event will the authors be held liable for any damages |
32 | | - * arising from the use of this software. |
33 | | - * |
34 | | - * Permission is granted to anyone to use this software for any purpose, |
35 | | - * including commercial applications, and to alter it and redistribute it |
36 | | - * freely, subject to the following restrictions: |
37 | | - * |
38 | | - * 1. The origin of this software must not be misrepresented; you must not |
39 | | - * claim that you wrote the original software. If you use this software |
40 | | - * in a product, an acknowledgment in the product documentation would be |
41 | | - * appreciated but is not required. |
42 | | - * 2. Altered source versions must be plainly marked as such, and must not be |
43 | | - * misrepresented as being the original software. |
44 | | - * 3. This notice may not be removed or altered from any source distribution. |
45 | | - */ |
46 | 24 | package de.pirckheimer_gymnasium.jbox2d.dynamics.joints; |
47 | 25 |
|
48 | 26 | import de.pirckheimer_gymnasium.jbox2d.common.MathUtils; |
|
62 | 40 | * A distance joint constrains two points on two bodies to remain at a fixed |
63 | 41 | * distance from each other. You can view this as a massless, rigid rod. |
64 | 42 | * |
| 43 | + * <p> |
| 44 | + * One of the simplest joint is a distance joint which says that the distance |
| 45 | + * between two points on two bodies must be constant. When you specify a |
| 46 | + * distance joint the two bodies should already be in place. Then you specify |
| 47 | + * the two anchor points in world coordinates. The first anchor point is |
| 48 | + * connected to body 1, and the second anchor point is connected to body 2. |
| 49 | + * These points imply the length of the distance constraint. |
| 50 | + * </p> |
| 51 | + * |
| 52 | + * <p> |
| 53 | + * Here is an example of a distance joint definition. In this case we decide to |
| 54 | + * allow the bodies to collide. |
| 55 | + * </p> |
| 56 | + * |
| 57 | + * <p> |
| 58 | + * The distance joint can also be made soft, like a spring-damper connection. |
| 59 | + * </p> |
| 60 | + * |
| 61 | + * <p> |
| 62 | + * Softness is achieved by tuning two constants in the definition: stiffness and |
| 63 | + * damping. It can be non-intuitive setting these values directly since they |
| 64 | + * have units in terms on Newtons. |
| 65 | + * </p> |
| 66 | + * |
| 67 | + * <p> |
| 68 | + * Think of the frequency as the frequency of a harmonic oscillator (like a |
| 69 | + * guitar string). The frequency is specified in Hertz. Typically the frequency |
| 70 | + * should be less than a half the frequency of the time step. So if you are |
| 71 | + * using a 60Hz time step, the frequency of the distance joint should be less |
| 72 | + * than 30Hz. The reason is related to the Nyquist frequency. |
| 73 | + * </p> |
| 74 | + * |
| 75 | + * <p> |
| 76 | + * The damping ratio is non-dimensional and is typically between 0 and 1, but |
| 77 | + * can be larger. At 1, the damping is critical (all oscillations should |
| 78 | + * vanish). |
| 79 | + * </p> |
| 80 | + * |
| 81 | + * <p> |
| 82 | + * It is also possible to define a minimum and maximum length for the distance |
| 83 | + * joint. |
| 84 | + * </p> |
| 85 | + * |
65 | 86 | * @author Daniel Murphy |
66 | 87 | */ |
67 | 88 | public class DistanceJoint extends Joint |
68 | 89 | { |
| 90 | + /** |
| 91 | + * The mass-spring-damper frequency in Hertz. |
| 92 | + */ |
69 | 93 | private float frequencyHz; |
70 | 94 |
|
| 95 | + /** |
| 96 | + * The damping ratio. 0 = no damping, 1 = critical damping. |
| 97 | + */ |
71 | 98 | private float dampingRatio; |
72 | 99 |
|
73 | 100 | private float bias; |
74 | 101 |
|
75 | | - // Solver shared |
| 102 | + /** |
| 103 | + * The local anchor point relative to body1's origin. |
| 104 | + */ |
76 | 105 | private final Vec2 localAnchorA; |
77 | 106 |
|
| 107 | + /** |
| 108 | + * The local anchor point relative to body2's origin. |
| 109 | + */ |
78 | 110 | private final Vec2 localAnchorB; |
79 | 111 |
|
80 | 112 | private float gamma; |
@@ -278,9 +310,9 @@ public void initVelocityConstraints(final SolverData data) |
278 | 310 | { |
279 | 311 | impulse = 0.0f; |
280 | 312 | } |
281 | | -// data.velocities[indexA].v.set(vA); |
| 313 | + // data.velocities[indexA].v.set(vA); |
282 | 314 | data.velocities[indexA].w = wA; |
283 | | -// data.velocities[indexB].v.set(vB); |
| 315 | + // data.velocities[indexB].v.set(vB); |
284 | 316 | data.velocities[indexB].w = wB; |
285 | 317 | } |
286 | 318 |
|
@@ -309,9 +341,9 @@ public void solveVelocityConstraints(final SolverData data) |
309 | 341 | vB.x += invMassB * Px; |
310 | 342 | vB.y += invMassB * Py; |
311 | 343 | wB += invIB * (rB.x * Py - rB.y * Px); |
312 | | -// data.velocities[indexA].v.set(vA); |
| 344 | + // data.velocities[indexA].v.set(vA); |
313 | 345 | data.velocities[indexA].w = wA; |
314 | | -// data.velocities[indexB].v.set(vB); |
| 346 | + // data.velocities[indexB].v.set(vB); |
315 | 347 | data.velocities[indexB].w = wB; |
316 | 348 | pool.pushVec2(2); |
317 | 349 | } |
@@ -350,9 +382,9 @@ public boolean solvePositionConstraints(final SolverData data) |
350 | 382 | cB.x += invMassB * Px; |
351 | 383 | cB.y += invMassB * Py; |
352 | 384 | aB += invIB * (rB.x * Py - rB.y * Px); |
353 | | -// data.positions[indexA].c.set(cA); |
| 385 | + // data.positions[indexA].c.set(cA); |
354 | 386 | data.positions[indexA].a = aA; |
355 | | -// data.positions[indexB].c.set(cB); |
| 387 | + // data.positions[indexB].c.set(cB); |
356 | 388 | data.positions[indexB].a = aB; |
357 | 389 | pool.pushVec2(3); |
358 | 390 | pool.pushRot(2); |
|
0 commit comments