pbox2d 0.6.0-java → 0.8.0-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (154) hide show
  1. checksums.yaml +4 -4
  2. data/.mvn/extensions.xml +8 -0
  3. data/.mvn/wrapper/maven-wrapper.properties +1 -0
  4. data/.travis.yml +23 -0
  5. data/CHANGELOG.md +8 -0
  6. data/README.md +7 -7
  7. data/Rakefile +1 -2
  8. data/lib/box2d.jar +0 -0
  9. data/lib/pbox2d/version.rb +1 -1
  10. data/lib/pbox2d.rb +1 -0
  11. data/pbox2d.gemspec +6 -11
  12. data/pom.rb +59 -0
  13. data/pom.xml +82 -73
  14. data/src/org/jbox2d/JBox2D.gwt.xml +12 -0
  15. data/src/org/jbox2d/callbacks/ContactAdaptor.java +27 -0
  16. data/src/org/jbox2d/callbacks/ContactFilter.java +59 -0
  17. data/src/org/jbox2d/callbacks/ContactImpulse.java +42 -0
  18. data/src/org/jbox2d/callbacks/ContactListener.java +87 -0
  19. data/src/org/jbox2d/callbacks/DebugDraw.java +297 -0
  20. data/src/org/jbox2d/callbacks/DestructionListener.java +53 -0
  21. data/src/org/jbox2d/callbacks/PairCallback.java +29 -0
  22. data/src/org/jbox2d/callbacks/ParticleDestructionListener.java +20 -0
  23. data/src/org/jbox2d/callbacks/ParticleQueryCallback.java +19 -0
  24. data/src/org/jbox2d/callbacks/ParticleRaycastCallback.java +19 -0
  25. data/src/org/jbox2d/callbacks/QueryCallback.java +45 -0
  26. data/src/org/jbox2d/callbacks/RayCastCallback.java +55 -0
  27. data/src/org/jbox2d/callbacks/TreeCallback.java +42 -0
  28. data/src/org/jbox2d/callbacks/TreeRayCastCallback.java +44 -0
  29. data/src/org/jbox2d/collision/AABB.java +338 -0
  30. data/src/org/jbox2d/collision/Collision.java +1444 -0
  31. data/src/org/jbox2d/collision/ContactID.java +106 -0
  32. data/src/org/jbox2d/collision/Distance.java +773 -0
  33. data/src/org/jbox2d/collision/DistanceInput.java +41 -0
  34. data/src/org/jbox2d/collision/DistanceOutput.java +43 -0
  35. data/src/org/jbox2d/collision/Manifold.java +116 -0
  36. data/src/org/jbox2d/collision/ManifoldPoint.java +104 -0
  37. data/src/org/jbox2d/collision/RayCastInput.java +47 -0
  38. data/src/org/jbox2d/collision/RayCastOutput.java +46 -0
  39. data/src/org/jbox2d/collision/TimeOfImpact.java +526 -0
  40. data/src/org/jbox2d/collision/WorldManifold.java +200 -0
  41. data/src/org/jbox2d/collision/broadphase/BroadPhase.java +92 -0
  42. data/src/org/jbox2d/collision/broadphase/BroadPhaseStrategy.java +88 -0
  43. data/src/org/jbox2d/collision/broadphase/DefaultBroadPhaseBuffer.java +268 -0
  44. data/src/org/jbox2d/collision/broadphase/DynamicTree.java +883 -0
  45. data/src/org/jbox2d/collision/broadphase/DynamicTreeFlatNodes.java +873 -0
  46. data/src/org/jbox2d/collision/broadphase/DynamicTreeNode.java +54 -0
  47. data/src/org/jbox2d/collision/broadphase/Pair.java +46 -0
  48. data/src/org/jbox2d/collision/shapes/ChainShape.java +264 -0
  49. data/src/org/jbox2d/collision/shapes/CircleShape.java +207 -0
  50. data/src/org/jbox2d/collision/shapes/EdgeShape.java +254 -0
  51. data/src/org/jbox2d/collision/shapes/MassData.java +105 -0
  52. data/src/org/jbox2d/collision/shapes/PolygonShape.java +718 -0
  53. data/src/org/jbox2d/collision/shapes/Shape.java +136 -0
  54. data/src/org/jbox2d/collision/shapes/ShapeType.java +32 -0
  55. data/src/org/jbox2d/common/BufferUtils.java +209 -0
  56. data/src/org/jbox2d/common/Color3f.java +88 -0
  57. data/src/org/jbox2d/common/IViewportTransform.java +133 -0
  58. data/src/org/jbox2d/common/Mat22.java +609 -0
  59. data/src/org/jbox2d/common/Mat33.java +290 -0
  60. data/src/org/jbox2d/common/MathUtils.java +335 -0
  61. data/src/org/jbox2d/common/OBBViewportTransform.java +174 -0
  62. data/src/org/jbox2d/common/PlatformMathUtils.java +46 -0
  63. data/src/org/jbox2d/common/RaycastResult.java +37 -0
  64. data/src/org/jbox2d/common/Rot.java +150 -0
  65. data/src/org/jbox2d/common/Settings.java +246 -0
  66. data/src/org/jbox2d/common/Sweep.java +116 -0
  67. data/src/org/jbox2d/common/Timer.java +46 -0
  68. data/src/org/jbox2d/common/Transform.java +203 -0
  69. data/src/org/jbox2d/common/Vec2.java +388 -0
  70. data/src/org/jbox2d/common/Vec3.java +170 -0
  71. data/src/org/jbox2d/dynamics/Body.java +1246 -0
  72. data/src/org/jbox2d/dynamics/BodyDef.java +382 -0
  73. data/src/org/jbox2d/dynamics/BodyType.java +41 -0
  74. data/src/org/jbox2d/dynamics/ContactManager.java +293 -0
  75. data/src/org/jbox2d/dynamics/Filter.java +62 -0
  76. data/src/org/jbox2d/dynamics/Fixture.java +454 -0
  77. data/src/org/jbox2d/dynamics/FixtureDef.java +214 -0
  78. data/src/org/jbox2d/dynamics/FixtureProxy.java +38 -0
  79. data/src/org/jbox2d/dynamics/Island.java +602 -0
  80. data/src/org/jbox2d/dynamics/Profile.java +97 -0
  81. data/src/org/jbox2d/dynamics/SolverData.java +33 -0
  82. data/src/org/jbox2d/dynamics/TimeStep.java +46 -0
  83. data/src/org/jbox2d/dynamics/World.java +2075 -0
  84. data/src/org/jbox2d/dynamics/contacts/ChainAndCircleContact.java +57 -0
  85. data/src/org/jbox2d/dynamics/contacts/ChainAndPolygonContact.java +57 -0
  86. data/src/org/jbox2d/dynamics/contacts/CircleContact.java +50 -0
  87. data/src/org/jbox2d/dynamics/contacts/Contact.java +365 -0
  88. data/src/org/jbox2d/dynamics/contacts/ContactCreator.java +35 -0
  89. data/src/org/jbox2d/dynamics/contacts/ContactEdge.java +56 -0
  90. data/src/org/jbox2d/dynamics/contacts/ContactPositionConstraint.java +49 -0
  91. data/src/org/jbox2d/dynamics/contacts/ContactRegister.java +31 -0
  92. data/src/org/jbox2d/dynamics/contacts/ContactSolver.java +1104 -0
  93. data/src/org/jbox2d/dynamics/contacts/ContactVelocityConstraint.java +60 -0
  94. data/src/org/jbox2d/dynamics/contacts/EdgeAndCircleContact.java +52 -0
  95. data/src/org/jbox2d/dynamics/contacts/EdgeAndPolygonContact.java +52 -0
  96. data/src/org/jbox2d/dynamics/contacts/PolygonAndCircleContact.java +51 -0
  97. data/src/org/jbox2d/dynamics/contacts/PolygonContact.java +50 -0
  98. data/src/org/jbox2d/dynamics/contacts/Position.java +31 -0
  99. data/src/org/jbox2d/dynamics/contacts/Velocity.java +31 -0
  100. data/src/org/jbox2d/dynamics/joints/ConstantVolumeJoint.java +258 -0
  101. data/src/org/jbox2d/dynamics/joints/ConstantVolumeJointDef.java +75 -0
  102. data/src/org/jbox2d/dynamics/joints/DistanceJoint.java +356 -0
  103. data/src/org/jbox2d/dynamics/joints/DistanceJointDef.java +106 -0
  104. data/src/org/jbox2d/dynamics/joints/FrictionJoint.java +294 -0
  105. data/src/org/jbox2d/dynamics/joints/FrictionJointDef.java +78 -0
  106. data/src/org/jbox2d/dynamics/joints/GearJoint.java +520 -0
  107. data/src/org/jbox2d/dynamics/joints/GearJointDef.java +58 -0
  108. data/src/org/jbox2d/dynamics/joints/Jacobian.java +32 -0
  109. data/src/org/jbox2d/dynamics/joints/Joint.java +235 -0
  110. data/src/org/jbox2d/dynamics/joints/JointDef.java +65 -0
  111. data/src/org/jbox2d/dynamics/joints/JointEdge.java +57 -0
  112. data/src/org/jbox2d/dynamics/joints/JointType.java +28 -0
  113. data/src/org/jbox2d/dynamics/joints/LimitState.java +28 -0
  114. data/src/org/jbox2d/dynamics/joints/MotorJoint.java +339 -0
  115. data/src/org/jbox2d/dynamics/joints/MotorJointDef.java +55 -0
  116. data/src/org/jbox2d/dynamics/joints/MouseJoint.java +262 -0
  117. data/src/org/jbox2d/dynamics/joints/MouseJointDef.java +62 -0
  118. data/src/org/jbox2d/dynamics/joints/PrismaticJoint.java +808 -0
  119. data/src/org/jbox2d/dynamics/joints/PrismaticJointDef.java +120 -0
  120. data/src/org/jbox2d/dynamics/joints/PulleyJoint.java +393 -0
  121. data/src/org/jbox2d/dynamics/joints/PulleyJointDef.java +105 -0
  122. data/src/org/jbox2d/dynamics/joints/RevoluteJoint.java +554 -0
  123. data/src/org/jbox2d/dynamics/joints/RevoluteJointDef.java +137 -0
  124. data/src/org/jbox2d/dynamics/joints/RopeJoint.java +276 -0
  125. data/src/org/jbox2d/dynamics/joints/RopeJointDef.java +34 -0
  126. data/src/org/jbox2d/dynamics/joints/WeldJoint.java +424 -0
  127. data/src/org/jbox2d/dynamics/joints/WeldJointDef.java +85 -0
  128. data/src/org/jbox2d/dynamics/joints/WheelJoint.java +498 -0
  129. data/src/org/jbox2d/dynamics/joints/WheelJointDef.java +98 -0
  130. data/src/org/jbox2d/particle/ParticleBodyContact.java +17 -0
  131. data/src/org/jbox2d/particle/ParticleColor.java +52 -0
  132. data/src/org/jbox2d/particle/ParticleContact.java +14 -0
  133. data/src/org/jbox2d/particle/ParticleDef.java +24 -0
  134. data/src/org/jbox2d/particle/ParticleGroup.java +154 -0
  135. data/src/org/jbox2d/particle/ParticleGroupDef.java +62 -0
  136. data/src/org/jbox2d/particle/ParticleGroupType.java +8 -0
  137. data/src/org/jbox2d/particle/ParticleSystem.java +2172 -0
  138. data/src/org/jbox2d/particle/ParticleType.java +28 -0
  139. data/src/org/jbox2d/particle/StackQueue.java +44 -0
  140. data/src/org/jbox2d/particle/VoronoiDiagram.java +209 -0
  141. data/src/org/jbox2d/pooling/IDynamicStack.java +47 -0
  142. data/src/org/jbox2d/pooling/IOrderedStack.java +57 -0
  143. data/src/org/jbox2d/pooling/IWorldPool.java +101 -0
  144. data/src/org/jbox2d/pooling/arrays/FloatArray.java +50 -0
  145. data/src/org/jbox2d/pooling/arrays/GeneratorArray.java +33 -0
  146. data/src/org/jbox2d/pooling/arrays/IntArray.java +53 -0
  147. data/src/org/jbox2d/pooling/arrays/Vec2Array.java +57 -0
  148. data/src/org/jbox2d/pooling/normal/CircleStack.java +77 -0
  149. data/src/org/jbox2d/pooling/normal/DefaultWorldPool.java +331 -0
  150. data/src/org/jbox2d/pooling/normal/MutableStack.java +72 -0
  151. data/src/org/jbox2d/pooling/normal/OrderedStack.java +73 -0
  152. data/src/org/jbox2d/pooling/stacks/DynamicIntStack.java +60 -0
  153. metadata +161 -14
  154. data/lib/jbox2d-library-2.3.1-SNAPSHOT.jar +0 -0
