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,388 @@
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.common;
27
+
28
+ import java.io.Serializable;
29
+
30
+ /**
31
+ * A 2D column vector
32
+ */
33
+ public class Vec2 implements Serializable {
34
+
35
+ private static final long serialVersionUID = 1L;
36
+
37
+ public float x, y;
38
+
39
+ public Vec2() {
40
+ this(0, 0);
41
+ }
42
+
43
+ public Vec2(float x, float y) {
44
+ this.x = x;
45
+ this.y = y;
46
+ }
47
+
48
+ public Vec2(Vec2 toCopy) {
49
+ this(toCopy.x, toCopy.y);
50
+ }
51
+
52
+ /**
53
+ * Zero out this vector.
54
+ */
55
+ public final void setZero() {
56
+ x = 0.0f;
57
+ y = 0.0f;
58
+ }
59
+
60
+ /**
61
+ * Set the vector component-wise.
62
+ *
63
+ * @param x
64
+ * @param y
65
+ * @return
66
+ */
67
+ public final Vec2 set(float x, float y) {
68
+ this.x = x;
69
+ this.y = y;
70
+ return this;
71
+ }
72
+
73
+ /**
74
+ * Set this vector to another vector.
75
+ *
76
+ * @param v
77
+ * @return
78
+ */
79
+ public final Vec2 set(Vec2 v) {
80
+ this.x = v.x;
81
+ this.y = v.y;
82
+ return this;
83
+ }
84
+
85
+ /**
86
+ * Return the sum of this vector and another; does not alter either one.
87
+ *
88
+ * @param v
89
+ * @return
90
+ */
91
+ public final Vec2 add(Vec2 v) {
92
+ return new Vec2(x + v.x, y + v.y);
93
+ }
94
+
95
+ /**
96
+ * Return the difference of this vector and another; does not alter either
97
+ * one.
98
+ *
99
+ * @param v
100
+ * @return
101
+ */
102
+ public final Vec2 sub(Vec2 v) {
103
+ return new Vec2(x - v.x, y - v.y);
104
+ }
105
+
106
+ /**
107
+ * Return this vector multiplied by a scalar; does not alter this vector.
108
+ *
109
+ * @param a
110
+ * @return
111
+ */
112
+ public final Vec2 mul(float a) {
113
+ return new Vec2(x * a, y * a);
114
+ }
115
+
116
+ /**
117
+ * Return the negation of this vector; does not alter this vector.
118
+ *
119
+ * @return
120
+ */
121
+ public final Vec2 negate() {
122
+ return new Vec2(-x, -y);
123
+ }
124
+
125
+ /**
126
+ * Flip the vector and return it - alters this vector.
127
+ *
128
+ * @return
129
+ */
130
+ public final Vec2 negateLocal() {
131
+ x = -x;
132
+ y = -y;
133
+ return this;
134
+ }
135
+
136
+ /**
137
+ * Add another vector to this one and returns result - alters this vector.
138
+ *
139
+ * @param v
140
+ * @return
141
+ */
142
+ public final Vec2 addLocal(Vec2 v) {
143
+ x += v.x;
144
+ y += v.y;
145
+ return this;
146
+ }
147
+
148
+ /**
149
+ * Adds values to this vector and returns result - alters this vector.
150
+ *
151
+ * @param x
152
+ * @param y
153
+ * @return
154
+ */
155
+ public final Vec2 addLocal(float x, float y) {
156
+ this.x += x;
157
+ this.y += y;
158
+ return this;
159
+ }
160
+
161
+ /**
162
+ * Subtract another vector from this one and return result - alters this
163
+ * vector.
164
+ *
165
+ * @param v
166
+ * @return
167
+ */
168
+ public final Vec2 subLocal(Vec2 v) {
169
+ x -= v.x;
170
+ y -= v.y;
171
+ return this;
172
+ }
173
+
174
+ /**
175
+ * Multiply this vector by a number and return result - alters this vector.
176
+ *
177
+ * @param a
178
+ * @return
179
+ */
180
+ public final Vec2 mulLocal(float a) {
181
+ x *= a;
182
+ y *= a;
183
+ return this;
184
+ }
185
+
186
+ /**
187
+ * Get the skew vector such that dot(skew_vec, other) == cross(vec, other)
188
+ *
189
+ * @return
190
+ */
191
+ public final Vec2 skew() {
192
+ return new Vec2(-y, x);
193
+ }
194
+
195
+ /**
196
+ * Get the skew vector such that dot(skew_vec, other) == cross(vec, other)
197
+ *
198
+ * @param out
199
+ */
200
+ public final void skew(Vec2 out) {
201
+ out.x = -y;
202
+ out.y = x;
203
+ }
204
+
205
+ /**
206
+ * Return the length of this vector.
207
+ *
208
+ * @return
209
+ */
210
+ public final float length() {
211
+ return MathUtils.sqrt(x * x + y * y);
212
+ }
213
+
214
+ /**
215
+ * Return the squared length of this vector.
216
+ *
217
+ * @return
218
+ */
219
+ public final float lengthSquared() {
220
+ return (x * x + y * y);
221
+ }
222
+
223
+ /**
224
+ * Normalize this vector and return the length before normalization. Alters
225
+ * this vector.
226
+ *
227
+ * @return
228
+ */
229
+ public final float normalize() {
230
+ float length = length();
231
+ if (length < Settings.EPSILON) {
232
+ return 0f;
233
+ }
234
+
235
+ float invLength = 1.0f / length;
236
+ x *= invLength;
237
+ y *= invLength;
238
+ return length;
239
+ }
240
+
241
+ /**
242
+ * True if the vector represents a pair of valid, non-infinite floating
243
+ * point numbers.
244
+ *
245
+ * @return
246
+ */
247
+ public final boolean isValid() {
248
+ return !Float.isNaN(x) && !Float.isInfinite(x) && !Float.isNaN(y) && !Float.isInfinite(y);
249
+ }
250
+
251
+ /**
252
+ * Return a new vector that has positive components.
253
+ *
254
+ * @return
255
+ */
256
+ public final Vec2 abs() {
257
+ return new Vec2(MathUtils.abs(x), MathUtils.abs(y));
258
+ }
259
+
260
+ public final void absLocal() {
261
+ x = MathUtils.abs(x);
262
+ y = MathUtils.abs(y);
263
+ }
264
+
265
+ // @Override // annotation omitted for GWT-compatibility
266
+ /**
267
+ * Return a copy of this vector.
268
+ *
269
+ * @return
270
+ */
271
+ @Override
272
+ public final Vec2 clone() {
273
+ return new Vec2(x, y);
274
+ }
275
+
276
+ @Override
277
+ public final String toString() {
278
+ return "(" + x + "," + y + ")";
279
+ }
280
+
281
+ /*
282
+ * Static
283
+ */
284
+ public final static Vec2 abs(Vec2 a) {
285
+ return new Vec2(MathUtils.abs(a.x), MathUtils.abs(a.y));
286
+ }
287
+
288
+ public final static void absToOut(Vec2 a, Vec2 out) {
289
+ out.x = MathUtils.abs(a.x);
290
+ out.y = MathUtils.abs(a.y);
291
+ }
292
+
293
+ public final static float dot(final Vec2 a, final Vec2 b) {
294
+ return a.x * b.x + a.y * b.y;
295
+ }
296
+
297
+ public final static float cross(final Vec2 a, final Vec2 b) {
298
+ return a.x * b.y - a.y * b.x;
299
+ }
300
+
301
+ public final static Vec2 cross(Vec2 a, float s) {
302
+ return new Vec2(s * a.y, -s * a.x);
303
+ }
304
+
305
+ public final static void crossToOut(Vec2 a, float s, Vec2 out) {
306
+ final float tempy = -s * a.x;
307
+ out.x = s * a.y;
308
+ out.y = tempy;
309
+ }
310
+
311
+ public final static void crossToOutUnsafe(Vec2 a, float s, Vec2 out) {
312
+ assert (out != a);
313
+ out.x = s * a.y;
314
+ out.y = -s * a.x;
315
+ }
316
+
317
+ public final static Vec2 cross(float s, Vec2 a) {
318
+ return new Vec2(-s * a.y, s * a.x);
319
+ }
320
+
321
+ public final static void crossToOut(float s, Vec2 a, Vec2 out) {
322
+ final float tempY = s * a.x;
323
+ out.x = -s * a.y;
324
+ out.y = tempY;
325
+ }
326
+
327
+ public final static void crossToOutUnsafe(float s, Vec2 a, Vec2 out) {
328
+ assert (out != a);
329
+ out.x = -s * a.y;
330
+ out.y = s * a.x;
331
+ }
332
+
333
+ public final static void negateToOut(Vec2 a, Vec2 out) {
334
+ out.x = -a.x;
335
+ out.y = -a.y;
336
+ }
337
+
338
+ public final static Vec2 min(Vec2 a, Vec2 b) {
339
+ return new Vec2(a.x < b.x ? a.x : b.x, a.y < b.y ? a.y : b.y);
340
+ }
341
+
342
+ public final static Vec2 max(Vec2 a, Vec2 b) {
343
+ return new Vec2(a.x > b.x ? a.x : b.x, a.y > b.y ? a.y : b.y);
344
+ }
345
+
346
+ public final static void minToOut(Vec2 a, Vec2 b, Vec2 out) {
347
+ out.x = a.x < b.x ? a.x : b.x;
348
+ out.y = a.y < b.y ? a.y : b.y;
349
+ }
350
+
351
+ public final static void maxToOut(Vec2 a, Vec2 b, Vec2 out) {
352
+ out.x = a.x > b.x ? a.x : b.x;
353
+ out.y = a.y > b.y ? a.y : b.y;
354
+ }
355
+
356
+ /**
357
+ * @see java.lang.Object#hashCode()
358
+ */
359
+ @Override
360
+ public int hashCode() { // automatically generated by Eclipse
361
+ final int prime = 31;
362
+ int result = 1;
363
+ result = prime * result + Float.floatToIntBits(x);
364
+ result = prime * result + Float.floatToIntBits(y);
365
+ return result;
366
+ }
367
+
368
+ /**
369
+ * @see java.lang.Object#equals(java.lang.Object)
370
+ */
371
+ @Override
372
+ public boolean equals(Object obj) { // automatically generated by Eclipse
373
+ if (this == obj) {
374
+ return true;
375
+ }
376
+ if (obj == null) {
377
+ return false;
378
+ }
379
+ if (getClass() != obj.getClass()) {
380
+ return false;
381
+ }
382
+ Vec2 other = (Vec2) obj;
383
+ if (Float.floatToIntBits(x) != Float.floatToIntBits(other.x)) {
384
+ return false;
385
+ }
386
+ return (Float.floatToIntBits(y) == Float.floatToIntBits(other.y));
387
+ }
388
+ }
@@ -0,0 +1,170 @@
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
+ * @author Daniel Murphy
30
+ */
31
+ public class Vec3 implements Serializable {
32
+ private static final long serialVersionUID = 1L;
33
+
34
+ public float x, y, z;
35
+
36
+ public Vec3() {
37
+ x = y = z = 0f;
38
+ }
39
+
40
+ public Vec3(float argX, float argY, float argZ) {
41
+ x = argX;
42
+ y = argY;
43
+ z = argZ;
44
+ }
45
+
46
+ public Vec3(Vec3 copy) {
47
+ x = copy.x;
48
+ y = copy.y;
49
+ z = copy.z;
50
+ }
51
+
52
+ public Vec3 set(Vec3 vec) {
53
+ x = vec.x;
54
+ y = vec.y;
55
+ z = vec.z;
56
+ return this;
57
+ }
58
+
59
+ public Vec3 set(float argX, float argY, float argZ) {
60
+ x = argX;
61
+ y = argY;
62
+ z = argZ;
63
+ return this;
64
+ }
65
+
66
+ public Vec3 addLocal(Vec3 argVec) {
67
+ x += argVec.x;
68
+ y += argVec.y;
69
+ z += argVec.z;
70
+ return this;
71
+ }
72
+
73
+ public Vec3 add(Vec3 argVec) {
74
+ return new Vec3(x + argVec.x, y + argVec.y, z + argVec.z);
75
+ }
76
+
77
+ public Vec3 subLocal(Vec3 argVec) {
78
+ x -= argVec.x;
79
+ y -= argVec.y;
80
+ z -= argVec.z;
81
+ return this;
82
+ }
83
+
84
+ public Vec3 sub(Vec3 argVec) {
85
+ return new Vec3(x - argVec.x, y - argVec.y, z - argVec.z);
86
+ }
87
+
88
+ public Vec3 mulLocal(float argScalar) {
89
+ x *= argScalar;
90
+ y *= argScalar;
91
+ z *= argScalar;
92
+ return this;
93
+ }
94
+
95
+ public Vec3 mul(float argScalar) {
96
+ return new Vec3(x * argScalar, y * argScalar, z * argScalar);
97
+ }
98
+
99
+ public Vec3 negate() {
100
+ return new Vec3(-x, -y, -z);
101
+ }
102
+
103
+ public Vec3 negateLocal() {
104
+ x = -x;
105
+ y = -y;
106
+ z = -z;
107
+ return this;
108
+ }
109
+
110
+ public void setZero() {
111
+ x = 0;
112
+ y = 0;
113
+ z = 0;
114
+ }
115
+
116
+ @Override
117
+ public Vec3 clone() {
118
+ return new Vec3(this);
119
+ }
120
+
121
+ @Override
122
+ public String toString() {
123
+ return "(" + x + "," + y + "," + z + ")";
124
+ }
125
+
126
+ @Override
127
+ public int hashCode() {
128
+ final int prime = 31;
129
+ int result = 1;
130
+ result = prime * result + Float.floatToIntBits(x);
131
+ result = prime * result + Float.floatToIntBits(y);
132
+ result = prime * result + Float.floatToIntBits(z);
133
+ return result;
134
+ }
135
+
136
+ @Override
137
+ public boolean equals(Object obj) {
138
+ if (this == obj) return true;
139
+ if (obj == null) return false;
140
+ if (getClass() != obj.getClass()) return false;
141
+ Vec3 other = (Vec3) obj;
142
+ if (Float.floatToIntBits(x) != Float.floatToIntBits(other.x)) return false;
143
+ if (Float.floatToIntBits(y) != Float.floatToIntBits(other.y)) return false;
144
+ return (Float.floatToIntBits(z) == Float.floatToIntBits(other.z));
145
+ }
146
+
147
+ public final static float dot(Vec3 a, Vec3 b) {
148
+ return a.x * b.x + a.y * b.y + a.z * b.z;
149
+ }
150
+
151
+ public final static Vec3 cross(Vec3 a, Vec3 b) {
152
+ return new Vec3(a.y * b.z - a.z * b.y, a.z * b.x - a.x * b.z, a.x * b.y - a.y * b.x);
153
+ }
154
+
155
+ public final static void crossToOut(Vec3 a, Vec3 b, Vec3 out) {
156
+ final float tempy = a.z * b.x - a.x * b.z;
157
+ final float tempz = a.x * b.y - a.y * b.x;
158
+ out.x = a.y * b.z - a.z * b.y;
159
+ out.y = tempy;
160
+ out.z = tempz;
161
+ }
162
+
163
+ public final static void crossToOutUnsafe(Vec3 a, Vec3 b, Vec3 out) {
164
+ assert(out != b);
165
+ assert(out != a);
166
+ out.x = a.y * b.z - a.z * b.y;
167
+ out.y = a.z * b.x - a.x * b.z;
168
+ out.z = a.x * b.y - a.y * b.x;
169
+ }
170
+ }