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,338 @@
|
|
1
|
+
/**
|
2
|
+
* *****************************************************************************
|
3
|
+
* Copyright (c) 2013, Daniel Murphy All rights reserved.
|
4
|
+
*
|
5
|
+
* Redistribution and use in source and binary forms, with or without
|
6
|
+
* modification, are permitted provided that the following conditions are met: *
|
7
|
+
* Redistributions of source code must retain the above copyright notice, this
|
8
|
+
* list of conditions and the following disclaimer. * Redistributions in binary
|
9
|
+
* form must reproduce the above copyright notice, this list of conditions and
|
10
|
+
* the following disclaimer in the documentation and/or other materials provided
|
11
|
+
* with the distribution.
|
12
|
+
*
|
13
|
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
14
|
+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
15
|
+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
16
|
+
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
17
|
+
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
18
|
+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
19
|
+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
20
|
+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
21
|
+
* 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.collision;
|
27
|
+
|
28
|
+
import org.jbox2d.common.MathUtils;
|
29
|
+
import org.jbox2d.common.Settings;
|
30
|
+
import org.jbox2d.common.Vec2;
|
31
|
+
import org.jbox2d.pooling.IWorldPool;
|
32
|
+
import org.jbox2d.pooling.normal.DefaultWorldPool;
|
33
|
+
|
34
|
+
/**
|
35
|
+
* An axis-aligned bounding box.
|
36
|
+
*/
|
37
|
+
public class AABB {
|
38
|
+
|
39
|
+
/**
|
40
|
+
* Bottom left vertex of bounding box.
|
41
|
+
*/
|
42
|
+
public final Vec2 lowerBound;
|
43
|
+
/**
|
44
|
+
* Top right vertex of bounding box.
|
45
|
+
*/
|
46
|
+
public final Vec2 upperBound;
|
47
|
+
|
48
|
+
/**
|
49
|
+
* Creates the default object, with vertices at 0,0 and 0,0.
|
50
|
+
*/
|
51
|
+
public AABB() {
|
52
|
+
lowerBound = new Vec2();
|
53
|
+
upperBound = new Vec2();
|
54
|
+
}
|
55
|
+
|
56
|
+
/**
|
57
|
+
* Copies from the given object
|
58
|
+
*
|
59
|
+
* @param copy the object to copy from
|
60
|
+
*/
|
61
|
+
public AABB(final AABB copy) {
|
62
|
+
this(copy.lowerBound, copy.upperBound);
|
63
|
+
}
|
64
|
+
|
65
|
+
/**
|
66
|
+
* Creates an AABB object using the given bounding vertices.
|
67
|
+
*
|
68
|
+
* @param lowerVertex the bottom left vertex of the bounding box
|
69
|
+
* @param upperVertex
|
70
|
+
*/
|
71
|
+
public AABB(final Vec2 lowerVertex, final Vec2 upperVertex) {
|
72
|
+
this.lowerBound = lowerVertex.clone(); // clone to be safe
|
73
|
+
this.upperBound = upperVertex.clone();
|
74
|
+
}
|
75
|
+
|
76
|
+
/**
|
77
|
+
* Sets this object from the given object
|
78
|
+
*
|
79
|
+
* @param aabb the object to copy from
|
80
|
+
*/
|
81
|
+
public final void set(final AABB aabb) {
|
82
|
+
Vec2 v = aabb.lowerBound;
|
83
|
+
lowerBound.x = v.x;
|
84
|
+
lowerBound.y = v.y;
|
85
|
+
Vec2 v1 = aabb.upperBound;
|
86
|
+
upperBound.x = v1.x;
|
87
|
+
upperBound.y = v1.y;
|
88
|
+
}
|
89
|
+
|
90
|
+
/**
|
91
|
+
* Verify that the bounds are sorted
|
92
|
+
*
|
93
|
+
* @return
|
94
|
+
*/
|
95
|
+
public final boolean isValid() {
|
96
|
+
final float dx = upperBound.x - lowerBound.x;
|
97
|
+
if (dx < 0f) {
|
98
|
+
return false;
|
99
|
+
}
|
100
|
+
final float dy = upperBound.y - lowerBound.y;
|
101
|
+
if (dy < 0) {
|
102
|
+
return false;
|
103
|
+
}
|
104
|
+
return lowerBound.isValid() && upperBound.isValid();
|
105
|
+
}
|
106
|
+
|
107
|
+
/**
|
108
|
+
* Get the center of the AABB
|
109
|
+
*
|
110
|
+
* @return
|
111
|
+
*/
|
112
|
+
public final Vec2 getCenter() {
|
113
|
+
final Vec2 center = new Vec2(lowerBound);
|
114
|
+
center.addLocal(upperBound);
|
115
|
+
center.mulLocal(.5f);
|
116
|
+
return center;
|
117
|
+
}
|
118
|
+
|
119
|
+
public final void getCenterToOut(final Vec2 out) {
|
120
|
+
out.x = (lowerBound.x + upperBound.x) * .5f;
|
121
|
+
out.y = (lowerBound.y + upperBound.y) * .5f;
|
122
|
+
}
|
123
|
+
|
124
|
+
/**
|
125
|
+
* Get the extents of the AABB (half-widths).
|
126
|
+
*
|
127
|
+
* @return
|
128
|
+
*/
|
129
|
+
public final Vec2 getExtents() {
|
130
|
+
final Vec2 center = new Vec2(upperBound);
|
131
|
+
center.subLocal(lowerBound);
|
132
|
+
center.mulLocal(.5f);
|
133
|
+
return center;
|
134
|
+
}
|
135
|
+
|
136
|
+
public final void getExtentsToOut(final Vec2 out) {
|
137
|
+
out.x = (upperBound.x - lowerBound.x) * .5f;
|
138
|
+
out.y = (upperBound.y - lowerBound.y) * .5f; // thanks FDN1
|
139
|
+
}
|
140
|
+
|
141
|
+
public final void getVertices(Vec2[] argRay) {
|
142
|
+
argRay[0].set(lowerBound);
|
143
|
+
argRay[1].set(lowerBound);
|
144
|
+
argRay[1].x += upperBound.x - lowerBound.x;
|
145
|
+
argRay[2].set(upperBound);
|
146
|
+
argRay[3].set(upperBound);
|
147
|
+
argRay[3].x -= upperBound.x - lowerBound.x;
|
148
|
+
}
|
149
|
+
|
150
|
+
/**
|
151
|
+
* Combine two AABBs into this one.
|
152
|
+
*
|
153
|
+
* @param aabb1
|
154
|
+
* @param aab
|
155
|
+
*/
|
156
|
+
public final void combine(final AABB aabb1, final AABB aab) {
|
157
|
+
lowerBound.x = aabb1.lowerBound.x < aab.lowerBound.x ? aabb1.lowerBound.x : aab.lowerBound.x;
|
158
|
+
lowerBound.y = aabb1.lowerBound.y < aab.lowerBound.y ? aabb1.lowerBound.y : aab.lowerBound.y;
|
159
|
+
upperBound.x = aabb1.upperBound.x > aab.upperBound.x ? aabb1.upperBound.x : aab.upperBound.x;
|
160
|
+
upperBound.y = aabb1.upperBound.y > aab.upperBound.y ? aabb1.upperBound.y : aab.upperBound.y;
|
161
|
+
}
|
162
|
+
|
163
|
+
/**
|
164
|
+
* Gets the perimeter length
|
165
|
+
*
|
166
|
+
* @return
|
167
|
+
*/
|
168
|
+
public final float getPerimeter() {
|
169
|
+
return 2.0f * (upperBound.x - lowerBound.x + upperBound.y - lowerBound.y);
|
170
|
+
}
|
171
|
+
|
172
|
+
/**
|
173
|
+
* Combines another aabb with this one
|
174
|
+
*
|
175
|
+
* @param aabb
|
176
|
+
*/
|
177
|
+
public final void combine(final AABB aabb) {
|
178
|
+
lowerBound.x = lowerBound.x < aabb.lowerBound.x ? lowerBound.x : aabb.lowerBound.x;
|
179
|
+
lowerBound.y = lowerBound.y < aabb.lowerBound.y ? lowerBound.y : aabb.lowerBound.y;
|
180
|
+
upperBound.x = upperBound.x > aabb.upperBound.x ? upperBound.x : aabb.upperBound.x;
|
181
|
+
upperBound.y = upperBound.y > aabb.upperBound.y ? upperBound.y : aabb.upperBound.y;
|
182
|
+
}
|
183
|
+
|
184
|
+
/**
|
185
|
+
* Does this aabb contain the provided AABB.
|
186
|
+
*
|
187
|
+
* @param aabb
|
188
|
+
* @return
|
189
|
+
*/
|
190
|
+
public final boolean contains(final AABB aabb) {
|
191
|
+
/*
|
192
|
+
* boolean result = true; result = result && lowerBound.x <= aabb.lowerBound.x; result = result
|
193
|
+
* && lowerBound.y <= aabb.lowerBound.y; result = result && aabb.upperBound.x <= upperBound.x;
|
194
|
+
* result = result && aabb.upperBound.y <= upperBound.y; return result;
|
195
|
+
*/
|
196
|
+
// djm: faster putting all of them together, as if one is false we leave the logic
|
197
|
+
// early
|
198
|
+
return lowerBound.x <= aabb.lowerBound.x && lowerBound.y <= aabb.lowerBound.y
|
199
|
+
&& aabb.upperBound.x <= upperBound.x && aabb.upperBound.y <= upperBound.y;
|
200
|
+
}
|
201
|
+
|
202
|
+
/**
|
203
|
+
* @deprecated please use
|
204
|
+
* {@link #raycast(RayCastOutput, RayCastInput, IWorldPool)} for better
|
205
|
+
* performance
|
206
|
+
* @param output
|
207
|
+
* @param input
|
208
|
+
* @return
|
209
|
+
*/
|
210
|
+
public final boolean raycast(final RayCastOutput output, final RayCastInput input) {
|
211
|
+
return raycast(output, input, new DefaultWorldPool(4, 4));
|
212
|
+
}
|
213
|
+
|
214
|
+
/**
|
215
|
+
* From Real-time Collision Detection, p179.
|
216
|
+
*
|
217
|
+
* @param output
|
218
|
+
* @param input
|
219
|
+
* @param argPool
|
220
|
+
* @return
|
221
|
+
*/
|
222
|
+
public final boolean raycast(final RayCastOutput output, final RayCastInput input,
|
223
|
+
IWorldPool argPool) {
|
224
|
+
float tmin = -Float.MAX_VALUE;
|
225
|
+
float tmax = Float.MAX_VALUE;
|
226
|
+
|
227
|
+
final Vec2 p = argPool.popVec2();
|
228
|
+
final Vec2 d = argPool.popVec2();
|
229
|
+
final Vec2 absD = argPool.popVec2();
|
230
|
+
final Vec2 normal = argPool.popVec2();
|
231
|
+
|
232
|
+
p.set(input.p1);
|
233
|
+
d.set(input.p2).subLocal(input.p1);
|
234
|
+
Vec2.absToOut(d, absD);
|
235
|
+
|
236
|
+
// x then y
|
237
|
+
if (absD.x < Settings.EPSILON) {
|
238
|
+
// Parallel.
|
239
|
+
if (p.x < lowerBound.x || upperBound.x < p.x) {
|
240
|
+
argPool.pushVec2(4);
|
241
|
+
return false;
|
242
|
+
}
|
243
|
+
} else {
|
244
|
+
final float inv_d = 1.0f / d.x;
|
245
|
+
float t1 = (lowerBound.x - p.x) * inv_d;
|
246
|
+
float t2 = (upperBound.x - p.x) * inv_d;
|
247
|
+
|
248
|
+
// Sign of the normal vector.
|
249
|
+
float s = -1.0f;
|
250
|
+
|
251
|
+
if (t1 > t2) {
|
252
|
+
final float temp = t1;
|
253
|
+
t1 = t2;
|
254
|
+
t2 = temp;
|
255
|
+
s = 1.0f;
|
256
|
+
}
|
257
|
+
|
258
|
+
// Push the min up
|
259
|
+
if (t1 > tmin) {
|
260
|
+
normal.setZero();
|
261
|
+
normal.x = s;
|
262
|
+
tmin = t1;
|
263
|
+
}
|
264
|
+
|
265
|
+
// Pull the max down
|
266
|
+
tmax = MathUtils.min(tmax, t2);
|
267
|
+
|
268
|
+
if (tmin > tmax) {
|
269
|
+
argPool.pushVec2(4);
|
270
|
+
return false;
|
271
|
+
}
|
272
|
+
}
|
273
|
+
|
274
|
+
if (absD.y < Settings.EPSILON) {
|
275
|
+
// Parallel.
|
276
|
+
if (p.y < lowerBound.y || upperBound.y < p.y) {
|
277
|
+
argPool.pushVec2(4);
|
278
|
+
return false;
|
279
|
+
}
|
280
|
+
} else {
|
281
|
+
final float inv_d = 1.0f / d.y;
|
282
|
+
float t1 = (lowerBound.y - p.y) * inv_d;
|
283
|
+
float t2 = (upperBound.y - p.y) * inv_d;
|
284
|
+
|
285
|
+
// Sign of the normal vector.
|
286
|
+
float s = -1.0f;
|
287
|
+
|
288
|
+
if (t1 > t2) {
|
289
|
+
final float temp = t1;
|
290
|
+
t1 = t2;
|
291
|
+
t2 = temp;
|
292
|
+
s = 1.0f;
|
293
|
+
}
|
294
|
+
|
295
|
+
// Push the min up
|
296
|
+
if (t1 > tmin) {
|
297
|
+
normal.setZero();
|
298
|
+
normal.y = s;
|
299
|
+
tmin = t1;
|
300
|
+
}
|
301
|
+
|
302
|
+
// Pull the max down
|
303
|
+
tmax = MathUtils.min(tmax, t2);
|
304
|
+
|
305
|
+
if (tmin > tmax) {
|
306
|
+
argPool.pushVec2(4);
|
307
|
+
return false;
|
308
|
+
}
|
309
|
+
}
|
310
|
+
|
311
|
+
// Does the ray start inside the box?
|
312
|
+
// Does the ray intersect beyond the max fraction?
|
313
|
+
if (tmin < 0.0f || input.maxFraction < tmin) {
|
314
|
+
argPool.pushVec2(4);
|
315
|
+
return false;
|
316
|
+
}
|
317
|
+
|
318
|
+
// Intersection.
|
319
|
+
output.fraction = tmin;
|
320
|
+
output.normal.x = normal.x;
|
321
|
+
output.normal.y = normal.y;
|
322
|
+
argPool.pushVec2(4);
|
323
|
+
return true;
|
324
|
+
}
|
325
|
+
|
326
|
+
public static final boolean testOverlap(final AABB a, final AABB b) {
|
327
|
+
if (b.lowerBound.x - a.upperBound.x > 0.0f || b.lowerBound.y - a.upperBound.y > 0.0f) {
|
328
|
+
return false;
|
329
|
+
}
|
330
|
+
return !(a.lowerBound.x - b.upperBound.x > 0.0f || a.lowerBound.y - b.upperBound.y > 0.0f);
|
331
|
+
}
|
332
|
+
|
333
|
+
@Override
|
334
|
+
public final String toString() {
|
335
|
+
final String s = "AABB[" + lowerBound + " . " + upperBound + "]";
|
336
|
+
return s;
|
337
|
+
}
|
338
|
+
}
|