Skip to content

Commit 197b9fa

Browse files
Add joint images
1 parent c4738d7 commit 197b9fa

File tree

14 files changed

+828
-32
lines changed

14 files changed

+828
-32
lines changed

jbox2d-library/src/main/java/de/pirckheimer_gymnasium/jbox2d/dynamics/World.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1041,23 +1041,23 @@ public int getContactCount()
10411041
}
10421042

10431043
/**
1044-
* Gets the height of the dynamic tree
1044+
* Get the height of the dynamic tree.
10451045
*/
10461046
public int getTreeHeight()
10471047
{
10481048
return contactManager.broadPhase.getTreeHeight();
10491049
}
10501050

10511051
/**
1052-
* Gets the balance of the dynamic tree
1052+
* Get the balance of the dynamic tree.
10531053
*/
10541054
public int getTreeBalance()
10551055
{
10561056
return contactManager.broadPhase.getTreeBalance();
10571057
}
10581058

10591059
/**
1060-
* Gets the quality of the dynamic tree
1060+
* Get the quality of the dynamic tree.
10611061
*/
10621062
public float getTreeQuality()
10631063
{

jbox2d-library/src/main/java/de/pirckheimer_gymnasium/jbox2d/dynamics/joints/DistanceJoint.java

Lines changed: 61 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -21,28 +21,6 @@
2121
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2222
* POSSIBILITY OF SUCH DAMAGE.
2323
*/
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-
*/
4624
package de.pirckheimer_gymnasium.jbox2d.dynamics.joints;
4725

4826
import de.pirckheimer_gymnasium.jbox2d.common.MathUtils;
@@ -62,19 +40,73 @@
6240
* A distance joint constrains two points on two bodies to remain at a fixed
6341
* distance from each other. You can view this as a massless, rigid rod.
6442
*
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+
*
6586
* @author Daniel Murphy
6687
*/
6788
public class DistanceJoint extends Joint
6889
{
90+
/**
91+
* The mass-spring-damper frequency in Hertz.
92+
*/
6993
private float frequencyHz;
7094

95+
/**
96+
* The damping ratio. 0 = no damping, 1 = critical damping.
97+
*/
7198
private float dampingRatio;
7299

73100
private float bias;
74101

75-
// Solver shared
102+
/**
103+
* The local anchor point relative to body1's origin.
104+
*/
76105
private final Vec2 localAnchorA;
77106

107+
/**
108+
* The local anchor point relative to body2's origin.
109+
*/
78110
private final Vec2 localAnchorB;
79111

80112
private float gamma;
@@ -278,9 +310,9 @@ public void initVelocityConstraints(final SolverData data)
278310
{
279311
impulse = 0.0f;
280312
}
281-
// data.velocities[indexA].v.set(vA);
313+
// data.velocities[indexA].v.set(vA);
282314
data.velocities[indexA].w = wA;
283-
// data.velocities[indexB].v.set(vB);
315+
// data.velocities[indexB].v.set(vB);
284316
data.velocities[indexB].w = wB;
285317
}
286318

@@ -309,9 +341,9 @@ public void solveVelocityConstraints(final SolverData data)
309341
vB.x += invMassB * Px;
310342
vB.y += invMassB * Py;
311343
wB += invIB * (rB.x * Py - rB.y * Px);
312-
// data.velocities[indexA].v.set(vA);
344+
// data.velocities[indexA].v.set(vA);
313345
data.velocities[indexA].w = wA;
314-
// data.velocities[indexB].v.set(vB);
346+
// data.velocities[indexB].v.set(vB);
315347
data.velocities[indexB].w = wB;
316348
pool.pushVec2(2);
317349
}
@@ -350,9 +382,9 @@ public boolean solvePositionConstraints(final SolverData data)
350382
cB.x += invMassB * Px;
351383
cB.y += invMassB * Py;
352384
aB += invIB * (rB.x * Py - rB.y * Px);
353-
// data.positions[indexA].c.set(cA);
385+
// data.positions[indexA].c.set(cA);
354386
data.positions[indexA].a = aA;
355-
// data.positions[indexB].c.set(cB);
387+
// data.positions[indexB].c.set(cB);
356388
data.positions[indexB].a = aB;
357389
pool.pushVec2(3);
358390
pool.pushRot(2);