@@ -0,0 +1,120 @@
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.Vec2;
27
+ import org.jbox2d.dynamics.Body;
28
+
29
+ /**
30
+ * Prismatic joint definition. This requires defining a line of motion using an axis and an anchor
31
+ * point. The definition uses local anchor points and a local axis so that the initial configuration
32
+ * can violate the constraint slightly. The joint translation is zero when the local anchor points
33
+ * coincide in world space. Using local anchors and a local axis helps when saving and loading a
34
+ * game.
35
+ *
36
+ * @warning at least one body should by dynamic with a non-fixed rotation.
37
+ * @author Daniel
38
+ *
39
+ */
40
+ public class PrismaticJointDef extends JointDef {
41
+
42
+
43
+ /**
44
+ * The local anchor point relative to body1's origin.
45
+ */
46
+ public final Vec2 localAnchorA;
47
+
48
+ /**
49
+ * The local anchor point relative to body2's origin.
50
+ */
51
+ public final Vec2 localAnchorB;
52
+
53
+ /**
54
+ * The local translation axis in body1.
55
+ */
56
+ public final Vec2 localAxisA;
57
+
58
+ /**
59
+ * The constrained angle between the bodies: body2_angle - body1_angle.
60
+ */
61
+ public float referenceAngle;
62
+
63
+ /**
64
+ * Enable/disable the joint limit.
65
+ */
66
+ public boolean enableLimit;
67
+
68
+ /**
69
+ * The lower translation limit, usually in meters.
70
+ */
71
+ public float lowerTranslation;
72
+
73
+ /**
74
+ * The upper translation limit, usually in meters.
75
+ */
76
+ public float upperTranslation;
77
+
78
+ /**
79
+ * Enable/disable the joint motor.
80
+ */
81
+ public boolean enableMotor;
82
+
83
+ /**
84
+ * The maximum motor torque, usually in N-m.
85
+ */
86
+ public float maxMotorForce;
87
+
88
+ /**
89
+ * The desired motor speed in radians per second.
90
+ */
91
+ public float motorSpeed;
92
+
93
+ public PrismaticJointDef() {
94
+ super(JointType.PRISMATIC);
95
+ localAnchorA = new Vec2();
96
+ localAnchorB = new Vec2();
97
+ localAxisA = new Vec2(1.0f, 0.0f);
98
+ referenceAngle = 0.0f;
99
+ enableLimit = false;
100
+ lowerTranslation = 0.0f;
101
+ upperTranslation = 0.0f;
102
+ enableMotor = false;
103
+ maxMotorForce = 0.0f;
104
+ motorSpeed = 0.0f;
105
+ }
106
+
107
+
108
+ /**
109
+ * Initialize the bodies, anchors, axis, and reference angle using the world anchor and world
110
+ * axis.
111
+ */
112
+ public void initialize(Body b1, Body b2, Vec2 anchor, Vec2 axis) {
113
+ bodyA = b1;
114
+ bodyB = b2;
115
+ bodyA.getLocalPointToOut(anchor, localAnchorA);
116
+ bodyB.getLocalPointToOut(anchor, localAnchorB);
117
+ bodyA.getLocalVectorToOut(axis, localAxisA);
118
+ referenceAngle = bodyB.getAngle() - bodyA.getAngle();
119
+ }
120
+ }
@@ -0,0 +1,393 @@
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
+ /**
25
+ * Created at 12:12:02 PM Jan 23, 2011
26
+ */
27
+ package org.jbox2d.dynamics.joints;
28
+
29
+ import org.jbox2d.common.MathUtils;
30
+ import org.jbox2d.common.Rot;
31
+ import org.jbox2d.common.Settings;
32
+ import org.jbox2d.common.Vec2;
33
+ import org.jbox2d.dynamics.SolverData;
34
+ import org.jbox2d.pooling.IWorldPool;
35
+
36
+ /**
37
+ * The pulley joint is connected to two bodies and two fixed ground points. The pulley supports a
38
+ * ratio such that: length1 + ratio * length2 <= constant Yes, the force transmitted is scaled by
39
+ * the ratio. Warning: the pulley joint can get a bit squirrelly by itself. They often work better
40
+ * when combined with prismatic joints. You should also cover the the anchor points with static
41
+ * shapes to prevent one side from going to zero length.
42
+ *
43
+ * @author Daniel Murphy
44
+ */
45
+ public class PulleyJoint extends Joint {
46
+
47
+ public static final float MIN_PULLEY_LENGTH = 2.0f;
48
+
49
+ private final Vec2 m_groundAnchorA = new Vec2();
50
+ private final Vec2 m_groundAnchorB = new Vec2();
51
+ private float m_lengthA;
52
+ private float m_lengthB;
53
+
54
+ // Solver shared
55
+ private final Vec2 m_localAnchorA = new Vec2();
56
+ private final Vec2 m_localAnchorB = new Vec2();
57
+ private float m_constant;
58
+ private float m_ratio;
59
+ private float m_impulse;
60
+
61
+ // Solver temp
62
+ private int m_indexA;
63
+ private int m_indexB;
64
+ private final Vec2 m_uA = new Vec2();
65
+ private final Vec2 m_uB = new Vec2();
66
+ private final Vec2 m_rA = new Vec2();
67
+ private final Vec2 m_rB = new Vec2();
68
+ private final Vec2 m_localCenterA = new Vec2();
69
+ private final Vec2 m_localCenterB = new Vec2();
70
+ private float m_invMassA;
71
+ private float m_invMassB;
72
+ private float m_invIA;
73
+ private float m_invIB;
74
+ private float m_mass;
75
+
76
+ protected PulleyJoint(IWorldPool argWorldPool, PulleyJointDef def) {
77
+ super(argWorldPool, def);
78
+ m_groundAnchorA.set(def.groundAnchorA);
79
+ m_groundAnchorB.set(def.groundAnchorB);
80
+ m_localAnchorA.set(def.localAnchorA);
81
+ m_localAnchorB.set(def.localAnchorB);
82
+
83
+ assert (def.ratio != 0.0f);
84
+ m_ratio = def.ratio;
85
+
86
+ m_lengthA = def.lengthA;
87
+ m_lengthB = def.lengthB;
88
+
89
+ m_constant = def.lengthA + m_ratio * def.lengthB;
90
+ m_impulse = 0.0f;
91
+ }
92
+
93
+ public float getLengthA() {
94
+ return m_lengthA;
95
+ }
96
+
97
+ public float getLengthB() {
98
+ return m_lengthB;
99
+ }
100
+
101
+ public float getCurrentLengthA() {
102
+ final Vec2 p = pool.popVec2();
103
+ m_bodyA.getWorldPointToOut(m_localAnchorA, p);
104
+ p.subLocal(m_groundAnchorA);
105
+ float length = p.length();
106
+ pool.pushVec2(1);
107
+ return length;
108
+ }
109
+
110
+ public float getCurrentLengthB() {
111
+ final Vec2 p = pool.popVec2();
112
+ m_bodyB.getWorldPointToOut(m_localAnchorB, p);
113
+ p.subLocal(m_groundAnchorB);
114
+ float length = p.length();
115
+ pool.pushVec2(1);
116
+ return length;
117
+ }
118
+
119
+
120
+ public Vec2 getLocalAnchorA() {
121
+ return m_localAnchorA;
122
+ }
123
+
124
+ public Vec2 getLocalAnchorB() {
125
+ return m_localAnchorB;
126
+ }
127
+
128
+
129
+ @Override
130
+ public void getAnchorA(Vec2 argOut) {
131
+ m_bodyA.getWorldPointToOut(m_localAnchorA, argOut);
132
+ }
133
+
134
+ @Override
135
+ public void getAnchorB(Vec2 argOut) {
136
+ m_bodyB.getWorldPointToOut(m_localAnchorB, argOut);
137
+ }
138
+
139
+ @Override
140
+ public void getReactionForce(float inv_dt, Vec2 argOut) {
141
+ argOut.set(m_uB).mulLocal(m_impulse).mulLocal(inv_dt);
142
+ }
143
+
144
+ @Override
145
+ public float getReactionTorque(float inv_dt) {
146
+ return 0f;
147
+ }
148
+
149
+ public Vec2 getGroundAnchorA() {
150
+ return m_groundAnchorA;
151
+ }
152
+
153
+ public Vec2 getGroundAnchorB() {
154
+ return m_groundAnchorB;
155
+ }
156
+
157
+ public float getLength1() {
158
+ final Vec2 p = pool.popVec2();
159
+ m_bodyA.getWorldPointToOut(m_localAnchorA, p);
160
+ p.subLocal(m_groundAnchorA);
161
+
162
+ float len = p.length();
163
+ pool.pushVec2(1);
164
+ return len;
165
+ }
166
+
167
+ public float getLength2() {
168
+ final Vec2 p = pool.popVec2();
169
+ m_bodyB.getWorldPointToOut(m_localAnchorB, p);
170
+ p.subLocal(m_groundAnchorB);
171
+
172
+ float len = p.length();
173
+ pool.pushVec2(1);
174
+ return len;
175
+ }
176
+
177
+ public float getRatio() {
178
+ return m_ratio;
179
+ }
180
+
181
+ @Override
182
+ public void initVelocityConstraints(final SolverData data) {
183
+ m_indexA = m_bodyA.m_islandIndex;
184
+ m_indexB = m_bodyB.m_islandIndex;
185
+ m_localCenterA.set(m_bodyA.m_sweep.localCenter);
186
+ m_localCenterB.set(m_bodyB.m_sweep.localCenter);
187
+ m_invMassA = m_bodyA.m_invMass;
188
+ m_invMassB = m_bodyB.m_invMass;
189
+ m_invIA = m_bodyA.m_invI;
190
+ m_invIB = m_bodyB.m_invI;
191
+
192
+ Vec2 cA = data.positions[m_indexA].c;
193
+ float aA = data.positions[m_indexA].a;
194
+ Vec2 vA = data.velocities[m_indexA].v;
195
+ float wA = data.velocities[m_indexA].w;
196
+
197
+ Vec2 cB = data.positions[m_indexB].c;
198
+ float aB = data.positions[m_indexB].a;
199
+ Vec2 vB = data.velocities[m_indexB].v;
200
+ float wB = data.velocities[m_indexB].w;
201
+
202
+ final Rot qA = pool.popRot();
203
+ final Rot qB = pool.popRot();
204
+ final Vec2 temp = pool.popVec2();
205
+
206
+ qA.set(aA);
207
+ qB.set(aB);
208
+
209
+ // Compute the effective masses.
210
+ Rot.mulToOutUnsafe(qA, temp.set(m_localAnchorA).subLocal(m_localCenterA), m_rA);
211
+ Rot.mulToOutUnsafe(qB, temp.set(m_localAnchorB).subLocal(m_localCenterB), m_rB);
212
+
213
+ m_uA.set(cA).addLocal(m_rA).subLocal(m_groundAnchorA);
214
+ m_uB.set(cB).addLocal(m_rB).subLocal(m_groundAnchorB);
215
+
216
+ float lengthA = m_uA.length();
217
+ float lengthB = m_uB.length();
218
+
219
+ if (lengthA > 10f * Settings.linearSlop) {
220
+ m_uA.mulLocal(1.0f / lengthA);
221
+ } else {
222
+ m_uA.setZero();
223
+ }
224
+
225
+ if (lengthB > 10f * Settings.linearSlop) {
226
+ m_uB.mulLocal(1.0f / lengthB);
227
+ } else {
228
+ m_uB.setZero();
229
+ }
230
+
231
+ // Compute effective mass.
232
+ float ruA = Vec2.cross(m_rA, m_uA);
233
+ float ruB = Vec2.cross(m_rB, m_uB);
234
+
235
+ float mA = m_invMassA + m_invIA * ruA * ruA;
236
+ float mB = m_invMassB + m_invIB * ruB * ruB;
237
+
238
+ m_mass = mA + m_ratio * m_ratio * mB;
239
+
240
+ if (m_mass > 0.0f) {
241
+ m_mass = 1.0f / m_mass;
242
+ }
243
+
244
+ if (data.step.warmStarting) {
245
+
246
+ // Scale impulses to support variable time steps.
247
+ m_impulse *= data.step.dtRatio;
248
+
249
+ // Warm starting.
250
+ final Vec2 PA = pool.popVec2();
251
+ final Vec2 PB = pool.popVec2();
252
+
253
+ PA.set(m_uA).mulLocal(-m_impulse);
254
+ PB.set(m_uB).mulLocal(-m_ratio * m_impulse);
255
+
256
+ vA.x += m_invMassA * PA.x;
257
+ vA.y += m_invMassA * PA.y;
258
+ wA += m_invIA * Vec2.cross(m_rA, PA);
259
+ vB.x += m_invMassB * PB.x;
260
+ vB.y += m_invMassB * PB.y;
261
+ wB += m_invIB * Vec2.cross(m_rB, PB);
262
+
263
+ pool.pushVec2(2);
264
+ } else {
265
+ m_impulse = 0.0f;
266
+ }
267
+ // data.velocities[m_indexA].v.set(vA);
268
+ data.velocities[m_indexA].w = wA;
269
+ // data.velocities[m_indexB].v.set(vB);
270
+ data.velocities[m_indexB].w = wB;
271
+
272
+ pool.pushVec2(1);
273
+ pool.pushRot(2);
274
+ }
275
+
276
+ @Override
277
+ public void solveVelocityConstraints(final SolverData data) {
278
+ Vec2 vA = data.velocities[m_indexA].v;
279
+ float wA = data.velocities[m_indexA].w;
280
+ Vec2 vB = data.velocities[m_indexB].v;
281
+ float wB = data.velocities[m_indexB].w;
282
+
283
+ final Vec2 vpA = pool.popVec2();
284
+ final Vec2 vpB = pool.popVec2();
285
+ final Vec2 PA = pool.popVec2();
286
+ final Vec2 PB = pool.popVec2();
287
+
288
+ Vec2.crossToOutUnsafe(wA, m_rA, vpA);
289
+ vpA.addLocal(vA);
290
+ Vec2.crossToOutUnsafe(wB, m_rB, vpB);
291
+ vpB.addLocal(vB);
292
+
293
+ float Cdot = -Vec2.dot(m_uA, vpA) - m_ratio * Vec2.dot(m_uB, vpB);
294
+ float impulse = -m_mass * Cdot;
295
+ m_impulse += impulse;
296
+
297
+ PA.set(m_uA).mulLocal(-impulse);
298
+ PB.set(m_uB).mulLocal(-m_ratio * impulse);
299
+ vA.x += m_invMassA * PA.x;
300
+ vA.y += m_invMassA * PA.y;
301
+ wA += m_invIA * Vec2.cross(m_rA, PA);
302
+ vB.x += m_invMassB * PB.x;
303
+ vB.y += m_invMassB * PB.y;
304
+ wB += m_invIB * Vec2.cross(m_rB, PB);
305
+
306
+ // data.velocities[m_indexA].v.set(vA);
307
+ data.velocities[m_indexA].w = wA;
308
+ // data.velocities[m_indexB].v.set(vB);
309
+ data.velocities[m_indexB].w = wB;
310
+
311
+ pool.pushVec2(4);
312
+ }
313
+
314
+ @Override
315
+ public boolean solvePositionConstraints(final SolverData data) {
316
+ final Rot qA = pool.popRot();
317
+ final Rot qB = pool.popRot();
318
+ final Vec2 rA = pool.popVec2();
319
+ final Vec2 rB = pool.popVec2();
320
+ final Vec2 uA = pool.popVec2();
321
+ final Vec2 uB = pool.popVec2();
322
+ final Vec2 temp = pool.popVec2();
323
+ final Vec2 PA = pool.popVec2();
324
+ final Vec2 PB = pool.popVec2();
325
+
326
+ Vec2 cA = data.positions[m_indexA].c;
327
+ float aA = data.positions[m_indexA].a;
328
+ Vec2 cB = data.positions[m_indexB].c;
329
+ float aB = data.positions[m_indexB].a;
330
+
331
+ qA.set(aA);
332
+ qB.set(aB);
333
+
334
+ Rot.mulToOutUnsafe(qA, temp.set(m_localAnchorA).subLocal(m_localCenterA), rA);
335
+ Rot.mulToOutUnsafe(qB, temp.set(m_localAnchorB).subLocal(m_localCenterB), rB);
336
+
337
+ uA.set(cA).addLocal(rA).subLocal(m_groundAnchorA);
338
+ uB.set(cB).addLocal(rB).subLocal(m_groundAnchorB);
339
+
340
+ float lengthA = uA.length();
341
+ float lengthB = uB.length();
342
+
343
+ if (lengthA > 10.0f * Settings.linearSlop) {
344
+ uA.mulLocal(1.0f / lengthA);
345
+ } else {
346
+ uA.setZero();
347
+ }
348
+
349
+ if (lengthB > 10.0f * Settings.linearSlop) {
350
+ uB.mulLocal(1.0f / lengthB);
351
+ } else {
352
+ uB.setZero();
353
+ }
354
+
355
+ // Compute effective mass.
356
+ float ruA = Vec2.cross(rA, uA);
357
+ float ruB = Vec2.cross(rB, uB);
358
+
359
+ float mA = m_invMassA + m_invIA * ruA * ruA;
360
+ float mB = m_invMassB + m_invIB * ruB * ruB;
361
+
362
+ float mass = mA + m_ratio * m_ratio * mB;
363
+
364
+ if (mass > 0.0f) {
365
+ mass = 1.0f / mass;
366
+ }
367
+
368
+ float C = m_constant - lengthA - m_ratio * lengthB;
369
+ float linearError = MathUtils.abs(C);
370
+
371
+ float impulse = -mass * C;
372
+
373
+ PA.set(uA).mulLocal(-impulse);
374
+ PB.set(uB).mulLocal(-m_ratio * impulse);
375
+
376
+ cA.x += m_invMassA * PA.x;
377
+ cA.y += m_invMassA * PA.y;
378
+ aA += m_invIA * Vec2.cross(rA, PA);
379
+ cB.x += m_invMassB * PB.x;
380
+ cB.y += m_invMassB * PB.y;
381
+ aB += m_invIB * Vec2.cross(rB, PB);
382
+
383
+ // data.positions[m_indexA].c.set(cA);
384
+ data.positions[m_indexA].a = aA;
385
+ // data.positions[m_indexB].c.set(cB);
386
+ data.positions[m_indexB].a = aB;
387
+
388
+ pool.pushRot(2);
389
+ pool.pushVec2(7);
390
+
391
+ return linearError < Settings.linearSlop;
392
+ }
393
+ }
@@ -0,0 +1,105 @@
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
+ /**
25
+ * Created at 12:11:41 PM Jan 23, 2011
26
+ */
27
+ package org.jbox2d.dynamics.joints;
28
+
29
+ import org.jbox2d.common.Settings;
30
+ import org.jbox2d.common.Vec2;
31
+ import org.jbox2d.dynamics.Body;
32
+
33
+ /**
34
+ * Pulley joint definition. This requires two ground anchors, two dynamic body anchor points, and a
35
+ * pulley ratio.
36
+ *
37
+ * @author Daniel Murphy
38
+ */
39
+ public class PulleyJointDef extends JointDef {
40
+
41
+ /**
42
+ * The first ground anchor in world coordinates. This point never moves.
43
+ */
44
+ public Vec2 groundAnchorA;
45
+
46
+ /**
47
+ * The second ground anchor in world coordinates. This point never moves.
48
+ */
49
+ public Vec2 groundAnchorB;
50
+
51
+ /**
52
+ * The local anchor point relative to bodyA's origin.
53
+ */
54
+ public Vec2 localAnchorA;
55
+
56
+ /**
57
+ * The local anchor point relative to bodyB's origin.
58
+ */
59
+ public Vec2 localAnchorB;
60
+
61
+ /**
62
+ * The a reference length for the segment attached to bodyA.
63
+ */
64
+ public float lengthA;
65
+
66
+ /**
67
+ * The a reference length for the segment attached to bodyB.
68
+ */
69
+ public float lengthB;
70
+
71
+ /**
72
+ * The pulley ratio, used to simulate a block-and-tackle.
73
+ */
74
+ public float ratio;
75
+
76
+ public PulleyJointDef() {
77
+ super(JointType.PULLEY);
78
+ groundAnchorA = new Vec2(-1.0f, 1.0f);
79
+ groundAnchorB = new Vec2(1.0f, 1.0f);
80
+ localAnchorA = new Vec2(-1.0f, 0.0f);
81
+ localAnchorB = new Vec2(1.0f, 0.0f);
82
+ lengthA = 0.0f;
83
+ lengthB = 0.0f;
84
+ ratio = 1.0f;
85
+ collideConnected = true;
86
+ }
87
+
88
+ /**
89
+ * Initialize the bodies, anchors, lengths, max lengths, and ratio using the world anchors.
90
+ */
91
+ public void initialize(Body b1, Body b2, Vec2 ga1, Vec2 ga2, Vec2 anchor1, Vec2 anchor2, float r) {
92
+ bodyA = b1;
93
+ bodyB = b2;
94
+ groundAnchorA = ga1;
95
+ groundAnchorB = ga2;
96
+ localAnchorA = bodyA.getLocalPoint(anchor1);
97
+ localAnchorB = bodyB.getLocalPoint(anchor2);
98
+ Vec2 d1 = anchor1.sub(ga1);
99
+ lengthA = d1.length();
100
+ Vec2 d2 = anchor2.sub(ga2);
101
+ lengthB = d2.length();
102
+ ratio = r;
103
+ assert (ratio > Settings.EPSILON);
104
+ }
105
+ }