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,116 @@
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
+ * This describes the motion of a body/shape for TOI computation. Shapes are defined with respect to
30
+ * the body origin, which may no coincide with the center of mass. However, to support dynamics we
31
+ * must interpolate the center of mass position.
32
+ */
33
+ public class Sweep implements Serializable {
34
+ private static final long serialVersionUID = 1L;
35
+
36
+ /** Local center of mass position */
37
+ public final Vec2 localCenter;
38
+ /** Center world positions */
39
+ public final Vec2 c0, c;
40
+ /** World angles */
41
+ public float a0, a;
42
+
43
+ /** Fraction of the current time step in the range [0,1] c0 and a0 are the positions at alpha0. */
44
+ public float alpha0;
45
+
46
+ public String toString() {
47
+ String s = "Sweep:\nlocalCenter: " + localCenter + "\n";
48
+ s += "c0: " + c0 + ", c: " + c + "\n";
49
+ s += "a0: " + a0 + ", a: " + a + "\n";
50
+ s += "alpha0: " + alpha0;
51
+ return s;
52
+ }
53
+
54
+ public Sweep() {
55
+ localCenter = new Vec2();
56
+ c0 = new Vec2();
57
+ c = new Vec2();
58
+ }
59
+
60
+ public final void normalize() {
61
+ float d = MathUtils.TWOPI * MathUtils.floor(a0 / MathUtils.TWOPI);
62
+ a0 -= d;
63
+ a -= d;
64
+ }
65
+
66
+ public final Sweep set(Sweep other) {
67
+ localCenter.set(other.localCenter);
68
+ c0.set(other.c0);
69
+ c.set(other.c);
70
+ a0 = other.a0;
71
+ a = other.a;
72
+ alpha0 = other.alpha0;
73
+ return this;
74
+ }
75
+
76
+ /**
77
+ * Get the interpolated transform at a specific time.
78
+ *
79
+ * @param xf the result is placed here - must not be null
80
+ * @param t the normalized time in [0,1].
81
+ */
82
+ public final void getTransform(final Transform xf, final float beta) {
83
+ assert (xf != null);
84
+ // xf->p = (1.0f - beta) * c0 + beta * c;
85
+ // float32 angle = (1.0f - beta) * a0 + beta * a;
86
+ // xf->q.Set(angle);
87
+ xf.p.x = (1.0f - beta) * c0.x + beta * c.x;
88
+ xf.p.y = (1.0f - beta) * c0.y + beta * c.y;
89
+ float angle = (1.0f - beta) * a0 + beta * a;
90
+ xf.q.set(angle);
91
+
92
+ // Shift to origin
93
+ // xf->p -= b2Mul(xf->q, localCenter);
94
+ final Rot q = xf.q;
95
+ xf.p.x -= q.c * localCenter.x - q.s * localCenter.y;
96
+ xf.p.y -= q.s * localCenter.x + q.c * localCenter.y;
97
+ }
98
+
99
+ /**
100
+ * Advance the sweep forward, yielding a new initial state.
101
+ *
102
+ * @param alpha the new initial time.
103
+ */
104
+ public final void advance(final float alpha) {
105
+ assert(alpha0 < 1.0f);
106
+ // float32 beta = (alpha - alpha0) / (1.0f - alpha0);
107
+ // c0 += beta * (c - c0);
108
+ // a0 += beta * (a - a0);
109
+ // alpha0 = alpha;
110
+ float beta = (alpha - alpha0) / (1.0f - alpha0);
111
+ c0.x += beta * (c.x - c0.x);
112
+ c0.y += beta * (c.y - c0.y);
113
+ a0 += beta * (a - a0);
114
+ alpha0 = alpha;
115
+ }
116
+ }
@@ -0,0 +1,46 @@
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
+ /**
27
+ * Timer for profiling
28
+ *
29
+ * @author Daniel
30
+ */
31
+ public class Timer {
32
+
33
+ private long resetNanos;
34
+
35
+ public Timer() {
36
+ reset();
37
+ }
38
+
39
+ public final void reset() {
40
+ resetNanos = System.nanoTime();
41
+ }
42
+
43
+ public float getMilliseconds() {
44
+ return (System.nanoTime() - resetNanos) / 1000 * 1f / 1000;
45
+ }
46
+ }
@@ -0,0 +1,203 @@
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
+ // updated to rev 100
31
+ /**
32
+ * A transform contains translation and rotation. It is used to represent the
33
+ * position and orientation of rigid frames.
34
+ */
35
+ public class Transform implements Serializable {
36
+
37
+ private static final long serialVersionUID = 1L;
38
+
39
+ /**
40
+ * The translation caused by the transform
41
+ */
42
+ public final Vec2 p;
43
+
44
+ /**
45
+ * A matrix representing a rotation
46
+ */
47
+ public final Rot q;
48
+
49
+ /**
50
+ * The default constructor.
51
+ */
52
+ public Transform() {
53
+ p = new Vec2();
54
+ q = new Rot();
55
+ }
56
+
57
+ /**
58
+ * Initialize as a copy of another transform.
59
+ *
60
+ * @param xf
61
+ */
62
+ public Transform(final Transform xf) {
63
+ p = xf.p.clone();
64
+ q = xf.q.clone();
65
+ }
66
+
67
+ /**
68
+ * Initialize using a position vector and a rotation matrix.
69
+ *
70
+ * @param _position
71
+ * @param _R
72
+ */
73
+ public Transform(final Vec2 _position, final Rot _R) {
74
+ p = _position.clone();
75
+ q = _R.clone();
76
+ }
77
+
78
+ /**
79
+ * Set this to equal another transform.
80
+ *
81
+ * @param xf
82
+ * @return
83
+ */
84
+ public final Transform set(final Transform xf) {
85
+ p.set(xf.p);
86
+ q.set(xf.q);
87
+ return this;
88
+ }
89
+
90
+ /**
91
+ * Set this based on the position and angle.
92
+ *
93
+ * @param p
94
+ * @param angle
95
+ */
96
+ public final void set(Vec2 p, float angle) {
97
+ this.p.set(p);
98
+ q.set(angle);
99
+ }
100
+
101
+ /**
102
+ * Set this to the identity transform.
103
+ */
104
+ public final void setIdentity() {
105
+ p.setZero();
106
+ q.setIdentity();
107
+ }
108
+
109
+ public final static Vec2 mul(final Transform T, final Vec2 v) {
110
+ return new Vec2((T.q.c * v.x - T.q.s * v.y) + T.p.x, (T.q.s * v.x + T.q.c * v.y) + T.p.y);
111
+ }
112
+
113
+ public final static void mulToOut(final Transform T, final Vec2 v, final Vec2 out) {
114
+ final float tempy = (T.q.s * v.x + T.q.c * v.y) + T.p.y;
115
+ out.x = (T.q.c * v.x - T.q.s * v.y) + T.p.x;
116
+ out.y = tempy;
117
+ }
118
+
119
+ public final static void mulToOutUnsafe(final Transform T, final Vec2 v, final Vec2 out) {
120
+ assert (v != out);
121
+ out.x = (T.q.c * v.x - T.q.s * v.y) + T.p.x;
122
+ out.y = (T.q.s * v.x + T.q.c * v.y) + T.p.y;
123
+ }
124
+
125
+ public final static Vec2 mulTrans(final Transform T, final Vec2 v) {
126
+ final float px = v.x - T.p.x;
127
+ final float py = v.y - T.p.y;
128
+ return new Vec2((T.q.c * px + T.q.s * py), (-T.q.s * px + T.q.c * py));
129
+ }
130
+
131
+ public final static void mulTransToOut(final Transform T, final Vec2 v, final Vec2 out) {
132
+ final float px = v.x - T.p.x;
133
+ final float py = v.y - T.p.y;
134
+ final float tempy = (-T.q.s * px + T.q.c * py);
135
+ out.x = (T.q.c * px + T.q.s * py);
136
+ out.y = tempy;
137
+ }
138
+
139
+ public final static void mulTransToOutUnsafe(final Transform T, final Vec2 v, final Vec2 out) {
140
+ assert (v != out);
141
+ final float px = v.x - T.p.x;
142
+ final float py = v.y - T.p.y;
143
+ out.x = (T.q.c * px + T.q.s * py);
144
+ out.y = (-T.q.s * px + T.q.c * py);
145
+ }
146
+
147
+ public final static Transform mul(final Transform A, final Transform B) {
148
+ Transform C = new Transform();
149
+ Rot.mulUnsafe(A.q, B.q, C.q);
150
+ Rot.mulToOutUnsafe(A.q, B.p, C.p);
151
+ C.p.addLocal(A.p);
152
+ return C;
153
+ }
154
+
155
+ public final static void mulToOut(final Transform A, final Transform B, final Transform out) {
156
+ assert (out != A);
157
+ Rot.mul(A.q, B.q, out.q);
158
+ Rot.mulToOut(A.q, B.p, out.p);
159
+ out.p.addLocal(A.p);
160
+ }
161
+
162
+ public final static void mulToOutUnsafe(final Transform A, final Transform B, final Transform out) {
163
+ assert (out != B);
164
+ assert (out != A);
165
+ Rot.mulUnsafe(A.q, B.q, out.q);
166
+ Rot.mulToOutUnsafe(A.q, B.p, out.p);
167
+ out.p.addLocal(A.p);
168
+ }
169
+
170
+ private static Vec2 pool = new Vec2();
171
+
172
+ public final static Transform mulTrans(final Transform A, final Transform B) {
173
+ Transform C = new Transform();
174
+ Rot.mulTransUnsafe(A.q, B.q, C.q);
175
+ pool.set(B.p).subLocal(A.p);
176
+ Rot.mulTransUnsafe(A.q, pool, C.p);
177
+ return C;
178
+ }
179
+
180
+ public final static void mulTransToOut(final Transform A, final Transform B, final Transform out) {
181
+ assert (out != A);
182
+ Rot.mulTrans(A.q, B.q, out.q);
183
+ pool.set(B.p).subLocal(A.p);
184
+ Rot.mulTrans(A.q, pool, out.p);
185
+ }
186
+
187
+ public final static void mulTransToOutUnsafe(final Transform A, final Transform B,
188
+ final Transform out) {
189
+ assert (out != A);
190
+ assert (out != B);
191
+ Rot.mulTransUnsafe(A.q, B.q, out.q);
192
+ pool.set(B.p).subLocal(A.p);
193
+ Rot.mulTransUnsafe(A.q, pool, out.p);
194
+ }
195
+
196
+ @Override
197
+ public final String toString() {
198
+ String s = "XForm:\n";
199
+ s += "Position: " + p + "\n";
200
+ s += "R: \n" + q + "\n";
201
+ return s;
202
+ }
203
+ }