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,290 @@
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.common;
25
+
26
+ import java.io.Serializable;
27
+
28
+ /**
29
+ * A 3-by-3 matrix. Stored in column-major order.
30
+ *
31
+ * @author Daniel Murphy
32
+ */
33
+ public class Mat33 implements Serializable {
34
+ private static final long serialVersionUID = 2L;
35
+
36
+ public static final Mat33 IDENTITY = new Mat33(new Vec3(1, 0, 0), new Vec3(0, 1, 0), new Vec3(0,
37
+ 0, 1));
38
+
39
+ public final Vec3 ex, ey, ez;
40
+
41
+ public Mat33() {
42
+ ex = new Vec3();
43
+ ey = new Vec3();
44
+ ez = new Vec3();
45
+ }
46
+
47
+ public Mat33(float exx, float exy, float exz, float eyx, float eyy, float eyz, float ezx,
48
+ float ezy, float ezz) {
49
+ ex = new Vec3(exx, exy, exz);
50
+ ey = new Vec3(eyx, eyy, eyz);
51
+ ez = new Vec3(ezx, ezy, ezz);
52
+ }
53
+
54
+ public Mat33(Vec3 argCol1, Vec3 argCol2, Vec3 argCol3) {
55
+ ex = argCol1.clone();
56
+ ey = argCol2.clone();
57
+ ez = argCol3.clone();
58
+ }
59
+
60
+ public void setZero() {
61
+ ex.setZero();
62
+ ey.setZero();
63
+ ez.setZero();
64
+ }
65
+
66
+ public void set(float exx, float exy, float exz, float eyx, float eyy, float eyz, float ezx,
67
+ float ezy, float ezz) {
68
+ ex.x = exx;
69
+ ex.y = exy;
70
+ ex.z = exz;
71
+ ey.x = eyx;
72
+ ey.y = eyy;
73
+ ey.z = eyz;
74
+ ez.x = eyx;
75
+ ez.y = eyy;
76
+ ez.z = eyz;
77
+ }
78
+
79
+ public void set(Mat33 mat) {
80
+ Vec3 vec = mat.ex;
81
+ ex.x = vec.x;
82
+ ex.y = vec.y;
83
+ ex.z = vec.z;
84
+ Vec3 vec1 = mat.ey;
85
+ ey.x = vec1.x;
86
+ ey.y = vec1.y;
87
+ ey.z = vec1.z;
88
+ Vec3 vec2 = mat.ez;
89
+ ez.x = vec2.x;
90
+ ez.y = vec2.y;
91
+ ez.z = vec2.z;
92
+ }
93
+
94
+ public void setIdentity() {
95
+ ex.x = (float) 1;
96
+ ex.y = (float) 0;
97
+ ex.z = (float) 0;
98
+ ey.x = (float) 0;
99
+ ey.y = (float) 1;
100
+ ey.z = (float) 0;
101
+ ez.x = (float) 0;
102
+ ez.y = (float) 0;
103
+ ez.z = (float) 1;
104
+ }
105
+
106
+ // / Multiply a matrix times a vector.
107
+ public static final Vec3 mul(Mat33 A, Vec3 v) {
108
+ return new Vec3(v.x * A.ex.x + v.y * A.ey.x + v.z + A.ez.x, v.x * A.ex.y + v.y * A.ey.y + v.z
109
+ * A.ez.y, v.x * A.ex.z + v.y * A.ey.z + v.z * A.ez.z);
110
+ }
111
+
112
+ public static final Vec2 mul22(Mat33 A, Vec2 v) {
113
+ return new Vec2(A.ex.x * v.x + A.ey.x * v.y, A.ex.y * v.x + A.ey.y * v.y);
114
+ }
115
+
116
+ public static final void mul22ToOut(Mat33 A, Vec2 v, Vec2 out) {
117
+ final float tempx = A.ex.x * v.x + A.ey.x * v.y;
118
+ out.y = A.ex.y * v.x + A.ey.y * v.y;
119
+ out.x = tempx;
120
+ }
121
+
122
+ public static final void mul22ToOutUnsafe(Mat33 A, Vec2 v, Vec2 out) {
123
+ assert (v != out);
124
+ out.y = A.ex.y * v.x + A.ey.y * v.y;
125
+ out.x = A.ex.x * v.x + A.ey.x * v.y;
126
+ }
127
+
128
+ public static final void mulToOut(Mat33 A, Vec3 v, Vec3 out) {
129
+ final float tempy = v.x * A.ex.y + v.y * A.ey.y + v.z * A.ez.y;
130
+ final float tempz = v.x * A.ex.z + v.y * A.ey.z + v.z * A.ez.z;
131
+ out.x = v.x * A.ex.x + v.y * A.ey.x + v.z * A.ez.x;
132
+ out.y = tempy;
133
+ out.z = tempz;
134
+ }
135
+
136
+ public static final void mulToOutUnsafe(Mat33 A, Vec3 v, Vec3 out) {
137
+ assert (out != v);
138
+ out.x = v.x * A.ex.x + v.y * A.ey.x + v.z * A.ez.x;
139
+ out.y = v.x * A.ex.y + v.y * A.ey.y + v.z * A.ez.y;
140
+ out.z = v.x * A.ex.z + v.y * A.ey.z + v.z * A.ez.z;
141
+ }
142
+
143
+ /**
144
+ * Solve A * x = b, where b is a column vector. This is more efficient than computing the inverse
145
+ * in one-shot cases.
146
+ *
147
+ * @param b
148
+ * @return
149
+ */
150
+ public final Vec2 solve22(Vec2 b) {
151
+ Vec2 x = new Vec2();
152
+ solve22ToOut(b, x);
153
+ return x;
154
+ }
155
+
156
+ /**
157
+ * Solve A * x = b, where b is a column vector. This is more efficient than computing the inverse
158
+ * in one-shot cases.
159
+ *
160
+ * @param b
161
+ * @return
162
+ */
163
+ public final void solve22ToOut(Vec2 b, Vec2 out) {
164
+ final float a11 = ex.x, a12 = ey.x, a21 = ex.y, a22 = ey.y;
165
+ float det = a11 * a22 - a12 * a21;
166
+ if (det != 0.0f) {
167
+ det = 1.0f / det;
168
+ }
169
+ out.x = det * (a22 * b.x - a12 * b.y);
170
+ out.y = det * (a11 * b.y - a21 * b.x);
171
+ }
172
+
173
+ // djm pooling from below
174
+ /**
175
+ * Solve A * x = b, where b is a column vector. This is more efficient than computing the inverse
176
+ * in one-shot cases.
177
+ *
178
+ * @param b
179
+ * @return
180
+ */
181
+ public final Vec3 solve33(Vec3 b) {
182
+ Vec3 x = new Vec3();
183
+ solve33ToOut(b, x);
184
+ return x;
185
+ }
186
+
187
+ /**
188
+ * Solve A * x = b, where b is a column vector. This is more efficient than computing the inverse
189
+ * in one-shot cases.
190
+ *
191
+ * @param b
192
+ * @param out the result
193
+ */
194
+ public final void solve33ToOut(Vec3 b, Vec3 out) {
195
+ assert (b != out);
196
+ Vec3.crossToOutUnsafe(ey, ez, out);
197
+ float det = Vec3.dot(ex, out);
198
+ if (det != 0.0f) {
199
+ det = 1.0f / det;
200
+ }
201
+ Vec3.crossToOutUnsafe(ey, ez, out);
202
+ final float x = det * Vec3.dot(b, out);
203
+ Vec3.crossToOutUnsafe(b, ez, out);
204
+ final float y = det * Vec3.dot(ex, out);
205
+ Vec3.crossToOutUnsafe(ey, b, out);
206
+ float z = det * Vec3.dot(ex, out);
207
+ out.x = x;
208
+ out.y = y;
209
+ out.z = z;
210
+ }
211
+
212
+ public void getInverse22(Mat33 M) {
213
+ float a = ex.x, b = ey.x, c = ex.y, d = ey.y;
214
+ float det = a * d - b * c;
215
+ if (det != 0.0f) {
216
+ det = 1.0f / det;
217
+ }
218
+
219
+ M.ex.x = det * d;
220
+ M.ey.x = -det * b;
221
+ M.ex.z = 0.0f;
222
+ M.ex.y = -det * c;
223
+ M.ey.y = det * a;
224
+ M.ey.z = 0.0f;
225
+ M.ez.x = 0.0f;
226
+ M.ez.y = 0.0f;
227
+ M.ez.z = 0.0f;
228
+ }
229
+
230
+ // / Returns the zero matrix if singular.
231
+ public void getSymInverse33(Mat33 M) {
232
+ float bx = ey.y * ez.z - ey.z * ez.y;
233
+ float by = ey.z * ez.x - ey.x * ez.z;
234
+ float bz = ey.x * ez.y - ey.y * ez.x;
235
+ float det = ex.x * bx + ex.y * by + ex.z * bz;
236
+ if (det != 0.0f) {
237
+ det = 1.0f / det;
238
+ }
239
+
240
+ float a11 = ex.x, a12 = ey.x, a13 = ez.x;
241
+ float a22 = ey.y, a23 = ez.y;
242
+ float a33 = ez.z;
243
+
244
+ M.ex.x = det * (a22 * a33 - a23 * a23);
245
+ M.ex.y = det * (a13 * a23 - a12 * a33);
246
+ M.ex.z = det * (a12 * a23 - a13 * a22);
247
+
248
+ M.ey.x = M.ex.y;
249
+ M.ey.y = det * (a11 * a33 - a13 * a13);
250
+ M.ey.z = det * (a13 * a12 - a11 * a23);
251
+
252
+ M.ez.x = M.ex.z;
253
+ M.ez.y = M.ey.z;
254
+ M.ez.z = det * (a11 * a22 - a12 * a12);
255
+ }
256
+
257
+
258
+ public final static void setScaleTransform(float scale, Mat33 out) {
259
+ out.ex.x = scale;
260
+ out.ey.y = scale;
261
+ }
262
+
263
+ @Override
264
+ public int hashCode() {
265
+ final int prime = 31;
266
+ int result = 1;
267
+ result = prime * result + ((ex == null) ? 0 : ex.hashCode());
268
+ result = prime * result + ((ey == null) ? 0 : ey.hashCode());
269
+ result = prime * result + ((ez == null) ? 0 : ez.hashCode());
270
+ return result;
271
+ }
272
+
273
+ @Override
274
+ public boolean equals(Object obj) {
275
+ if (this == obj) return true;
276
+ if (obj == null) return false;
277
+ if (getClass() != obj.getClass()) return false;
278
+ Mat33 other = (Mat33) obj;
279
+ if (ex == null) {
280
+ if (other.ex != null) return false;
281
+ } else if (!ex.equals(other.ex)) return false;
282
+ if (ey == null) {
283
+ if (other.ey != null) return false;
284
+ } else if (!ey.equals(other.ey)) return false;
285
+ if (ez == null) {
286
+ if (other.ez != null) return false;
287
+ } else if (!ez.equals(other.ez)) return false;
288
+ return true;
289
+ }
290
+ }
@@ -0,0 +1,335 @@
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
+ * JBox2D - A Java Port of Erin Catto's Box2D
26
+ *
27
+ * JBox2D homepage: http://jbox2d.sourceforge.net/
28
+ * Box2D homepage: http://www.box2d.org
29
+ *
30
+ * This software is provided 'as-is', without any express or implied
31
+ * warranty. In no event will the authors be held liable for any damages
32
+ * arising from the use of this software.
33
+ *
34
+ * Permission is granted to anyone to use this software for any purpose,
35
+ * including commercial applications, and to alter it and redistribute it
36
+ * freely, subject to the following restrictions:
37
+ *
38
+ * 1. The origin of this software must not be misrepresented; you must not
39
+ * claim that you wrote the original software. If you use this software
40
+ * in a product, an acknowledgment in the product documentation would be
41
+ * appreciated but is not required.
42
+ * 2. Altered source versions must be plainly marked as such, and must not be
43
+ * misrepresented as being the original software.
44
+ * 3. This notice may not be removed or altered from any source distribution.
45
+ */
46
+
47
+ package org.jbox2d.common;
48
+
49
+ import java.util.Random;
50
+
51
+ /**
52
+ * A few math methods that don't fit very well anywhere else.
53
+ */
54
+ public class MathUtils extends PlatformMathUtils {
55
+ public static final float PI = (float) Math.PI;
56
+ public static final float TWOPI = (float) (Math.PI * 2);
57
+ public static final float INV_PI = 1f / PI;
58
+ public static final float HALF_PI = PI / 2;
59
+ public static final float QUARTER_PI = PI / 4;
60
+ public static final float THREE_HALVES_PI = TWOPI - HALF_PI;
61
+
62
+ /**
63
+ * Degrees to radians conversion factor
64
+ */
65
+ public static final float DEG2RAD = PI / 180;
66
+
67
+ /**
68
+ * Radians to degrees conversion factor
69
+ */
70
+ public static final float RAD2DEG = 180 / PI;
71
+
72
+ public static final float[] sinLUT = new float[Settings.SINCOS_LUT_LENGTH];
73
+
74
+ static {
75
+ for (int i = 0; i < Settings.SINCOS_LUT_LENGTH; i++) {
76
+ sinLUT[i] = (float) Math.sin(i * Settings.SINCOS_LUT_PRECISION);
77
+ }
78
+ }
79
+
80
+ public static final float sin(float x) {
81
+ if (Settings.SINCOS_LUT_ENABLED) {
82
+ return sinLUT(x);
83
+ } else {
84
+ return (float) StrictMath.sin(x);
85
+ }
86
+ }
87
+
88
+ public static final float sinLUT(float x) {
89
+ x %= TWOPI;
90
+
91
+ if (x < 0) {
92
+ x += TWOPI;
93
+ }
94
+
95
+ if (Settings.SINCOS_LUT_LERP) {
96
+
97
+ x /= Settings.SINCOS_LUT_PRECISION;
98
+
99
+ final int index = (int) x;
100
+
101
+ if (index != 0) {
102
+ x %= index;
103
+ }
104
+
105
+ // the next index is 0
106
+ if (index == Settings.SINCOS_LUT_LENGTH - 1) {
107
+ return ((1 - x) * sinLUT[index] + x * sinLUT[0]);
108
+ } else {
109
+ return ((1 - x) * sinLUT[index] + x * sinLUT[index + 1]);
110
+ }
111
+
112
+ } else {
113
+ return sinLUT[MathUtils.round(x / Settings.SINCOS_LUT_PRECISION) % Settings.SINCOS_LUT_LENGTH];
114
+ }
115
+ }
116
+
117
+ public static final float cos(float x) {
118
+ if (Settings.SINCOS_LUT_ENABLED) {
119
+ return sinLUT(HALF_PI - x);
120
+ } else {
121
+ return (float) StrictMath.cos(x);
122
+ }
123
+ }
124
+
125
+ public static final float abs(final float x) {
126
+ if (Settings.FAST_ABS) {
127
+ return x > 0 ? x : -x;
128
+ } else {
129
+ return Math.abs(x);
130
+ }
131
+ }
132
+
133
+ public static final float fastAbs(final float x) {
134
+ return x > 0 ? x : -x;
135
+ }
136
+
137
+ public static final int abs(int x) {
138
+ int y = x >> 31;
139
+ return (x ^ y) - y;
140
+ }
141
+
142
+ public static final int floor(final float x) {
143
+ if (Settings.FAST_FLOOR) {
144
+ return fastFloor(x);
145
+ } else {
146
+ return (int) Math.floor(x);
147
+ }
148
+ }
149
+
150
+ public static final int fastFloor(final float x) {
151
+ int y = (int) x;
152
+ if (x < y) {
153
+ return y - 1;
154
+ }
155
+ return y;
156
+ }
157
+
158
+ public static final int ceil(final float x) {
159
+ if (Settings.FAST_CEIL) {
160
+ return fastCeil(x);
161
+ } else {
162
+ return (int) Math.ceil(x);
163
+ }
164
+ }
165
+
166
+ public static final int fastCeil(final float x) {
167
+ int y = (int) x;
168
+ if (x > y) {
169
+ return y + 1;
170
+ }
171
+ return y;
172
+ }
173
+
174
+ public static final int round(final float x) {
175
+ if (Settings.FAST_ROUND) {
176
+ return floor(x + .5f);
177
+ } else {
178
+ return StrictMath.round(x);
179
+ }
180
+ }
181
+
182
+ /**
183
+ * Rounds up the value to the nearest higher power^2 value.
184
+ *
185
+ * @param x
186
+ * @return power^2 value
187
+ */
188
+ public static final int ceilPowerOf2(int x) {
189
+ int pow2 = 1;
190
+ while (pow2 < x) {
191
+ pow2 <<= 1;
192
+ }
193
+ return pow2;
194
+ }
195
+
196
+ public final static float max(final float a, final float b) {
197
+ return a > b ? a : b;
198
+ }
199
+
200
+ public final static int max(final int a, final int b) {
201
+ return a > b ? a : b;
202
+ }
203
+
204
+ public final static float min(final float a, final float b) {
205
+ return a < b ? a : b;
206
+ }
207
+
208
+ public final static int min(final int a, final int b) {
209
+ return a < b ? a : b;
210
+ }
211
+
212
+ public final static float map(final float val, final float fromMin, final float fromMax,
213
+ final float toMin, final float toMax) {
214
+ final float mult = (val - fromMin) / (fromMax - fromMin);
215
+ final float res = toMin + mult * (toMax - toMin);
216
+ return res;
217
+ }
218
+
219
+ /** Returns the closest value to 'a' that is in between 'low' and 'high'
220
+ * @param a
221
+ * @param low
222
+ * @param high
223
+ * @return
224
+ */
225
+ public final static float clamp(final float a, final float low, final float high) {
226
+ return max(low, min(a, high));
227
+ }
228
+
229
+ public final static Vec2 clamp(final Vec2 a, final Vec2 low, final Vec2 high) {
230
+ final Vec2 min = new Vec2();
231
+ min.x = a.x < high.x ? a.x : high.x;
232
+ min.y = a.y < high.y ? a.y : high.y;
233
+ min.x = low.x > min.x ? low.x : min.x;
234
+ min.y = low.y > min.y ? low.y : min.y;
235
+ return min;
236
+ }
237
+
238
+ public final static void clampToOut(final Vec2 a, final Vec2 low, final Vec2 high, final Vec2 dest) {
239
+ dest.x = a.x < high.x ? a.x : high.x;
240
+ dest.y = a.y < high.y ? a.y : high.y;
241
+ dest.x = low.x > dest.x ? low.x : dest.x;
242
+ dest.y = low.y > dest.y ? low.y : dest.y;
243
+ }
244
+
245
+ /**
246
+ * Next Largest Power of 2: Given a binary integer value x, the next largest power of 2 can be
247
+ * computed by a SWAR algorithm that recursively "folds" the upper bits into the lower bits. This
248
+ * process yields a bit vector with the same most significant 1 as x, but all 1's below it. Adding
249
+ * 1 to that value yields the next largest power of 2.
250
+ * @param x
251
+ * @return
252
+ */
253
+ public final static int nextPowerOfTwo(int x) {
254
+ x |= x >> 1;
255
+ x |= x >> 2;
256
+ x |= x >> 4;
257
+ x |= x >> 8;
258
+ x |= x >> 16;
259
+ return x + 1;
260
+ }
261
+
262
+ public final static boolean isPowerOfTwo(final int x) {
263
+ return x > 0 && (x & x - 1) == 0;
264
+ }
265
+
266
+ public static final float pow(float a, float b) {
267
+ if (Settings.FAST_POW) {
268
+ return fastPow(a, b);
269
+ } else {
270
+ return (float)Math.pow(a, b);
271
+ }
272
+ }
273
+
274
+ public static final float atan2(final float y, final float x) {
275
+ if (Settings.FAST_ATAN2) {
276
+ return fastAtan2(y, x);
277
+ } else {
278
+ return (float) StrictMath.atan2(y, x);
279
+ }
280
+ }
281
+
282
+ public static final float fastAtan2(float y, float x) {
283
+ if (x == 0.0f) {
284
+ if (y > 0.0f) return HALF_PI;
285
+ if (y == 0.0f) return 0.0f;
286
+ return -HALF_PI;
287
+ }
288
+ float atan;
289
+ final float z = y / x;
290
+ if (abs(z) < 1.0f) {
291
+ atan = z / (1.0f + 0.28f * z * z);
292
+ if (x < 0.0f) {
293
+ if (y < 0.0f) return atan - PI;
294
+ return atan + PI;
295
+ }
296
+ } else {
297
+ atan = HALF_PI - z / (z * z + 0.28f);
298
+ if (y < 0.0f) return atan - PI;
299
+ }
300
+ return atan;
301
+ }
302
+
303
+ public static final float reduceAngle(float theta) {
304
+ theta %= TWOPI;
305
+ if (abs(theta) > PI) {
306
+ theta = theta - TWOPI;
307
+ }
308
+ if (abs(theta) > HALF_PI) {
309
+ theta = PI - theta;
310
+ }
311
+ return theta;
312
+ }
313
+
314
+ public static final float randomFloat(float argLow, float argHigh) {
315
+ return (float) Math.random() * (argHigh - argLow) + argLow;
316
+ }
317
+
318
+ public static final float randomFloat(Random r, float argLow, float argHigh) {
319
+ return r.nextFloat() * (argHigh - argLow) + argLow;
320
+ }
321
+
322
+ public static final float sqrt(float x) {
323
+ return (float) StrictMath.sqrt(x);
324
+ }
325
+
326
+ public final static float distanceSquared(Vec2 v1, Vec2 v2) {
327
+ float dx = (v1.x - v2.x);
328
+ float dy = (v1.y - v2.y);
329
+ return dx * dx + dy * dy;
330
+ }
331
+
332
+ public final static float distance(Vec2 v1, Vec2 v2) {
333
+ return sqrt(distanceSquared(v1, v2));
334
+ }
335
+ }