pbox2d 0.6.0-java → 0.8.0-java
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.
- checksums.yaml +4 -4
- data/.mvn/extensions.xml +8 -0
- data/.mvn/wrapper/maven-wrapper.properties +1 -0
- data/.travis.yml +23 -0
- data/CHANGELOG.md +8 -0
- data/README.md +7 -7
- data/Rakefile +1 -2
- data/lib/box2d.jar +0 -0
- data/lib/pbox2d/version.rb +1 -1
- data/lib/pbox2d.rb +1 -0
- data/pbox2d.gemspec +6 -11
- data/pom.rb +59 -0
- data/pom.xml +82 -73
- data/src/org/jbox2d/JBox2D.gwt.xml +12 -0
- data/src/org/jbox2d/callbacks/ContactAdaptor.java +27 -0
- data/src/org/jbox2d/callbacks/ContactFilter.java +59 -0
- data/src/org/jbox2d/callbacks/ContactImpulse.java +42 -0
- data/src/org/jbox2d/callbacks/ContactListener.java +87 -0
- data/src/org/jbox2d/callbacks/DebugDraw.java +297 -0
- data/src/org/jbox2d/callbacks/DestructionListener.java +53 -0
- data/src/org/jbox2d/callbacks/PairCallback.java +29 -0
- data/src/org/jbox2d/callbacks/ParticleDestructionListener.java +20 -0
- data/src/org/jbox2d/callbacks/ParticleQueryCallback.java +19 -0
- data/src/org/jbox2d/callbacks/ParticleRaycastCallback.java +19 -0
- data/src/org/jbox2d/callbacks/QueryCallback.java +45 -0
- data/src/org/jbox2d/callbacks/RayCastCallback.java +55 -0
- data/src/org/jbox2d/callbacks/TreeCallback.java +42 -0
- data/src/org/jbox2d/callbacks/TreeRayCastCallback.java +44 -0
- data/src/org/jbox2d/collision/AABB.java +338 -0
- data/src/org/jbox2d/collision/Collision.java +1444 -0
- data/src/org/jbox2d/collision/ContactID.java +106 -0
- data/src/org/jbox2d/collision/Distance.java +773 -0
- data/src/org/jbox2d/collision/DistanceInput.java +41 -0
- data/src/org/jbox2d/collision/DistanceOutput.java +43 -0
- data/src/org/jbox2d/collision/Manifold.java +116 -0
- data/src/org/jbox2d/collision/ManifoldPoint.java +104 -0
- data/src/org/jbox2d/collision/RayCastInput.java +47 -0
- data/src/org/jbox2d/collision/RayCastOutput.java +46 -0
- data/src/org/jbox2d/collision/TimeOfImpact.java +526 -0
- data/src/org/jbox2d/collision/WorldManifold.java +200 -0
- data/src/org/jbox2d/collision/broadphase/BroadPhase.java +92 -0
- data/src/org/jbox2d/collision/broadphase/BroadPhaseStrategy.java +88 -0
- data/src/org/jbox2d/collision/broadphase/DefaultBroadPhaseBuffer.java +268 -0
- data/src/org/jbox2d/collision/broadphase/DynamicTree.java +883 -0
- data/src/org/jbox2d/collision/broadphase/DynamicTreeFlatNodes.java +873 -0
- data/src/org/jbox2d/collision/broadphase/DynamicTreeNode.java +54 -0
- data/src/org/jbox2d/collision/broadphase/Pair.java +46 -0
- data/src/org/jbox2d/collision/shapes/ChainShape.java +264 -0
- data/src/org/jbox2d/collision/shapes/CircleShape.java +207 -0
- data/src/org/jbox2d/collision/shapes/EdgeShape.java +254 -0
- data/src/org/jbox2d/collision/shapes/MassData.java +105 -0
- data/src/org/jbox2d/collision/shapes/PolygonShape.java +718 -0
- data/src/org/jbox2d/collision/shapes/Shape.java +136 -0
- data/src/org/jbox2d/collision/shapes/ShapeType.java +32 -0
- data/src/org/jbox2d/common/BufferUtils.java +209 -0
- data/src/org/jbox2d/common/Color3f.java +88 -0
- data/src/org/jbox2d/common/IViewportTransform.java +133 -0
- data/src/org/jbox2d/common/Mat22.java +609 -0
- data/src/org/jbox2d/common/Mat33.java +290 -0
- data/src/org/jbox2d/common/MathUtils.java +335 -0
- data/src/org/jbox2d/common/OBBViewportTransform.java +174 -0
- data/src/org/jbox2d/common/PlatformMathUtils.java +46 -0
- data/src/org/jbox2d/common/RaycastResult.java +37 -0
- data/src/org/jbox2d/common/Rot.java +150 -0
- data/src/org/jbox2d/common/Settings.java +246 -0
- data/src/org/jbox2d/common/Sweep.java +116 -0
- data/src/org/jbox2d/common/Timer.java +46 -0
- data/src/org/jbox2d/common/Transform.java +203 -0
- data/src/org/jbox2d/common/Vec2.java +388 -0
- data/src/org/jbox2d/common/Vec3.java +170 -0
- data/src/org/jbox2d/dynamics/Body.java +1246 -0
- data/src/org/jbox2d/dynamics/BodyDef.java +382 -0
- data/src/org/jbox2d/dynamics/BodyType.java +41 -0
- data/src/org/jbox2d/dynamics/ContactManager.java +293 -0
- data/src/org/jbox2d/dynamics/Filter.java +62 -0
- data/src/org/jbox2d/dynamics/Fixture.java +454 -0
- data/src/org/jbox2d/dynamics/FixtureDef.java +214 -0
- data/src/org/jbox2d/dynamics/FixtureProxy.java +38 -0
- data/src/org/jbox2d/dynamics/Island.java +602 -0
- data/src/org/jbox2d/dynamics/Profile.java +97 -0
- data/src/org/jbox2d/dynamics/SolverData.java +33 -0
- data/src/org/jbox2d/dynamics/TimeStep.java +46 -0
- data/src/org/jbox2d/dynamics/World.java +2075 -0
- data/src/org/jbox2d/dynamics/contacts/ChainAndCircleContact.java +57 -0
- data/src/org/jbox2d/dynamics/contacts/ChainAndPolygonContact.java +57 -0
- data/src/org/jbox2d/dynamics/contacts/CircleContact.java +50 -0
- data/src/org/jbox2d/dynamics/contacts/Contact.java +365 -0
- data/src/org/jbox2d/dynamics/contacts/ContactCreator.java +35 -0
- data/src/org/jbox2d/dynamics/contacts/ContactEdge.java +56 -0
- data/src/org/jbox2d/dynamics/contacts/ContactPositionConstraint.java +49 -0
- data/src/org/jbox2d/dynamics/contacts/ContactRegister.java +31 -0
- data/src/org/jbox2d/dynamics/contacts/ContactSolver.java +1104 -0
- data/src/org/jbox2d/dynamics/contacts/ContactVelocityConstraint.java +60 -0
- data/src/org/jbox2d/dynamics/contacts/EdgeAndCircleContact.java +52 -0
- data/src/org/jbox2d/dynamics/contacts/EdgeAndPolygonContact.java +52 -0
- data/src/org/jbox2d/dynamics/contacts/PolygonAndCircleContact.java +51 -0
- data/src/org/jbox2d/dynamics/contacts/PolygonContact.java +50 -0
- data/src/org/jbox2d/dynamics/contacts/Position.java +31 -0
- data/src/org/jbox2d/dynamics/contacts/Velocity.java +31 -0
- data/src/org/jbox2d/dynamics/joints/ConstantVolumeJoint.java +258 -0
- data/src/org/jbox2d/dynamics/joints/ConstantVolumeJointDef.java +75 -0
- data/src/org/jbox2d/dynamics/joints/DistanceJoint.java +356 -0
- data/src/org/jbox2d/dynamics/joints/DistanceJointDef.java +106 -0
- data/src/org/jbox2d/dynamics/joints/FrictionJoint.java +294 -0
- data/src/org/jbox2d/dynamics/joints/FrictionJointDef.java +78 -0
- data/src/org/jbox2d/dynamics/joints/GearJoint.java +520 -0
- data/src/org/jbox2d/dynamics/joints/GearJointDef.java +58 -0
- data/src/org/jbox2d/dynamics/joints/Jacobian.java +32 -0
- data/src/org/jbox2d/dynamics/joints/Joint.java +235 -0
- data/src/org/jbox2d/dynamics/joints/JointDef.java +65 -0
- data/src/org/jbox2d/dynamics/joints/JointEdge.java +57 -0
- data/src/org/jbox2d/dynamics/joints/JointType.java +28 -0
- data/src/org/jbox2d/dynamics/joints/LimitState.java +28 -0
- data/src/org/jbox2d/dynamics/joints/MotorJoint.java +339 -0
- data/src/org/jbox2d/dynamics/joints/MotorJointDef.java +55 -0
- data/src/org/jbox2d/dynamics/joints/MouseJoint.java +262 -0
- data/src/org/jbox2d/dynamics/joints/MouseJointDef.java +62 -0
- data/src/org/jbox2d/dynamics/joints/PrismaticJoint.java +808 -0
- data/src/org/jbox2d/dynamics/joints/PrismaticJointDef.java +120 -0
- data/src/org/jbox2d/dynamics/joints/PulleyJoint.java +393 -0
- data/src/org/jbox2d/dynamics/joints/PulleyJointDef.java +105 -0
- data/src/org/jbox2d/dynamics/joints/RevoluteJoint.java +554 -0
- data/src/org/jbox2d/dynamics/joints/RevoluteJointDef.java +137 -0
- data/src/org/jbox2d/dynamics/joints/RopeJoint.java +276 -0
- data/src/org/jbox2d/dynamics/joints/RopeJointDef.java +34 -0
- data/src/org/jbox2d/dynamics/joints/WeldJoint.java +424 -0
- data/src/org/jbox2d/dynamics/joints/WeldJointDef.java +85 -0
- data/src/org/jbox2d/dynamics/joints/WheelJoint.java +498 -0
- data/src/org/jbox2d/dynamics/joints/WheelJointDef.java +98 -0
- data/src/org/jbox2d/particle/ParticleBodyContact.java +17 -0
- data/src/org/jbox2d/particle/ParticleColor.java +52 -0
- data/src/org/jbox2d/particle/ParticleContact.java +14 -0
- data/src/org/jbox2d/particle/ParticleDef.java +24 -0
- data/src/org/jbox2d/particle/ParticleGroup.java +154 -0
- data/src/org/jbox2d/particle/ParticleGroupDef.java +62 -0
- data/src/org/jbox2d/particle/ParticleGroupType.java +8 -0
- data/src/org/jbox2d/particle/ParticleSystem.java +2172 -0
- data/src/org/jbox2d/particle/ParticleType.java +28 -0
- data/src/org/jbox2d/particle/StackQueue.java +44 -0
- data/src/org/jbox2d/particle/VoronoiDiagram.java +209 -0
- data/src/org/jbox2d/pooling/IDynamicStack.java +47 -0
- data/src/org/jbox2d/pooling/IOrderedStack.java +57 -0
- data/src/org/jbox2d/pooling/IWorldPool.java +101 -0
- data/src/org/jbox2d/pooling/arrays/FloatArray.java +50 -0
- data/src/org/jbox2d/pooling/arrays/GeneratorArray.java +33 -0
- data/src/org/jbox2d/pooling/arrays/IntArray.java +53 -0
- data/src/org/jbox2d/pooling/arrays/Vec2Array.java +57 -0
- data/src/org/jbox2d/pooling/normal/CircleStack.java +77 -0
- data/src/org/jbox2d/pooling/normal/DefaultWorldPool.java +331 -0
- data/src/org/jbox2d/pooling/normal/MutableStack.java +72 -0
- data/src/org/jbox2d/pooling/normal/OrderedStack.java +73 -0
- data/src/org/jbox2d/pooling/stacks/DynamicIntStack.java +60 -0
- metadata +161 -14
- data/lib/jbox2d-library-2.3.1-SNAPSHOT.jar +0 -0
@@ -0,0 +1,60 @@
|
|
1
|
+
/*******************************************************************************
|
2
|
+
* Copyright (c) 2013, Daniel Murphy
|
3
|
+
* All rights reserved.
|
4
|
+
*
|
5
|
+
* Redistribution and use in source and binary forms, with or without modification,
|
6
|
+
* are permitted provided that the following conditions are met:
|
7
|
+
* * Redistributions of source code must retain the above copyright notice,
|
8
|
+
* this list of conditions and the following disclaimer.
|
9
|
+
* * Redistributions in binary form must reproduce the above copyright notice,
|
10
|
+
* this list of conditions and the following disclaimer in the documentation
|
11
|
+
* and/or other materials provided with the distribution.
|
12
|
+
*
|
13
|
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
14
|
+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
15
|
+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
16
|
+
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
17
|
+
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
18
|
+
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
19
|
+
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
20
|
+
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
21
|
+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
22
|
+
* POSSIBILITY OF SUCH DAMAGE.
|
23
|
+
******************************************************************************/
|
24
|
+
package org.jbox2d.dynamics.contacts;
|
25
|
+
|
26
|
+
import org.jbox2d.common.Mat22;
|
27
|
+
import org.jbox2d.common.Settings;
|
28
|
+
import org.jbox2d.common.Vec2;
|
29
|
+
|
30
|
+
public class ContactVelocityConstraint {
|
31
|
+
public VelocityConstraintPoint[] points = new VelocityConstraintPoint[Settings.maxManifoldPoints];
|
32
|
+
public final Vec2 normal = new Vec2();
|
33
|
+
public final Mat22 normalMass = new Mat22();
|
34
|
+
public final Mat22 K = new Mat22();
|
35
|
+
public int indexA;
|
36
|
+
public int indexB;
|
37
|
+
public float invMassA, invMassB;
|
38
|
+
public float invIA, invIB;
|
39
|
+
public float friction;
|
40
|
+
public float restitution;
|
41
|
+
public float tangentSpeed;
|
42
|
+
public int pointCount;
|
43
|
+
public int contactIndex;
|
44
|
+
|
45
|
+
public ContactVelocityConstraint() {
|
46
|
+
for (int i = 0; i < points.length; i++) {
|
47
|
+
points[i] = new VelocityConstraintPoint();
|
48
|
+
}
|
49
|
+
}
|
50
|
+
|
51
|
+
public static class VelocityConstraintPoint {
|
52
|
+
public final Vec2 rA = new Vec2();
|
53
|
+
public final Vec2 rB = new Vec2();
|
54
|
+
public float normalImpulse;
|
55
|
+
public float tangentImpulse;
|
56
|
+
public float normalMass;
|
57
|
+
public float tangentMass;
|
58
|
+
public float velocityBias;
|
59
|
+
}
|
60
|
+
}
|
@@ -0,0 +1,52 @@
|
|
1
|
+
/*******************************************************************************
|
2
|
+
* Copyright (c) 2013, Daniel Murphy
|
3
|
+
* All rights reserved.
|
4
|
+
*
|
5
|
+
* Redistribution and use in source and binary forms, with or without modification,
|
6
|
+
* are permitted provided that the following conditions are met:
|
7
|
+
* * Redistributions of source code must retain the above copyright notice,
|
8
|
+
* this list of conditions and the following disclaimer.
|
9
|
+
* * Redistributions in binary form must reproduce the above copyright notice,
|
10
|
+
* this list of conditions and the following disclaimer in the documentation
|
11
|
+
* and/or other materials provided with the distribution.
|
12
|
+
*
|
13
|
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
14
|
+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
15
|
+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
16
|
+
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
17
|
+
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
18
|
+
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
19
|
+
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
20
|
+
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
21
|
+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
22
|
+
* POSSIBILITY OF SUCH DAMAGE.
|
23
|
+
******************************************************************************/
|
24
|
+
package org.jbox2d.dynamics.contacts;
|
25
|
+
|
26
|
+
import org.jbox2d.collision.Manifold;
|
27
|
+
import org.jbox2d.collision.shapes.CircleShape;
|
28
|
+
import org.jbox2d.collision.shapes.EdgeShape;
|
29
|
+
import org.jbox2d.collision.shapes.ShapeType;
|
30
|
+
import org.jbox2d.common.Transform;
|
31
|
+
import org.jbox2d.dynamics.Fixture;
|
32
|
+
import org.jbox2d.pooling.IWorldPool;
|
33
|
+
|
34
|
+
public class EdgeAndCircleContact extends Contact {
|
35
|
+
|
36
|
+
public EdgeAndCircleContact(IWorldPool argPool) {
|
37
|
+
super(argPool);
|
38
|
+
}
|
39
|
+
|
40
|
+
@Override
|
41
|
+
public void init(Fixture fA, int indexA, Fixture fB, int indexB) {
|
42
|
+
super.init(fA, indexA, fB, indexB);
|
43
|
+
assert (m_fixtureA.getType() == ShapeType.EDGE);
|
44
|
+
assert (m_fixtureB.getType() == ShapeType.CIRCLE);
|
45
|
+
}
|
46
|
+
|
47
|
+
@Override
|
48
|
+
public void evaluate(Manifold manifold, Transform xfA, Transform xfB) {
|
49
|
+
pool.getCollision().collideEdgeAndCircle(manifold, (EdgeShape) m_fixtureA.getShape(), xfA,
|
50
|
+
(CircleShape) m_fixtureB.getShape(), xfB);
|
51
|
+
}
|
52
|
+
}
|
@@ -0,0 +1,52 @@
|
|
1
|
+
/*******************************************************************************
|
2
|
+
* Copyright (c) 2013, Daniel Murphy
|
3
|
+
* All rights reserved.
|
4
|
+
*
|
5
|
+
* Redistribution and use in source and binary forms, with or without modification,
|
6
|
+
* are permitted provided that the following conditions are met:
|
7
|
+
* * Redistributions of source code must retain the above copyright notice,
|
8
|
+
* this list of conditions and the following disclaimer.
|
9
|
+
* * Redistributions in binary form must reproduce the above copyright notice,
|
10
|
+
* this list of conditions and the following disclaimer in the documentation
|
11
|
+
* and/or other materials provided with the distribution.
|
12
|
+
*
|
13
|
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
14
|
+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
15
|
+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
16
|
+
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
17
|
+
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
18
|
+
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
19
|
+
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
20
|
+
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
21
|
+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
22
|
+
* POSSIBILITY OF SUCH DAMAGE.
|
23
|
+
******************************************************************************/
|
24
|
+
package org.jbox2d.dynamics.contacts;
|
25
|
+
|
26
|
+
import org.jbox2d.collision.Manifold;
|
27
|
+
import org.jbox2d.collision.shapes.EdgeShape;
|
28
|
+
import org.jbox2d.collision.shapes.PolygonShape;
|
29
|
+
import org.jbox2d.collision.shapes.ShapeType;
|
30
|
+
import org.jbox2d.common.Transform;
|
31
|
+
import org.jbox2d.dynamics.Fixture;
|
32
|
+
import org.jbox2d.pooling.IWorldPool;
|
33
|
+
|
34
|
+
public class EdgeAndPolygonContact extends Contact {
|
35
|
+
|
36
|
+
public EdgeAndPolygonContact(IWorldPool argPool) {
|
37
|
+
super(argPool);
|
38
|
+
}
|
39
|
+
|
40
|
+
@Override
|
41
|
+
public void init(Fixture fA, int indexA, Fixture fB, int indexB) {
|
42
|
+
super.init(fA, indexA, fB, indexB);
|
43
|
+
assert (m_fixtureA.getType() == ShapeType.EDGE);
|
44
|
+
assert (m_fixtureB.getType() == ShapeType.POLYGON);
|
45
|
+
}
|
46
|
+
|
47
|
+
@Override
|
48
|
+
public void evaluate(Manifold manifold, Transform xfA, Transform xfB) {
|
49
|
+
pool.getCollision().collideEdgeAndPolygon(manifold, (EdgeShape) m_fixtureA.getShape(), xfA,
|
50
|
+
(PolygonShape) m_fixtureB.getShape(), xfB);
|
51
|
+
}
|
52
|
+
}
|
@@ -0,0 +1,51 @@
|
|
1
|
+
/*******************************************************************************
|
2
|
+
* Copyright (c) 2013, Daniel Murphy
|
3
|
+
* All rights reserved.
|
4
|
+
*
|
5
|
+
* Redistribution and use in source and binary forms, with or without modification,
|
6
|
+
* are permitted provided that the following conditions are met:
|
7
|
+
* * Redistributions of source code must retain the above copyright notice,
|
8
|
+
* this list of conditions and the following disclaimer.
|
9
|
+
* * Redistributions in binary form must reproduce the above copyright notice,
|
10
|
+
* this list of conditions and the following disclaimer in the documentation
|
11
|
+
* and/or other materials provided with the distribution.
|
12
|
+
*
|
13
|
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
14
|
+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
15
|
+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
16
|
+
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
17
|
+
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
18
|
+
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
19
|
+
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
20
|
+
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
21
|
+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
22
|
+
* POSSIBILITY OF SUCH DAMAGE.
|
23
|
+
******************************************************************************/
|
24
|
+
package org.jbox2d.dynamics.contacts;
|
25
|
+
|
26
|
+
import org.jbox2d.collision.Manifold;
|
27
|
+
import org.jbox2d.collision.shapes.CircleShape;
|
28
|
+
import org.jbox2d.collision.shapes.PolygonShape;
|
29
|
+
import org.jbox2d.collision.shapes.ShapeType;
|
30
|
+
import org.jbox2d.common.Transform;
|
31
|
+
import org.jbox2d.dynamics.Fixture;
|
32
|
+
import org.jbox2d.pooling.IWorldPool;
|
33
|
+
|
34
|
+
public class PolygonAndCircleContact extends Contact {
|
35
|
+
|
36
|
+
public PolygonAndCircleContact(IWorldPool argPool) {
|
37
|
+
super(argPool);
|
38
|
+
}
|
39
|
+
|
40
|
+
public void init(Fixture fixtureA, Fixture fixtureB) {
|
41
|
+
super.init(fixtureA, 0, fixtureB, 0);
|
42
|
+
assert (m_fixtureA.getType() == ShapeType.POLYGON);
|
43
|
+
assert (m_fixtureB.getType() == ShapeType.CIRCLE);
|
44
|
+
}
|
45
|
+
|
46
|
+
@Override
|
47
|
+
public void evaluate(Manifold manifold, Transform xfA, Transform xfB) {
|
48
|
+
pool.getCollision().collidePolygonAndCircle(manifold, (PolygonShape) m_fixtureA.getShape(),
|
49
|
+
xfA, (CircleShape) m_fixtureB.getShape(), xfB);
|
50
|
+
}
|
51
|
+
}
|
@@ -0,0 +1,50 @@
|
|
1
|
+
/*******************************************************************************
|
2
|
+
* Copyright (c) 2013, Daniel Murphy
|
3
|
+
* All rights reserved.
|
4
|
+
*
|
5
|
+
* Redistribution and use in source and binary forms, with or without modification,
|
6
|
+
* are permitted provided that the following conditions are met:
|
7
|
+
* * Redistributions of source code must retain the above copyright notice,
|
8
|
+
* this list of conditions and the following disclaimer.
|
9
|
+
* * Redistributions in binary form must reproduce the above copyright notice,
|
10
|
+
* this list of conditions and the following disclaimer in the documentation
|
11
|
+
* and/or other materials provided with the distribution.
|
12
|
+
*
|
13
|
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
14
|
+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
15
|
+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
16
|
+
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
17
|
+
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
18
|
+
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
19
|
+
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
20
|
+
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
21
|
+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
22
|
+
* POSSIBILITY OF SUCH DAMAGE.
|
23
|
+
******************************************************************************/
|
24
|
+
package org.jbox2d.dynamics.contacts;
|
25
|
+
|
26
|
+
import org.jbox2d.collision.Manifold;
|
27
|
+
import org.jbox2d.collision.shapes.PolygonShape;
|
28
|
+
import org.jbox2d.collision.shapes.ShapeType;
|
29
|
+
import org.jbox2d.common.Transform;
|
30
|
+
import org.jbox2d.dynamics.Fixture;
|
31
|
+
import org.jbox2d.pooling.IWorldPool;
|
32
|
+
|
33
|
+
public class PolygonContact extends Contact {
|
34
|
+
|
35
|
+
public PolygonContact(IWorldPool argPool) {
|
36
|
+
super(argPool);
|
37
|
+
}
|
38
|
+
|
39
|
+
public void init(Fixture fixtureA, Fixture fixtureB) {
|
40
|
+
super.init(fixtureA, 0, fixtureB, 0);
|
41
|
+
assert (m_fixtureA.getType() == ShapeType.POLYGON);
|
42
|
+
assert (m_fixtureB.getType() == ShapeType.POLYGON);
|
43
|
+
}
|
44
|
+
|
45
|
+
@Override
|
46
|
+
public void evaluate(Manifold manifold, Transform xfA, Transform xfB) {
|
47
|
+
pool.getCollision().collidePolygons(manifold, (PolygonShape) m_fixtureA.getShape(), xfA,
|
48
|
+
(PolygonShape) m_fixtureB.getShape(), xfB);
|
49
|
+
}
|
50
|
+
}
|
@@ -0,0 +1,31 @@
|
|
1
|
+
/*******************************************************************************
|
2
|
+
* Copyright (c) 2013, Daniel Murphy
|
3
|
+
* All rights reserved.
|
4
|
+
*
|
5
|
+
* Redistribution and use in source and binary forms, with or without modification,
|
6
|
+
* are permitted provided that the following conditions are met:
|
7
|
+
* * Redistributions of source code must retain the above copyright notice,
|
8
|
+
* this list of conditions and the following disclaimer.
|
9
|
+
* * Redistributions in binary form must reproduce the above copyright notice,
|
10
|
+
* this list of conditions and the following disclaimer in the documentation
|
11
|
+
* and/or other materials provided with the distribution.
|
12
|
+
*
|
13
|
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
14
|
+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
15
|
+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
16
|
+
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
17
|
+
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
18
|
+
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
19
|
+
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
20
|
+
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
21
|
+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
22
|
+
* POSSIBILITY OF SUCH DAMAGE.
|
23
|
+
******************************************************************************/
|
24
|
+
package org.jbox2d.dynamics.contacts;
|
25
|
+
|
26
|
+
import org.jbox2d.common.Vec2;
|
27
|
+
|
28
|
+
public class Position {
|
29
|
+
public final Vec2 c = new Vec2();
|
30
|
+
public float a;
|
31
|
+
}
|
@@ -0,0 +1,31 @@
|
|
1
|
+
/*******************************************************************************
|
2
|
+
* Copyright (c) 2013, Daniel Murphy
|
3
|
+
* All rights reserved.
|
4
|
+
*
|
5
|
+
* Redistribution and use in source and binary forms, with or without modification,
|
6
|
+
* are permitted provided that the following conditions are met:
|
7
|
+
* * Redistributions of source code must retain the above copyright notice,
|
8
|
+
* this list of conditions and the following disclaimer.
|
9
|
+
* * Redistributions in binary form must reproduce the above copyright notice,
|
10
|
+
* this list of conditions and the following disclaimer in the documentation
|
11
|
+
* and/or other materials provided with the distribution.
|
12
|
+
*
|
13
|
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
14
|
+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
15
|
+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
16
|
+
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
17
|
+
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
18
|
+
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
19
|
+
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
20
|
+
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
21
|
+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
22
|
+
* POSSIBILITY OF SUCH DAMAGE.
|
23
|
+
******************************************************************************/
|
24
|
+
package org.jbox2d.dynamics.contacts;
|
25
|
+
|
26
|
+
import org.jbox2d.common.Vec2;
|
27
|
+
|
28
|
+
public class Velocity {
|
29
|
+
public final Vec2 v = new Vec2();
|
30
|
+
public float w;
|
31
|
+
}
|
@@ -0,0 +1,258 @@
|
|
1
|
+
/*******************************************************************************
|
2
|
+
* Copyright (c) 2013, Daniel Murphy
|
3
|
+
* All rights reserved.
|
4
|
+
*
|
5
|
+
* Redistribution and use in source and binary forms, with or without modification,
|
6
|
+
* are permitted provided that the following conditions are met:
|
7
|
+
* * Redistributions of source code must retain the above copyright notice,
|
8
|
+
* this list of conditions and the following disclaimer.
|
9
|
+
* * Redistributions in binary form must reproduce the above copyright notice,
|
10
|
+
* this list of conditions and the following disclaimer in the documentation
|
11
|
+
* and/or other materials provided with the distribution.
|
12
|
+
*
|
13
|
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
14
|
+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
15
|
+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
16
|
+
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
17
|
+
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
18
|
+
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
19
|
+
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
20
|
+
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
21
|
+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
22
|
+
* POSSIBILITY OF SUCH DAMAGE.
|
23
|
+
******************************************************************************/
|
24
|
+
package org.jbox2d.dynamics.joints;
|
25
|
+
|
26
|
+
import org.jbox2d.common.MathUtils;
|
27
|
+
import org.jbox2d.common.Settings;
|
28
|
+
import org.jbox2d.common.Vec2;
|
29
|
+
import org.jbox2d.dynamics.Body;
|
30
|
+
import org.jbox2d.dynamics.SolverData;
|
31
|
+
import org.jbox2d.dynamics.World;
|
32
|
+
import org.jbox2d.dynamics.contacts.Position;
|
33
|
+
import org.jbox2d.dynamics.contacts.Velocity;
|
34
|
+
|
35
|
+
public class ConstantVolumeJoint extends Joint {
|
36
|
+
|
37
|
+
private final Body[] bodies;
|
38
|
+
private float[] targetLengths;
|
39
|
+
private float targetVolume;
|
40
|
+
|
41
|
+
private Vec2[] normals;
|
42
|
+
private float m_impulse = 0.0f;
|
43
|
+
|
44
|
+
private World world;
|
45
|
+
|
46
|
+
private DistanceJoint[] distanceJoints;
|
47
|
+
|
48
|
+
public Body[] getBodies() {
|
49
|
+
return bodies;
|
50
|
+
}
|
51
|
+
|
52
|
+
public DistanceJoint[] getJoints() {
|
53
|
+
return distanceJoints;
|
54
|
+
}
|
55
|
+
|
56
|
+
public void inflate(float factor) {
|
57
|
+
targetVolume *= factor;
|
58
|
+
}
|
59
|
+
|
60
|
+
public ConstantVolumeJoint(World argWorld, ConstantVolumeJointDef def) {
|
61
|
+
super(argWorld.getPool(), def);
|
62
|
+
world = argWorld;
|
63
|
+
if (def.bodies.size() <= 2) {
|
64
|
+
throw new IllegalArgumentException(
|
65
|
+
"You cannot create a constant volume joint with less than three bodies.");
|
66
|
+
}
|
67
|
+
bodies = def.bodies.toArray(new Body[0]);
|
68
|
+
|
69
|
+
targetLengths = new float[bodies.length];
|
70
|
+
for (int i = 0; i < targetLengths.length; ++i) {
|
71
|
+
final int next = (i == targetLengths.length - 1) ? 0 : i + 1;
|
72
|
+
float dist = bodies[i].getWorldCenter().sub(bodies[next].getWorldCenter()).length();
|
73
|
+
targetLengths[i] = dist;
|
74
|
+
}
|
75
|
+
targetVolume = getBodyArea();
|
76
|
+
|
77
|
+
if (def.joints != null && def.joints.size() != def.bodies.size()) {
|
78
|
+
throw new IllegalArgumentException(
|
79
|
+
"Incorrect joint definition. Joints have to correspond to the bodies");
|
80
|
+
}
|
81
|
+
if (def.joints == null) {
|
82
|
+
final DistanceJointDef djd = new DistanceJointDef();
|
83
|
+
distanceJoints = new DistanceJoint[bodies.length];
|
84
|
+
for (int i = 0; i < targetLengths.length; ++i) {
|
85
|
+
final int next = (i == targetLengths.length - 1) ? 0 : i + 1;
|
86
|
+
djd.frequencyHz = def.frequencyHz;// 20.0f;
|
87
|
+
djd.dampingRatio = def.dampingRatio;// 50.0f;
|
88
|
+
djd.collideConnected = def.collideConnected;
|
89
|
+
djd.initialize(bodies[i], bodies[next], bodies[i].getWorldCenter(),
|
90
|
+
bodies[next].getWorldCenter());
|
91
|
+
distanceJoints[i] = (DistanceJoint) world.createJoint(djd);
|
92
|
+
}
|
93
|
+
} else {
|
94
|
+
distanceJoints = def.joints.toArray(new DistanceJoint[0]);
|
95
|
+
}
|
96
|
+
|
97
|
+
normals = new Vec2[bodies.length];
|
98
|
+
for (int i = 0; i < normals.length; ++i) {
|
99
|
+
normals[i] = new Vec2();
|
100
|
+
}
|
101
|
+
}
|
102
|
+
|
103
|
+
@Override
|
104
|
+
public void destructor() {
|
105
|
+
for (int i = 0; i < distanceJoints.length; ++i) {
|
106
|
+
world.destroyJoint(distanceJoints[i]);
|
107
|
+
}
|
108
|
+
}
|
109
|
+
|
110
|
+
private float getBodyArea() {
|
111
|
+
float area = 0.0f;
|
112
|
+
for (int i = 0; i < bodies.length; ++i) {
|
113
|
+
final int next = (i == bodies.length - 1) ? 0 : i + 1;
|
114
|
+
area +=
|
115
|
+
bodies[i].getWorldCenter().x * bodies[next].getWorldCenter().y
|
116
|
+
- bodies[next].getWorldCenter().x * bodies[i].getWorldCenter().y;
|
117
|
+
}
|
118
|
+
area *= .5f;
|
119
|
+
return area;
|
120
|
+
}
|
121
|
+
|
122
|
+
private float getSolverArea(Position[] positions) {
|
123
|
+
float area = 0.0f;
|
124
|
+
for (int i = 0; i < bodies.length; ++i) {
|
125
|
+
final int next = (i == bodies.length - 1) ? 0 : i + 1;
|
126
|
+
area +=
|
127
|
+
positions[bodies[i].m_islandIndex].c.x * positions[bodies[next].m_islandIndex].c.y
|
128
|
+
- positions[bodies[next].m_islandIndex].c.x * positions[bodies[i].m_islandIndex].c.y;
|
129
|
+
}
|
130
|
+
area *= .5f;
|
131
|
+
return area;
|
132
|
+
}
|
133
|
+
|
134
|
+
private boolean constrainEdges(Position[] positions) {
|
135
|
+
float perimeter = 0.0f;
|
136
|
+
for (int i = 0; i < bodies.length; ++i) {
|
137
|
+
final int next = (i == bodies.length - 1) ? 0 : i + 1;
|
138
|
+
float dx = positions[bodies[next].m_islandIndex].c.x - positions[bodies[i].m_islandIndex].c.x;
|
139
|
+
float dy = positions[bodies[next].m_islandIndex].c.y - positions[bodies[i].m_islandIndex].c.y;
|
140
|
+
float dist = MathUtils.sqrt(dx * dx + dy * dy);
|
141
|
+
if (dist < Settings.EPSILON) {
|
142
|
+
dist = 1.0f;
|
143
|
+
}
|
144
|
+
normals[i].x = dy / dist;
|
145
|
+
normals[i].y = -dx / dist;
|
146
|
+
perimeter += dist;
|
147
|
+
}
|
148
|
+
|
149
|
+
final Vec2 delta = pool.popVec2();
|
150
|
+
|
151
|
+
float deltaArea = targetVolume - getSolverArea(positions);
|
152
|
+
float toExtrude = 0.5f * deltaArea / perimeter; // *relaxationFactor
|
153
|
+
// float sumdeltax = 0.0f;
|
154
|
+
boolean done = true;
|
155
|
+
for (int i = 0; i < bodies.length; ++i) {
|
156
|
+
final int next = (i == bodies.length - 1) ? 0 : i + 1;
|
157
|
+
delta.set(toExtrude * (normals[i].x + normals[next].x), toExtrude
|
158
|
+
* (normals[i].y + normals[next].y));
|
159
|
+
// sumdeltax += dx;
|
160
|
+
float normSqrd = delta.lengthSquared();
|
161
|
+
if (normSqrd > Settings.maxLinearCorrection * Settings.maxLinearCorrection) {
|
162
|
+
delta.mulLocal(Settings.maxLinearCorrection / MathUtils.sqrt(normSqrd));
|
163
|
+
}
|
164
|
+
if (normSqrd > Settings.linearSlop * Settings.linearSlop) {
|
165
|
+
done = false;
|
166
|
+
}
|
167
|
+
positions[bodies[next].m_islandIndex].c.x += delta.x;
|
168
|
+
positions[bodies[next].m_islandIndex].c.y += delta.y;
|
169
|
+
// bodies[next].m_linearVelocity.x += delta.x * step.inv_dt;
|
170
|
+
// bodies[next].m_linearVelocity.y += delta.y * step.inv_dt;
|
171
|
+
}
|
172
|
+
|
173
|
+
pool.pushVec2(1);
|
174
|
+
// System.out.println(sumdeltax);
|
175
|
+
return done;
|
176
|
+
}
|
177
|
+
|
178
|
+
@Override
|
179
|
+
public void initVelocityConstraints(final SolverData step) {
|
180
|
+
Velocity[] velocities = step.velocities;
|
181
|
+
Position[] positions = step.positions;
|
182
|
+
final Vec2[] d = pool.getVec2Array(bodies.length);
|
183
|
+
|
184
|
+
for (int i = 0; i < bodies.length; ++i) {
|
185
|
+
final int prev = (i == 0) ? bodies.length - 1 : i - 1;
|
186
|
+
final int next = (i == bodies.length - 1) ? 0 : i + 1;
|
187
|
+
d[i].set(positions[bodies[next].m_islandIndex].c);
|
188
|
+
d[i].subLocal(positions[bodies[prev].m_islandIndex].c);
|
189
|
+
}
|
190
|
+
|
191
|
+
if (step.step.warmStarting) {
|
192
|
+
m_impulse *= step.step.dtRatio;
|
193
|
+
// float lambda = -2.0f * crossMassSum / dotMassSum;
|
194
|
+
// System.out.println(crossMassSum + " " +dotMassSum);
|
195
|
+
// lambda = MathUtils.clamp(lambda, -Settings.maxLinearCorrection,
|
196
|
+
// Settings.maxLinearCorrection);
|
197
|
+
// m_impulse = lambda;
|
198
|
+
for (int i = 0; i < bodies.length; ++i) {
|
199
|
+
velocities[bodies[i].m_islandIndex].v.x += bodies[i].m_invMass * d[i].y * .5f * m_impulse;
|
200
|
+
velocities[bodies[i].m_islandIndex].v.y += bodies[i].m_invMass * -d[i].x * .5f * m_impulse;
|
201
|
+
}
|
202
|
+
} else {
|
203
|
+
m_impulse = 0.0f;
|
204
|
+
}
|
205
|
+
}
|
206
|
+
|
207
|
+
@Override
|
208
|
+
public boolean solvePositionConstraints(SolverData step) {
|
209
|
+
return constrainEdges(step.positions);
|
210
|
+
}
|
211
|
+
|
212
|
+
@Override
|
213
|
+
public void solveVelocityConstraints(final SolverData step) {
|
214
|
+
float crossMassSum = 0.0f;
|
215
|
+
float dotMassSum = 0.0f;
|
216
|
+
|
217
|
+
Velocity[] velocities = step.velocities;
|
218
|
+
Position[] positions = step.positions;
|
219
|
+
final Vec2 d[] = pool.getVec2Array(bodies.length);
|
220
|
+
|
221
|
+
for (int i = 0; i < bodies.length; ++i) {
|
222
|
+
final int prev = (i == 0) ? bodies.length - 1 : i - 1;
|
223
|
+
final int next = (i == bodies.length - 1) ? 0 : i + 1;
|
224
|
+
d[i].set(positions[bodies[next].m_islandIndex].c);
|
225
|
+
d[i].subLocal(positions[bodies[prev].m_islandIndex].c);
|
226
|
+
dotMassSum += (d[i].lengthSquared()) / bodies[i].getMass();
|
227
|
+
crossMassSum += Vec2.cross(velocities[bodies[i].m_islandIndex].v, d[i]);
|
228
|
+
}
|
229
|
+
float lambda = -2.0f * crossMassSum / dotMassSum;
|
230
|
+
// System.out.println(crossMassSum + " " +dotMassSum);
|
231
|
+
// lambda = MathUtils.clamp(lambda, -Settings.maxLinearCorrection,
|
232
|
+
// Settings.maxLinearCorrection);
|
233
|
+
m_impulse += lambda;
|
234
|
+
// System.out.println(m_impulse);
|
235
|
+
for (int i = 0; i < bodies.length; ++i) {
|
236
|
+
velocities[bodies[i].m_islandIndex].v.x += bodies[i].m_invMass * d[i].y * .5f * lambda;
|
237
|
+
velocities[bodies[i].m_islandIndex].v.y += bodies[i].m_invMass * -d[i].x * .5f * lambda;
|
238
|
+
}
|
239
|
+
}
|
240
|
+
|
241
|
+
/** No-op */
|
242
|
+
@Override
|
243
|
+
public void getAnchorA(Vec2 argOut) {}
|
244
|
+
|
245
|
+
/** No-op */
|
246
|
+
@Override
|
247
|
+
public void getAnchorB(Vec2 argOut) {}
|
248
|
+
|
249
|
+
/** No-op */
|
250
|
+
@Override
|
251
|
+
public void getReactionForce(float inv_dt, Vec2 argOut) {}
|
252
|
+
|
253
|
+
/** No-op */
|
254
|
+
@Override
|
255
|
+
public float getReactionTorque(float inv_dt) {
|
256
|
+
return 0;
|
257
|
+
}
|
258
|
+
}
|
@@ -0,0 +1,75 @@
|
|
1
|
+
/*******************************************************************************
|
2
|
+
* Copyright (c) 2013, Daniel Murphy
|
3
|
+
* All rights reserved.
|
4
|
+
*
|
5
|
+
* Redistribution and use in source and binary forms, with or without modification,
|
6
|
+
* are permitted provided that the following conditions are met:
|
7
|
+
* * Redistributions of source code must retain the above copyright notice,
|
8
|
+
* this list of conditions and the following disclaimer.
|
9
|
+
* * Redistributions in binary form must reproduce the above copyright notice,
|
10
|
+
* this list of conditions and the following disclaimer in the documentation
|
11
|
+
* and/or other materials provided with the distribution.
|
12
|
+
*
|
13
|
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
14
|
+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
15
|
+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
16
|
+
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
17
|
+
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
18
|
+
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
19
|
+
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
20
|
+
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
21
|
+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
22
|
+
* POSSIBILITY OF SUCH DAMAGE.
|
23
|
+
******************************************************************************/
|
24
|
+
package org.jbox2d.dynamics.joints;
|
25
|
+
|
26
|
+
import java.util.ArrayList;
|
27
|
+
|
28
|
+
import org.jbox2d.dynamics.Body;
|
29
|
+
|
30
|
+
/**
|
31
|
+
* Definition for a {@link ConstantVolumeJoint}, which connects a group a bodies together so they
|
32
|
+
* maintain a constant volume within them.
|
33
|
+
*/
|
34
|
+
public class ConstantVolumeJointDef extends JointDef {
|
35
|
+
public float frequencyHz;
|
36
|
+
public float dampingRatio;
|
37
|
+
|
38
|
+
ArrayList<Body> bodies;
|
39
|
+
ArrayList<DistanceJoint> joints;
|
40
|
+
|
41
|
+
public ConstantVolumeJointDef() {
|
42
|
+
super(JointType.CONSTANT_VOLUME);
|
43
|
+
bodies = new ArrayList<Body>();
|
44
|
+
joints = null;
|
45
|
+
collideConnected = false;
|
46
|
+
frequencyHz = 0.0f;
|
47
|
+
dampingRatio = 0.0f;
|
48
|
+
}
|
49
|
+
|
50
|
+
/**
|
51
|
+
* Adds a body to the group
|
52
|
+
*
|
53
|
+
* @param argBody
|
54
|
+
*/
|
55
|
+
public void addBody(Body argBody) {
|
56
|
+
bodies.add(argBody);
|
57
|
+
if (bodies.size() == 1) {
|
58
|
+
bodyA = argBody;
|
59
|
+
}
|
60
|
+
if (bodies.size() == 2) {
|
61
|
+
bodyB = argBody;
|
62
|
+
}
|
63
|
+
}
|
64
|
+
|
65
|
+
/**
|
66
|
+
* Adds a body and the pre-made distance joint. Should only be used for deserialization.
|
67
|
+
*/
|
68
|
+
public void addBodyAndJoint(Body argBody, DistanceJoint argJoint) {
|
69
|
+
addBody(argBody);
|
70
|
+
if (joints == null) {
|
71
|
+
joints = new ArrayList<DistanceJoint>();
|
72
|
+
}
|
73
|
+
joints.add(argJoint);
|
74
|
+
}
|
75
|
+
}
|