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,174 @@
|
|
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
|
+
* Orientated bounding box viewport transform
|
28
|
+
*
|
29
|
+
* @author Daniel Murphy
|
30
|
+
*/
|
31
|
+
public class OBBViewportTransform implements IViewportTransform {
|
32
|
+
|
33
|
+
public static class OBB {
|
34
|
+
public final Mat22 R = new Mat22();
|
35
|
+
public final Vec2 center = new Vec2();
|
36
|
+
public final Vec2 extents = new Vec2();
|
37
|
+
}
|
38
|
+
|
39
|
+
protected final OBB box = new OBB();
|
40
|
+
private boolean yFlip = false;
|
41
|
+
private final Mat22 yFlipMat = new Mat22(1, 0, 0, -1);
|
42
|
+
|
43
|
+
public OBBViewportTransform() {
|
44
|
+
box.R.setIdentity();
|
45
|
+
}
|
46
|
+
|
47
|
+
public void set(OBBViewportTransform vpt) {
|
48
|
+
box.center.set(vpt.box.center);
|
49
|
+
box.extents.set(vpt.box.extents);
|
50
|
+
box.R.set(vpt.box.R);
|
51
|
+
yFlip = vpt.yFlip;
|
52
|
+
}
|
53
|
+
|
54
|
+
@Override
|
55
|
+
public void setCamera(float x, float y, float scale) {
|
56
|
+
box.center.set(x, y);
|
57
|
+
Mat22.createScaleTransform(scale, box.R);
|
58
|
+
}
|
59
|
+
|
60
|
+
@Override
|
61
|
+
public Vec2 getExtents() {
|
62
|
+
return box.extents;
|
63
|
+
}
|
64
|
+
|
65
|
+
@Override
|
66
|
+
public Mat22 getMat22Representation() {
|
67
|
+
return box.R;
|
68
|
+
}
|
69
|
+
|
70
|
+
@Override
|
71
|
+
public void setExtents(Vec2 argExtents) {
|
72
|
+
box.extents.set(argExtents);
|
73
|
+
}
|
74
|
+
|
75
|
+
@Override
|
76
|
+
public void setExtents(float halfWidth, float halfHeight) {
|
77
|
+
box.extents.set(halfWidth, halfHeight);
|
78
|
+
}
|
79
|
+
|
80
|
+
@Override
|
81
|
+
public Vec2 getCenter() {
|
82
|
+
return box.center;
|
83
|
+
}
|
84
|
+
|
85
|
+
@Override
|
86
|
+
public void setCenter(Vec2 argPos) {
|
87
|
+
box.center.set(argPos);
|
88
|
+
}
|
89
|
+
|
90
|
+
@Override
|
91
|
+
public void setCenter(float x, float y) {
|
92
|
+
box.center.set(x, y);
|
93
|
+
}
|
94
|
+
|
95
|
+
/**
|
96
|
+
* Gets the transform of the viewport, transforms around the center. Not a copy.
|
97
|
+
* @return
|
98
|
+
*/
|
99
|
+
public Mat22 getTransform() {
|
100
|
+
return box.R;
|
101
|
+
}
|
102
|
+
|
103
|
+
/**
|
104
|
+
* Sets the transform of the viewport. Transforms about the center.
|
105
|
+
* @param transform
|
106
|
+
*/
|
107
|
+
public void setTransform(Mat22 transform) {
|
108
|
+
box.R.set(transform);
|
109
|
+
}
|
110
|
+
|
111
|
+
/**
|
112
|
+
* Multiplies the obb transform by the given transform
|
113
|
+
*/
|
114
|
+
@Override
|
115
|
+
public void mulByTransform(Mat22 transform) {
|
116
|
+
box.R.mulLocal(transform);
|
117
|
+
}
|
118
|
+
|
119
|
+
@Override
|
120
|
+
public boolean isYFlip() {
|
121
|
+
return yFlip;
|
122
|
+
}
|
123
|
+
|
124
|
+
@Override
|
125
|
+
public void setYFlip(boolean yFlip) {
|
126
|
+
this.yFlip = yFlip;
|
127
|
+
}
|
128
|
+
|
129
|
+
private final Mat22 inv = new Mat22();
|
130
|
+
|
131
|
+
@Override
|
132
|
+
public void getScreenVectorToWorld(Vec2 screen, Vec2 world) {
|
133
|
+
box.R.invertToOut(inv);
|
134
|
+
inv.mulToOut(screen, world);
|
135
|
+
if (yFlip) {
|
136
|
+
yFlipMat.mulToOut(world, world);
|
137
|
+
}
|
138
|
+
}
|
139
|
+
|
140
|
+
@Override
|
141
|
+
public void getWorldVectorToScreen(Vec2 world, Vec2 screen) {
|
142
|
+
box.R.mulToOut(world, screen);
|
143
|
+
if (yFlip) {
|
144
|
+
yFlipMat.mulToOut(screen, screen);
|
145
|
+
}
|
146
|
+
}
|
147
|
+
|
148
|
+
@Override
|
149
|
+
public void getWorldToScreen(Vec2 world, Vec2 screen) {
|
150
|
+
screen.x = world.x - box.center.x;
|
151
|
+
screen.y = world.y - box.center.y;
|
152
|
+
box.R.mulToOut(screen, screen);
|
153
|
+
if (yFlip) {
|
154
|
+
yFlipMat.mulToOut(screen, screen);
|
155
|
+
}
|
156
|
+
screen.x += box.extents.x;
|
157
|
+
screen.y += box.extents.y;
|
158
|
+
}
|
159
|
+
|
160
|
+
private final Mat22 inv2 = new Mat22();
|
161
|
+
|
162
|
+
@Override
|
163
|
+
public void getScreenToWorld(Vec2 screen, Vec2 world) {
|
164
|
+
world.x = screen.x - box.extents.x;
|
165
|
+
world.y = screen.y - box.extents.y;
|
166
|
+
if (yFlip) {
|
167
|
+
yFlipMat.mulToOut(world, world);
|
168
|
+
}
|
169
|
+
box.R.invertToOut(inv2);
|
170
|
+
inv2.mulToOut(world, world);
|
171
|
+
world.x += box.center.x;
|
172
|
+
world.y += box.center.y;
|
173
|
+
}
|
174
|
+
}
|
@@ -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
|
+
* Contains methods from MathUtils that rely on JVM features. These are separated out from
|
28
|
+
* MathUtils so that they can be overridden when compiling for GWT.
|
29
|
+
*/
|
30
|
+
class PlatformMathUtils {
|
31
|
+
|
32
|
+
private static final float SHIFT23 = 1 << 23;
|
33
|
+
private static final float INV_SHIFT23 = 1.0f / SHIFT23;
|
34
|
+
|
35
|
+
public static final float fastPow(float a, float b) {
|
36
|
+
float x = Float.floatToRawIntBits(a);
|
37
|
+
x *= INV_SHIFT23;
|
38
|
+
x -= 127;
|
39
|
+
float y = x - (x >= 0 ? (int) x : (int) x - 1);
|
40
|
+
b *= x + (y - y * y) * 0.346607f;
|
41
|
+
y = b - (b >= 0 ? (int) b : (int) b - 1);
|
42
|
+
y = (y - y * y) * 0.33971f;
|
43
|
+
return Float.intBitsToFloat((int) ((b + 127 - y) * SHIFT23));
|
44
|
+
}
|
45
|
+
}
|
46
|
+
|
@@ -0,0 +1,37 @@
|
|
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
|
+
// updated to rev 100
|
27
|
+
|
28
|
+
public class RaycastResult {
|
29
|
+
public float lambda = 0.0f;
|
30
|
+
public final Vec2 normal = new Vec2();
|
31
|
+
|
32
|
+
public RaycastResult set(RaycastResult argOther){
|
33
|
+
lambda = argOther.lambda;
|
34
|
+
normal.set( argOther.normal);
|
35
|
+
return this;
|
36
|
+
}
|
37
|
+
}
|
@@ -0,0 +1,150 @@
|
|
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
|
+
* Represents a rotation
|
30
|
+
*
|
31
|
+
* @author Daniel
|
32
|
+
*/
|
33
|
+
public class Rot implements Serializable {
|
34
|
+
private static final long serialVersionUID = 1L;
|
35
|
+
|
36
|
+
public float s, c; // sin and cos
|
37
|
+
|
38
|
+
public Rot() {
|
39
|
+
setIdentity();
|
40
|
+
}
|
41
|
+
|
42
|
+
public Rot(float angle) {
|
43
|
+
set(angle);
|
44
|
+
}
|
45
|
+
|
46
|
+
public float getSin() {
|
47
|
+
return s;
|
48
|
+
}
|
49
|
+
|
50
|
+
@Override
|
51
|
+
public String toString() {
|
52
|
+
return "Rot(s:" + s + ", c:" + c + ")";
|
53
|
+
}
|
54
|
+
|
55
|
+
public float getCos() {
|
56
|
+
return c;
|
57
|
+
}
|
58
|
+
|
59
|
+
public Rot set(float angle) {
|
60
|
+
s = MathUtils.sin(angle);
|
61
|
+
c = MathUtils.cos(angle);
|
62
|
+
return this;
|
63
|
+
}
|
64
|
+
|
65
|
+
public Rot set(Rot other) {
|
66
|
+
s = other.s;
|
67
|
+
c = other.c;
|
68
|
+
return this;
|
69
|
+
}
|
70
|
+
|
71
|
+
public Rot setIdentity() {
|
72
|
+
s = 0;
|
73
|
+
c = 1;
|
74
|
+
return this;
|
75
|
+
}
|
76
|
+
|
77
|
+
public float getAngle() {
|
78
|
+
return MathUtils.atan2(s, c);
|
79
|
+
}
|
80
|
+
|
81
|
+
public void getXAxis(Vec2 xAxis) {
|
82
|
+
xAxis.set(c, s);
|
83
|
+
}
|
84
|
+
|
85
|
+
public void getYAxis(Vec2 yAxis) {
|
86
|
+
yAxis.set(-s, c);
|
87
|
+
}
|
88
|
+
|
89
|
+
// @Override // annotation omitted for GWT-compatibility
|
90
|
+
public Rot clone() {
|
91
|
+
Rot copy = new Rot();
|
92
|
+
copy.s = s;
|
93
|
+
copy.c = c;
|
94
|
+
return copy;
|
95
|
+
}
|
96
|
+
|
97
|
+
public static final void mul(Rot q, Rot r, Rot out) {
|
98
|
+
float tempc = q.c * r.c - q.s * r.s;
|
99
|
+
out.s = q.s * r.c + q.c * r.s;
|
100
|
+
out.c = tempc;
|
101
|
+
}
|
102
|
+
|
103
|
+
public static final void mulUnsafe(Rot q, Rot r, Rot out) {
|
104
|
+
assert (r != out);
|
105
|
+
assert (q != out);
|
106
|
+
// [qc -qs] * [rc -rs] = [qc*rc-qs*rs -qc*rs-qs*rc]
|
107
|
+
// [qs qc] [rs rc] [qs*rc+qc*rs -qs*rs+qc*rc]
|
108
|
+
// s = qs * rc + qc * rs
|
109
|
+
// c = qc * rc - qs * rs
|
110
|
+
out.s = q.s * r.c + q.c * r.s;
|
111
|
+
out.c = q.c * r.c - q.s * r.s;
|
112
|
+
}
|
113
|
+
|
114
|
+
public static final void mulTrans(Rot q, Rot r, Rot out) {
|
115
|
+
final float tempc = q.c * r.c + q.s * r.s;
|
116
|
+
out.s = q.c * r.s - q.s * r.c;
|
117
|
+
out.c = tempc;
|
118
|
+
}
|
119
|
+
|
120
|
+
public static final void mulTransUnsafe(Rot q, Rot r, Rot out) {
|
121
|
+
// [ qc qs] * [rc -rs] = [qc*rc+qs*rs -qc*rs+qs*rc]
|
122
|
+
// [-qs qc] [rs rc] [-qs*rc+qc*rs qs*rs+qc*rc]
|
123
|
+
// s = qc * rs - qs * rc
|
124
|
+
// c = qc * rc + qs * rs
|
125
|
+
out.s = q.c * r.s - q.s * r.c;
|
126
|
+
out.c = q.c * r.c + q.s * r.s;
|
127
|
+
}
|
128
|
+
|
129
|
+
public static final void mulToOut(Rot q, Vec2 v, Vec2 out) {
|
130
|
+
float tempy = q.s * v.x + q.c * v.y;
|
131
|
+
out.x = q.c * v.x - q.s * v.y;
|
132
|
+
out.y = tempy;
|
133
|
+
}
|
134
|
+
|
135
|
+
public static final void mulToOutUnsafe(Rot q, Vec2 v, Vec2 out) {
|
136
|
+
out.x = q.c * v.x - q.s * v.y;
|
137
|
+
out.y = q.s * v.x + q.c * v.y;
|
138
|
+
}
|
139
|
+
|
140
|
+
public static final void mulTrans(Rot q, Vec2 v, Vec2 out) {
|
141
|
+
final float tempy = -q.s * v.x + q.c * v.y;
|
142
|
+
out.x = q.c * v.x + q.s * v.y;
|
143
|
+
out.y = tempy;
|
144
|
+
}
|
145
|
+
|
146
|
+
public static final void mulTransUnsafe(Rot q, Vec2 v, Vec2 out) {
|
147
|
+
out.x = q.c * v.x + q.s * v.y;
|
148
|
+
out.y = -q.s * v.x + q.c * v.y;
|
149
|
+
}
|
150
|
+
}
|
@@ -0,0 +1,246 @@
|
|
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
|
+
* Global tuning constants based on MKS units and various integer maximums (vertices per shape,
|
28
|
+
* pairs, etc.).
|
29
|
+
*/
|
30
|
+
public class Settings {
|
31
|
+
|
32
|
+
/** A "close to zero" float epsilon value for use */
|
33
|
+
public static final float EPSILON = 1.1920928955078125E-7f;
|
34
|
+
|
35
|
+
/** Pi. */
|
36
|
+
public static final float PI = (float) Math.PI;
|
37
|
+
|
38
|
+
// JBox2D specific settings
|
39
|
+
public static boolean FAST_ABS = true;
|
40
|
+
public static boolean FAST_FLOOR = true;
|
41
|
+
public static boolean FAST_CEIL = true;
|
42
|
+
public static boolean FAST_ROUND = true;
|
43
|
+
public static boolean FAST_ATAN2 = true;
|
44
|
+
public static boolean FAST_POW = true;
|
45
|
+
public static int CONTACT_STACK_INIT_SIZE = 10;
|
46
|
+
public static boolean SINCOS_LUT_ENABLED = true;
|
47
|
+
/**
|
48
|
+
* smaller the precision, the larger the table. If a small table is used (eg, precision is .006 or
|
49
|
+
* greater), make sure you set the table to lerp it's results. Accuracy chart is in the MathUtils
|
50
|
+
* source. Or, run the tests yourself in {@link SinCosTest}.</br> </br> Good lerp precision
|
51
|
+
* values:
|
52
|
+
* <ul>
|
53
|
+
* <li>.0092</li>
|
54
|
+
* <li>.008201</li>
|
55
|
+
* <li>.005904</li>
|
56
|
+
* <li>.005204</li>
|
57
|
+
* <li>.004305</li>
|
58
|
+
* <li>.002807</li>
|
59
|
+
* <li>.001508</li>
|
60
|
+
* <li>9.32500E-4</li>
|
61
|
+
* <li>7.48000E-4</li>
|
62
|
+
* <li>8.47000E-4</li>
|
63
|
+
* <li>.0005095</li>
|
64
|
+
* <li>.0001098</li>
|
65
|
+
* <li>9.50499E-5</li>
|
66
|
+
* <li>6.08500E-5</li>
|
67
|
+
* <li>3.07000E-5</li>
|
68
|
+
* <li>1.53999E-5</li>
|
69
|
+
* </ul>
|
70
|
+
*/
|
71
|
+
public static final float SINCOS_LUT_PRECISION = .00011f;
|
72
|
+
public static final int SINCOS_LUT_LENGTH = (int) Math.ceil(Math.PI * 2 / SINCOS_LUT_PRECISION);
|
73
|
+
/**
|
74
|
+
* Use if the table's precision is large (eg .006 or greater). Although it is more expensive, it
|
75
|
+
* greatly increases accuracy. Look in the MathUtils source for some test results on the accuracy
|
76
|
+
* and speed of lerp vs non lerp. Or, run the tests yourself in {@link SinCosTest}.
|
77
|
+
*/
|
78
|
+
public static boolean SINCOS_LUT_LERP = false;
|
79
|
+
|
80
|
+
|
81
|
+
// Collision
|
82
|
+
|
83
|
+
/**
|
84
|
+
* The maximum number of contact points between two convex shapes.
|
85
|
+
*/
|
86
|
+
public static int maxManifoldPoints = 2;
|
87
|
+
|
88
|
+
/**
|
89
|
+
* The maximum number of vertices on a convex polygon.
|
90
|
+
*/
|
91
|
+
public static int maxPolygonVertices = 8;
|
92
|
+
|
93
|
+
/**
|
94
|
+
* This is used to fatten AABBs in the dynamic tree. This allows proxies to move by a small amount
|
95
|
+
* without triggering a tree adjustment. This is in meters.
|
96
|
+
*/
|
97
|
+
public static float aabbExtension = 0.1f;
|
98
|
+
|
99
|
+
/**
|
100
|
+
* This is used to fatten AABBs in the dynamic tree. This is used to predict the future position
|
101
|
+
* based on the current displacement. This is a dimensionless multiplier.
|
102
|
+
*/
|
103
|
+
public static float aabbMultiplier = 2.0f;
|
104
|
+
|
105
|
+
/**
|
106
|
+
* A small length used as a collision and constraint tolerance. Usually it is chosen to be
|
107
|
+
* numerically significant, but visually insignificant.
|
108
|
+
*/
|
109
|
+
public static float linearSlop = 0.005f;
|
110
|
+
|
111
|
+
/**
|
112
|
+
* A small angle used as a collision and constraint tolerance. Usually it is chosen to be
|
113
|
+
* numerically significant, but visually insignificant.
|
114
|
+
*/
|
115
|
+
public static float angularSlop = (2.0f / 180.0f * PI);
|
116
|
+
|
117
|
+
/**
|
118
|
+
* The radius of the polygon/edge shape skin. This should not be modified. Making this smaller
|
119
|
+
* means polygons will have and insufficient for continuous collision. Making it larger may create
|
120
|
+
* artifacts for vertex collision.
|
121
|
+
*/
|
122
|
+
public static float polygonRadius = (2.0f * linearSlop);
|
123
|
+
|
124
|
+
/** Maximum number of sub-steps per contact in continuous physics simulation. */
|
125
|
+
public static int maxSubSteps = 8;
|
126
|
+
|
127
|
+
// Dynamics
|
128
|
+
|
129
|
+
/**
|
130
|
+
* Maximum number of contacts to be handled to solve a TOI island.
|
131
|
+
*/
|
132
|
+
public static int maxTOIContacts = 32;
|
133
|
+
|
134
|
+
/**
|
135
|
+
* A velocity threshold for elastic collisions. Any collision with a relative linear velocity
|
136
|
+
* below this threshold will be treated as inelastic.
|
137
|
+
*/
|
138
|
+
public static float velocityThreshold = 1.0f;
|
139
|
+
|
140
|
+
/**
|
141
|
+
* The maximum linear position correction used when solving constraints. This helps to prevent
|
142
|
+
* overshoot.
|
143
|
+
*/
|
144
|
+
public static float maxLinearCorrection = 0.2f;
|
145
|
+
|
146
|
+
/**
|
147
|
+
* The maximum angular position correction used when solving constraints. This helps to prevent
|
148
|
+
* overshoot.
|
149
|
+
*/
|
150
|
+
public static float maxAngularCorrection = (8.0f / 180.0f * PI);
|
151
|
+
|
152
|
+
/**
|
153
|
+
* The maximum linear velocity of a body. This limit is very large and is used to prevent
|
154
|
+
* numerical problems. You shouldn't need to adjust this.
|
155
|
+
*/
|
156
|
+
public static float maxTranslation = 2.0f;
|
157
|
+
public static float maxTranslationSquared = (maxTranslation * maxTranslation);
|
158
|
+
|
159
|
+
/**
|
160
|
+
* The maximum angular velocity of a body. This limit is very large and is used to prevent
|
161
|
+
* numerical problems. You shouldn't need to adjust this.
|
162
|
+
*/
|
163
|
+
public static float maxRotation = (0.5f * PI);
|
164
|
+
public static float maxRotationSquared = (maxRotation * maxRotation);
|
165
|
+
|
166
|
+
/**
|
167
|
+
* This scale factor controls how fast overlap is resolved. Ideally this would be 1 so that
|
168
|
+
* overlap is removed in one time step. However using values close to 1 often lead to overshoot.
|
169
|
+
*/
|
170
|
+
public static float baumgarte = 0.2f;
|
171
|
+
public static float toiBaugarte = 0.75f;
|
172
|
+
|
173
|
+
|
174
|
+
// Sleep
|
175
|
+
|
176
|
+
/**
|
177
|
+
* The time that a body must be still before it will go to sleep.
|
178
|
+
*/
|
179
|
+
public static float timeToSleep = 0.5f;
|
180
|
+
|
181
|
+
/**
|
182
|
+
* A body cannot sleep if its linear velocity is above this tolerance.
|
183
|
+
*/
|
184
|
+
public static float linearSleepTolerance = 0.01f;
|
185
|
+
|
186
|
+
/**
|
187
|
+
* A body cannot sleep if its angular velocity is above this tolerance.
|
188
|
+
*/
|
189
|
+
public static float angularSleepTolerance = (2.0f / 180.0f * PI);
|
190
|
+
|
191
|
+
// Particle
|
192
|
+
|
193
|
+
/**
|
194
|
+
* A symbolic constant that stands for particle allocation error.
|
195
|
+
*/
|
196
|
+
public static final int invalidParticleIndex = (-1);
|
197
|
+
|
198
|
+
/**
|
199
|
+
* The standard distance between particles, divided by the particle radius.
|
200
|
+
*/
|
201
|
+
public static final float particleStride = 0.75f;
|
202
|
+
|
203
|
+
/**
|
204
|
+
* The minimum particle weight that produces pressure.
|
205
|
+
*/
|
206
|
+
public static final float minParticleWeight = 1.0f;
|
207
|
+
|
208
|
+
/**
|
209
|
+
* The upper limit for particle weight used in pressure calculation.
|
210
|
+
*/
|
211
|
+
public static final float maxParticleWeight = 5.0f;
|
212
|
+
|
213
|
+
/**
|
214
|
+
* The maximum distance between particles in a triad, divided by the particle radius.
|
215
|
+
*/
|
216
|
+
public static final int maxTriadDistance = 2;
|
217
|
+
public static final int maxTriadDistanceSquared = (maxTriadDistance * maxTriadDistance);
|
218
|
+
|
219
|
+
/**
|
220
|
+
* The initial size of particle data buffers.
|
221
|
+
*/
|
222
|
+
public static final int minParticleBufferCapacity = 256;
|
223
|
+
|
224
|
+
|
225
|
+
/**
|
226
|
+
* Friction mixing law. Feel free to customize this. TODO djm: add customization
|
227
|
+
*
|
228
|
+
* @param friction1
|
229
|
+
* @param friction2
|
230
|
+
* @return
|
231
|
+
*/
|
232
|
+
public static float mixFriction(float friction1, float friction2) {
|
233
|
+
return MathUtils.sqrt(friction1 * friction2);
|
234
|
+
}
|
235
|
+
|
236
|
+
/**
|
237
|
+
* Restitution mixing law. Feel free to customize this. TODO djm: add customization
|
238
|
+
*
|
239
|
+
* @param restitution1
|
240
|
+
* @param restitution2
|
241
|
+
* @return
|
242
|
+
*/
|
243
|
+
public static float mixRestitution(float restitution1, float restitution2) {
|
244
|
+
return restitution1 > restitution2 ? restitution1 : restitution2;
|
245
|
+
}
|
246
|
+
}
|