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,1246 @@
1
+ /**
2
+ * *****************************************************************************
3
+ * Copyright (c) 2013, Daniel Murphy
4
+ * All rights reserved.
5
+ *
6
+ * Redistribution and use in source and binary forms, with or without modification,
7
+ * are permitted provided that the following conditions are met:
8
+ * * Redistributions of source code must retain the above copyright notice,
9
+ * this list of conditions and the following disclaimer.
10
+ * * Redistributions in binary form must reproduce the above copyright notice,
11
+ * this list of conditions and the following disclaimer in the documentation
12
+ * and/or other materials provided with the distribution.
13
+ *
14
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
15
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
16
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17
+ * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
18
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
19
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
21
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
23
+ * POSSIBILITY OF SUCH DAMAGE.
24
+ *****************************************************************************
25
+ */
26
+ package org.jbox2d.dynamics;
27
+
28
+ import org.jbox2d.collision.broadphase.BroadPhase;
29
+ import org.jbox2d.collision.shapes.MassData;
30
+ import org.jbox2d.collision.shapes.Shape;
31
+ import org.jbox2d.common.MathUtils;
32
+ import org.jbox2d.common.Rot;
33
+ import org.jbox2d.common.Sweep;
34
+ import org.jbox2d.common.Transform;
35
+ import org.jbox2d.common.Vec2;
36
+ import org.jbox2d.dynamics.contacts.Contact;
37
+ import org.jbox2d.dynamics.contacts.ContactEdge;
38
+ import org.jbox2d.dynamics.joints.JointEdge;
39
+
40
+ /**
41
+ * A rigid body. These are created via World.createBody.
42
+ *
43
+ * @author Daniel Murphy
44
+ */
45
+ public class Body {
46
+
47
+ public static final int E_ISLAND_FLAG = 0x0001;
48
+ public static final int E_AWAKE_FLAG = 0x0002;
49
+ public static final int E_AUTO_SLEEP_FLAG = 0x0004;
50
+ public static final int E_BULLET_FLAG = 0x0008;
51
+ public static final int E_FIXED_ROTATION_FLAG = 0x0010;
52
+ public static final int E_ACTIVE_FLAG = 0x0020;
53
+ public static final int E_TO_I_FLAG = 0x0040;
54
+
55
+ public BodyType m_type;
56
+
57
+ public int m_flags;
58
+
59
+ public int m_islandIndex;
60
+
61
+ /**
62
+ * The body origin transform.
63
+ */
64
+ public final Transform m_xf = new Transform();
65
+ /**
66
+ * The previous transform for particle simulation
67
+ */
68
+ public final Transform m_xf0 = new Transform();
69
+
70
+ /**
71
+ * The swept motion for CCD
72
+ */
73
+ public final Sweep m_sweep = new Sweep();
74
+
75
+ public final Vec2 m_linearVelocity = new Vec2();
76
+ public float m_angularVelocity = 0;
77
+
78
+ public final Vec2 m_force = new Vec2();
79
+ public float m_torque = 0;
80
+
81
+ public World m_world;
82
+ public Body m_prev;
83
+ public Body m_next;
84
+
85
+ public Fixture m_fixtureList;
86
+ public int m_fixtureCount;
87
+
88
+ public JointEdge m_jointList;
89
+ public ContactEdge m_contactList;
90
+
91
+ public float m_mass, m_invMass;
92
+
93
+ // Rotational inertia about the center of mass.
94
+ public float m_I, m_invI;
95
+
96
+ public float m_linearDamping;
97
+ public float m_angularDamping;
98
+ public float m_gravityScale;
99
+
100
+ public float m_sleepTime;
101
+
102
+ public Object m_userData;
103
+
104
+ public Body(final BodyDef bd, World world) {
105
+ assert (bd.position.isValid());
106
+ assert (bd.linearVelocity.isValid());
107
+ assert (bd.gravityScale >= 0.0f);
108
+ assert (bd.angularDamping >= 0.0f);
109
+ assert (bd.linearDamping >= 0.0f);
110
+
111
+ m_flags = 0;
112
+
113
+ if (bd.bullet) {
114
+ m_flags |= E_BULLET_FLAG;
115
+ }
116
+ if (bd.fixedRotation) {
117
+ m_flags |= E_FIXED_ROTATION_FLAG;
118
+ }
119
+ if (bd.allowSleep) {
120
+ m_flags |= E_AUTO_SLEEP_FLAG;
121
+ }
122
+ if (bd.awake) {
123
+ m_flags |= E_AWAKE_FLAG;
124
+ }
125
+ if (bd.active) {
126
+ m_flags |= E_ACTIVE_FLAG;
127
+ }
128
+
129
+ m_world = world;
130
+
131
+ m_xf.p.set(bd.position);
132
+ m_xf.q.set(bd.angle);
133
+
134
+ m_sweep.localCenter.setZero();
135
+ m_sweep.c0.set(m_xf.p);
136
+ m_sweep.c.set(m_xf.p);
137
+ m_sweep.a0 = bd.angle;
138
+ m_sweep.a = bd.angle;
139
+ m_sweep.alpha0 = 0.0f;
140
+
141
+ m_jointList = null;
142
+ m_contactList = null;
143
+ m_prev = null;
144
+ m_next = null;
145
+
146
+ m_linearVelocity.set(bd.linearVelocity);
147
+ m_angularVelocity = bd.angularVelocity;
148
+
149
+ m_linearDamping = bd.linearDamping;
150
+ m_angularDamping = bd.angularDamping;
151
+ m_gravityScale = bd.gravityScale;
152
+
153
+ m_force.setZero();
154
+ m_torque = 0.0f;
155
+
156
+ m_sleepTime = 0.0f;
157
+
158
+ m_type = bd.type;
159
+
160
+ if (m_type == BodyType.DYNAMIC) {
161
+ m_mass = 1f;
162
+ m_invMass = 1f;
163
+ } else {
164
+ m_mass = 0f;
165
+ m_invMass = 0f;
166
+ }
167
+
168
+ m_I = 0.0f;
169
+ m_invI = 0.0f;
170
+
171
+ m_userData = bd.userData;
172
+
173
+ m_fixtureList = null;
174
+ m_fixtureCount = 0;
175
+ }
176
+
177
+ /**
178
+ * Creates a fixture and attach it to this body. Use this function if you
179
+ * need to set some fixture parameters, like friction. Otherwise you can
180
+ * create the fixture directly from a shape. If the density is non-zero,
181
+ * this function automatically updates the mass of the body. Contacts are
182
+ * not created until the next time step.
183
+ *
184
+ * @param def the fixture definition.
185
+ * @return
186
+ * @warning This function is locked during callbacks.
187
+ */
188
+ public final Fixture createFixture(FixtureDef def) {
189
+ assert (m_world.isLocked() == false);
190
+
191
+ if (m_world.isLocked() == true) {
192
+ return null;
193
+ }
194
+
195
+ Fixture fixture = new Fixture();
196
+ fixture.create(this, def);
197
+
198
+ if ((m_flags & E_ACTIVE_FLAG) == E_ACTIVE_FLAG) {
199
+ BroadPhase broadPhase = m_world.m_contactManager.m_broadPhase;
200
+ fixture.createProxies(broadPhase, m_xf);
201
+ }
202
+
203
+ fixture.m_next = m_fixtureList;
204
+ m_fixtureList = fixture;
205
+ ++m_fixtureCount;
206
+
207
+ fixture.m_body = this;
208
+
209
+ // Adjust mass properties if needed.
210
+ if (fixture.m_density > 0.0f) {
211
+ resetMassData();
212
+ }
213
+
214
+ // Let the world know we have a new fixture. This will cause new contacts
215
+ // to be created at the beginning of the next time step.
216
+ m_world.m_flags |= World.NEW_FIXTURE;
217
+
218
+ return fixture;
219
+ }
220
+
221
+ private final FixtureDef fixDef = new FixtureDef();
222
+
223
+ /**
224
+ * Creates a fixture from a shape and attach it to this body. This is a
225
+ * convenience function. Use FixtureDef if you need to set parameters like
226
+ * friction, restitution, user data, or filtering. If the density is
227
+ * non-zero, this function automatically updates the mass of the body.
228
+ *
229
+ * @param shape the shape to be cloned.
230
+ * @param density the shape density (set to zero for static bodies).
231
+ * @return
232
+ * @warning This function is locked during callbacks.
233
+ */
234
+ public final Fixture createFixture(Shape shape, float density) {
235
+ fixDef.shape = shape;
236
+ fixDef.density = density;
237
+
238
+ return createFixture(fixDef);
239
+ }
240
+
241
+ /**
242
+ * Destroy a fixture. This removes the fixture from the broad-phase and
243
+ * destroys all contacts associated with this fixture. This will
244
+ * automatically adjust the mass of the body if the body is dynamic and the
245
+ * fixture has positive density. All fixtures attached to a body are
246
+ * implicitly destroyed when the body is destroyed.
247
+ *
248
+ * @param fixture the fixture to be removed.
249
+ * @warning This function is locked during callbacks.
250
+ */
251
+ public final void destroyFixture(Fixture fixture) {
252
+ assert (m_world.isLocked() == false);
253
+ if (m_world.isLocked() == true) {
254
+ return;
255
+ }
256
+
257
+ assert (fixture.m_body == this);
258
+
259
+ // Remove the fixture from this body's singly linked list.
260
+ assert (m_fixtureCount > 0);
261
+ Fixture node = m_fixtureList;
262
+ Fixture last = null; // java change
263
+ boolean found = false;
264
+ while (node != null) {
265
+ if (node == fixture) {
266
+ node = fixture.m_next;
267
+ found = true;
268
+ break;
269
+ }
270
+ last = node;
271
+ node = node.m_next;
272
+ }
273
+
274
+ // You tried to remove a shape that is not attached to this body.
275
+ assert (found);
276
+
277
+ // java change, remove it from the list
278
+ if (last == null) {
279
+ m_fixtureList = fixture.m_next;
280
+ } else {
281
+ last.m_next = fixture.m_next;
282
+ }
283
+
284
+ // Destroy any contacts associated with the fixture.
285
+ ContactEdge edge = m_contactList;
286
+ while (edge != null) {
287
+ Contact c = edge.contact;
288
+ edge = edge.next;
289
+
290
+ Fixture fixtureA = c.getFixtureA();
291
+ Fixture fixtureB = c.getFixtureB();
292
+
293
+ if (fixture == fixtureA || fixture == fixtureB) {
294
+ // This destroys the contact and removes it from
295
+ // this body's contact list.
296
+ m_world.m_contactManager.destroy(c);
297
+ }
298
+ }
299
+
300
+ if ((m_flags & E_ACTIVE_FLAG) == E_ACTIVE_FLAG) {
301
+ BroadPhase broadPhase = m_world.m_contactManager.m_broadPhase;
302
+ fixture.destroyProxies(broadPhase);
303
+ }
304
+
305
+ fixture.destroy();
306
+ fixture.m_body = null;
307
+ fixture.m_next = null;
308
+ fixture = null;
309
+
310
+ --m_fixtureCount;
311
+
312
+ // Reset the mass data.
313
+ resetMassData();
314
+ }
315
+
316
+ /**
317
+ * Set the position of the body's origin and rotation. This breaks any
318
+ * contacts and wakes the other bodies. Manipulating a body's transform may
319
+ * cause non-physical behavior. Note: contacts are updated on the next call
320
+ * to World.step().
321
+ *
322
+ * @param position the world position of the body's local origin.
323
+ * @param angle the world rotation in radians.
324
+ */
325
+ public final void setTransform(Vec2 position, float angle) {
326
+ assert (m_world.isLocked() == false);
327
+ if (m_world.isLocked() == true) {
328
+ return;
329
+ }
330
+
331
+ m_xf.q.set(angle);
332
+ m_xf.p.set(position);
333
+
334
+ // m_sweep.c0 = m_sweep.c = Mul(m_xf, m_sweep.localCenter);
335
+ Transform.mulToOutUnsafe(m_xf, m_sweep.localCenter, m_sweep.c);
336
+ m_sweep.a = angle;
337
+
338
+ m_sweep.c0.set(m_sweep.c);
339
+ m_sweep.a0 = m_sweep.a;
340
+
341
+ BroadPhase broadPhase = m_world.m_contactManager.m_broadPhase;
342
+ for (Fixture f = m_fixtureList; f != null; f = f.m_next) {
343
+ f.synchronize(broadPhase, m_xf, m_xf);
344
+ }
345
+ }
346
+
347
+ /**
348
+ * Get the body transform for the body's origin.
349
+ *
350
+ * @return the world transform of the body's origin.
351
+ */
352
+ public final Transform getTransform() {
353
+ return m_xf;
354
+ }
355
+
356
+ /**
357
+ * Get the world body origin position. Do not modify.
358
+ *
359
+ * @return the world position of the body's origin.
360
+ */
361
+ public final Vec2 getPosition() {
362
+ return m_xf.p;
363
+ }
364
+
365
+ /**
366
+ * Get the angle in radians.
367
+ *
368
+ * @return the current world rotation angle in radians.
369
+ */
370
+ public final float getAngle() {
371
+ return m_sweep.a;
372
+ }
373
+
374
+ /**
375
+ * Get the world position of the center of mass. Do not modify.
376
+ * @return
377
+ */
378
+ public final Vec2 getWorldCenter() {
379
+ return m_sweep.c;
380
+ }
381
+
382
+ /**
383
+ * Get the local position of the center of mass. Do not modify.
384
+ * @return
385
+ */
386
+ public final Vec2 getLocalCenter() {
387
+ return m_sweep.localCenter;
388
+ }
389
+
390
+ /**
391
+ * Set the linear velocity of the center of mass.
392
+ *
393
+ * @param v the new linear velocity of the center of mass.
394
+ */
395
+ public final void setLinearVelocity(Vec2 v) {
396
+ if (m_type == BodyType.STATIC) {
397
+ return;
398
+ }
399
+
400
+ if (Vec2.dot(v, v) > 0.0f) {
401
+ setAwake(true);
402
+ }
403
+
404
+ m_linearVelocity.set(v);
405
+ }
406
+
407
+ /**
408
+ * Get the linear velocity of the center of mass. Do not modify, instead use
409
+ * {@link #setLinearVelocity(Vec2)}.
410
+ *
411
+ * @return the linear velocity of the center of mass.
412
+ */
413
+ public final Vec2 getLinearVelocity() {
414
+ return m_linearVelocity;
415
+ }
416
+
417
+ /**
418
+ * Set the angular velocity.
419
+ *
420
+ * @param w the new angular velocity in radians/second.
421
+ */
422
+ public final void setAngularVelocity(float w) {
423
+ if (m_type == BodyType.STATIC) {
424
+ return;
425
+ }
426
+
427
+ if (w * w > 0f) {
428
+ setAwake(true);
429
+ }
430
+
431
+ m_angularVelocity = w;
432
+ }
433
+
434
+ /**
435
+ * Get the angular velocity.
436
+ *
437
+ * @return the angular velocity in radians/second.
438
+ */
439
+ public final float getAngularVelocity() {
440
+ return m_angularVelocity;
441
+ }
442
+
443
+ /**
444
+ * Get the gravity scale of the body.
445
+ *
446
+ * @return
447
+ */
448
+ public float getGravityScale() {
449
+ return m_gravityScale;
450
+ }
451
+
452
+ /**
453
+ * Set the gravity scale of the body.
454
+ *
455
+ * @param gravityScale
456
+ */
457
+ public void setGravityScale(float gravityScale) {
458
+ this.m_gravityScale = gravityScale;
459
+ }
460
+
461
+ /**
462
+ * Apply a force at a world point. If the force is not applied at the center
463
+ * of mass, it will generate a torque and affect the angular velocity. This
464
+ * wakes up the body.
465
+ *
466
+ * @param force the world force vector, usually in Newtons (N).
467
+ * @param point the world position of the point of application.
468
+ */
469
+ public final void applyForce(Vec2 force, Vec2 point) {
470
+ if (m_type != BodyType.DYNAMIC) {
471
+ return;
472
+ }
473
+
474
+ if (isAwake() == false) {
475
+ setAwake(true);
476
+ }
477
+
478
+ // m_force.addLocal(force);
479
+ // Vec2 temp = tltemp.get();
480
+ // temp.set(point).subLocal(m_sweep.c);
481
+ // m_torque += Vec2.cross(temp, force);
482
+ m_force.x += force.x;
483
+ m_force.y += force.y;
484
+
485
+ m_torque += (point.x - m_sweep.c.x) * force.y - (point.y - m_sweep.c.y) * force.x;
486
+ }
487
+
488
+ /**
489
+ * Apply a force to the center of mass. This wakes up the body.
490
+ *
491
+ * @param force the world force vector, usually in Newtons (N).
492
+ */
493
+ public final void applyForceToCenter(Vec2 force) {
494
+ if (m_type != BodyType.DYNAMIC) {
495
+ return;
496
+ }
497
+
498
+ if (isAwake() == false) {
499
+ setAwake(true);
500
+ }
501
+
502
+ m_force.x += force.x;
503
+ m_force.y += force.y;
504
+ }
505
+
506
+ /**
507
+ * Apply a torque. This affects the angular velocity without affecting the
508
+ * linear velocity of the center of mass. This wakes up the body.
509
+ *
510
+ * @param torque about the z-axis (out of the screen), usually in N-m.
511
+ */
512
+ public final void applyTorque(float torque) {
513
+ if (m_type != BodyType.DYNAMIC) {
514
+ return;
515
+ }
516
+
517
+ if (isAwake() == false) {
518
+ setAwake(true);
519
+ }
520
+
521
+ m_torque += torque;
522
+ }
523
+
524
+ /**
525
+ * Apply an impulse at a point. This immediately modifies the velocity. It
526
+ * also modifies the angular velocity if the point of application is not at
527
+ * the center of mass. This wakes up the body if 'wake' is set to true. If
528
+ * the body is sleeping and 'wake' is false, then there is no effect.
529
+ *
530
+ * @param impulse the world impulse vector, usually in N-seconds or kg-m/s.
531
+ * @param point the world position of the point of application.
532
+ * @param wake also wake up the body
533
+ */
534
+ public final void applyLinearImpulse(Vec2 impulse, Vec2 point, boolean wake) {
535
+ if (m_type != BodyType.DYNAMIC) {
536
+ return;
537
+ }
538
+
539
+ if (!isAwake()) {
540
+ if (wake) {
541
+ setAwake(true);
542
+ } else {
543
+ return;
544
+ }
545
+ }
546
+
547
+ m_linearVelocity.x += impulse.x * m_invMass;
548
+ m_linearVelocity.y += impulse.y * m_invMass;
549
+
550
+ m_angularVelocity
551
+ += m_invI * ((point.x - m_sweep.c.x) * impulse.y - (point.y - m_sweep.c.y) * impulse.x);
552
+ }
553
+
554
+ /**
555
+ * Apply an angular impulse.
556
+ *
557
+ * @param impulse the angular impulse in units of kg*m*m/s
558
+ */
559
+ public void applyAngularImpulse(float impulse) {
560
+ if (m_type != BodyType.DYNAMIC) {
561
+ return;
562
+ }
563
+
564
+ if (isAwake() == false) {
565
+ setAwake(true);
566
+ }
567
+ m_angularVelocity += m_invI * impulse;
568
+ }
569
+
570
+ /**
571
+ * Get the total mass of the body.
572
+ *
573
+ * @return the mass, usually in kilograms (kg).
574
+ */
575
+ public final float getMass() {
576
+ return m_mass;
577
+ }
578
+
579
+ /**
580
+ * Get the central rotational inertia of the body.
581
+ *
582
+ * @return the rotational inertia, usually in kg-m^2.
583
+ */
584
+ public final float getInertia() {
585
+ return m_I
586
+ + m_mass
587
+ * (m_sweep.localCenter.x * m_sweep.localCenter.x + m_sweep.localCenter.y
588
+ * m_sweep.localCenter.y);
589
+ }
590
+
591
+ /**
592
+ * Get the mass data of the body. The rotational inertia is relative to the
593
+ * center of mass.
594
+ *
595
+ * @param data
596
+ */
597
+ public final void getMassData(MassData data) {
598
+ // data.mass = m_mass;
599
+ // data.I = m_I + m_mass * Vec2.dot(m_sweep.localCenter, m_sweep.localCenter);
600
+ // data.center.set(m_sweep.localCenter);
601
+
602
+ data.mass = m_mass;
603
+ data.I
604
+ = m_I
605
+ + m_mass
606
+ * (m_sweep.localCenter.x * m_sweep.localCenter.x + m_sweep.localCenter.y
607
+ * m_sweep.localCenter.y);
608
+ data.center.x = m_sweep.localCenter.x;
609
+ data.center.y = m_sweep.localCenter.y;
610
+ }
611
+
612
+ /**
613
+ * Set the mass properties to override the mass properties of the fixtures.
614
+ * Note that this changes the center of mass position. Note that creating or
615
+ * destroying fixtures can also alter the mass. This function has no effect
616
+ * if the body isn't dynamic.
617
+ *
618
+ * @param massData the mass properties.
619
+ */
620
+ public final void setMassData(MassData massData) {
621
+ // TODO_ERIN adjust linear velocity and torque to account for movement of center.
622
+ assert (m_world.isLocked() == false);
623
+ if (m_world.isLocked() == true) {
624
+ return;
625
+ }
626
+
627
+ if (m_type != BodyType.DYNAMIC) {
628
+ return;
629
+ }
630
+
631
+ m_invMass = 0.0f;
632
+ m_I = 0.0f;
633
+ m_invI = 0.0f;
634
+
635
+ m_mass = massData.mass;
636
+ if (m_mass <= 0.0f) {
637
+ m_mass = 1f;
638
+ }
639
+
640
+ m_invMass = 1.0f / m_mass;
641
+
642
+ if (massData.I > 0.0f && (m_flags & E_FIXED_ROTATION_FLAG) == 0) {
643
+ m_I = massData.I - m_mass * Vec2.dot(massData.center, massData.center);
644
+ assert (m_I > 0.0f);
645
+ m_invI = 1.0f / m_I;
646
+ }
647
+
648
+ final Vec2 oldCenter = m_world.getPool().popVec2();
649
+ // Move center of mass.
650
+ oldCenter.set(m_sweep.c);
651
+ m_sweep.localCenter.set(massData.center);
652
+ // m_sweep.c0 = m_sweep.c = Mul(m_xf, m_sweep.localCenter);
653
+ Transform.mulToOutUnsafe(m_xf, m_sweep.localCenter, m_sweep.c0);
654
+ m_sweep.c.set(m_sweep.c0);
655
+
656
+ // Update center of mass velocity.
657
+ // m_linearVelocity += Cross(m_angularVelocity, m_sweep.c - oldCenter);
658
+ final Vec2 temp = m_world.getPool().popVec2();
659
+ temp.set(m_sweep.c).subLocal(oldCenter);
660
+ Vec2.crossToOut(m_angularVelocity, temp, temp);
661
+ m_linearVelocity.addLocal(temp);
662
+
663
+ m_world.getPool().pushVec2(2);
664
+ }
665
+
666
+ private final MassData pmd = new MassData();
667
+
668
+ /**
669
+ * This resets the mass properties to the sum of the mass properties of the
670
+ * fixtures. This normally does not need to be called unless you called
671
+ * setMassData to override the mass and you later want to reset the mass.
672
+ */
673
+ public final void resetMassData() {
674
+ // Compute mass data from shapes. Each shape has its own density.
675
+ m_mass = 0.0f;
676
+ m_invMass = 0.0f;
677
+ m_I = 0.0f;
678
+ m_invI = 0.0f;
679
+ m_sweep.localCenter.setZero();
680
+
681
+ // Static and kinematic bodies have zero mass.
682
+ if (m_type == BodyType.STATIC || m_type == BodyType.KINEMATIC) {
683
+ // m_sweep.c0 = m_sweep.c = m_xf.position;
684
+ m_sweep.c0.set(m_xf.p);
685
+ m_sweep.c.set(m_xf.p);
686
+ m_sweep.a0 = m_sweep.a;
687
+ return;
688
+ }
689
+
690
+ assert (m_type == BodyType.DYNAMIC);
691
+
692
+ // Accumulate mass over all fixtures.
693
+ final Vec2 localCenter = m_world.getPool().popVec2();
694
+ localCenter.setZero();
695
+ final Vec2 temp = m_world.getPool().popVec2();
696
+ final MassData massData = pmd;
697
+ for (Fixture f = m_fixtureList; f != null; f = f.m_next) {
698
+ if (f.m_density == 0.0f) {
699
+ continue;
700
+ }
701
+ f.getMassData(massData);
702
+ m_mass += massData.mass;
703
+ // center += massData.mass * massData.center;
704
+ temp.set(massData.center).mulLocal(massData.mass);
705
+ localCenter.addLocal(temp);
706
+ m_I += massData.I;
707
+ }
708
+
709
+ // Compute center of mass.
710
+ if (m_mass > 0.0f) {
711
+ m_invMass = 1.0f / m_mass;
712
+ localCenter.mulLocal(m_invMass);
713
+ } else {
714
+ // Force all dynamic bodies to have a positive mass.
715
+ m_mass = 1.0f;
716
+ m_invMass = 1.0f;
717
+ }
718
+
719
+ if (m_I > 0.0f && (m_flags & E_FIXED_ROTATION_FLAG) == 0) {
720
+ // Center the inertia about the center of mass.
721
+ m_I -= m_mass * Vec2.dot(localCenter, localCenter);
722
+ assert (m_I > 0.0f);
723
+ m_invI = 1.0f / m_I;
724
+ } else {
725
+ m_I = 0.0f;
726
+ m_invI = 0.0f;
727
+ }
728
+
729
+ Vec2 oldCenter = m_world.getPool().popVec2();
730
+ // Move center of mass.
731
+ oldCenter.set(m_sweep.c);
732
+ m_sweep.localCenter.set(localCenter);
733
+ // m_sweep.c0 = m_sweep.c = Mul(m_xf, m_sweep.localCenter);
734
+ Transform.mulToOutUnsafe(m_xf, m_sweep.localCenter, m_sweep.c0);
735
+ m_sweep.c.set(m_sweep.c0);
736
+
737
+ // Update center of mass velocity.
738
+ // m_linearVelocity += Cross(m_angularVelocity, m_sweep.c - oldCenter);
739
+ temp.set(m_sweep.c).subLocal(oldCenter);
740
+
741
+ final Vec2 temp2 = oldCenter;
742
+ Vec2.crossToOutUnsafe(m_angularVelocity, temp, temp2);
743
+ m_linearVelocity.addLocal(temp2);
744
+
745
+ m_world.getPool().pushVec2(3);
746
+ }
747
+
748
+ /**
749
+ * Get the world coordinates of a point given the local coordinates.
750
+ *
751
+ * @param localPoint a point on the body measured relative the the body's
752
+ * origin.
753
+ * @return the same point expressed in world coordinates.
754
+ */
755
+ public final Vec2 getWorldPoint(Vec2 localPoint) {
756
+ Vec2 v = new Vec2();
757
+ getWorldPointToOut(localPoint, v);
758
+ return v;
759
+ }
760
+
761
+ public final void getWorldPointToOut(Vec2 localPoint, Vec2 out) {
762
+ Transform.mulToOut(m_xf, localPoint, out);
763
+ }
764
+
765
+ /**
766
+ * Get the world coordinates of a vector given the local coordinates.
767
+ *
768
+ * @param localVector a vector fixed in the body.
769
+ * @return the same vector expressed in world coordinates.
770
+ */
771
+ public final Vec2 getWorldVector(Vec2 localVector) {
772
+ Vec2 out = new Vec2();
773
+ getWorldVectorToOut(localVector, out);
774
+ return out;
775
+ }
776
+
777
+ public final void getWorldVectorToOut(Vec2 localVector, Vec2 out) {
778
+ Rot.mulToOut(m_xf.q, localVector, out);
779
+ }
780
+
781
+ public final void getWorldVectorToOutUnsafe(Vec2 localVector, Vec2 out) {
782
+ Rot.mulToOutUnsafe(m_xf.q, localVector, out);
783
+ }
784
+
785
+ /**
786
+ * Gets a local point relative to the body's origin given a world point.
787
+ *
788
+ * @param worldPoint a point in world coordinates.
789
+ * @return the corresponding local point relative to the body's origin.
790
+ */
791
+ public final Vec2 getLocalPoint(Vec2 worldPoint) {
792
+ Vec2 out = new Vec2();
793
+ getLocalPointToOut(worldPoint, out);
794
+ return out;
795
+ }
796
+
797
+ public final void getLocalPointToOut(Vec2 worldPoint, Vec2 out) {
798
+ Transform.mulTransToOut(m_xf, worldPoint, out);
799
+ }
800
+
801
+ /**
802
+ * Gets a local vector given a world vector.
803
+ *
804
+ * @param worldVector a vector in world coordinates.
805
+ * @return the corresponding local vector.
806
+ */
807
+ public final Vec2 getLocalVector(Vec2 worldVector) {
808
+ Vec2 out = new Vec2();
809
+ getLocalVectorToOut(worldVector, out);
810
+ return out;
811
+ }
812
+
813
+ public final void getLocalVectorToOut(Vec2 worldVector, Vec2 out) {
814
+ Rot.mulTrans(m_xf.q, worldVector, out);
815
+ }
816
+
817
+ public final void getLocalVectorToOutUnsafe(Vec2 worldVector, Vec2 out) {
818
+ Rot.mulTransUnsafe(m_xf.q, worldVector, out);
819
+ }
820
+
821
+ /**
822
+ * Get the world linear velocity of a world point attached to this body.
823
+ *
824
+ * @param worldPoint a point in world coordinates.
825
+ * @return the world velocity of a point.
826
+ */
827
+ public final Vec2 getLinearVelocityFromWorldPoint(Vec2 worldPoint) {
828
+ Vec2 out = new Vec2();
829
+ getLinearVelocityFromWorldPointToOut(worldPoint, out);
830
+ return out;
831
+ }
832
+
833
+ public final void getLinearVelocityFromWorldPointToOut(Vec2 worldPoint, Vec2 out) {
834
+ final float tempX = worldPoint.x - m_sweep.c.x;
835
+ final float tempY = worldPoint.y - m_sweep.c.y;
836
+ out.x = -m_angularVelocity * tempY + m_linearVelocity.x;
837
+ out.y = m_angularVelocity * tempX + m_linearVelocity.y;
838
+ }
839
+
840
+ /**
841
+ * Get the world velocity of a local point.
842
+ *
843
+ * @param localPoint a point in local coordinates.
844
+ * @return the world velocity of a point.
845
+ */
846
+ public final Vec2 getLinearVelocityFromLocalPoint(Vec2 localPoint) {
847
+ Vec2 out = new Vec2();
848
+ getLinearVelocityFromLocalPointToOut(localPoint, out);
849
+ return out;
850
+ }
851
+
852
+ public final void getLinearVelocityFromLocalPointToOut(Vec2 localPoint, Vec2 out) {
853
+ getWorldPointToOut(localPoint, out);
854
+ getLinearVelocityFromWorldPointToOut(out, out);
855
+ }
856
+
857
+ /**
858
+ * Get the linear damping of the body.
859
+ *
860
+ * @return
861
+ */
862
+ public final float getLinearDamping() {
863
+ return m_linearDamping;
864
+ }
865
+
866
+ /**
867
+ * Set the linear damping of the body.
868
+ *
869
+ * @param linearDamping
870
+ */
871
+ public final void setLinearDamping(float linearDamping) {
872
+ m_linearDamping = linearDamping;
873
+ }
874
+
875
+ /**
876
+ * Get the angular damping of the body.
877
+ *
878
+ * @return
879
+ */
880
+ public final float getAngularDamping() {
881
+ return m_angularDamping;
882
+ }
883
+
884
+ /**
885
+ * Set the angular damping of the body.
886
+ *
887
+ * @param angularDamping
888
+ */
889
+ public final void setAngularDamping(float angularDamping) {
890
+ m_angularDamping = angularDamping;
891
+ }
892
+
893
+ public BodyType getType() {
894
+ return m_type;
895
+ }
896
+
897
+ /**
898
+ * Set the type of this body. This may alter the mass and velocity.
899
+ *
900
+ * @param type
901
+ */
902
+ public void setType(BodyType type) {
903
+ assert (m_world.isLocked() == false);
904
+ if (m_world.isLocked() == true) {
905
+ return;
906
+ }
907
+
908
+ if (m_type == type) {
909
+ return;
910
+ }
911
+
912
+ m_type = type;
913
+
914
+ resetMassData();
915
+
916
+ if (m_type == BodyType.STATIC) {
917
+ m_linearVelocity.setZero();
918
+ m_angularVelocity = 0.0f;
919
+ m_sweep.a0 = m_sweep.a;
920
+ m_sweep.c0.set(m_sweep.c);
921
+ synchronizeFixtures();
922
+ }
923
+
924
+ setAwake(true);
925
+
926
+ m_force.setZero();
927
+ m_torque = 0.0f;
928
+
929
+ // Delete the attached contacts.
930
+ ContactEdge ce = m_contactList;
931
+ while (ce != null) {
932
+ ContactEdge ce0 = ce;
933
+ ce = ce.next;
934
+ m_world.m_contactManager.destroy(ce0.contact);
935
+ }
936
+ m_contactList = null;
937
+
938
+ // Touch the proxies so that new contacts will be created (when appropriate)
939
+ BroadPhase broadPhase = m_world.m_contactManager.m_broadPhase;
940
+ for (Fixture f = m_fixtureList; f != null; f = f.m_next) {
941
+ int proxyCount = f.m_proxyCount;
942
+ for (int i = 0; i < proxyCount; ++i) {
943
+ broadPhase.touchProxy(f.m_proxies[i].proxyId);
944
+ }
945
+ }
946
+ }
947
+
948
+ /**
949
+ * Is this body treated like a bullet for continuous collision detection?
950
+ *
951
+ * @return
952
+ */
953
+ public final boolean isBullet() {
954
+ return (m_flags & E_BULLET_FLAG) == E_BULLET_FLAG;
955
+ }
956
+
957
+ /**
958
+ * Should this body be treated like a bullet for continuous collision
959
+ * detection?
960
+ *
961
+ * @param flag
962
+ */
963
+ public final void setBullet(boolean flag) {
964
+ if (flag) {
965
+ m_flags |= E_BULLET_FLAG;
966
+ } else {
967
+ m_flags &= ~E_BULLET_FLAG;
968
+ }
969
+ }
970
+
971
+ /**
972
+ * You can disable sleeping on this body. If you disable sleeping, the body
973
+ * will be woken.
974
+ *
975
+ * @param flag
976
+ */
977
+ public void setSleepingAllowed(boolean flag) {
978
+ if (flag) {
979
+ m_flags |= E_AUTO_SLEEP_FLAG;
980
+ } else {
981
+ m_flags &= ~E_AUTO_SLEEP_FLAG;
982
+ setAwake(true);
983
+ }
984
+ }
985
+
986
+ /**
987
+ * Is this body allowed to sleep
988
+ *
989
+ * @return
990
+ */
991
+ public boolean isSleepingAllowed() {
992
+ return (m_flags & E_AUTO_SLEEP_FLAG) == E_AUTO_SLEEP_FLAG;
993
+ }
994
+
995
+ /**
996
+ * Set the sleep state of the body. A sleeping body has very low CPU cost.
997
+ *
998
+ * @param flag set to true to put body to sleep, false to wake it.
999
+ */
1000
+ public void setAwake(boolean flag) {
1001
+ if (flag) {
1002
+ if ((m_flags & E_AWAKE_FLAG) == 0) {
1003
+ m_flags |= E_AWAKE_FLAG;
1004
+ m_sleepTime = 0.0f;
1005
+ }
1006
+ } else {
1007
+ m_flags &= ~E_AWAKE_FLAG;
1008
+ m_sleepTime = 0.0f;
1009
+ m_linearVelocity.setZero();
1010
+ m_angularVelocity = 0.0f;
1011
+ m_force.setZero();
1012
+ m_torque = 0.0f;
1013
+ }
1014
+ }
1015
+
1016
+ /**
1017
+ * Get the sleeping state of this body.
1018
+ *
1019
+ * @return true if the body is awake.
1020
+ */
1021
+ public boolean isAwake() {
1022
+ return (m_flags & E_AWAKE_FLAG) == E_AWAKE_FLAG;
1023
+ }
1024
+
1025
+ /**
1026
+ * Set the active state of the body. An inactive body is not simulated and
1027
+ * cannot be collided with or woken up. If you pass a flag of true, all
1028
+ * fixtures will be added to the broad-phase. If you pass a flag of false,
1029
+ * all fixtures will be removed from the broad-phase and all contacts will
1030
+ * be destroyed. Fixtures and joints are otherwise unaffected. You may
1031
+ * continue to create/destroy fixtures and joints on inactive bodies.
1032
+ * Fixtures on an inactive body are implicitly inactive and will not
1033
+ * participate in collisions, ray-casts, or queries. Joints connected to an
1034
+ * inactive body are implicitly inactive. An inactive body is still owned by
1035
+ * a World object and remains in the body list.
1036
+ *
1037
+ * @param flag
1038
+ */
1039
+ public void setActive(boolean flag) {
1040
+ assert (m_world.isLocked() == false);
1041
+
1042
+ if (flag == isActive()) {
1043
+ return;
1044
+ }
1045
+
1046
+ if (flag) {
1047
+ m_flags |= E_ACTIVE_FLAG;
1048
+
1049
+ // Create all proxies.
1050
+ BroadPhase broadPhase = m_world.m_contactManager.m_broadPhase;
1051
+ for (Fixture f = m_fixtureList; f != null; f = f.m_next) {
1052
+ f.createProxies(broadPhase, m_xf);
1053
+ }
1054
+
1055
+ // Contacts are created the next time step.
1056
+ } else {
1057
+ m_flags &= ~E_ACTIVE_FLAG;
1058
+
1059
+ // Destroy all proxies.
1060
+ BroadPhase broadPhase = m_world.m_contactManager.m_broadPhase;
1061
+ for (Fixture f = m_fixtureList; f != null; f = f.m_next) {
1062
+ f.destroyProxies(broadPhase);
1063
+ }
1064
+
1065
+ // Destroy the attached contacts.
1066
+ ContactEdge ce = m_contactList;
1067
+ while (ce != null) {
1068
+ ContactEdge ce0 = ce;
1069
+ ce = ce.next;
1070
+ m_world.m_contactManager.destroy(ce0.contact);
1071
+ }
1072
+ m_contactList = null;
1073
+ }
1074
+ }
1075
+
1076
+ /**
1077
+ * Get the active state of the body.
1078
+ *
1079
+ * @return
1080
+ */
1081
+ public boolean isActive() {
1082
+ return (m_flags & E_ACTIVE_FLAG) == E_ACTIVE_FLAG;
1083
+ }
1084
+
1085
+ /**
1086
+ * Set this body to have fixed rotation. This causes the mass to be reset.
1087
+ *
1088
+ * @param flag
1089
+ */
1090
+ public void setFixedRotation(boolean flag) {
1091
+ if (flag) {
1092
+ m_flags |= E_FIXED_ROTATION_FLAG;
1093
+ } else {
1094
+ m_flags &= ~E_FIXED_ROTATION_FLAG;
1095
+ }
1096
+
1097
+ resetMassData();
1098
+ }
1099
+
1100
+ /**
1101
+ * Does this body have fixed rotation?
1102
+ *
1103
+ * @return
1104
+ */
1105
+ public boolean isFixedRotation() {
1106
+ return (m_flags & E_FIXED_ROTATION_FLAG) == E_FIXED_ROTATION_FLAG;
1107
+ }
1108
+
1109
+ /**
1110
+ * Get the list of all fixtures attached to this body.
1111
+ *
1112
+ * @return
1113
+ */
1114
+ public final Fixture getFixtureList() {
1115
+ return m_fixtureList;
1116
+ }
1117
+
1118
+ /**
1119
+ * Get the list of all joints attached to this body.
1120
+ *
1121
+ * @return
1122
+ */
1123
+ public final JointEdge getJointList() {
1124
+ return m_jointList;
1125
+ }
1126
+
1127
+ /**
1128
+ * Get the list of all contacts attached to this body.
1129
+ *
1130
+ * @return
1131
+ * @warning this list changes during the time step and you may miss some
1132
+ * collisions if you don't use ContactListener.
1133
+ */
1134
+ public final ContactEdge getContactList() {
1135
+ return m_contactList;
1136
+ }
1137
+
1138
+ /**
1139
+ * Get the next body in the world's body list.
1140
+ *
1141
+ * @return
1142
+ */
1143
+ public final Body getNext() {
1144
+ return m_next;
1145
+ }
1146
+
1147
+ /**
1148
+ * Get the user data pointer that was provided in the body definition.
1149
+ *
1150
+ * @return
1151
+ */
1152
+ public final Object getUserData() {
1153
+ return m_userData;
1154
+ }
1155
+
1156
+ /**
1157
+ * Set the user data. Use this to store your application specific data.
1158
+ *
1159
+ * @param data
1160
+ */
1161
+ public final void setUserData(Object data) {
1162
+ m_userData = data;
1163
+ }
1164
+
1165
+ /**
1166
+ * Get the parent world of this body.
1167
+ *
1168
+ * @return
1169
+ */
1170
+ public final World getWorld() {
1171
+ return m_world;
1172
+ }
1173
+
1174
+ // djm pooling
1175
+ private final Transform pxf = new Transform();
1176
+
1177
+ protected final void synchronizeFixtures() {
1178
+ final Transform xf1 = pxf;
1179
+ // xf1.position = m_sweep.c0 - Mul(xf1.R, m_sweep.localCenter);
1180
+
1181
+ // xf1.q.set(m_sweep.a0);
1182
+ // Rot.mulToOutUnsafe(xf1.q, m_sweep.localCenter, xf1.p);
1183
+ // xf1.p.mulLocal(-1).addLocal(m_sweep.c0);
1184
+ // inlined:
1185
+ xf1.q.s = MathUtils.sin(m_sweep.a0);
1186
+ xf1.q.c = MathUtils.cos(m_sweep.a0);
1187
+ xf1.p.x = m_sweep.c0.x - xf1.q.c * m_sweep.localCenter.x + xf1.q.s * m_sweep.localCenter.y;
1188
+ xf1.p.y = m_sweep.c0.y - xf1.q.s * m_sweep.localCenter.x - xf1.q.c * m_sweep.localCenter.y;
1189
+ // end inline
1190
+
1191
+ for (Fixture f = m_fixtureList; f != null; f = f.m_next) {
1192
+ f.synchronize(m_world.m_contactManager.m_broadPhase, xf1, m_xf);
1193
+ }
1194
+ }
1195
+
1196
+ public final void synchronizeTransform() {
1197
+ // m_xf.q.set(m_sweep.a);
1198
+ //
1199
+ // // m_xf.position = m_sweep.c - Mul(m_xf.R, m_sweep.localCenter);
1200
+ // Rot.mulToOutUnsafe(m_xf.q, m_sweep.localCenter, m_xf.p);
1201
+ // m_xf.p.mulLocal(-1).addLocal(m_sweep.c);
1202
+ //
1203
+ m_xf.q.s = MathUtils.sin(m_sweep.a);
1204
+ m_xf.q.c = MathUtils.cos(m_sweep.a);
1205
+ Rot q = m_xf.q;
1206
+ Vec2 v = m_sweep.localCenter;
1207
+ m_xf.p.x = m_sweep.c.x - q.c * v.x + q.s * v.y;
1208
+ m_xf.p.y = m_sweep.c.y - q.s * v.x - q.c * v.y;
1209
+ }
1210
+
1211
+ /**
1212
+ * This is used to prevent connected bodies from colliding. It may lie,
1213
+ * depending on the collideConnected flag.
1214
+ *
1215
+ * @param other
1216
+ * @return
1217
+ */
1218
+ public boolean shouldCollide(Body other) {
1219
+ // At least one body should be dynamic.
1220
+ if (m_type != BodyType.DYNAMIC && other.m_type != BodyType.DYNAMIC) {
1221
+ return false;
1222
+ }
1223
+
1224
+ // Does a joint prevent collision?
1225
+ for (JointEdge jn = m_jointList; jn != null; jn = jn.next) {
1226
+ if (jn.other == other) {
1227
+ if (jn.joint.getCollideConnected() == false) {
1228
+ return false;
1229
+ }
1230
+ }
1231
+ }
1232
+
1233
+ return true;
1234
+ }
1235
+
1236
+ protected final void advance(float t) {
1237
+ // Advance to the new safe time. This doesn't sync the broad-phase.
1238
+ m_sweep.advance(t);
1239
+ m_sweep.c.set(m_sweep.c0);
1240
+ m_sweep.a = m_sweep.a0;
1241
+ m_xf.q.set(m_sweep.a);
1242
+ // m_xf.position = m_sweep.c - Mul(m_xf.R, m_sweep.localCenter);
1243
+ Rot.mulToOutUnsafe(m_xf.q, m_sweep.localCenter, m_xf.p);
1244
+ m_xf.p.mulLocal(-1).addLocal(m_sweep.c);
1245
+ }
1246
+ }