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,382 @@
|
|
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;
|
25
|
+
|
26
|
+
import org.jbox2d.common.Vec2;
|
27
|
+
|
28
|
+
/**
|
29
|
+
* A body definition holds all the data needed to construct a rigid body. You can safely re-use body
|
30
|
+
* definitions. Shapes are added to a body after construction.
|
31
|
+
*
|
32
|
+
* @author daniel
|
33
|
+
*/
|
34
|
+
public class BodyDef {
|
35
|
+
|
36
|
+
/**
|
37
|
+
* The body type: static, kinematic, or dynamic. Note: if a dynamic body would have zero mass, the
|
38
|
+
* mass is set to one.
|
39
|
+
*/
|
40
|
+
public BodyType type;
|
41
|
+
|
42
|
+
/**
|
43
|
+
* Use this to store application specific body data.
|
44
|
+
*/
|
45
|
+
public Object userData;
|
46
|
+
|
47
|
+
/**
|
48
|
+
* The world position of the body. Avoid creating bodies at the origin since this can lead to many
|
49
|
+
* overlapping shapes.
|
50
|
+
*/
|
51
|
+
public Vec2 position;
|
52
|
+
|
53
|
+
/**
|
54
|
+
* The world angle of the body in radians.
|
55
|
+
*/
|
56
|
+
public float angle;
|
57
|
+
|
58
|
+
/**
|
59
|
+
* The linear velocity of the body in world co-ordinates.
|
60
|
+
*/
|
61
|
+
public Vec2 linearVelocity;
|
62
|
+
|
63
|
+
/**
|
64
|
+
* The angular velocity of the body.
|
65
|
+
*/
|
66
|
+
public float angularVelocity;
|
67
|
+
|
68
|
+
/**
|
69
|
+
* Linear damping is use to reduce the linear velocity. The damping parameter can be larger than
|
70
|
+
* 1.0f but the damping effect becomes sensitive to the time step when the damping parameter is
|
71
|
+
* large.
|
72
|
+
*/
|
73
|
+
public float linearDamping;
|
74
|
+
|
75
|
+
/**
|
76
|
+
* Angular damping is use to reduce the angular velocity. The damping parameter can be larger than
|
77
|
+
* 1.0f but the damping effect becomes sensitive to the time step when the damping parameter is
|
78
|
+
* large.
|
79
|
+
*/
|
80
|
+
public float angularDamping;
|
81
|
+
|
82
|
+
/**
|
83
|
+
* Set this flag to false if this body should never fall asleep. Note that this increases CPU
|
84
|
+
* usage.
|
85
|
+
*/
|
86
|
+
public boolean allowSleep;
|
87
|
+
|
88
|
+
/**
|
89
|
+
* Is this body initially sleeping?
|
90
|
+
*/
|
91
|
+
public boolean awake;
|
92
|
+
|
93
|
+
/**
|
94
|
+
* Should this body be prevented from rotating? Useful for characters.
|
95
|
+
*/
|
96
|
+
public boolean fixedRotation;
|
97
|
+
|
98
|
+
/**
|
99
|
+
* Is this a fast moving body that should be prevented from tunneling through other moving bodies?
|
100
|
+
* Note that all bodies are prevented from tunneling through kinematic and static bodies. This
|
101
|
+
* setting is only considered on dynamic bodies.
|
102
|
+
*
|
103
|
+
* @warning You should use this flag sparingly since it increases processing time.
|
104
|
+
*/
|
105
|
+
public boolean bullet;
|
106
|
+
|
107
|
+
/**
|
108
|
+
* Does this body start out active?
|
109
|
+
*/
|
110
|
+
public boolean active;
|
111
|
+
|
112
|
+
/**
|
113
|
+
* Experimental: scales the inertia tensor.
|
114
|
+
*/
|
115
|
+
public float gravityScale;
|
116
|
+
|
117
|
+
/**
|
118
|
+
*
|
119
|
+
*/
|
120
|
+
public BodyDef() {
|
121
|
+
userData = null;
|
122
|
+
position = new Vec2();
|
123
|
+
angle = 0f;
|
124
|
+
linearVelocity = new Vec2();
|
125
|
+
angularVelocity = 0f;
|
126
|
+
linearDamping = 0f;
|
127
|
+
angularDamping = 0f;
|
128
|
+
allowSleep = true;
|
129
|
+
awake = true;
|
130
|
+
fixedRotation = false;
|
131
|
+
bullet = false;
|
132
|
+
type = BodyType.STATIC;
|
133
|
+
active = true;
|
134
|
+
gravityScale = 1.0f;
|
135
|
+
}
|
136
|
+
|
137
|
+
/**
|
138
|
+
* The body type: static, kinematic, or dynamic. Note: if a dynamic body would have zero mass, the
|
139
|
+
* mass is set to one.
|
140
|
+
* @return
|
141
|
+
*/
|
142
|
+
public BodyType getType() {
|
143
|
+
return type;
|
144
|
+
}
|
145
|
+
|
146
|
+
/**
|
147
|
+
* The body type: static, kinematic, or dynamic. Note: if a dynamic body would have zero mass, the
|
148
|
+
* mass is set to one.
|
149
|
+
* @param type
|
150
|
+
*/
|
151
|
+
public void setType(BodyType type) {
|
152
|
+
this.type = type;
|
153
|
+
}
|
154
|
+
|
155
|
+
/**
|
156
|
+
* Use this to store application specific body data.
|
157
|
+
* @return
|
158
|
+
*/
|
159
|
+
public Object getUserData() {
|
160
|
+
return userData;
|
161
|
+
}
|
162
|
+
|
163
|
+
/**
|
164
|
+
* Use this to store application specific body data.
|
165
|
+
* @param userData
|
166
|
+
*/
|
167
|
+
public void setUserData(Object userData) {
|
168
|
+
this.userData = userData;
|
169
|
+
}
|
170
|
+
|
171
|
+
/**
|
172
|
+
* The world position of the body. Avoid creating bodies at the origin since this can lead to many
|
173
|
+
* overlapping shapes.
|
174
|
+
* @return
|
175
|
+
*/
|
176
|
+
public Vec2 getPosition() {
|
177
|
+
return position;
|
178
|
+
}
|
179
|
+
|
180
|
+
/**
|
181
|
+
* The world position of the body. Avoid creating bodies at the origin since this can lead to many
|
182
|
+
* overlapping shapes.
|
183
|
+
* @param position
|
184
|
+
*/
|
185
|
+
public void setPosition(Vec2 position) {
|
186
|
+
this.position = position;
|
187
|
+
}
|
188
|
+
|
189
|
+
/**
|
190
|
+
* The world angle of the body in radians.
|
191
|
+
* @return
|
192
|
+
*/
|
193
|
+
public float getAngle() {
|
194
|
+
return angle;
|
195
|
+
}
|
196
|
+
|
197
|
+
/**
|
198
|
+
* The world angle of the body in radians.
|
199
|
+
* @param angle
|
200
|
+
*/
|
201
|
+
public void setAngle(float angle) {
|
202
|
+
this.angle = angle;
|
203
|
+
}
|
204
|
+
|
205
|
+
/**
|
206
|
+
* The linear velocity of the body in world co-ordinates.
|
207
|
+
* @return
|
208
|
+
*/
|
209
|
+
public Vec2 getLinearVelocity() {
|
210
|
+
return linearVelocity;
|
211
|
+
}
|
212
|
+
|
213
|
+
/**
|
214
|
+
* The linear velocity of the body in world co-ordinates.
|
215
|
+
* @param linearVelocity
|
216
|
+
*/
|
217
|
+
public void setLinearVelocity(Vec2 linearVelocity) {
|
218
|
+
this.linearVelocity = linearVelocity;
|
219
|
+
}
|
220
|
+
|
221
|
+
/**
|
222
|
+
* The angular velocity of the body.
|
223
|
+
* @return
|
224
|
+
*/
|
225
|
+
public float getAngularVelocity() {
|
226
|
+
return angularVelocity;
|
227
|
+
}
|
228
|
+
|
229
|
+
/**
|
230
|
+
* The angular velocity of the body.
|
231
|
+
* @param angularVelocity
|
232
|
+
*/
|
233
|
+
public void setAngularVelocity(float angularVelocity) {
|
234
|
+
this.angularVelocity = angularVelocity;
|
235
|
+
}
|
236
|
+
|
237
|
+
/**
|
238
|
+
* Linear damping is use to reduce the linear velocity. The damping parameter can be larger than
|
239
|
+
* 1.0f but the damping effect becomes sensitive to the time step when the damping parameter is
|
240
|
+
* large.
|
241
|
+
* @return
|
242
|
+
*/
|
243
|
+
public float getLinearDamping() {
|
244
|
+
return linearDamping;
|
245
|
+
}
|
246
|
+
|
247
|
+
/**
|
248
|
+
* Linear damping is use to reduce the linear velocity. The damping parameter can be larger than
|
249
|
+
* 1.0f but the damping effect becomes sensitive to the time step when the damping parameter is
|
250
|
+
* large.
|
251
|
+
* @param linearDamping
|
252
|
+
*/
|
253
|
+
public void setLinearDamping(float linearDamping) {
|
254
|
+
this.linearDamping = linearDamping;
|
255
|
+
}
|
256
|
+
|
257
|
+
/**
|
258
|
+
* Angular damping is use to reduce the angular velocity. The damping parameter can be larger than
|
259
|
+
* 1.0f but the damping effect becomes sensitive to the time step when the damping parameter is
|
260
|
+
* large.
|
261
|
+
* @return
|
262
|
+
*/
|
263
|
+
public float getAngularDamping() {
|
264
|
+
return angularDamping;
|
265
|
+
}
|
266
|
+
|
267
|
+
/**
|
268
|
+
* Angular damping is use to reduce the angular velocity. The damping parameter can be larger than
|
269
|
+
* 1.0f but the damping effect becomes sensitive to the time step when the damping parameter is
|
270
|
+
* large.
|
271
|
+
* @param angularDamping
|
272
|
+
*/
|
273
|
+
public void setAngularDamping(float angularDamping) {
|
274
|
+
this.angularDamping = angularDamping;
|
275
|
+
}
|
276
|
+
|
277
|
+
/**
|
278
|
+
* Set this flag to false if this body should never fall asleep. Note that this increases CPU
|
279
|
+
* usage.
|
280
|
+
* @return
|
281
|
+
*/
|
282
|
+
public boolean isAllowSleep() {
|
283
|
+
return allowSleep;
|
284
|
+
}
|
285
|
+
|
286
|
+
/**
|
287
|
+
* Set this flag to false if this body should never fall asleep. Note that this increases CPU
|
288
|
+
* usage.
|
289
|
+
* @param allowSleep
|
290
|
+
*/
|
291
|
+
public void setAllowSleep(boolean allowSleep) {
|
292
|
+
this.allowSleep = allowSleep;
|
293
|
+
}
|
294
|
+
|
295
|
+
/**
|
296
|
+
* Is this body initially sleeping?
|
297
|
+
* @return
|
298
|
+
*/
|
299
|
+
public boolean isAwake() {
|
300
|
+
return awake;
|
301
|
+
}
|
302
|
+
|
303
|
+
/**
|
304
|
+
* Is this body initially sleeping?
|
305
|
+
* @param awake
|
306
|
+
*/
|
307
|
+
public void setAwake(boolean awake) {
|
308
|
+
this.awake = awake;
|
309
|
+
}
|
310
|
+
|
311
|
+
/**
|
312
|
+
* Should this body be prevented from rotating? Useful for characters.
|
313
|
+
* @return
|
314
|
+
*/
|
315
|
+
public boolean isFixedRotation() {
|
316
|
+
return fixedRotation;
|
317
|
+
}
|
318
|
+
|
319
|
+
/**
|
320
|
+
* Should this body be prevented from rotating? Useful for characters.
|
321
|
+
* @param fixedRotation
|
322
|
+
*/
|
323
|
+
public void setFixedRotation(boolean fixedRotation) {
|
324
|
+
this.fixedRotation = fixedRotation;
|
325
|
+
}
|
326
|
+
|
327
|
+
/**
|
328
|
+
* Is this a fast moving body that should be prevented from tunneling through other moving bodies?
|
329
|
+
* Note that all bodies are prevented from tunneling through kinematic and static bodies. This
|
330
|
+
* setting is only considered on dynamic bodies.
|
331
|
+
*
|
332
|
+
* @return
|
333
|
+
* @warning You should use this flag sparingly since it increases processing time.
|
334
|
+
*/
|
335
|
+
public boolean isBullet() {
|
336
|
+
return bullet;
|
337
|
+
}
|
338
|
+
|
339
|
+
/**
|
340
|
+
* Is this a fast moving body that should be prevented from tunneling through other moving bodies?
|
341
|
+
* Note that all bodies are prevented from tunneling through kinematic and static bodies. This
|
342
|
+
* setting is only considered on dynamic bodies.
|
343
|
+
*
|
344
|
+
* @param bullet
|
345
|
+
* @warning You should use this flag sparingly since it increases processing time.
|
346
|
+
*/
|
347
|
+
public void setBullet(boolean bullet) {
|
348
|
+
this.bullet = bullet;
|
349
|
+
}
|
350
|
+
|
351
|
+
/**
|
352
|
+
* Does this body start out active?
|
353
|
+
* @return
|
354
|
+
*/
|
355
|
+
public boolean isActive() {
|
356
|
+
return active;
|
357
|
+
}
|
358
|
+
|
359
|
+
/**
|
360
|
+
* Does this body start out active?
|
361
|
+
* @param active
|
362
|
+
*/
|
363
|
+
public void setActive(boolean active) {
|
364
|
+
this.active = active;
|
365
|
+
}
|
366
|
+
|
367
|
+
/**
|
368
|
+
* Experimental: scales the inertia tensor.
|
369
|
+
* @return
|
370
|
+
*/
|
371
|
+
public float getGravityScale() {
|
372
|
+
return gravityScale;
|
373
|
+
}
|
374
|
+
|
375
|
+
/**
|
376
|
+
* Experimental: scales the inertia tensor.
|
377
|
+
* @param gravityScale
|
378
|
+
*/
|
379
|
+
public void setGravityScale(float gravityScale) {
|
380
|
+
this.gravityScale = gravityScale;
|
381
|
+
}
|
382
|
+
}
|
@@ -0,0 +1,41 @@
|
|
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 3:59:59 AM Jul 7, 2010
|
26
|
+
*/
|
27
|
+
package org.jbox2d.dynamics;
|
28
|
+
|
29
|
+
// updated to rev 100
|
30
|
+
|
31
|
+
/**
|
32
|
+
* The body type.
|
33
|
+
* static: zero mass, zero velocity, may be manually moved
|
34
|
+
* kinematic: zero mass, non-zero velocity set by user, moved by solver
|
35
|
+
* dynamic: positive mass, non-zero velocity determined by forces, moved by solver
|
36
|
+
*
|
37
|
+
* @author daniel
|
38
|
+
*/
|
39
|
+
public enum BodyType {
|
40
|
+
STATIC, KINEMATIC, DYNAMIC
|
41
|
+
}
|
@@ -0,0 +1,293 @@
|
|
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;
|
25
|
+
|
26
|
+
import org.jbox2d.callbacks.ContactFilter;
|
27
|
+
import org.jbox2d.callbacks.ContactListener;
|
28
|
+
import org.jbox2d.callbacks.PairCallback;
|
29
|
+
import org.jbox2d.collision.broadphase.BroadPhase;
|
30
|
+
import org.jbox2d.dynamics.contacts.Contact;
|
31
|
+
import org.jbox2d.dynamics.contacts.ContactEdge;
|
32
|
+
|
33
|
+
/**
|
34
|
+
* Delegate of World.
|
35
|
+
*
|
36
|
+
* @author Daniel Murphy
|
37
|
+
*/
|
38
|
+
public class ContactManager implements PairCallback {
|
39
|
+
|
40
|
+
public BroadPhase m_broadPhase;
|
41
|
+
public Contact m_contactList;
|
42
|
+
public int m_contactCount;
|
43
|
+
public ContactFilter m_contactFilter;
|
44
|
+
public ContactListener m_contactListener;
|
45
|
+
|
46
|
+
private final World pool;
|
47
|
+
|
48
|
+
public ContactManager(World argPool, BroadPhase broadPhase) {
|
49
|
+
m_contactList = null;
|
50
|
+
m_contactCount = 0;
|
51
|
+
m_contactFilter = new ContactFilter();
|
52
|
+
m_contactListener = null;
|
53
|
+
m_broadPhase = broadPhase;
|
54
|
+
pool = argPool;
|
55
|
+
}
|
56
|
+
|
57
|
+
/**
|
58
|
+
* Broad-phase callback.
|
59
|
+
*
|
60
|
+
* @param proxyUserDataA
|
61
|
+
* @param proxyUserDataB
|
62
|
+
*/
|
63
|
+
@Override
|
64
|
+
public void addPair(Object proxyUserDataA, Object proxyUserDataB) {
|
65
|
+
FixtureProxy proxyA = (FixtureProxy) proxyUserDataA;
|
66
|
+
FixtureProxy proxyB = (FixtureProxy) proxyUserDataB;
|
67
|
+
|
68
|
+
Fixture fixtureA = proxyA.fixture;
|
69
|
+
Fixture fixtureB = proxyB.fixture;
|
70
|
+
|
71
|
+
int indexA = proxyA.childIndex;
|
72
|
+
int indexB = proxyB.childIndex;
|
73
|
+
|
74
|
+
Body bodyA = fixtureA.getBody();
|
75
|
+
Body bodyB = fixtureB.getBody();
|
76
|
+
|
77
|
+
// Are the fixtures on the same body?
|
78
|
+
if (bodyA == bodyB) {
|
79
|
+
return;
|
80
|
+
}
|
81
|
+
|
82
|
+
// TODO_ERIN use a hash table to remove a potential bottleneck when both
|
83
|
+
// bodies have a lot of contacts.
|
84
|
+
// Does a contact already exist?
|
85
|
+
ContactEdge edge = bodyB.getContactList();
|
86
|
+
while (edge != null) {
|
87
|
+
if (edge.other == bodyA) {
|
88
|
+
Fixture fA = edge.contact.getFixtureA();
|
89
|
+
Fixture fB = edge.contact.getFixtureB();
|
90
|
+
int iA = edge.contact.getChildIndexA();
|
91
|
+
int iB = edge.contact.getChildIndexB();
|
92
|
+
|
93
|
+
if (fA == fixtureA && iA == indexA && fB == fixtureB && iB == indexB) {
|
94
|
+
// A contact already exists.
|
95
|
+
return;
|
96
|
+
}
|
97
|
+
|
98
|
+
if (fA == fixtureB && iA == indexB && fB == fixtureA && iB == indexA) {
|
99
|
+
// A contact already exists.
|
100
|
+
return;
|
101
|
+
}
|
102
|
+
}
|
103
|
+
|
104
|
+
edge = edge.next;
|
105
|
+
}
|
106
|
+
|
107
|
+
// Does a joint override collision? is at least one body dynamic?
|
108
|
+
if (bodyB.shouldCollide(bodyA) == false) {
|
109
|
+
return;
|
110
|
+
}
|
111
|
+
|
112
|
+
// Check user filtering.
|
113
|
+
if (m_contactFilter != null && m_contactFilter.shouldCollide(fixtureA, fixtureB) == false) {
|
114
|
+
return;
|
115
|
+
}
|
116
|
+
|
117
|
+
// Call the factory.
|
118
|
+
Contact c = pool.popContact(fixtureA, indexA, fixtureB, indexB);
|
119
|
+
if (c == null) {
|
120
|
+
return;
|
121
|
+
}
|
122
|
+
|
123
|
+
// Contact creation may swap fixtures.
|
124
|
+
fixtureA = c.getFixtureA();
|
125
|
+
fixtureB = c.getFixtureB();
|
126
|
+
indexA = c.getChildIndexA();
|
127
|
+
indexB = c.getChildIndexB();
|
128
|
+
bodyA = fixtureA.getBody();
|
129
|
+
bodyB = fixtureB.getBody();
|
130
|
+
|
131
|
+
// Insert into the world.
|
132
|
+
c.m_prev = null;
|
133
|
+
c.m_next = m_contactList;
|
134
|
+
if (m_contactList != null) {
|
135
|
+
m_contactList.m_prev = c;
|
136
|
+
}
|
137
|
+
m_contactList = c;
|
138
|
+
|
139
|
+
// Connect to island graph.
|
140
|
+
|
141
|
+
// Connect to body A
|
142
|
+
c.m_nodeA.contact = c;
|
143
|
+
c.m_nodeA.other = bodyB;
|
144
|
+
|
145
|
+
c.m_nodeA.prev = null;
|
146
|
+
c.m_nodeA.next = bodyA.m_contactList;
|
147
|
+
if (bodyA.m_contactList != null) {
|
148
|
+
bodyA.m_contactList.prev = c.m_nodeA;
|
149
|
+
}
|
150
|
+
bodyA.m_contactList = c.m_nodeA;
|
151
|
+
|
152
|
+
// Connect to body B
|
153
|
+
c.m_nodeB.contact = c;
|
154
|
+
c.m_nodeB.other = bodyA;
|
155
|
+
|
156
|
+
c.m_nodeB.prev = null;
|
157
|
+
c.m_nodeB.next = bodyB.m_contactList;
|
158
|
+
if (bodyB.m_contactList != null) {
|
159
|
+
bodyB.m_contactList.prev = c.m_nodeB;
|
160
|
+
}
|
161
|
+
bodyB.m_contactList = c.m_nodeB;
|
162
|
+
|
163
|
+
// wake up the bodies
|
164
|
+
if (!fixtureA.isSensor() && !fixtureB.isSensor()) {
|
165
|
+
bodyA.setAwake(true);
|
166
|
+
bodyB.setAwake(true);
|
167
|
+
}
|
168
|
+
|
169
|
+
++m_contactCount;
|
170
|
+
}
|
171
|
+
|
172
|
+
public void findNewContacts() {
|
173
|
+
m_broadPhase.updatePairs(this);
|
174
|
+
}
|
175
|
+
|
176
|
+
public void destroy(Contact c) {
|
177
|
+
Fixture fixtureA = c.getFixtureA();
|
178
|
+
Fixture fixtureB = c.getFixtureB();
|
179
|
+
Body bodyA = fixtureA.getBody();
|
180
|
+
Body bodyB = fixtureB.getBody();
|
181
|
+
|
182
|
+
if (m_contactListener != null && c.isTouching()) {
|
183
|
+
m_contactListener.endContact(c);
|
184
|
+
}
|
185
|
+
|
186
|
+
// Remove from the world.
|
187
|
+
if (c.m_prev != null) {
|
188
|
+
c.m_prev.m_next = c.m_next;
|
189
|
+
}
|
190
|
+
|
191
|
+
if (c.m_next != null) {
|
192
|
+
c.m_next.m_prev = c.m_prev;
|
193
|
+
}
|
194
|
+
|
195
|
+
if (c == m_contactList) {
|
196
|
+
m_contactList = c.m_next;
|
197
|
+
}
|
198
|
+
|
199
|
+
// Remove from body 1
|
200
|
+
if (c.m_nodeA.prev != null) {
|
201
|
+
c.m_nodeA.prev.next = c.m_nodeA.next;
|
202
|
+
}
|
203
|
+
|
204
|
+
if (c.m_nodeA.next != null) {
|
205
|
+
c.m_nodeA.next.prev = c.m_nodeA.prev;
|
206
|
+
}
|
207
|
+
|
208
|
+
if (c.m_nodeA == bodyA.m_contactList) {
|
209
|
+
bodyA.m_contactList = c.m_nodeA.next;
|
210
|
+
}
|
211
|
+
|
212
|
+
// Remove from body 2
|
213
|
+
if (c.m_nodeB.prev != null) {
|
214
|
+
c.m_nodeB.prev.next = c.m_nodeB.next;
|
215
|
+
}
|
216
|
+
|
217
|
+
if (c.m_nodeB.next != null) {
|
218
|
+
c.m_nodeB.next.prev = c.m_nodeB.prev;
|
219
|
+
}
|
220
|
+
|
221
|
+
if (c.m_nodeB == bodyB.m_contactList) {
|
222
|
+
bodyB.m_contactList = c.m_nodeB.next;
|
223
|
+
}
|
224
|
+
|
225
|
+
// Call the factory.
|
226
|
+
pool.pushContact(c);
|
227
|
+
--m_contactCount;
|
228
|
+
}
|
229
|
+
|
230
|
+
/**
|
231
|
+
* This is the top level collision call for the time step. Here all the narrow phase collision is
|
232
|
+
* processed for the world contact list.
|
233
|
+
*/
|
234
|
+
public void collide() {
|
235
|
+
// Update awake contacts.
|
236
|
+
Contact c = m_contactList;
|
237
|
+
while (c != null) {
|
238
|
+
Fixture fixtureA = c.getFixtureA();
|
239
|
+
Fixture fixtureB = c.getFixtureB();
|
240
|
+
int indexA = c.getChildIndexA();
|
241
|
+
int indexB = c.getChildIndexB();
|
242
|
+
Body bodyA = fixtureA.getBody();
|
243
|
+
Body bodyB = fixtureB.getBody();
|
244
|
+
|
245
|
+
// is this contact flagged for filtering?
|
246
|
+
if ((c.m_flags & Contact.FILTER_FLAG) == Contact.FILTER_FLAG) {
|
247
|
+
// Should these bodies collide?
|
248
|
+
if (bodyB.shouldCollide(bodyA) == false) {
|
249
|
+
Contact cNuke = c;
|
250
|
+
c = cNuke.getNext();
|
251
|
+
destroy(cNuke);
|
252
|
+
continue;
|
253
|
+
}
|
254
|
+
|
255
|
+
// Check user filtering.
|
256
|
+
if (m_contactFilter != null && m_contactFilter.shouldCollide(fixtureA, fixtureB) == false) {
|
257
|
+
Contact cNuke = c;
|
258
|
+
c = cNuke.getNext();
|
259
|
+
destroy(cNuke);
|
260
|
+
continue;
|
261
|
+
}
|
262
|
+
|
263
|
+
// Clear the filtering flag.
|
264
|
+
c.m_flags &= ~Contact.FILTER_FLAG;
|
265
|
+
}
|
266
|
+
|
267
|
+
boolean activeA = bodyA.isAwake() && bodyA.m_type != BodyType.STATIC;
|
268
|
+
boolean activeB = bodyB.isAwake() && bodyB.m_type != BodyType.STATIC;
|
269
|
+
|
270
|
+
// At least one body must be awake and it must be dynamic or kinematic.
|
271
|
+
if (activeA == false && activeB == false) {
|
272
|
+
c = c.getNext();
|
273
|
+
continue;
|
274
|
+
}
|
275
|
+
|
276
|
+
int proxyIdA = fixtureA.m_proxies[indexA].proxyId;
|
277
|
+
int proxyIdB = fixtureB.m_proxies[indexB].proxyId;
|
278
|
+
boolean overlap = m_broadPhase.testOverlap(proxyIdA, proxyIdB);
|
279
|
+
|
280
|
+
// Here we destroy contacts that cease to overlap in the broad-phase.
|
281
|
+
if (overlap == false) {
|
282
|
+
Contact cNuke = c;
|
283
|
+
c = cNuke.getNext();
|
284
|
+
destroy(cNuke);
|
285
|
+
continue;
|
286
|
+
}
|
287
|
+
|
288
|
+
// The contact persists.
|
289
|
+
c.update(m_contactListener);
|
290
|
+
c = c.getNext();
|
291
|
+
}
|
292
|
+
}
|
293
|
+
}
|