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,54 @@
1
+ /*******************************************************************************
2
+ * Copyright (c) 2013, Daniel Murphy
3
+ * All rights reserved.
4
+ *
5
+ * Redistribution and use in source and binary forms, with or without modification,
6
+ * are permitted provided that the following conditions are met:
7
+ * * Redistributions of source code must retain the above copyright notice,
8
+ * this list of conditions and the following disclaimer.
9
+ * * Redistributions in binary form must reproduce the above copyright notice,
10
+ * this list of conditions and the following disclaimer in the documentation
11
+ * and/or other materials provided with the distribution.
12
+ *
13
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
14
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
15
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
16
+ * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
17
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
18
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
19
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
20
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
21
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
22
+ * POSSIBILITY OF SUCH DAMAGE.
23
+ ******************************************************************************/
24
+ package org.jbox2d.collision.broadphase;
25
+
26
+ import org.jbox2d.collision.AABB;
27
+
28
+ public class DynamicTreeNode {
29
+ /**
30
+ * Enlarged AABB
31
+ */
32
+ public final AABB aabb = new AABB();
33
+
34
+ public Object userData;
35
+
36
+ protected DynamicTreeNode parent;
37
+
38
+ protected DynamicTreeNode child1;
39
+ protected DynamicTreeNode child2;
40
+ protected final int id;
41
+ protected int height;
42
+
43
+ public Object getUserData() {
44
+ return userData;
45
+ }
46
+
47
+ public void setUserData(Object argData) {
48
+ userData = argData;
49
+ }
50
+
51
+ protected DynamicTreeNode(int id) {
52
+ this.id = id;
53
+ }
54
+ }
@@ -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.collision.broadphase;
25
+
26
+ // updated to rev 100
27
+ /**
28
+ * Java note: at the "creation" of each node, a random key is given to that node, and that's what we
29
+ * sort from.
30
+ */
31
+ public class Pair implements Comparable<Pair> {
32
+ public int proxyIdA;
33
+ public int proxyIdB;
34
+
35
+ public int compareTo(Pair pair2) {
36
+ if (this.proxyIdA < pair2.proxyIdA) {
37
+ return -1;
38
+ }
39
+
40
+ if (this.proxyIdA == pair2.proxyIdA) {
41
+ return proxyIdB < pair2.proxyIdB ? -1 : proxyIdB == pair2.proxyIdB ? 0 : 1;
42
+ }
43
+
44
+ return 1;
45
+ }
46
+ }
@@ -0,0 +1,264 @@
1
+ /*******************************************************************************
2
+ * Copyright (c) 2013, Daniel Murphy
3
+ * All rights reserved.
4
+ *
5
+ * Redistribution and use in source and binary forms, with or without modification,
6
+ * are permitted provided that the following conditions are met:
7
+ * * Redistributions of source code must retain the above copyright notice,
8
+ * this list of conditions and the following disclaimer.
9
+ * * Redistributions in binary form must reproduce the above copyright notice,
10
+ * this list of conditions and the following disclaimer in the documentation
11
+ * and/or other materials provided with the distribution.
12
+ *
13
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
14
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
15
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
16
+ * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
17
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
18
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
19
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
20
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
21
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
22
+ * POSSIBILITY OF SUCH DAMAGE.
23
+ ******************************************************************************/
24
+ package org.jbox2d.collision.shapes;
25
+
26
+
27
+ import org.jbox2d.collision.AABB;
28
+ import org.jbox2d.collision.RayCastInput;
29
+ import org.jbox2d.collision.RayCastOutput;
30
+ import org.jbox2d.common.MathUtils;
31
+ import org.jbox2d.common.Rot;
32
+ import org.jbox2d.common.Settings;
33
+ import org.jbox2d.common.Transform;
34
+ import org.jbox2d.common.Vec2;
35
+
36
+ /**
37
+ * A chain shape is a free form sequence of line segments. The chain has two-sided collision, so you
38
+ * can use inside and outside collision. Therefore, you may use any winding order. Connectivity
39
+ * information is used to create smooth collisions. WARNING: The chain will not collide properly if
40
+ * there are self-intersections.
41
+ *
42
+ * @author Daniel
43
+ */
44
+ public class ChainShape extends Shape {
45
+
46
+ public Vec2[] m_vertices;
47
+ public int m_count;
48
+ public final Vec2 m_prevVertex = new Vec2(), m_nextVertex = new Vec2();
49
+ public boolean m_hasPrevVertex = false, m_hasNextVertex = false;
50
+
51
+ private final EdgeShape pool0 = new EdgeShape();
52
+
53
+ public ChainShape() {
54
+ super(ShapeType.CHAIN);
55
+ m_vertices = null;
56
+ m_radius = Settings.polygonRadius;
57
+ m_count = 0;
58
+ }
59
+
60
+ public void clear() {
61
+ m_vertices = null;
62
+ m_count = 0;
63
+ }
64
+
65
+ @Override
66
+ public int getChildCount() {
67
+ return m_count - 1;
68
+ }
69
+
70
+ /**
71
+ * Get a child edge.
72
+ * @param edge
73
+ * @param index
74
+ */
75
+ public void getChildEdge(EdgeShape edge, int index) {
76
+ assert (0 <= index && index < m_count - 1);
77
+ edge.m_radius = m_radius;
78
+
79
+ final Vec2 v0 = m_vertices[index + 0];
80
+ final Vec2 v1 = m_vertices[index + 1];
81
+ edge.m_vertex1.x = v0.x;
82
+ edge.m_vertex1.y = v0.y;
83
+ edge.m_vertex2.x = v1.x;
84
+ edge.m_vertex2.y = v1.y;
85
+
86
+ if (index > 0) {
87
+ Vec2 v = m_vertices[index - 1];
88
+ edge.m_vertex0.x = v.x;
89
+ edge.m_vertex0.y = v.y;
90
+ edge.m_hasVertex0 = true;
91
+ } else {
92
+ edge.m_vertex0.x = m_prevVertex.x;
93
+ edge.m_vertex0.y = m_prevVertex.y;
94
+ edge.m_hasVertex0 = m_hasPrevVertex;
95
+ }
96
+
97
+ if (index < m_count - 2) {
98
+ Vec2 v = m_vertices[index + 2];
99
+ edge.m_vertex3.x = v.x;
100
+ edge.m_vertex3.y = v.y;
101
+ edge.m_hasVertex3 = true;
102
+ } else {
103
+ edge.m_vertex3.x = m_nextVertex.x;
104
+ edge.m_vertex3.y = m_nextVertex.y;
105
+ edge.m_hasVertex3 = m_hasNextVertex;
106
+ }
107
+ }
108
+
109
+ @Override
110
+ public float computeDistanceToOut(Transform xf, Vec2 p, int childIndex, Vec2 normalOut) {
111
+ final EdgeShape edge = pool0;
112
+ getChildEdge(edge, childIndex);
113
+ return edge.computeDistanceToOut(xf, p, 0, normalOut);
114
+ }
115
+
116
+ @Override
117
+ public boolean testPoint(Transform xf, Vec2 p) {
118
+ return false;
119
+ }
120
+
121
+ @Override
122
+ public boolean raycast(RayCastOutput output, RayCastInput input, Transform xf, int childIndex) {
123
+ assert (childIndex < m_count);
124
+
125
+ final EdgeShape edgeShape = pool0;
126
+
127
+ int i1 = childIndex;
128
+ int i2 = childIndex + 1;
129
+ if (i2 == m_count) {
130
+ i2 = 0;
131
+ }
132
+ Vec2 v = m_vertices[i1];
133
+ edgeShape.m_vertex1.x = v.x;
134
+ edgeShape.m_vertex1.y = v.y;
135
+ Vec2 v1 = m_vertices[i2];
136
+ edgeShape.m_vertex2.x = v1.x;
137
+ edgeShape.m_vertex2.y = v1.y;
138
+
139
+ return edgeShape.raycast(output, input, xf, 0);
140
+ }
141
+
142
+ @Override
143
+ public void computeAABB(AABB aabb, Transform xf, int childIndex) {
144
+ assert (childIndex < m_count);
145
+ final Vec2 lower = aabb.lowerBound;
146
+ final Vec2 upper = aabb.upperBound;
147
+
148
+ int i1 = childIndex;
149
+ int i2 = childIndex + 1;
150
+ if (i2 == m_count) {
151
+ i2 = 0;
152
+ }
153
+
154
+ final Vec2 vi1 = m_vertices[i1];
155
+ final Vec2 vi2 = m_vertices[i2];
156
+ final Rot xfq = xf.q;
157
+ final Vec2 xfp = xf.p;
158
+ float v1x = (xfq.c * vi1.x - xfq.s * vi1.y) + xfp.x;
159
+ float v1y = (xfq.s * vi1.x + xfq.c * vi1.y) + xfp.y;
160
+ float v2x = (xfq.c * vi2.x - xfq.s * vi2.y) + xfp.x;
161
+ float v2y = (xfq.s * vi2.x + xfq.c * vi2.y) + xfp.y;
162
+
163
+ lower.x = v1x < v2x ? v1x : v2x;
164
+ lower.y = v1y < v2y ? v1y : v2y;
165
+ upper.x = v1x > v2x ? v1x : v2x;
166
+ upper.y = v1y > v2y ? v1y : v2y;
167
+ }
168
+
169
+ @Override
170
+ public void computeMass(MassData massData, float density) {
171
+ massData.mass = 0.0f;
172
+ massData.center.setZero();
173
+ massData.I = 0.0f;
174
+ }
175
+
176
+ @Override
177
+ public Shape clone() {
178
+ ChainShape clone = new ChainShape();
179
+ clone.createChain(m_vertices, m_count);
180
+ clone.m_prevVertex.set(m_prevVertex);
181
+ clone.m_nextVertex.set(m_nextVertex);
182
+ clone.m_hasPrevVertex = m_hasPrevVertex;
183
+ clone.m_hasNextVertex = m_hasNextVertex;
184
+ return clone;
185
+ }
186
+
187
+ /**
188
+ * Create a loop. This automatically adjusts connectivity.
189
+ *
190
+ * @param vertices an array of vertices, these are copied
191
+ * @param count the vertex count
192
+ */
193
+ public void createLoop(final Vec2[] vertices, int count) {
194
+ assert (m_vertices == null && m_count == 0);
195
+ assert (count >= 3);
196
+ m_count = count + 1;
197
+ m_vertices = new Vec2[m_count];
198
+ for (int i = 1; i < count; i++) {
199
+ Vec2 v1 = vertices[i - 1];
200
+ Vec2 v2 = vertices[i];
201
+ // If the code crashes here, it means your vertices are too close together.
202
+ if (MathUtils.distanceSquared(v1, v2) < Settings.linearSlop * Settings.linearSlop) {
203
+ throw new RuntimeException("Vertices of chain shape are too close together");
204
+ }
205
+ }
206
+ for (int i = 0; i < count; i++) {
207
+ m_vertices[i] = new Vec2(vertices[i]);
208
+ }
209
+ m_vertices[count] = new Vec2(m_vertices[0]);
210
+ m_prevVertex.set(m_vertices[m_count - 2]);
211
+ m_nextVertex.set(m_vertices[1]);
212
+ m_hasPrevVertex = true;
213
+ m_hasNextVertex = true;
214
+ }
215
+
216
+ /**
217
+ * Create a chain with isolated end vertices.
218
+ *
219
+ * @param vertices an array of vertices, these are copied
220
+ * @param count the vertex count
221
+ */
222
+ public void createChain(final Vec2 vertices[], int count) {
223
+ assert (m_vertices == null && m_count == 0);
224
+ assert (count >= 2);
225
+ m_count = count;
226
+ m_vertices = new Vec2[m_count];
227
+ for (int i = 1; i < m_count; i++) {
228
+ Vec2 v1 = vertices[i - 1];
229
+ Vec2 v2 = vertices[i];
230
+ // If the code crashes here, it means your vertices are too close together.
231
+ if (MathUtils.distanceSquared(v1, v2) < Settings.linearSlop * Settings.linearSlop) {
232
+ throw new RuntimeException("Vertices of chain shape are too close together");
233
+ }
234
+ }
235
+ for (int i = 0; i < m_count; i++) {
236
+ m_vertices[i] = new Vec2(vertices[i]);
237
+ }
238
+ m_hasPrevVertex = false;
239
+ m_hasNextVertex = false;
240
+
241
+ m_prevVertex.setZero();
242
+ m_nextVertex.setZero();
243
+ }
244
+
245
+ /**
246
+ * Establish connectivity to a vertex that precedes the first vertex. Don't call this for loops.
247
+ *
248
+ * @param prevVertex
249
+ */
250
+ public void setPrevVertex(final Vec2 prevVertex) {
251
+ m_prevVertex.set(prevVertex);
252
+ m_hasPrevVertex = true;
253
+ }
254
+
255
+ /**
256
+ * Establish connectivity to a vertex that follows the last vertex. Don't call this for loops.
257
+ *
258
+ * @param nextVertex
259
+ */
260
+ public void setNextVertex(final Vec2 nextVertex) {
261
+ m_nextVertex.set(nextVertex);
262
+ m_hasNextVertex = true;
263
+ }
264
+ }
@@ -0,0 +1,207 @@
1
+ /*******************************************************************************
2
+ * Copyright (c) 2013, Daniel Murphy
3
+ * All rights reserved.
4
+ *
5
+ * Redistribution and use in source and binary forms, with or without modification,
6
+ * are permitted provided that the following conditions are met:
7
+ * * Redistributions of source code must retain the above copyright notice,
8
+ * this list of conditions and the following disclaimer.
9
+ * * Redistributions in binary form must reproduce the above copyright notice,
10
+ * this list of conditions and the following disclaimer in the documentation
11
+ * and/or other materials provided with the distribution.
12
+ *
13
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
14
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
15
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
16
+ * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
17
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
18
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
19
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
20
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
21
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
22
+ * POSSIBILITY OF SUCH DAMAGE.
23
+ ******************************************************************************/
24
+ package org.jbox2d.collision.shapes;
25
+
26
+ import org.jbox2d.collision.AABB;
27
+ import org.jbox2d.collision.RayCastInput;
28
+ import org.jbox2d.collision.RayCastOutput;
29
+
30
+ import org.jbox2d.common.MathUtils;
31
+ import org.jbox2d.common.Rot;
32
+ import org.jbox2d.common.Settings;
33
+ import org.jbox2d.common.Transform;
34
+ import org.jbox2d.common.Vec2;
35
+
36
+ /**
37
+ * A circle shape.
38
+ */
39
+ public class CircleShape extends Shape {
40
+
41
+ public final Vec2 m_p;
42
+
43
+ public CircleShape() {
44
+ super(ShapeType.CIRCLE);
45
+ m_p = new Vec2();
46
+ m_radius = 0;
47
+ }
48
+
49
+ @Override
50
+ public final Shape clone() {
51
+ CircleShape shape = new CircleShape();
52
+ shape.m_p.x = m_p.x;
53
+ shape.m_p.y = m_p.y;
54
+ shape.m_radius = m_radius;
55
+ return shape;
56
+ }
57
+
58
+ @Override
59
+ public final int getChildCount() {
60
+ return 1;
61
+ }
62
+
63
+ /**
64
+ * Get the supporting vertex index in the given direction.
65
+ *
66
+ * @param d
67
+ * @return
68
+ */
69
+ public final int getSupport(final Vec2 d) {
70
+ return 0;
71
+ }
72
+
73
+ /**
74
+ * Get the supporting vertex in the given direction.
75
+ *
76
+ * @param d
77
+ * @return
78
+ */
79
+ public final Vec2 getSupportVertex(final Vec2 d) {
80
+ return m_p;
81
+ }
82
+
83
+ /**
84
+ * Get the vertex count.
85
+ *
86
+ * @return
87
+ */
88
+ public final int getVertexCount() {
89
+ return 1;
90
+ }
91
+
92
+ /**
93
+ * Get a vertex by index.
94
+ *
95
+ * @param index
96
+ * @return
97
+ */
98
+ public final Vec2 getVertex(final int index) {
99
+ assert (index == 0);
100
+ return m_p;
101
+ }
102
+
103
+ @Override
104
+ public final boolean testPoint(final Transform transform, final Vec2 p) {
105
+ // Rot.mulToOutUnsafe(transform.q, m_p, center);
106
+ // center.addLocal(transform.p);
107
+ //
108
+ // final Vec2 d = center.subLocal(p).negateLocal();
109
+ // return Vec2.dot(d, d) <= m_radius * m_radius;
110
+ final Rot q = transform.q;
111
+ final Vec2 tp = transform.p;
112
+ float centerx = -(q.c * m_p.x - q.s * m_p.y + tp.x - p.x);
113
+ float centery = -(q.s * m_p.x + q.c * m_p.y + tp.y - p.y);
114
+
115
+ return centerx * centerx + centery * centery <= m_radius * m_radius;
116
+ }
117
+
118
+ @Override
119
+ public float computeDistanceToOut(Transform xf, Vec2 p, int childIndex, Vec2 normalOut) {
120
+ final Rot xfq = xf.q;
121
+ float centerx = xfq.c * m_p.x - xfq.s * m_p.y + xf.p.x;
122
+ float centery = xfq.s * m_p.x + xfq.c * m_p.y + xf.p.y;
123
+ float dx = p.x - centerx;
124
+ float dy = p.y - centery;
125
+ float d1 = MathUtils.sqrt(dx * dx + dy * dy);
126
+ normalOut.x = dx * 1 / d1;
127
+ normalOut.y = dy * 1 / d1;
128
+ return d1 - m_radius;
129
+ }
130
+
131
+ // Collision Detection in Interactive 3D Environments by Gino van den Bergen
132
+ // From Section 3.1.2
133
+ // x = s + a * r
134
+ // norm(x) = radius
135
+ @Override
136
+ public final boolean raycast(RayCastOutput output, RayCastInput input, Transform transform,
137
+ int childIndex) {
138
+
139
+ final Vec2 inputp1 = input.p1;
140
+ final Vec2 inputp2 = input.p2;
141
+ final Rot tq = transform.q;
142
+ final Vec2 tp = transform.p;
143
+
144
+ // Rot.mulToOutUnsafe(transform.q, m_p, position);
145
+ // position.addLocal(transform.p);
146
+ final float positionx = tq.c * m_p.x - tq.s * m_p.y + tp.x;
147
+ final float positiony = tq.s * m_p.x + tq.c * m_p.y + tp.y;
148
+
149
+ final float sx = inputp1.x - positionx;
150
+ final float sy = inputp1.y - positiony;
151
+ // final float b = Vec2.dot(s, s) - m_radius * m_radius;
152
+ final float b = sx * sx + sy * sy - m_radius * m_radius;
153
+
154
+ // Solve quadratic equation.
155
+ final float rx = inputp2.x - inputp1.x;
156
+ final float ry = inputp2.y - inputp1.y;
157
+ // final float c = Vec2.dot(s, r);
158
+ // final float rr = Vec2.dot(r, r);
159
+ final float c = sx * rx + sy * ry;
160
+ final float rr = rx * rx + ry * ry;
161
+ final float sigma = c * c - rr * b;
162
+
163
+ // Check for negative discriminant and short segment.
164
+ if (sigma < 0.0f || rr < Settings.EPSILON) {
165
+ return false;
166
+ }
167
+
168
+ // Find the point of intersection of the line with the circle.
169
+ float a = -(c + MathUtils.sqrt(sigma));
170
+
171
+ // Is the intersection point on the segment?
172
+ if (0.0f <= a && a <= input.maxFraction * rr) {
173
+ a /= rr;
174
+ output.fraction = a;
175
+ output.normal.x = rx * a + sx;
176
+ output.normal.y = ry * a + sy;
177
+ output.normal.normalize();
178
+ return true;
179
+ }
180
+
181
+ return false;
182
+ }
183
+
184
+ @Override
185
+ public final void computeAABB(final AABB aabb, final Transform transform, int childIndex) {
186
+ final Rot tq = transform.q;
187
+ final Vec2 tp = transform.p;
188
+ final float px = tq.c * m_p.x - tq.s * m_p.y + tp.x;
189
+ final float py = tq.s * m_p.x + tq.c * m_p.y + tp.y;
190
+
191
+ aabb.lowerBound.x = px - m_radius;
192
+ aabb.lowerBound.y = py - m_radius;
193
+ aabb.upperBound.x = px + m_radius;
194
+ aabb.upperBound.y = py + m_radius;
195
+ }
196
+
197
+ @Override
198
+ public final void computeMass(final MassData massData, final float density) {
199
+ massData.mass = density * Settings.PI * m_radius * m_radius;
200
+ massData.center.x = m_p.x;
201
+ massData.center.y = m_p.y;
202
+
203
+ // inertia about the local origin
204
+ // massData.I = massData.mass * (0.5f * m_radius * m_radius + Vec2.dot(m_p, m_p));
205
+ massData.I = massData.mass * (0.5f * m_radius * m_radius + (m_p.x * m_p.x + m_p.y * m_p.y));
206
+ }
207
+ }