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,609 @@
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 2-by-2 matrix. Stored in column-major order.
32
+ */
33
+ public class Mat22 implements Serializable {
34
+
35
+ private static final long serialVersionUID = 2L;
36
+
37
+ public final Vec2 ex, ey;
38
+
39
+ /**
40
+ * Convert the matrix to printable format.
41
+ */
42
+ @Override
43
+ public String toString() {
44
+ String s = "";
45
+ s += "[" + ex.x + "," + ey.x + "]\n";
46
+ s += "[" + ex.y + "," + ey.y + "]";
47
+ return s;
48
+ }
49
+
50
+ /**
51
+ * Construct zero matrix. Note: this is NOT an identity matrix! djm fixed
52
+ * double allocation problem
53
+ */
54
+ public Mat22() {
55
+ ex = new Vec2();
56
+ ey = new Vec2();
57
+ }
58
+
59
+ /**
60
+ * Create a matrix with given vectors as columns.
61
+ *
62
+ * @param c1 Column 1 of matrix
63
+ * @param c2 Column 2 of matrix
64
+ */
65
+ public Mat22(final Vec2 c1, final Vec2 c2) {
66
+ ex = c1.clone();
67
+ ey = c2.clone();
68
+ }
69
+
70
+ /**
71
+ * Create a matrix from four floats.
72
+ *
73
+ * @param exx
74
+ * @param col2x
75
+ * @param exy
76
+ * @param col2y
77
+ */
78
+ public Mat22(final float exx, final float col2x, final float exy, final float col2y) {
79
+ ex = new Vec2(exx, exy);
80
+ ey = new Vec2(col2x, col2y);
81
+ }
82
+
83
+ /**
84
+ * Set as a copy of another matrix.
85
+ *
86
+ * @param m Matrix to copy
87
+ * @return
88
+ */
89
+ public final Mat22 set(final Mat22 m) {
90
+ ex.x = m.ex.x;
91
+ ex.y = m.ex.y;
92
+ ey.x = m.ey.x;
93
+ ey.y = m.ey.y;
94
+ return this;
95
+ }
96
+
97
+ public final Mat22 set(final float exx, final float col2x, final float exy, final float col2y) {
98
+ ex.x = exx;
99
+ ex.y = exy;
100
+ ey.x = col2x;
101
+ ey.y = col2y;
102
+ return this;
103
+ }
104
+
105
+ /**
106
+ * Return a clone of this matrix. djm fixed double allocation
107
+ *
108
+ * @return
109
+ */
110
+ // @Override // annotation omitted for GWT-compatibility
111
+ @Override
112
+ public final Mat22 clone() {
113
+ return new Mat22(ex, ey);
114
+ }
115
+
116
+ /**
117
+ * Set as a matrix representing a rotation.
118
+ *
119
+ * @param angle Rotation (in radians) that matrix represents.
120
+ */
121
+ public final void set(final float angle) {
122
+ final float c = MathUtils.cos(angle), s = MathUtils.sin(angle);
123
+ ex.x = c;
124
+ ey.x = -s;
125
+ ex.y = s;
126
+ ey.y = c;
127
+ }
128
+
129
+ /**
130
+ * Set as the identity matrix.
131
+ */
132
+ public final void setIdentity() {
133
+ ex.x = 1.0f;
134
+ ey.x = 0.0f;
135
+ ex.y = 0.0f;
136
+ ey.y = 1.0f;
137
+ }
138
+
139
+ /**
140
+ * Set as the zero matrix.
141
+ */
142
+ public final void setZero() {
143
+ ex.x = 0.0f;
144
+ ey.x = 0.0f;
145
+ ex.y = 0.0f;
146
+ ey.y = 0.0f;
147
+ }
148
+
149
+ /**
150
+ * Extract the angle from this matrix (assumed to be a rotation matrix).
151
+ *
152
+ * @return
153
+ */
154
+ public final float getAngle() {
155
+ return MathUtils.atan2(ex.y, ex.x);
156
+ }
157
+
158
+ /**
159
+ * Set by column vectors.
160
+ *
161
+ * @param c1 Column 1
162
+ * @param c2 Column 2
163
+ */
164
+ public final void set(final Vec2 c1, final Vec2 c2) {
165
+ ex.x = c1.x;
166
+ ey.x = c2.x;
167
+ ex.y = c1.y;
168
+ ey.y = c2.y;
169
+ }
170
+
171
+ /**
172
+ * Returns the inverted Mat22 - does NOT invert the matrix locally!
173
+ *
174
+ * @return
175
+ */
176
+ public final Mat22 invert() {
177
+ final float a = ex.x, b = ey.x, c = ex.y, d = ey.y;
178
+ final Mat22 B = new Mat22();
179
+ float det = a * d - b * c;
180
+ if (det != 0) {
181
+ det = 1.0f / det;
182
+ }
183
+ B.ex.x = det * d;
184
+ B.ey.x = -det * b;
185
+ B.ex.y = -det * c;
186
+ B.ey.y = det * a;
187
+ return B;
188
+ }
189
+
190
+ public final Mat22 invertLocal() {
191
+ final float a = ex.x, b = ey.x, c = ex.y, d = ey.y;
192
+ float det = a * d - b * c;
193
+ if (det != 0) {
194
+ det = 1.0f / det;
195
+ }
196
+ ex.x = det * d;
197
+ ey.x = -det * b;
198
+ ex.y = -det * c;
199
+ ey.y = det * a;
200
+ return this;
201
+ }
202
+
203
+ public final void invertToOut(final Mat22 out) {
204
+ final float a = ex.x, b = ey.x, c = ex.y, d = ey.y;
205
+ float det = a * d - b * c;
206
+ // b2Assert(det != 0.0f);
207
+ det = 1.0f / det;
208
+ out.ex.x = det * d;
209
+ out.ey.x = -det * b;
210
+ out.ex.y = -det * c;
211
+ out.ey.y = det * a;
212
+ }
213
+
214
+ /**
215
+ * Return the matrix composed of the absolute values of all elements. djm:
216
+ * fixed double allocation
217
+ *
218
+ * @return Absolute value matrix
219
+ */
220
+ public final Mat22 abs() {
221
+ return new Mat22(MathUtils.abs(ex.x), MathUtils.abs(ey.x), MathUtils.abs(ex.y),
222
+ MathUtils.abs(ey.y));
223
+ }
224
+
225
+ /* djm: added */
226
+ public final void absLocal() {
227
+ ex.absLocal();
228
+ ey.absLocal();
229
+ }
230
+
231
+ /**
232
+ * Return the matrix composed of the absolute values of all elements.
233
+ *
234
+ * @param R
235
+ * @return Absolute value matrix
236
+ */
237
+ public final static Mat22 abs(final Mat22 R) {
238
+ return R.abs();
239
+ }
240
+
241
+ /* djm created */
242
+ public static void absToOut(final Mat22 R, final Mat22 out) {
243
+ out.ex.x = MathUtils.abs(R.ex.x);
244
+ out.ex.y = MathUtils.abs(R.ex.y);
245
+ out.ey.x = MathUtils.abs(R.ey.x);
246
+ out.ey.y = MathUtils.abs(R.ey.y);
247
+ }
248
+
249
+ /**
250
+ * Multiply a vector by this matrix.
251
+ *
252
+ * @param v Vector to multiply by matrix.
253
+ * @return Resulting vector
254
+ */
255
+ public final Vec2 mul(final Vec2 v) {
256
+ return new Vec2(ex.x * v.x + ey.x * v.y, ex.y * v.x + ey.y * v.y);
257
+ }
258
+
259
+ public final void mulToOut(final Vec2 v, final Vec2 out) {
260
+ final float tempy = ex.y * v.x + ey.y * v.y;
261
+ out.x = ex.x * v.x + ey.x * v.y;
262
+ out.y = tempy;
263
+ }
264
+
265
+ public final void mulToOutUnsafe(final Vec2 v, final Vec2 out) {
266
+ assert (v != out);
267
+ out.x = ex.x * v.x + ey.x * v.y;
268
+ out.y = ex.y * v.x + ey.y * v.y;
269
+ }
270
+
271
+ /**
272
+ * Multiply another matrix by this one (this one on left). djm optimized
273
+ *
274
+ * @param R
275
+ * @return
276
+ */
277
+ public final Mat22 mul(final Mat22 R) {
278
+ /*
279
+ * Mat22 C = new Mat22();C.set(this.mul(R.ex), this.mul(R.ey));return C;
280
+ */
281
+ final Mat22 C = new Mat22();
282
+ C.ex.x = ex.x * R.ex.x + ey.x * R.ex.y;
283
+ C.ex.y = ex.y * R.ex.x + ey.y * R.ex.y;
284
+ C.ey.x = ex.x * R.ey.x + ey.x * R.ey.y;
285
+ C.ey.y = ex.y * R.ey.x + ey.y * R.ey.y;
286
+ // C.set(ex,col2);
287
+ return C;
288
+ }
289
+
290
+ public final Mat22 mulLocal(final Mat22 R) {
291
+ mulToOut(R, this);
292
+ return this;
293
+ }
294
+
295
+ public final void mulToOut(final Mat22 R, final Mat22 out) {
296
+ final float tempy1 = this.ex.y * R.ex.x + this.ey.y * R.ex.y;
297
+ final float tempx1 = this.ex.x * R.ex.x + this.ey.x * R.ex.y;
298
+ out.ex.x = tempx1;
299
+ out.ex.y = tempy1;
300
+ final float tempy2 = this.ex.y * R.ey.x + this.ey.y * R.ey.y;
301
+ final float tempx2 = this.ex.x * R.ey.x + this.ey.x * R.ey.y;
302
+ out.ey.x = tempx2;
303
+ out.ey.y = tempy2;
304
+ }
305
+
306
+ public final void mulToOutUnsafe(final Mat22 R, final Mat22 out) {
307
+ assert (out != R);
308
+ assert (out != this);
309
+ out.ex.x = this.ex.x * R.ex.x + this.ey.x * R.ex.y;
310
+ out.ex.y = this.ex.y * R.ex.x + this.ey.y * R.ex.y;
311
+ out.ey.x = this.ex.x * R.ey.x + this.ey.x * R.ey.y;
312
+ out.ey.y = this.ex.y * R.ey.x + this.ey.y * R.ey.y;
313
+ }
314
+
315
+ /**
316
+ * Multiply another matrix by the transpose of this one (transpose of this
317
+ * one on left). djm: optimized
318
+ *
319
+ * @param B
320
+ * @return
321
+ */
322
+ public final Mat22 mulTrans(final Mat22 B) {
323
+ /*
324
+ * Vec2 c1 = new Vec2(Vec2.dot(this.ex, B.ex), Vec2.dot(this.ey, B.ex)); Vec2 c2 = new
325
+ * Vec2(Vec2.dot(this.ex, B.ey), Vec2.dot(this.ey, B.ey)); Mat22 C = new Mat22(); C.set(c1, c2);
326
+ * return C;
327
+ */
328
+ final Mat22 C = new Mat22();
329
+
330
+ C.ex.x = Vec2.dot(this.ex, B.ex);
331
+ C.ex.y = Vec2.dot(this.ey, B.ex);
332
+
333
+ C.ey.x = Vec2.dot(this.ex, B.ey);
334
+ C.ey.y = Vec2.dot(this.ey, B.ey);
335
+ return C;
336
+ }
337
+
338
+ public final Mat22 mulTransLocal(final Mat22 B) {
339
+ mulTransToOut(B, this);
340
+ return this;
341
+ }
342
+
343
+ public final void mulTransToOut(final Mat22 B, final Mat22 out) {
344
+ /*
345
+ * out.ex.x = Vec2.dot(this.ex, B.ex); out.ex.y = Vec2.dot(this.ey, B.ex); out.ey.x =
346
+ * Vec2.dot(this.ex, B.ey); out.ey.y = Vec2.dot(this.ey, B.ey);
347
+ */
348
+ final float x1 = this.ex.x * B.ex.x + this.ex.y * B.ex.y;
349
+ final float y1 = this.ey.x * B.ex.x + this.ey.y * B.ex.y;
350
+ final float x2 = this.ex.x * B.ey.x + this.ex.y * B.ey.y;
351
+ final float y2 = this.ey.x * B.ey.x + this.ey.y * B.ey.y;
352
+ out.ex.x = x1;
353
+ out.ey.x = x2;
354
+ out.ex.y = y1;
355
+ out.ey.y = y2;
356
+ }
357
+
358
+ public final void mulTransToOutUnsafe(final Mat22 B, final Mat22 out) {
359
+ assert (B != out);
360
+ assert (this != out);
361
+ out.ex.x = this.ex.x * B.ex.x + this.ex.y * B.ex.y;
362
+ out.ey.x = this.ex.x * B.ey.x + this.ex.y * B.ey.y;
363
+ out.ex.y = this.ey.x * B.ex.x + this.ey.y * B.ex.y;
364
+ out.ey.y = this.ey.x * B.ey.x + this.ey.y * B.ey.y;
365
+ }
366
+
367
+ /**
368
+ * Multiply a vector by the transpose of this matrix.
369
+ *
370
+ * @param v
371
+ * @return
372
+ */
373
+ public final Vec2 mulTrans(final Vec2 v) {
374
+ // return new Vec2(Vec2.dot(v, ex), Vec2.dot(v, col2));
375
+ return new Vec2((v.x * ex.x + v.y * ex.y), (v.x * ey.x + v.y * ey.y));
376
+ }
377
+
378
+ /* djm added */
379
+ public final void mulTransToOut(final Vec2 v, final Vec2 out) {
380
+ /*
381
+ * out.x = Vec2.dot(v, ex); out.y = Vec2.dot(v, col2);
382
+ */
383
+ final float tempx = v.x * ex.x + v.y * ex.y;
384
+ out.y = v.x * ey.x + v.y * ey.y;
385
+ out.x = tempx;
386
+ }
387
+
388
+ /**
389
+ * Add this matrix to B, return the result.
390
+ *
391
+ * @param B
392
+ * @return
393
+ */
394
+ public final Mat22 add(final Mat22 B) {
395
+ // return new Mat22(ex.add(B.ex), col2.add(B.ey));
396
+ Mat22 m = new Mat22();
397
+ m.ex.x = ex.x + B.ex.x;
398
+ m.ex.y = ex.y + B.ex.y;
399
+ m.ey.x = ey.x + B.ey.x;
400
+ m.ey.y = ey.y + B.ey.y;
401
+ return m;
402
+ }
403
+
404
+ /**
405
+ * Add B to this matrix locally.
406
+ *
407
+ * @param B
408
+ * @return
409
+ */
410
+ public final Mat22 addLocal(final Mat22 B) {
411
+ // ex.addLocal(B.ex);
412
+ // col2.addLocal(B.ey);
413
+ ex.x += B.ex.x;
414
+ ex.y += B.ex.y;
415
+ ey.x += B.ey.x;
416
+ ey.y += B.ey.y;
417
+ return this;
418
+ }
419
+
420
+ /**
421
+ * Solve A * x = b where A = this matrix.
422
+ *
423
+ * @param b
424
+ * @return The vector x that solves the above equation.
425
+ */
426
+ public final Vec2 solve(final Vec2 b) {
427
+ final float a11 = ex.x, a12 = ey.x, a21 = ex.y, a22 = ey.y;
428
+ float det = a11 * a22 - a12 * a21;
429
+ if (det != 0.0f) {
430
+ det = 1.0f / det;
431
+ }
432
+ final Vec2 x = new Vec2(det * (a22 * b.x - a12 * b.y), det * (a11 * b.y - a21 * b.x));
433
+ return x;
434
+ }
435
+
436
+ public final void solveToOut(final Vec2 b, final Vec2 out) {
437
+ final float a11 = ex.x, a12 = ey.x, a21 = ex.y, a22 = ey.y;
438
+ float det = a11 * a22 - a12 * a21;
439
+ if (det != 0.0f) {
440
+ det = 1.0f / det;
441
+ }
442
+ final float tempy = det * (a11 * b.y - a21 * b.x);
443
+ out.x = det * (a22 * b.x - a12 * b.y);
444
+ out.y = tempy;
445
+ }
446
+
447
+ public final static Vec2 mul(final Mat22 R, final Vec2 v) {
448
+ // return R.mul(v);
449
+ return new Vec2(R.ex.x * v.x + R.ey.x * v.y, R.ex.y * v.x + R.ey.y * v.y);
450
+ }
451
+
452
+ public final static void mulToOut(final Mat22 R, final Vec2 v, final Vec2 out) {
453
+ final float tempy = R.ex.y * v.x + R.ey.y * v.y;
454
+ out.x = R.ex.x * v.x + R.ey.x * v.y;
455
+ out.y = tempy;
456
+ }
457
+
458
+ public final static void mulToOutUnsafe(final Mat22 R, final Vec2 v, final Vec2 out) {
459
+ assert (v != out);
460
+ out.x = R.ex.x * v.x + R.ey.x * v.y;
461
+ out.y = R.ex.y * v.x + R.ey.y * v.y;
462
+ }
463
+
464
+ public final static Mat22 mul(final Mat22 A, final Mat22 B) {
465
+ // return A.mul(B);
466
+ final Mat22 C = new Mat22();
467
+ C.ex.x = A.ex.x * B.ex.x + A.ey.x * B.ex.y;
468
+ C.ex.y = A.ex.y * B.ex.x + A.ey.y * B.ex.y;
469
+ C.ey.x = A.ex.x * B.ey.x + A.ey.x * B.ey.y;
470
+ C.ey.y = A.ex.y * B.ey.x + A.ey.y * B.ey.y;
471
+ return C;
472
+ }
473
+
474
+ public final static void mulToOut(final Mat22 A, final Mat22 B, final Mat22 out) {
475
+ final float tempy1 = A.ex.y * B.ex.x + A.ey.y * B.ex.y;
476
+ final float tempx1 = A.ex.x * B.ex.x + A.ey.x * B.ex.y;
477
+ final float tempy2 = A.ex.y * B.ey.x + A.ey.y * B.ey.y;
478
+ final float tempx2 = A.ex.x * B.ey.x + A.ey.x * B.ey.y;
479
+ out.ex.x = tempx1;
480
+ out.ex.y = tempy1;
481
+ out.ey.x = tempx2;
482
+ out.ey.y = tempy2;
483
+ }
484
+
485
+ public final static void mulToOutUnsafe(final Mat22 A, final Mat22 B, final Mat22 out) {
486
+ assert (out != A);
487
+ assert (out != B);
488
+ out.ex.x = A.ex.x * B.ex.x + A.ey.x * B.ex.y;
489
+ out.ex.y = A.ex.y * B.ex.x + A.ey.y * B.ex.y;
490
+ out.ey.x = A.ex.x * B.ey.x + A.ey.x * B.ey.y;
491
+ out.ey.y = A.ex.y * B.ey.x + A.ey.y * B.ey.y;
492
+ }
493
+
494
+ public final static Vec2 mulTrans(final Mat22 R, final Vec2 v) {
495
+ return new Vec2((v.x * R.ex.x + v.y * R.ex.y), (v.x * R.ey.x + v.y * R.ey.y));
496
+ }
497
+
498
+ public final static void mulTransToOut(final Mat22 R, final Vec2 v, final Vec2 out) {
499
+ float outx = v.x * R.ex.x + v.y * R.ex.y;
500
+ out.y = v.x * R.ey.x + v.y * R.ey.y;
501
+ out.x = outx;
502
+ }
503
+
504
+ public final static void mulTransToOutUnsafe(final Mat22 R, final Vec2 v, final Vec2 out) {
505
+ assert (out != v);
506
+ out.y = v.x * R.ey.x + v.y * R.ey.y;
507
+ out.x = v.x * R.ex.x + v.y * R.ex.y;
508
+ }
509
+
510
+ public final static Mat22 mulTrans(final Mat22 A, final Mat22 B) {
511
+ final Mat22 C = new Mat22();
512
+ C.ex.x = A.ex.x * B.ex.x + A.ex.y * B.ex.y;
513
+ C.ex.y = A.ey.x * B.ex.x + A.ey.y * B.ex.y;
514
+ C.ey.x = A.ex.x * B.ey.x + A.ex.y * B.ey.y;
515
+ C.ey.y = A.ey.x * B.ey.x + A.ey.y * B.ey.y;
516
+ return C;
517
+ }
518
+
519
+ public final static void mulTransToOut(final Mat22 A, final Mat22 B, final Mat22 out) {
520
+ final float x1 = A.ex.x * B.ex.x + A.ex.y * B.ex.y;
521
+ final float y1 = A.ey.x * B.ex.x + A.ey.y * B.ex.y;
522
+ final float x2 = A.ex.x * B.ey.x + A.ex.y * B.ey.y;
523
+ final float y2 = A.ey.x * B.ey.x + A.ey.y * B.ey.y;
524
+
525
+ out.ex.x = x1;
526
+ out.ex.y = y1;
527
+ out.ey.x = x2;
528
+ out.ey.y = y2;
529
+ }
530
+
531
+ public final static void mulTransToOutUnsafe(final Mat22 A, final Mat22 B, final Mat22 out) {
532
+ assert (A != out);
533
+ assert (B != out);
534
+ out.ex.x = A.ex.x * B.ex.x + A.ex.y * B.ex.y;
535
+ out.ex.y = A.ey.x * B.ex.x + A.ey.y * B.ex.y;
536
+ out.ey.x = A.ex.x * B.ey.x + A.ex.y * B.ey.y;
537
+ out.ey.y = A.ey.x * B.ey.x + A.ey.y * B.ey.y;
538
+ }
539
+
540
+ public final static Mat22 createRotationalTransform(float angle) {
541
+ Mat22 mat = new Mat22();
542
+ final float c = MathUtils.cos(angle);
543
+ final float s = MathUtils.sin(angle);
544
+ mat.ex.x = c;
545
+ mat.ey.x = -s;
546
+ mat.ex.y = s;
547
+ mat.ey.y = c;
548
+ return mat;
549
+ }
550
+
551
+ public final static void createRotationalTransform(float angle, Mat22 out) {
552
+ final float c = MathUtils.cos(angle);
553
+ final float s = MathUtils.sin(angle);
554
+ out.ex.x = c;
555
+ out.ey.x = -s;
556
+ out.ex.y = s;
557
+ out.ey.y = c;
558
+ }
559
+
560
+ public final static Mat22 createScaleTransform(float scale) {
561
+ Mat22 mat = new Mat22();
562
+ mat.ex.x = scale;
563
+ mat.ey.y = scale;
564
+ return mat;
565
+ }
566
+
567
+ public final static void createScaleTransform(float scale, Mat22 out) {
568
+ out.ex.x = scale;
569
+ out.ey.y = scale;
570
+ }
571
+
572
+ @Override
573
+ public int hashCode() {
574
+ final int prime = 31;
575
+ int result = 1;
576
+ result = prime * result + ((ex == null) ? 0 : ex.hashCode());
577
+ result = prime * result + ((ey == null) ? 0 : ey.hashCode());
578
+ return result;
579
+ }
580
+
581
+ @Override
582
+ public boolean equals(Object obj) {
583
+ if (this == obj) {
584
+ return true;
585
+ }
586
+ if (obj == null) {
587
+ return false;
588
+ }
589
+ if (getClass() != obj.getClass()) {
590
+ return false;
591
+ }
592
+ Mat22 other = (Mat22) obj;
593
+ if (ex == null) {
594
+ if (other.ex != null) {
595
+ return false;
596
+ }
597
+ } else if (!ex.equals(other.ex)) {
598
+ return false;
599
+ }
600
+ if (ey == null) {
601
+ if (other.ey != null) {
602
+ return false;
603
+ }
604
+ } else if (!ey.equals(other.ey)) {
605
+ return false;
606
+ }
607
+ return true;
608
+ }
609
+ }