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,254 @@
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.collision.shapes;
25
+
26
+ import org.jbox2d.collision.AABB;
27
+ import org.jbox2d.collision.RayCastInput;
28
+ import org.jbox2d.collision.RayCastOutput;
29
+ import org.jbox2d.common.MathUtils;
30
+ import org.jbox2d.common.Rot;
31
+ import org.jbox2d.common.Settings;
32
+ import org.jbox2d.common.Transform;
33
+ import org.jbox2d.common.Vec2;
34
+
35
+ /**
36
+ * A line segment (edge) shape. These can be connected in chains or loops to other edge shapes. The
37
+ * connectivity information is used to ensure correct contact normals.
38
+ *
39
+ * @author Daniel
40
+ */
41
+ public class EdgeShape extends Shape {
42
+
43
+ /**
44
+ * edge vertex 1
45
+ */
46
+ public final Vec2 m_vertex1 = new Vec2();
47
+ /**
48
+ * edge vertex 2
49
+ */
50
+ public final Vec2 m_vertex2 = new Vec2();
51
+
52
+ /**
53
+ * optional adjacent vertex 1. Used for smooth collision
54
+ */
55
+ public final Vec2 m_vertex0 = new Vec2();
56
+ /**
57
+ * optional adjacent vertex 2. Used for smooth collision
58
+ */
59
+ public final Vec2 m_vertex3 = new Vec2();
60
+ public boolean m_hasVertex0 = false, m_hasVertex3 = false;
61
+
62
+
63
+ public EdgeShape() {
64
+ super(ShapeType.EDGE);
65
+ m_radius = Settings.polygonRadius;
66
+ }
67
+
68
+ @Override
69
+ public int getChildCount() {
70
+ return 1;
71
+ }
72
+
73
+ public void set(Vec2 v1, Vec2 v2) {
74
+ m_vertex1.set(v1);
75
+ m_vertex2.set(v2);
76
+ m_hasVertex0 = m_hasVertex3 = false;
77
+ }
78
+
79
+ @Override
80
+ public boolean testPoint(Transform xf, Vec2 p) {
81
+ return false;
82
+ }
83
+
84
+ // for pooling
85
+ private final Vec2 normal = new Vec2();
86
+
87
+ @Override
88
+ public float computeDistanceToOut(Transform xf, Vec2 p, int childIndex, Vec2 normalOut) {
89
+ float xfqc = xf.q.c;
90
+ float xfqs = xf.q.s;
91
+ float xfpx = xf.p.x;
92
+ float xfpy = xf.p.y;
93
+ float v1x = (xfqc * m_vertex1.x - xfqs * m_vertex1.y) + xfpx;
94
+ float v1y = (xfqs * m_vertex1.x + xfqc * m_vertex1.y) + xfpy;
95
+ float v2x = (xfqc * m_vertex2.x - xfqs * m_vertex2.y) + xfpx;
96
+ float v2y = (xfqs * m_vertex2.x + xfqc * m_vertex2.y) + xfpy;
97
+
98
+ float dx = p.x - v1x;
99
+ float dy = p.y - v1y;
100
+ float sx = v2x - v1x;
101
+ float sy = v2y - v1y;
102
+ float ds = dx * sx + dy * sy;
103
+ if (ds > 0) {
104
+ float s2 = sx * sx + sy * sy;
105
+ if (ds > s2) {
106
+ dx = p.x - v2x;
107
+ dy = p.y - v2y;
108
+ } else {
109
+ dx -= ds / s2 * sx;
110
+ dy -= ds / s2 * sy;
111
+ }
112
+ }
113
+
114
+ float d1 = MathUtils.sqrt(dx * dx + dy * dy);
115
+ if (d1 > 0) {
116
+ normalOut.x = 1 / d1 * dx;
117
+ normalOut.y = 1 / d1 * dy;
118
+ } else {
119
+ normalOut.x = 0;
120
+ normalOut.y = 0;
121
+ }
122
+ return d1;
123
+ }
124
+
125
+ // p = p1 + t * d
126
+ // v = v1 + s * e
127
+ // p1 + t * d = v1 + s * e
128
+ // s * e - t * d = p1 - v1
129
+ @Override
130
+ public boolean raycast(RayCastOutput output, RayCastInput input, Transform xf, int childIndex) {
131
+
132
+ float tempx, tempy;
133
+ final Vec2 v1 = m_vertex1;
134
+ final Vec2 v2 = m_vertex2;
135
+ final Rot xfq = xf.q;
136
+ final Vec2 xfp = xf.p;
137
+
138
+ // Put the ray into the edge's frame of reference.
139
+ // b2Vec2 p1 = b2MulT(xf.q, input.p1 - xf.p);
140
+ // b2Vec2 p2 = b2MulT(xf.q, input.p2 - xf.p);
141
+ tempx = input.p1.x - xfp.x;
142
+ tempy = input.p1.y - xfp.y;
143
+ final float p1x = xfq.c * tempx + xfq.s * tempy;
144
+ final float p1y = -xfq.s * tempx + xfq.c * tempy;
145
+
146
+ tempx = input.p2.x - xfp.x;
147
+ tempy = input.p2.y - xfp.y;
148
+ final float p2x = xfq.c * tempx + xfq.s * tempy;
149
+ final float p2y = -xfq.s * tempx + xfq.c * tempy;
150
+
151
+ final float dx = p2x - p1x;
152
+ final float dy = p2y - p1y;
153
+
154
+ // final Vec2 normal = pool2.set(v2).subLocal(v1);
155
+ // normal.set(normal.y, -normal.x);
156
+ normal.x = v2.y - v1.y;
157
+ normal.y = v1.x - v2.x;
158
+ normal.normalize();
159
+ final float normalx = normal.x;
160
+ final float normaly = normal.y;
161
+
162
+ // q = p1 + t * d
163
+ // dot(normal, q - v1) = 0
164
+ // dot(normal, p1 - v1) + t * dot(normal, d) = 0
165
+ tempx = v1.x - p1x;
166
+ tempy = v1.y - p1y;
167
+ float numerator = normalx * tempx + normaly * tempy;
168
+ float denominator = normalx * dx + normaly * dy;
169
+
170
+ if (denominator == 0.0f) {
171
+ return false;
172
+ }
173
+
174
+ float t = numerator / denominator;
175
+ if (t < 0.0f || 1.0f < t) {
176
+ return false;
177
+ }
178
+
179
+ // Vec2 q = p1 + t * d;
180
+ final float qx = p1x + t * dx;
181
+ final float qy = p1y + t * dy;
182
+
183
+ // q = v1 + s * r
184
+ // s = dot(q - v1, r) / dot(r, r)
185
+ // Vec2 r = v2 - v1;
186
+ final float rx = v2.x - v1.x;
187
+ final float ry = v2.y - v1.y;
188
+ final float rr = rx * rx + ry * ry;
189
+ if (rr == 0.0f) {
190
+ return false;
191
+ }
192
+ tempx = qx - v1.x;
193
+ tempy = qy - v1.y;
194
+ // float s = Vec2.dot(pool5, r) / rr;
195
+ float s = (tempx * rx + tempy * ry) / rr;
196
+ if (s < 0.0f || 1.0f < s) {
197
+ return false;
198
+ }
199
+
200
+ output.fraction = t;
201
+ if (numerator > 0.0f) {
202
+ // output.normal = -b2Mul(xf.q, normal);
203
+ output.normal.x = -xfq.c * normal.x + xfq.s * normal.y;
204
+ output.normal.y = -xfq.s * normal.x - xfq.c * normal.y;
205
+ } else {
206
+ // output->normal = b2Mul(xf.q, normal);
207
+ output.normal.x = xfq.c * normal.x - xfq.s * normal.y;
208
+ output.normal.y = xfq.s * normal.x + xfq.c * normal.y;
209
+ }
210
+ return true;
211
+ }
212
+
213
+ @Override
214
+ public void computeAABB(AABB aabb, Transform xf, int childIndex) {
215
+ final Vec2 lowerBound = aabb.lowerBound;
216
+ final Vec2 upperBound = aabb.upperBound;
217
+ final Rot xfq = xf.q;
218
+
219
+ final float v1x = (xfq.c * m_vertex1.x - xfq.s * m_vertex1.y) + xf.p.x;
220
+ final float v1y = (xfq.s * m_vertex1.x + xfq.c * m_vertex1.y) + xf.p.y;
221
+ final float v2x = (xfq.c * m_vertex2.x - xfq.s * m_vertex2.y) + xf.p.x;
222
+ final float v2y = (xfq.s * m_vertex2.x + xfq.c * m_vertex2.y) + xf.p.y;
223
+
224
+ lowerBound.x = v1x < v2x ? v1x : v2x;
225
+ lowerBound.y = v1y < v2y ? v1y : v2y;
226
+ upperBound.x = v1x > v2x ? v1x : v2x;
227
+ upperBound.y = v1y > v2y ? v1y : v2y;
228
+
229
+ lowerBound.x -= m_radius;
230
+ lowerBound.y -= m_radius;
231
+ upperBound.x += m_radius;
232
+ upperBound.y += m_radius;
233
+ }
234
+
235
+ @Override
236
+ public void computeMass(MassData massData, float density) {
237
+ massData.mass = 0.0f;
238
+ massData.center.set(m_vertex1).addLocal(m_vertex2).mulLocal(0.5f);
239
+ massData.I = 0.0f;
240
+ }
241
+
242
+ @Override
243
+ public Shape clone() {
244
+ EdgeShape edge = new EdgeShape();
245
+ edge.m_radius = this.m_radius;
246
+ edge.m_hasVertex0 = this.m_hasVertex0;
247
+ edge.m_hasVertex3 = this.m_hasVertex3;
248
+ edge.m_vertex0.set(this.m_vertex0);
249
+ edge.m_vertex1.set(this.m_vertex1);
250
+ edge.m_vertex2.set(this.m_vertex2);
251
+ edge.m_vertex3.set(this.m_vertex3);
252
+ return edge;
253
+ }
254
+ }
@@ -0,0 +1,105 @@
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
+ /*
27
+ * JBox2D - A Java Port of Erin Catto's Box2D
28
+ *
29
+ * JBox2D homepage: http://jbox2d.sourceforge.net/
30
+ * Box2D homepage: http://www.box2d.org
31
+ *
32
+ * This software is provided 'as-is', without any express or implied
33
+ * warranty. In no event will the authors be held liable for any damages
34
+ * arising from the use of this software.
35
+ *
36
+ * Permission is granted to anyone to use this software for any purpose,
37
+ * including commercial applications, and to alter it and redistribute it
38
+ * freely, subject to the following restrictions:
39
+ *
40
+ * 1. The origin of this software must not be misrepresented; you must not
41
+ * claim that you wrote the original software. If you use this software
42
+ * in a product, an acknowledgment in the product documentation would be
43
+ * appreciated but is not required.
44
+ * 2. Altered source versions must be plainly marked as such, and must not be
45
+ * misrepresented as being the original software.
46
+ * 3. This notice may not be removed or altered from any source distribution.
47
+ */
48
+ package org.jbox2d.collision.shapes;
49
+
50
+ import org.jbox2d.common.Vec2;
51
+
52
+ // Updated to rev 100
53
+ /**
54
+ * This holds the mass data computed for a shape.
55
+ */
56
+ public class MassData {
57
+
58
+ /**
59
+ * The mass of the shape, usually in kilograms.
60
+ */
61
+ public float mass;
62
+ /**
63
+ * The position of the shape's centroid relative to the shape's origin.
64
+ */
65
+ public final Vec2 center;
66
+ /**
67
+ * The rotational inertia of the shape about the local origin.
68
+ */
69
+ public float I;
70
+
71
+ /**
72
+ * Blank mass data
73
+ */
74
+ public MassData() {
75
+ mass = I = 0f;
76
+ center = new Vec2();
77
+ }
78
+
79
+ /**
80
+ * Copies from the given mass data
81
+ *
82
+ * @param md mass data to copy from
83
+ */
84
+ public MassData(MassData md) {
85
+ mass = md.mass;
86
+ I = md.I;
87
+ center = md.center.clone();
88
+ }
89
+
90
+ public void set(MassData md) {
91
+ mass = md.mass;
92
+ I = md.I;
93
+ center.set(md.center);
94
+ }
95
+
96
+ /**
97
+ * Return a copy of this object.
98
+ *
99
+ * @return
100
+ */
101
+ @Override
102
+ public MassData clone() {
103
+ return new MassData(this);
104
+ }
105
+ }