jbox2d-library/src/main/java/de/pirckheimer_gymnasium/jbox2d/dynamics/joints/Joint.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,23 @@
3333
* The base joint class. Joints are used to constrain two bodies together in
3434
* various fashions. Some joints also feature limits and motors.
3535
*
36+
* <p>Joints are used to constrain bodies to the world or to each other. Typical
37+
* examples in games include ragdolls, teeters, and pulleys. Joints can be
38+
* combined in many different ways to create interesting motions.</p>
39+
*
40+
* <p>Some joints provide limits so you can control the range of motion. Some joint
41+
* provide motors which can be used to drive the joint at a prescribed speed
42+
* until a prescribed force/torque is exceeded.</p>
43+
*
44+
* <p>Joint motors can be used in many ways. You can use motors to control position
45+
* by specifying a joint velocity that is proportional to the difference between
46+
* the actual and desired position. You can also use motors to simulate joint
47+
* friction: set the joint velocity to zero and provide a small, but significant
48+
* maximum motor force/torque. Then the motor will attempt to keep the joint
49+
* from moving until the load becomes too strong.</p>
50+
*
51+
* https://box2d.org/documentation/md__d_1__git_hub_box2d_docs_dynamics.html#autotoc_md81
52+
*
3653
* @author Daniel Murphy
3754
*/
3855
public abstract class Joint

jbox2d-library/src/main/java/de/pirckheimer_gymnasium/jbox2d/dynamics/joints/JointDef.java

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,46 @@
2828
/**
2929
* Joint definitions are used to construct joints.
3030
*
31+
* <p>
32+
* Each joint type has a definition that derives from {@link JointDef}. All
33+
* joints are connected between two different bodies. One body may static.
34+
* Joints between static and/or kinematic bodies are allowed, but have no effect
35+
* and use some processing time.
36+
* </p>
37+
*
38+
* <p>
39+
* You can specify user data for any joint type and you can provide a flag to
40+
* prevent the attached bodies from colliding with each other. This is actually
41+
* the default behavior and you must set the
42+
* {@link JointDef#collideConnectedcollideConnected} Boolean to allow collision
43+
* between to connected bodies.
44+
* </p>
45+
*
46+
* <p>
47+
* Many joint definitions require that you provide some geometric data. Often a
48+
* joint will be defined by anchor points. These are points fixed in the
49+
* attached bodies. jbox2d requires these points to be specified in local
50+
* coordinates. This way the joint can be specified even when the current body
51+
* transforms violate the joint constraint - a common occurrence when a game
52+
* is saved and reloaded. Additionally, some joint definitions need to know the
53+
* default relative angle between the bodies. This is necessary to constrain
54+
* rotation correctly.
55+
* </p>
56+
*
57+
* <p>
58+
* Initializing the geometric data can be tedious, so many joints have
59+
* initialization functions that use the current body transforms to remove much
60+
* of the work. However, these initialization functions should usually only be
61+
* used for prototyping. Production code should define the geometry directly.
62+
* This will make joint behavior more robust.
63+
* </p>
64+
*
65+
* <p>
66+
* The rest of the joint definition data depends on the joint type.
67+
* </p>
68+
*
69+
* https://box2d.org/documentation/md__d_1__git_hub_box2d_docs_dynamics.html#autotoc_md82
70+
*
3171
* @author Daniel Murphy
3272
*/
3373
public class JointDef

misc/images/joints/README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
https://box2d.org/documentation_v3/distance_joint.svg
2+
https://box2d.org/documentation_v3/prismatic_joint.svg
3+
https://box2d.org/documentation_v3/revolute_joint.svg
4+
https://box2d.org/documentation_v3/wheel_joint.svg
5+
https://box2d.org/documentation/distance_joint.gif
6+
https://box2d.org/documentation/gear_joint.gif
7+
https://box2d.org/documentation/prismatic_joint.gif
8+
https://box2d.org/documentation/pulley_joint.gif
9+
https://box2d.org/documentation/revolute_joint.gif
2.3 KB
Loading

0 commit comments

Comments
 (0)