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.
- checksums.yaml +4 -4
- data/.mvn/extensions.xml +8 -0
- data/.mvn/wrapper/maven-wrapper.properties +1 -0
- data/.travis.yml +23 -0
- data/CHANGELOG.md +8 -0
- data/README.md +7 -7
- data/Rakefile +1 -2
- data/lib/box2d.jar +0 -0
- data/lib/pbox2d/version.rb +1 -1
- data/lib/pbox2d.rb +1 -0
- data/pbox2d.gemspec +6 -11
- data/pom.rb +59 -0
- data/pom.xml +82 -73
- data/src/org/jbox2d/JBox2D.gwt.xml +12 -0
- data/src/org/jbox2d/callbacks/ContactAdaptor.java +27 -0
- data/src/org/jbox2d/callbacks/ContactFilter.java +59 -0
- data/src/org/jbox2d/callbacks/ContactImpulse.java +42 -0
- data/src/org/jbox2d/callbacks/ContactListener.java +87 -0
- data/src/org/jbox2d/callbacks/DebugDraw.java +297 -0
- data/src/org/jbox2d/callbacks/DestructionListener.java +53 -0
- data/src/org/jbox2d/callbacks/PairCallback.java +29 -0
- data/src/org/jbox2d/callbacks/ParticleDestructionListener.java +20 -0
- data/src/org/jbox2d/callbacks/ParticleQueryCallback.java +19 -0
- data/src/org/jbox2d/callbacks/ParticleRaycastCallback.java +19 -0
- data/src/org/jbox2d/callbacks/QueryCallback.java +45 -0
- data/src/org/jbox2d/callbacks/RayCastCallback.java +55 -0
- data/src/org/jbox2d/callbacks/TreeCallback.java +42 -0
- data/src/org/jbox2d/callbacks/TreeRayCastCallback.java +44 -0
- data/src/org/jbox2d/collision/AABB.java +338 -0
- data/src/org/jbox2d/collision/Collision.java +1444 -0
- data/src/org/jbox2d/collision/ContactID.java +106 -0
- data/src/org/jbox2d/collision/Distance.java +773 -0
- data/src/org/jbox2d/collision/DistanceInput.java +41 -0
- data/src/org/jbox2d/collision/DistanceOutput.java +43 -0
- data/src/org/jbox2d/collision/Manifold.java +116 -0
- data/src/org/jbox2d/collision/ManifoldPoint.java +104 -0
- data/src/org/jbox2d/collision/RayCastInput.java +47 -0
- data/src/org/jbox2d/collision/RayCastOutput.java +46 -0
- data/src/org/jbox2d/collision/TimeOfImpact.java +526 -0
- data/src/org/jbox2d/collision/WorldManifold.java +200 -0
- data/src/org/jbox2d/collision/broadphase/BroadPhase.java +92 -0
- data/src/org/jbox2d/collision/broadphase/BroadPhaseStrategy.java +88 -0
- data/src/org/jbox2d/collision/broadphase/DefaultBroadPhaseBuffer.java +268 -0
- data/src/org/jbox2d/collision/broadphase/DynamicTree.java +883 -0
- data/src/org/jbox2d/collision/broadphase/DynamicTreeFlatNodes.java +873 -0
- data/src/org/jbox2d/collision/broadphase/DynamicTreeNode.java +54 -0
- data/src/org/jbox2d/collision/broadphase/Pair.java +46 -0
- data/src/org/jbox2d/collision/shapes/ChainShape.java +264 -0
- data/src/org/jbox2d/collision/shapes/CircleShape.java +207 -0
- data/src/org/jbox2d/collision/shapes/EdgeShape.java +254 -0
- data/src/org/jbox2d/collision/shapes/MassData.java +105 -0
- data/src/org/jbox2d/collision/shapes/PolygonShape.java +718 -0
- data/src/org/jbox2d/collision/shapes/Shape.java +136 -0
- data/src/org/jbox2d/collision/shapes/ShapeType.java +32 -0
- data/src/org/jbox2d/common/BufferUtils.java +209 -0
- data/src/org/jbox2d/common/Color3f.java +88 -0
- data/src/org/jbox2d/common/IViewportTransform.java +133 -0
- data/src/org/jbox2d/common/Mat22.java +609 -0
- data/src/org/jbox2d/common/Mat33.java +290 -0
- data/src/org/jbox2d/common/MathUtils.java +335 -0
- data/src/org/jbox2d/common/OBBViewportTransform.java +174 -0
- data/src/org/jbox2d/common/PlatformMathUtils.java +46 -0
- data/src/org/jbox2d/common/RaycastResult.java +37 -0
- data/src/org/jbox2d/common/Rot.java +150 -0
- data/src/org/jbox2d/common/Settings.java +246 -0
- data/src/org/jbox2d/common/Sweep.java +116 -0
- data/src/org/jbox2d/common/Timer.java +46 -0
- data/src/org/jbox2d/common/Transform.java +203 -0
- data/src/org/jbox2d/common/Vec2.java +388 -0
- data/src/org/jbox2d/common/Vec3.java +170 -0
- data/src/org/jbox2d/dynamics/Body.java +1246 -0
- data/src/org/jbox2d/dynamics/BodyDef.java +382 -0
- data/src/org/jbox2d/dynamics/BodyType.java +41 -0
- data/src/org/jbox2d/dynamics/ContactManager.java +293 -0
- data/src/org/jbox2d/dynamics/Filter.java +62 -0
- data/src/org/jbox2d/dynamics/Fixture.java +454 -0
- data/src/org/jbox2d/dynamics/FixtureDef.java +214 -0
- data/src/org/jbox2d/dynamics/FixtureProxy.java +38 -0
- data/src/org/jbox2d/dynamics/Island.java +602 -0
- data/src/org/jbox2d/dynamics/Profile.java +97 -0
- data/src/org/jbox2d/dynamics/SolverData.java +33 -0
- data/src/org/jbox2d/dynamics/TimeStep.java +46 -0
- data/src/org/jbox2d/dynamics/World.java +2075 -0
- data/src/org/jbox2d/dynamics/contacts/ChainAndCircleContact.java +57 -0
- data/src/org/jbox2d/dynamics/contacts/ChainAndPolygonContact.java +57 -0
- data/src/org/jbox2d/dynamics/contacts/CircleContact.java +50 -0
- data/src/org/jbox2d/dynamics/contacts/Contact.java +365 -0
- data/src/org/jbox2d/dynamics/contacts/ContactCreator.java +35 -0
- data/src/org/jbox2d/dynamics/contacts/ContactEdge.java +56 -0
- data/src/org/jbox2d/dynamics/contacts/ContactPositionConstraint.java +49 -0
- data/src/org/jbox2d/dynamics/contacts/ContactRegister.java +31 -0
- data/src/org/jbox2d/dynamics/contacts/ContactSolver.java +1104 -0
- data/src/org/jbox2d/dynamics/contacts/ContactVelocityConstraint.java +60 -0
- data/src/org/jbox2d/dynamics/contacts/EdgeAndCircleContact.java +52 -0
- data/src/org/jbox2d/dynamics/contacts/EdgeAndPolygonContact.java +52 -0
- data/src/org/jbox2d/dynamics/contacts/PolygonAndCircleContact.java +51 -0
- data/src/org/jbox2d/dynamics/contacts/PolygonContact.java +50 -0
- data/src/org/jbox2d/dynamics/contacts/Position.java +31 -0
- data/src/org/jbox2d/dynamics/contacts/Velocity.java +31 -0
- data/src/org/jbox2d/dynamics/joints/ConstantVolumeJoint.java +258 -0
- data/src/org/jbox2d/dynamics/joints/ConstantVolumeJointDef.java +75 -0
- data/src/org/jbox2d/dynamics/joints/DistanceJoint.java +356 -0
- data/src/org/jbox2d/dynamics/joints/DistanceJointDef.java +106 -0
- data/src/org/jbox2d/dynamics/joints/FrictionJoint.java +294 -0
- data/src/org/jbox2d/dynamics/joints/FrictionJointDef.java +78 -0
- data/src/org/jbox2d/dynamics/joints/GearJoint.java +520 -0
- data/src/org/jbox2d/dynamics/joints/GearJointDef.java +58 -0
- data/src/org/jbox2d/dynamics/joints/Jacobian.java +32 -0
- data/src/org/jbox2d/dynamics/joints/Joint.java +235 -0
- data/src/org/jbox2d/dynamics/joints/JointDef.java +65 -0
- data/src/org/jbox2d/dynamics/joints/JointEdge.java +57 -0
- data/src/org/jbox2d/dynamics/joints/JointType.java +28 -0
- data/src/org/jbox2d/dynamics/joints/LimitState.java +28 -0
- data/src/org/jbox2d/dynamics/joints/MotorJoint.java +339 -0
- data/src/org/jbox2d/dynamics/joints/MotorJointDef.java +55 -0
- data/src/org/jbox2d/dynamics/joints/MouseJoint.java +262 -0
- data/src/org/jbox2d/dynamics/joints/MouseJointDef.java +62 -0
- data/src/org/jbox2d/dynamics/joints/PrismaticJoint.java +808 -0
- data/src/org/jbox2d/dynamics/joints/PrismaticJointDef.java +120 -0
- data/src/org/jbox2d/dynamics/joints/PulleyJoint.java +393 -0
- data/src/org/jbox2d/dynamics/joints/PulleyJointDef.java +105 -0
- data/src/org/jbox2d/dynamics/joints/RevoluteJoint.java +554 -0
- data/src/org/jbox2d/dynamics/joints/RevoluteJointDef.java +137 -0
- data/src/org/jbox2d/dynamics/joints/RopeJoint.java +276 -0
- data/src/org/jbox2d/dynamics/joints/RopeJointDef.java +34 -0
- data/src/org/jbox2d/dynamics/joints/WeldJoint.java +424 -0
- data/src/org/jbox2d/dynamics/joints/WeldJointDef.java +85 -0
- data/src/org/jbox2d/dynamics/joints/WheelJoint.java +498 -0
- data/src/org/jbox2d/dynamics/joints/WheelJointDef.java +98 -0
- data/src/org/jbox2d/particle/ParticleBodyContact.java +17 -0
- data/src/org/jbox2d/particle/ParticleColor.java +52 -0
- data/src/org/jbox2d/particle/ParticleContact.java +14 -0
- data/src/org/jbox2d/particle/ParticleDef.java +24 -0
- data/src/org/jbox2d/particle/ParticleGroup.java +154 -0
- data/src/org/jbox2d/particle/ParticleGroupDef.java +62 -0
- data/src/org/jbox2d/particle/ParticleGroupType.java +8 -0
- data/src/org/jbox2d/particle/ParticleSystem.java +2172 -0
- data/src/org/jbox2d/particle/ParticleType.java +28 -0
- data/src/org/jbox2d/particle/StackQueue.java +44 -0
- data/src/org/jbox2d/particle/VoronoiDiagram.java +209 -0
- data/src/org/jbox2d/pooling/IDynamicStack.java +47 -0
- data/src/org/jbox2d/pooling/IOrderedStack.java +57 -0
- data/src/org/jbox2d/pooling/IWorldPool.java +101 -0
- data/src/org/jbox2d/pooling/arrays/FloatArray.java +50 -0
- data/src/org/jbox2d/pooling/arrays/GeneratorArray.java +33 -0
- data/src/org/jbox2d/pooling/arrays/IntArray.java +53 -0
- data/src/org/jbox2d/pooling/arrays/Vec2Array.java +57 -0
- data/src/org/jbox2d/pooling/normal/CircleStack.java +77 -0
- data/src/org/jbox2d/pooling/normal/DefaultWorldPool.java +331 -0
- data/src/org/jbox2d/pooling/normal/MutableStack.java +72 -0
- data/src/org/jbox2d/pooling/normal/OrderedStack.java +73 -0
- data/src/org/jbox2d/pooling/stacks/DynamicIntStack.java +60 -0
- metadata +161 -14
- data/lib/jbox2d-library-2.3.1-SNAPSHOT.jar +0 -0
@@ -0,0 +1,526 @@
|
|
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;
|
25
|
+
|
26
|
+
import org.jbox2d.collision.Distance.DistanceProxy;
|
27
|
+
import org.jbox2d.collision.Distance.SimplexCache;
|
28
|
+
import org.jbox2d.common.MathUtils;
|
29
|
+
import org.jbox2d.common.Rot;
|
30
|
+
import org.jbox2d.common.Settings;
|
31
|
+
import org.jbox2d.common.Sweep;
|
32
|
+
import org.jbox2d.common.Transform;
|
33
|
+
import org.jbox2d.common.Vec2;
|
34
|
+
import org.jbox2d.pooling.IWorldPool;
|
35
|
+
|
36
|
+
/**
|
37
|
+
* Class used for computing the time of impact. This class should not be constructed usually, just
|
38
|
+
* retrieve from the {@link IWorldPool#getTimeOfImpact()}.
|
39
|
+
*
|
40
|
+
* @author daniel
|
41
|
+
*/
|
42
|
+
public class TimeOfImpact {
|
43
|
+
public static final int MAX_ITERATIONS = 20;
|
44
|
+
public static final int MAX_ROOT_ITERATIONS = 50;
|
45
|
+
|
46
|
+
public static int toiCalls = 0;
|
47
|
+
public static int toiIters = 0;
|
48
|
+
public static int toiMaxIters = 0;
|
49
|
+
public static int toiRootIters = 0;
|
50
|
+
public static int toiMaxRootIters = 0;
|
51
|
+
|
52
|
+
/**
|
53
|
+
* Input parameters for TOI
|
54
|
+
*
|
55
|
+
* @author Daniel Murphy
|
56
|
+
*/
|
57
|
+
public static class TOIInput {
|
58
|
+
public final DistanceProxy proxyA = new DistanceProxy();
|
59
|
+
public final DistanceProxy proxyB = new DistanceProxy();
|
60
|
+
public final Sweep sweepA = new Sweep();
|
61
|
+
public final Sweep sweepB = new Sweep();
|
62
|
+
/**
|
63
|
+
* defines sweep interval [0, tMax]
|
64
|
+
*/
|
65
|
+
public float tMax;
|
66
|
+
}
|
67
|
+
|
68
|
+
public static enum TOIOutputState {
|
69
|
+
UNKNOWN, FAILED, OVERLAPPED, TOUCHING, SEPARATED
|
70
|
+
}
|
71
|
+
|
72
|
+
/**
|
73
|
+
* Output parameters for TimeOfImpact
|
74
|
+
*
|
75
|
+
* @author daniel
|
76
|
+
*/
|
77
|
+
public static class TOIOutput {
|
78
|
+
public TOIOutputState state;
|
79
|
+
public float t;
|
80
|
+
}
|
81
|
+
|
82
|
+
|
83
|
+
// djm pooling
|
84
|
+
private final SimplexCache cache = new SimplexCache();
|
85
|
+
private final DistanceInput distanceInput = new DistanceInput();
|
86
|
+
private final Transform xfA = new Transform();
|
87
|
+
private final Transform xfB = new Transform();
|
88
|
+
private final DistanceOutput distanceOutput = new DistanceOutput();
|
89
|
+
private final SeparationFunction fcn = new SeparationFunction();
|
90
|
+
private final int[] indexes = new int[2];
|
91
|
+
private final Sweep sweepA = new Sweep();
|
92
|
+
private final Sweep sweepB = new Sweep();
|
93
|
+
|
94
|
+
|
95
|
+
private final IWorldPool pool;
|
96
|
+
|
97
|
+
public TimeOfImpact(IWorldPool argPool) {
|
98
|
+
pool = argPool;
|
99
|
+
}
|
100
|
+
|
101
|
+
/**
|
102
|
+
* Compute the upper bound on time before two shapes penetrate. Time is represented as a fraction
|
103
|
+
* between [0,tMax]. This uses a swept separating axis and may miss some intermediate,
|
104
|
+
* non-tunneling collision. If you change the time interval, you should call this function again.
|
105
|
+
* Note: use Distance to compute the contact point and normal at the time of impact.
|
106
|
+
*
|
107
|
+
* @param output
|
108
|
+
* @param input
|
109
|
+
*/
|
110
|
+
public final void timeOfImpact(TOIOutput output, TOIInput input) {
|
111
|
+
// CCD via the local separating axis method. This seeks progression
|
112
|
+
// by computing the largest time at which separation is maintained.
|
113
|
+
|
114
|
+
++toiCalls;
|
115
|
+
|
116
|
+
output.state = TOIOutputState.UNKNOWN;
|
117
|
+
output.t = input.tMax;
|
118
|
+
|
119
|
+
final DistanceProxy proxyA = input.proxyA;
|
120
|
+
final DistanceProxy proxyB = input.proxyB;
|
121
|
+
|
122
|
+
sweepA.set(input.sweepA);
|
123
|
+
sweepB.set(input.sweepB);
|
124
|
+
|
125
|
+
// Large rotations can make the root finder fail, so we normalize the
|
126
|
+
// sweep angles.
|
127
|
+
sweepA.normalize();
|
128
|
+
sweepB.normalize();
|
129
|
+
|
130
|
+
float tMax = input.tMax;
|
131
|
+
|
132
|
+
float totalRadius = proxyA.m_radius + proxyB.m_radius;
|
133
|
+
// djm: whats with all these constants?
|
134
|
+
float target = MathUtils.max(Settings.linearSlop, totalRadius - 3.0f * Settings.linearSlop);
|
135
|
+
float tolerance = 0.25f * Settings.linearSlop;
|
136
|
+
|
137
|
+
assert (target > tolerance);
|
138
|
+
|
139
|
+
float t1 = 0f;
|
140
|
+
int iter = 0;
|
141
|
+
|
142
|
+
cache.count = 0;
|
143
|
+
distanceInput.proxyA = input.proxyA;
|
144
|
+
distanceInput.proxyB = input.proxyB;
|
145
|
+
distanceInput.useRadii = false;
|
146
|
+
|
147
|
+
// The outer loop progressively attempts to compute new separating axes.
|
148
|
+
// This loop terminates when an axis is repeated (no progress is made).
|
149
|
+
for (;;) {
|
150
|
+
sweepA.getTransform(xfA, t1);
|
151
|
+
sweepB.getTransform(xfB, t1);
|
152
|
+
// System.out.printf("sweepA: %f, %f, sweepB: %f, %f\n",
|
153
|
+
// sweepA.c.x, sweepA.c.y, sweepB.c.x, sweepB.c.y);
|
154
|
+
// Get the distance between shapes. We can also use the results
|
155
|
+
// to get a separating axis
|
156
|
+
distanceInput.transformA = xfA;
|
157
|
+
distanceInput.transformB = xfB;
|
158
|
+
pool.getDistance().distance(distanceOutput, cache, distanceInput);
|
159
|
+
|
160
|
+
// System.out.printf("Dist: %f at points %f, %f and %f, %f. %d iterations\n",
|
161
|
+
// distanceOutput.distance, distanceOutput.pointA.x, distanceOutput.pointA.y,
|
162
|
+
// distanceOutput.pointB.x, distanceOutput.pointB.y,
|
163
|
+
// distanceOutput.iterations);
|
164
|
+
|
165
|
+
// If the shapes are overlapped, we give up on continuous collision.
|
166
|
+
if (distanceOutput.distance <= 0f) {
|
167
|
+
// Failure!
|
168
|
+
output.state = TOIOutputState.OVERLAPPED;
|
169
|
+
output.t = 0f;
|
170
|
+
break;
|
171
|
+
}
|
172
|
+
|
173
|
+
if (distanceOutput.distance < target + tolerance) {
|
174
|
+
// Victory!
|
175
|
+
output.state = TOIOutputState.TOUCHING;
|
176
|
+
output.t = t1;
|
177
|
+
break;
|
178
|
+
}
|
179
|
+
|
180
|
+
// Initialize the separating axis.
|
181
|
+
fcn.initialize(cache, proxyA, sweepA, proxyB, sweepB, t1);
|
182
|
+
|
183
|
+
// Compute the TOI on the separating axis. We do this by successively
|
184
|
+
// resolving the deepest point. This loop is bounded by the number of
|
185
|
+
// vertices.
|
186
|
+
boolean done = false;
|
187
|
+
float t2 = tMax;
|
188
|
+
int pushBackIter = 0;
|
189
|
+
for (;;) {
|
190
|
+
|
191
|
+
// Find the deepest point at t2. Store the witness point indices.
|
192
|
+
float s2 = fcn.findMinSeparation(indexes, t2);
|
193
|
+
// System.out.printf("s2: %f\n", s2);
|
194
|
+
// Is the final configuration separated?
|
195
|
+
if (s2 > target + tolerance) {
|
196
|
+
// Victory!
|
197
|
+
output.state = TOIOutputState.SEPARATED;
|
198
|
+
output.t = tMax;
|
199
|
+
done = true;
|
200
|
+
break;
|
201
|
+
}
|
202
|
+
|
203
|
+
// Has the separation reached tolerance?
|
204
|
+
if (s2 > target - tolerance) {
|
205
|
+
// Advance the sweeps
|
206
|
+
t1 = t2;
|
207
|
+
break;
|
208
|
+
}
|
209
|
+
|
210
|
+
// Compute the initial separation of the witness points.
|
211
|
+
float s1 = fcn.evaluate(indexes[0], indexes[1], t1);
|
212
|
+
// Check for initial overlap. This might happen if the root finder
|
213
|
+
// runs out of iterations.
|
214
|
+
// System.out.printf("s1: %f, target: %f, tolerance: %f\n", s1, target,
|
215
|
+
// tolerance);
|
216
|
+
if (s1 < target - tolerance) {
|
217
|
+
output.state = TOIOutputState.FAILED;
|
218
|
+
output.t = t1;
|
219
|
+
done = true;
|
220
|
+
break;
|
221
|
+
}
|
222
|
+
|
223
|
+
// Check for touching
|
224
|
+
if (s1 <= target + tolerance) {
|
225
|
+
// Victory! t1 should hold the TOI (could be 0.0).
|
226
|
+
output.state = TOIOutputState.TOUCHING;
|
227
|
+
output.t = t1;
|
228
|
+
done = true;
|
229
|
+
break;
|
230
|
+
}
|
231
|
+
|
232
|
+
// Compute 1D root of: f(x) - target = 0
|
233
|
+
int rootIterCount = 0;
|
234
|
+
float a1 = t1, a2 = t2;
|
235
|
+
for (;;) {
|
236
|
+
// Use a mix of the secant rule and bisection.
|
237
|
+
float t;
|
238
|
+
if ((rootIterCount & 1) == 1) {
|
239
|
+
// Secant rule to improve convergence.
|
240
|
+
t = a1 + (target - s1) * (a2 - a1) / (s2 - s1);
|
241
|
+
} else {
|
242
|
+
// Bisection to guarantee progress.
|
243
|
+
t = 0.5f * (a1 + a2);
|
244
|
+
}
|
245
|
+
|
246
|
+
++rootIterCount;
|
247
|
+
++toiRootIters;
|
248
|
+
|
249
|
+
float s = fcn.evaluate(indexes[0], indexes[1], t);
|
250
|
+
|
251
|
+
if (MathUtils.abs(s - target) < tolerance) {
|
252
|
+
// t2 holds a tentative value for t1
|
253
|
+
t2 = t;
|
254
|
+
break;
|
255
|
+
}
|
256
|
+
|
257
|
+
// Ensure we continue to bracket the root.
|
258
|
+
if (s > target) {
|
259
|
+
a1 = t;
|
260
|
+
s1 = s;
|
261
|
+
} else {
|
262
|
+
a2 = t;
|
263
|
+
s2 = s;
|
264
|
+
}
|
265
|
+
|
266
|
+
if (rootIterCount == MAX_ROOT_ITERATIONS) {
|
267
|
+
break;
|
268
|
+
}
|
269
|
+
}
|
270
|
+
|
271
|
+
toiMaxRootIters = MathUtils.max(toiMaxRootIters, rootIterCount);
|
272
|
+
|
273
|
+
++pushBackIter;
|
274
|
+
|
275
|
+
if (pushBackIter == Settings.maxPolygonVertices || rootIterCount == MAX_ROOT_ITERATIONS) {
|
276
|
+
break;
|
277
|
+
}
|
278
|
+
}
|
279
|
+
|
280
|
+
++iter;
|
281
|
+
++toiIters;
|
282
|
+
|
283
|
+
if (done) {
|
284
|
+
// System.out.println("done");
|
285
|
+
break;
|
286
|
+
}
|
287
|
+
|
288
|
+
if (iter == MAX_ITERATIONS) {
|
289
|
+
// System.out.println("failed, root finder stuck");
|
290
|
+
// Root finder got stuck. Semi-victory.
|
291
|
+
output.state = TOIOutputState.FAILED;
|
292
|
+
output.t = t1;
|
293
|
+
break;
|
294
|
+
}
|
295
|
+
}
|
296
|
+
|
297
|
+
// System.out.printf("final sweeps: %f, %f, %f; %f, %f, %f", input.s)
|
298
|
+
toiMaxIters = MathUtils.max(toiMaxIters, iter);
|
299
|
+
}
|
300
|
+
}
|
301
|
+
|
302
|
+
|
303
|
+
enum Type {
|
304
|
+
POINTS, FACE_A, FACE_B;
|
305
|
+
}
|
306
|
+
|
307
|
+
|
308
|
+
class SeparationFunction {
|
309
|
+
|
310
|
+
public DistanceProxy m_proxyA;
|
311
|
+
public DistanceProxy m_proxyB;
|
312
|
+
public Type m_type;
|
313
|
+
public final Vec2 m_localPoint = new Vec2();
|
314
|
+
public final Vec2 m_axis = new Vec2();
|
315
|
+
public Sweep m_sweepA;
|
316
|
+
public Sweep m_sweepB;
|
317
|
+
|
318
|
+
// djm pooling
|
319
|
+
private final Vec2 localPointA = new Vec2();
|
320
|
+
private final Vec2 localPointB = new Vec2();
|
321
|
+
private final Vec2 pointA = new Vec2();
|
322
|
+
private final Vec2 pointB = new Vec2();
|
323
|
+
private final Vec2 localPointA1 = new Vec2();
|
324
|
+
private final Vec2 localPointA2 = new Vec2();
|
325
|
+
private final Vec2 normal = new Vec2();
|
326
|
+
private final Vec2 localPointB1 = new Vec2();
|
327
|
+
private final Vec2 localPointB2 = new Vec2();
|
328
|
+
private final Vec2 temp = new Vec2();
|
329
|
+
private final Transform xfa = new Transform();
|
330
|
+
private final Transform xfb = new Transform();
|
331
|
+
|
332
|
+
// TODO_ERIN might not need to return the separation
|
333
|
+
|
334
|
+
public float initialize(final SimplexCache cache, final DistanceProxy proxyA, final Sweep sweepA,
|
335
|
+
final DistanceProxy proxyB, final Sweep sweepB, float t1) {
|
336
|
+
m_proxyA = proxyA;
|
337
|
+
m_proxyB = proxyB;
|
338
|
+
int count = cache.count;
|
339
|
+
assert (0 < count && count < 3);
|
340
|
+
|
341
|
+
m_sweepA = sweepA;
|
342
|
+
m_sweepB = sweepB;
|
343
|
+
|
344
|
+
m_sweepA.getTransform(xfa, t1);
|
345
|
+
m_sweepB.getTransform(xfb, t1);
|
346
|
+
|
347
|
+
// log.debug("initializing separation.\n" +
|
348
|
+
// "cache: "+cache.count+"-"+cache.metric+"-"+cache.indexA+"-"+cache.indexB+"\n"
|
349
|
+
// "distance: "+proxyA.
|
350
|
+
|
351
|
+
if (count == 1) {
|
352
|
+
m_type = Type.POINTS;
|
353
|
+
/*
|
354
|
+
* Vec2 localPointA = m_proxyA.GetVertex(cache.indexA[0]); Vec2 localPointB =
|
355
|
+
* m_proxyB.GetVertex(cache.indexB[0]); Vec2 pointA = Mul(transformA, localPointA); Vec2
|
356
|
+
* pointB = Mul(transformB, localPointB); m_axis = pointB - pointA; m_axis.Normalize();
|
357
|
+
*/
|
358
|
+
localPointA.set(m_proxyA.getVertex(cache.indexA[0]));
|
359
|
+
localPointB.set(m_proxyB.getVertex(cache.indexB[0]));
|
360
|
+
Transform.mulToOutUnsafe(xfa, localPointA, pointA);
|
361
|
+
Transform.mulToOutUnsafe(xfb, localPointB, pointB);
|
362
|
+
m_axis.set(pointB).subLocal(pointA);
|
363
|
+
float s = m_axis.normalize();
|
364
|
+
return s;
|
365
|
+
} else if (cache.indexA[0] == cache.indexA[1]) {
|
366
|
+
// Two points on B and one on A.
|
367
|
+
m_type = Type.FACE_B;
|
368
|
+
|
369
|
+
localPointB1.set(m_proxyB.getVertex(cache.indexB[0]));
|
370
|
+
localPointB2.set(m_proxyB.getVertex(cache.indexB[1]));
|
371
|
+
|
372
|
+
temp.set(localPointB2).subLocal(localPointB1);
|
373
|
+
Vec2.crossToOutUnsafe(temp, 1f, m_axis);
|
374
|
+
m_axis.normalize();
|
375
|
+
|
376
|
+
Rot.mulToOutUnsafe(xfb.q, m_axis, normal);
|
377
|
+
|
378
|
+
m_localPoint.set(localPointB1).addLocal(localPointB2).mulLocal(.5f);
|
379
|
+
Transform.mulToOutUnsafe(xfb, m_localPoint, pointB);
|
380
|
+
|
381
|
+
localPointA.set(proxyA.getVertex(cache.indexA[0]));
|
382
|
+
Transform.mulToOutUnsafe(xfa, localPointA, pointA);
|
383
|
+
|
384
|
+
temp.set(pointA).subLocal(pointB);
|
385
|
+
float s = Vec2.dot(temp, normal);
|
386
|
+
if (s < 0.0f) {
|
387
|
+
m_axis.negateLocal();
|
388
|
+
s = -s;
|
389
|
+
}
|
390
|
+
return s;
|
391
|
+
} else {
|
392
|
+
// Two points on A and one or two points on B.
|
393
|
+
m_type = Type.FACE_A;
|
394
|
+
|
395
|
+
localPointA1.set(m_proxyA.getVertex(cache.indexA[0]));
|
396
|
+
localPointA2.set(m_proxyA.getVertex(cache.indexA[1]));
|
397
|
+
|
398
|
+
temp.set(localPointA2).subLocal(localPointA1);
|
399
|
+
Vec2.crossToOutUnsafe(temp, 1.0f, m_axis);
|
400
|
+
m_axis.normalize();
|
401
|
+
|
402
|
+
Rot.mulToOutUnsafe(xfa.q, m_axis, normal);
|
403
|
+
|
404
|
+
m_localPoint.set(localPointA1).addLocal(localPointA2).mulLocal(.5f);
|
405
|
+
Transform.mulToOutUnsafe(xfa, m_localPoint, pointA);
|
406
|
+
|
407
|
+
localPointB.set(m_proxyB.getVertex(cache.indexB[0]));
|
408
|
+
Transform.mulToOutUnsafe(xfb, localPointB, pointB);
|
409
|
+
|
410
|
+
temp.set(pointB).subLocal(pointA);
|
411
|
+
float s = Vec2.dot(temp, normal);
|
412
|
+
if (s < 0.0f) {
|
413
|
+
m_axis.negateLocal();
|
414
|
+
s = -s;
|
415
|
+
}
|
416
|
+
return s;
|
417
|
+
}
|
418
|
+
}
|
419
|
+
|
420
|
+
private final Vec2 axisA = new Vec2();
|
421
|
+
private final Vec2 axisB = new Vec2();
|
422
|
+
|
423
|
+
// float FindMinSeparation(int* indexA, int* indexB, float t) const
|
424
|
+
public float findMinSeparation(int[] indexes, float t) {
|
425
|
+
|
426
|
+
m_sweepA.getTransform(xfa, t);
|
427
|
+
m_sweepB.getTransform(xfb, t);
|
428
|
+
|
429
|
+
switch (m_type) {
|
430
|
+
case POINTS: {
|
431
|
+
Rot.mulTransUnsafe(xfa.q, m_axis, axisA);
|
432
|
+
Rot.mulTransUnsafe(xfb.q, m_axis.negateLocal(), axisB);
|
433
|
+
m_axis.negateLocal();
|
434
|
+
|
435
|
+
indexes[0] = m_proxyA.getSupport(axisA);
|
436
|
+
indexes[1] = m_proxyB.getSupport(axisB);
|
437
|
+
|
438
|
+
localPointA.set(m_proxyA.getVertex(indexes[0]));
|
439
|
+
localPointB.set(m_proxyB.getVertex(indexes[1]));
|
440
|
+
|
441
|
+
Transform.mulToOutUnsafe(xfa, localPointA, pointA);
|
442
|
+
Transform.mulToOutUnsafe(xfb, localPointB, pointB);
|
443
|
+
|
444
|
+
float separation = Vec2.dot(pointB.subLocal(pointA), m_axis);
|
445
|
+
return separation;
|
446
|
+
}
|
447
|
+
case FACE_A: {
|
448
|
+
Rot.mulToOutUnsafe(xfa.q, m_axis, normal);
|
449
|
+
Transform.mulToOutUnsafe(xfa, m_localPoint, pointA);
|
450
|
+
|
451
|
+
Rot.mulTransUnsafe(xfb.q, normal.negateLocal(), axisB);
|
452
|
+
normal.negateLocal();
|
453
|
+
|
454
|
+
indexes[0] = -1;
|
455
|
+
indexes[1] = m_proxyB.getSupport(axisB);
|
456
|
+
|
457
|
+
localPointB.set(m_proxyB.getVertex(indexes[1]));
|
458
|
+
Transform.mulToOutUnsafe(xfb, localPointB, pointB);
|
459
|
+
|
460
|
+
float separation = Vec2.dot(pointB.subLocal(pointA), normal);
|
461
|
+
return separation;
|
462
|
+
}
|
463
|
+
case FACE_B: {
|
464
|
+
Rot.mulToOutUnsafe(xfb.q, m_axis, normal);
|
465
|
+
Transform.mulToOutUnsafe(xfb, m_localPoint, pointB);
|
466
|
+
|
467
|
+
Rot.mulTransUnsafe(xfa.q, normal.negateLocal(), axisA);
|
468
|
+
normal.negateLocal();
|
469
|
+
|
470
|
+
indexes[1] = -1;
|
471
|
+
indexes[0] = m_proxyA.getSupport(axisA);
|
472
|
+
|
473
|
+
localPointA.set(m_proxyA.getVertex(indexes[0]));
|
474
|
+
Transform.mulToOutUnsafe(xfa, localPointA, pointA);
|
475
|
+
|
476
|
+
float separation = Vec2.dot(pointA.subLocal(pointB), normal);
|
477
|
+
return separation;
|
478
|
+
}
|
479
|
+
default:
|
480
|
+
assert (false);
|
481
|
+
indexes[0] = -1;
|
482
|
+
indexes[1] = -1;
|
483
|
+
return 0f;
|
484
|
+
}
|
485
|
+
}
|
486
|
+
|
487
|
+
public float evaluate(int indexA, int indexB, float t) {
|
488
|
+
m_sweepA.getTransform(xfa, t);
|
489
|
+
m_sweepB.getTransform(xfb, t);
|
490
|
+
|
491
|
+
switch (m_type) {
|
492
|
+
case POINTS: {
|
493
|
+
localPointA.set(m_proxyA.getVertex(indexA));
|
494
|
+
localPointB.set(m_proxyB.getVertex(indexB));
|
495
|
+
|
496
|
+
Transform.mulToOutUnsafe(xfa, localPointA, pointA);
|
497
|
+
Transform.mulToOutUnsafe(xfb, localPointB, pointB);
|
498
|
+
|
499
|
+
float separation = Vec2.dot(pointB.subLocal(pointA), m_axis);
|
500
|
+
return separation;
|
501
|
+
}
|
502
|
+
case FACE_A: {
|
503
|
+
Rot.mulToOutUnsafe(xfa.q, m_axis, normal);
|
504
|
+
Transform.mulToOutUnsafe(xfa, m_localPoint, pointA);
|
505
|
+
|
506
|
+
localPointB.set(m_proxyB.getVertex(indexB));
|
507
|
+
Transform.mulToOutUnsafe(xfb, localPointB, pointB);
|
508
|
+
float separation = Vec2.dot(pointB.subLocal(pointA), normal);
|
509
|
+
return separation;
|
510
|
+
}
|
511
|
+
case FACE_B: {
|
512
|
+
Rot.mulToOutUnsafe(xfb.q, m_axis, normal);
|
513
|
+
Transform.mulToOutUnsafe(xfb, m_localPoint, pointB);
|
514
|
+
|
515
|
+
localPointA.set(m_proxyA.getVertex(indexA));
|
516
|
+
Transform.mulToOutUnsafe(xfa, localPointA, pointA);
|
517
|
+
|
518
|
+
float separation = Vec2.dot(pointA.subLocal(pointB), normal);
|
519
|
+
return separation;
|
520
|
+
}
|
521
|
+
default:
|
522
|
+
assert (false);
|
523
|
+
return 0f;
|
524
|
+
}
|
525
|
+
}
|
526
|
+
}
|