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,62 @@
|
|
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.dynamics;
|
25
|
+
|
26
|
+
// updated to rev 100
|
27
|
+
/**
|
28
|
+
* This holds contact filtering data.
|
29
|
+
*
|
30
|
+
* @author daniel
|
31
|
+
*/
|
32
|
+
public class Filter {
|
33
|
+
/**
|
34
|
+
* The collision category bits. Normally you would just set one bit.
|
35
|
+
*/
|
36
|
+
public int categoryBits;
|
37
|
+
|
38
|
+
/**
|
39
|
+
* The collision mask bits. This states the categories that this
|
40
|
+
* shape would accept for collision.
|
41
|
+
*/
|
42
|
+
public int maskBits;
|
43
|
+
|
44
|
+
/**
|
45
|
+
* Collision groups allow a certain group of objects to never collide (negative)
|
46
|
+
* or always collide (positive). Zero means no collision group. Non-zero group
|
47
|
+
* filtering always wins against the mask bits.
|
48
|
+
*/
|
49
|
+
public int groupIndex;
|
50
|
+
|
51
|
+
public Filter() {
|
52
|
+
categoryBits = 0x0001;
|
53
|
+
maskBits = 0xFFFF;
|
54
|
+
groupIndex = 0;
|
55
|
+
}
|
56
|
+
|
57
|
+
public void set(Filter argOther) {
|
58
|
+
categoryBits = argOther.categoryBits;
|
59
|
+
maskBits = argOther.maskBits;
|
60
|
+
groupIndex = argOther.groupIndex;
|
61
|
+
}
|
62
|
+
}
|
@@ -0,0 +1,454 @@
|
|
1
|
+
/**
|
2
|
+
* *****************************************************************************
|
3
|
+
* Copyright (c) 2013, Daniel Murphy
|
4
|
+
* All rights reserved.
|
5
|
+
*
|
6
|
+
* Redistribution and use in source and binary forms, with or without modification,
|
7
|
+
* are permitted provided that the following conditions are met:
|
8
|
+
* * Redistributions of source code must retain the above copyright notice,
|
9
|
+
* this list of conditions and the following disclaimer.
|
10
|
+
* * Redistributions in binary form must reproduce the above copyright notice,
|
11
|
+
* this list of conditions and the following disclaimer in the documentation
|
12
|
+
* and/or other materials provided with the distribution.
|
13
|
+
*
|
14
|
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
15
|
+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
16
|
+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
17
|
+
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
18
|
+
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
19
|
+
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
20
|
+
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
21
|
+
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
22
|
+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
23
|
+
* POSSIBILITY OF SUCH DAMAGE.
|
24
|
+
*****************************************************************************
|
25
|
+
*/
|
26
|
+
package org.jbox2d.dynamics;
|
27
|
+
|
28
|
+
import org.jbox2d.collision.AABB;
|
29
|
+
import org.jbox2d.collision.RayCastInput;
|
30
|
+
import org.jbox2d.collision.RayCastOutput;
|
31
|
+
import org.jbox2d.collision.broadphase.BroadPhase;
|
32
|
+
import org.jbox2d.collision.shapes.MassData;
|
33
|
+
import org.jbox2d.collision.shapes.Shape;
|
34
|
+
import org.jbox2d.collision.shapes.ShapeType;
|
35
|
+
import org.jbox2d.common.MathUtils;
|
36
|
+
import org.jbox2d.common.Transform;
|
37
|
+
import org.jbox2d.common.Vec2;
|
38
|
+
import org.jbox2d.dynamics.contacts.Contact;
|
39
|
+
import org.jbox2d.dynamics.contacts.ContactEdge;
|
40
|
+
|
41
|
+
/**
|
42
|
+
* A fixture is used to attach a shape to a body for collision detection. A
|
43
|
+
* fixture inherits its transform from its parent. Fixtures hold additional
|
44
|
+
* non-geometric data such as friction, collision filters, etc. Fixtures are
|
45
|
+
* created via Body::CreateFixture.
|
46
|
+
*
|
47
|
+
* @warning you cannot reuse fixtures.
|
48
|
+
*
|
49
|
+
* @author daniel
|
50
|
+
*/
|
51
|
+
public class Fixture {
|
52
|
+
|
53
|
+
public float m_density;
|
54
|
+
|
55
|
+
public Fixture m_next;
|
56
|
+
public Body m_body;
|
57
|
+
|
58
|
+
public Shape m_shape;
|
59
|
+
|
60
|
+
public float m_friction;
|
61
|
+
public float m_restitution;
|
62
|
+
|
63
|
+
public FixtureProxy[] m_proxies;
|
64
|
+
public int m_proxyCount;
|
65
|
+
|
66
|
+
public final Filter m_filter;
|
67
|
+
|
68
|
+
public boolean m_isSensor;
|
69
|
+
|
70
|
+
public Object m_userData;
|
71
|
+
|
72
|
+
public Fixture() {
|
73
|
+
m_userData = null;
|
74
|
+
m_body = null;
|
75
|
+
m_next = null;
|
76
|
+
m_proxies = null;
|
77
|
+
m_proxyCount = 0;
|
78
|
+
m_shape = null;
|
79
|
+
m_filter = new Filter();
|
80
|
+
}
|
81
|
+
|
82
|
+
/**
|
83
|
+
* Get the type of the child shape. You can use this to down cast to the
|
84
|
+
* concrete shape.
|
85
|
+
*
|
86
|
+
* @return the shape type.
|
87
|
+
*/
|
88
|
+
public ShapeType getType() {
|
89
|
+
return m_shape.getType();
|
90
|
+
}
|
91
|
+
|
92
|
+
/**
|
93
|
+
* Get the child shape. You can modify the child shape, however you should
|
94
|
+
* not change the number of vertices because this will crash some collision
|
95
|
+
* caching mechanisms.
|
96
|
+
*
|
97
|
+
* @return
|
98
|
+
*/
|
99
|
+
public Shape getShape() {
|
100
|
+
return m_shape;
|
101
|
+
}
|
102
|
+
|
103
|
+
/**
|
104
|
+
* Is this fixture a sensor (non-solid)?
|
105
|
+
*
|
106
|
+
* @return the true if the shape is a sensor.
|
107
|
+
*/
|
108
|
+
public boolean isSensor() {
|
109
|
+
return m_isSensor;
|
110
|
+
}
|
111
|
+
|
112
|
+
/**
|
113
|
+
* Set if this fixture is a sensor.
|
114
|
+
*
|
115
|
+
* @param sensor
|
116
|
+
*/
|
117
|
+
public void setSensor(boolean sensor) {
|
118
|
+
if (sensor != m_isSensor) {
|
119
|
+
m_body.setAwake(true);
|
120
|
+
m_isSensor = sensor;
|
121
|
+
}
|
122
|
+
}
|
123
|
+
|
124
|
+
/**
|
125
|
+
* Set the contact filtering data. This is an expensive operation and should
|
126
|
+
* not be called frequently. This will not update contacts until the next
|
127
|
+
* time step when either parent body is awake. This automatically calls
|
128
|
+
* refilter.
|
129
|
+
*
|
130
|
+
* @param filter
|
131
|
+
*/
|
132
|
+
public void setFilterData(final Filter filter) {
|
133
|
+
m_filter.set(filter);
|
134
|
+
|
135
|
+
refilter();
|
136
|
+
}
|
137
|
+
|
138
|
+
/**
|
139
|
+
* Get the contact filtering data.
|
140
|
+
*
|
141
|
+
* @return
|
142
|
+
*/
|
143
|
+
public Filter getFilterData() {
|
144
|
+
return m_filter;
|
145
|
+
}
|
146
|
+
|
147
|
+
/**
|
148
|
+
* Call this if you want to establish collision that was previously disabled
|
149
|
+
* by ContactFilter::ShouldCollide.
|
150
|
+
*/
|
151
|
+
public void refilter() {
|
152
|
+
if (m_body == null) {
|
153
|
+
return;
|
154
|
+
}
|
155
|
+
|
156
|
+
// Flag associated contacts for filtering.
|
157
|
+
ContactEdge edge = m_body.getContactList();
|
158
|
+
while (edge != null) {
|
159
|
+
Contact contact = edge.contact;
|
160
|
+
Fixture fixtureA = contact.getFixtureA();
|
161
|
+
Fixture fixtureB = contact.getFixtureB();
|
162
|
+
if (fixtureA == this || fixtureB == this) {
|
163
|
+
contact.flagForFiltering();
|
164
|
+
}
|
165
|
+
edge = edge.next;
|
166
|
+
}
|
167
|
+
|
168
|
+
World world = m_body.getWorld();
|
169
|
+
|
170
|
+
if (world == null) {
|
171
|
+
return;
|
172
|
+
}
|
173
|
+
|
174
|
+
// Touch each proxy so that new pairs may be created
|
175
|
+
BroadPhase broadPhase = world.m_contactManager.m_broadPhase;
|
176
|
+
for (int i = 0; i < m_proxyCount; ++i) {
|
177
|
+
broadPhase.touchProxy(m_proxies[i].proxyId);
|
178
|
+
}
|
179
|
+
}
|
180
|
+
|
181
|
+
/**
|
182
|
+
* Get the parent body of this fixture. This is NULL if the fixture is not
|
183
|
+
* attached.
|
184
|
+
*
|
185
|
+
* @return the parent body.
|
186
|
+
*/
|
187
|
+
public Body getBody() {
|
188
|
+
return m_body;
|
189
|
+
}
|
190
|
+
|
191
|
+
/**
|
192
|
+
* Get the next fixture in the parent body's fixture list.
|
193
|
+
*
|
194
|
+
* @return the next shape.
|
195
|
+
*/
|
196
|
+
public Fixture getNext() {
|
197
|
+
return m_next;
|
198
|
+
}
|
199
|
+
|
200
|
+
public void setDensity(float density) {
|
201
|
+
assert (density >= 0f);
|
202
|
+
m_density = density;
|
203
|
+
}
|
204
|
+
|
205
|
+
public float getDensity() {
|
206
|
+
return m_density;
|
207
|
+
}
|
208
|
+
|
209
|
+
/**
|
210
|
+
* Get the user data that was assigned in the fixture definition. Use this
|
211
|
+
* to store your application specific data.
|
212
|
+
*
|
213
|
+
* @return
|
214
|
+
*/
|
215
|
+
public Object getUserData() {
|
216
|
+
return m_userData;
|
217
|
+
}
|
218
|
+
|
219
|
+
/**
|
220
|
+
* Set the user data. Use this to store your application specific data.
|
221
|
+
*
|
222
|
+
* @param data
|
223
|
+
*/
|
224
|
+
public void setUserData(Object data) {
|
225
|
+
m_userData = data;
|
226
|
+
}
|
227
|
+
|
228
|
+
/**
|
229
|
+
* Test a point for containment in this fixture. This only works for convex
|
230
|
+
* shapes.
|
231
|
+
*
|
232
|
+
* @param p a point in world coordinates.
|
233
|
+
* @return
|
234
|
+
*/
|
235
|
+
public boolean testPoint(final Vec2 p) {
|
236
|
+
return m_shape.testPoint(m_body.m_xf, p);
|
237
|
+
}
|
238
|
+
|
239
|
+
/**
|
240
|
+
* Cast a ray against this shape.
|
241
|
+
*
|
242
|
+
* @param output the ray-cast results.
|
243
|
+
* @param input the ray-cast input parameters.
|
244
|
+
* @param childIndex
|
245
|
+
* @return
|
246
|
+
*/
|
247
|
+
public boolean raycast(RayCastOutput output, RayCastInput input, int childIndex) {
|
248
|
+
return m_shape.raycast(output, input, m_body.m_xf, childIndex);
|
249
|
+
}
|
250
|
+
|
251
|
+
/**
|
252
|
+
* Get the mass data for this fixture. The mass data is based on the density
|
253
|
+
* and the shape. The rotational inertia is about the shape's origin.
|
254
|
+
*
|
255
|
+
* @param massData
|
256
|
+
*/
|
257
|
+
public void getMassData(MassData massData) {
|
258
|
+
m_shape.computeMass(massData, m_density);
|
259
|
+
}
|
260
|
+
|
261
|
+
/**
|
262
|
+
* Get the coefficient of friction.
|
263
|
+
*
|
264
|
+
* @return
|
265
|
+
*/
|
266
|
+
public float getFriction() {
|
267
|
+
return m_friction;
|
268
|
+
}
|
269
|
+
|
270
|
+
/**
|
271
|
+
* Set the coefficient of friction. This will _not_ change the friction of
|
272
|
+
* existing contacts.
|
273
|
+
*
|
274
|
+
* @param friction
|
275
|
+
*/
|
276
|
+
public void setFriction(float friction) {
|
277
|
+
m_friction = friction;
|
278
|
+
}
|
279
|
+
|
280
|
+
/**
|
281
|
+
* Get the coefficient of restitution.
|
282
|
+
*
|
283
|
+
* @return
|
284
|
+
*/
|
285
|
+
public float getRestitution() {
|
286
|
+
return m_restitution;
|
287
|
+
}
|
288
|
+
|
289
|
+
/**
|
290
|
+
* Set the coefficient of restitution. This will _not_ change the
|
291
|
+
* restitution of existing contacts.
|
292
|
+
*
|
293
|
+
* @param restitution
|
294
|
+
*/
|
295
|
+
public void setRestitution(float restitution) {
|
296
|
+
m_restitution = restitution;
|
297
|
+
}
|
298
|
+
|
299
|
+
/**
|
300
|
+
* Get the fixture's AABB. This AABB may be enlarge and/or stale. If you
|
301
|
+
* need a more accurate AABB, compute it using the shape and the body
|
302
|
+
* transform.
|
303
|
+
*
|
304
|
+
* @param childIndex
|
305
|
+
* @return
|
306
|
+
*/
|
307
|
+
public AABB getAABB(int childIndex) {
|
308
|
+
assert (childIndex >= 0 && childIndex < m_proxyCount);
|
309
|
+
return m_proxies[childIndex].aabb;
|
310
|
+
}
|
311
|
+
|
312
|
+
/**
|
313
|
+
* Compute the distance from this fixture.
|
314
|
+
*
|
315
|
+
* @param p a point in world coordinates.
|
316
|
+
* @param childIndex
|
317
|
+
* @param normalOut
|
318
|
+
* @return distance
|
319
|
+
*/
|
320
|
+
public float computeDistance(Vec2 p, int childIndex, Vec2 normalOut) {
|
321
|
+
return m_shape.computeDistanceToOut(m_body.getTransform(), p, childIndex, normalOut);
|
322
|
+
}
|
323
|
+
|
324
|
+
// We need separation create/destroy functions from the constructor/destructor because
|
325
|
+
// the destructor cannot access the allocator (no destructor arguments allowed by C++).
|
326
|
+
public void create(Body body, FixtureDef def) {
|
327
|
+
m_userData = def.userData;
|
328
|
+
m_friction = def.friction;
|
329
|
+
m_restitution = def.restitution;
|
330
|
+
|
331
|
+
m_body = body;
|
332
|
+
m_next = null;
|
333
|
+
|
334
|
+
m_filter.set(def.filter);
|
335
|
+
|
336
|
+
m_isSensor = def.isSensor;
|
337
|
+
|
338
|
+
m_shape = def.shape.clone();
|
339
|
+
|
340
|
+
// Reserve proxy space
|
341
|
+
int childCount = m_shape.getChildCount();
|
342
|
+
if (m_proxies == null) {
|
343
|
+
m_proxies = new FixtureProxy[childCount];
|
344
|
+
for (int i = 0; i < childCount; i++) {
|
345
|
+
m_proxies[i] = new FixtureProxy();
|
346
|
+
m_proxies[i].fixture = null;
|
347
|
+
m_proxies[i].proxyId = BroadPhase.NULL_PROXY;
|
348
|
+
}
|
349
|
+
}
|
350
|
+
|
351
|
+
if (m_proxies.length < childCount) {
|
352
|
+
FixtureProxy[] old = m_proxies;
|
353
|
+
int newLen = MathUtils.max(old.length * 2, childCount);
|
354
|
+
m_proxies = new FixtureProxy[newLen];
|
355
|
+
System.arraycopy(old, 0, m_proxies, 0, old.length);
|
356
|
+
for (int i = 0; i < newLen; i++) {
|
357
|
+
if (i >= old.length) {
|
358
|
+
m_proxies[i] = new FixtureProxy();
|
359
|
+
}
|
360
|
+
m_proxies[i].fixture = null;
|
361
|
+
m_proxies[i].proxyId = BroadPhase.NULL_PROXY;
|
362
|
+
}
|
363
|
+
}
|
364
|
+
m_proxyCount = 0;
|
365
|
+
|
366
|
+
m_density = def.density;
|
367
|
+
}
|
368
|
+
|
369
|
+
public void destroy() {
|
370
|
+
// The proxies must be destroyed before calling this.
|
371
|
+
assert (m_proxyCount == 0);
|
372
|
+
|
373
|
+
// Free the child shape.
|
374
|
+
m_shape = null;
|
375
|
+
m_proxies = null;
|
376
|
+
m_next = null;
|
377
|
+
|
378
|
+
// TODO pool shapes
|
379
|
+
// TODO pool fixtures
|
380
|
+
}
|
381
|
+
|
382
|
+
// These support body activation/deactivation.
|
383
|
+
public void createProxies(BroadPhase broadPhase, final Transform xf) {
|
384
|
+
assert (m_proxyCount == 0);
|
385
|
+
|
386
|
+
// Create proxies in the broad-phase.
|
387
|
+
m_proxyCount = m_shape.getChildCount();
|
388
|
+
|
389
|
+
for (int i = 0; i < m_proxyCount; ++i) {
|
390
|
+
FixtureProxy proxy = m_proxies[i];
|
391
|
+
m_shape.computeAABB(proxy.aabb, xf, i);
|
392
|
+
proxy.proxyId = broadPhase.createProxy(proxy.aabb, proxy);
|
393
|
+
proxy.fixture = this;
|
394
|
+
proxy.childIndex = i;
|
395
|
+
}
|
396
|
+
}
|
397
|
+
|
398
|
+
/**
|
399
|
+
* Internal method
|
400
|
+
*
|
401
|
+
* @param broadPhase
|
402
|
+
*/
|
403
|
+
public void destroyProxies(BroadPhase broadPhase) {
|
404
|
+
// Destroy proxies in the broad-phase.
|
405
|
+
for (int i = 0; i < m_proxyCount; ++i) {
|
406
|
+
FixtureProxy proxy = m_proxies[i];
|
407
|
+
broadPhase.destroyProxy(proxy.proxyId);
|
408
|
+
proxy.proxyId = BroadPhase.NULL_PROXY;
|
409
|
+
}
|
410
|
+
|
411
|
+
m_proxyCount = 0;
|
412
|
+
}
|
413
|
+
|
414
|
+
private final AABB pool1 = new AABB();
|
415
|
+
private final AABB pool2 = new AABB();
|
416
|
+
private final Vec2 displacement = new Vec2();
|
417
|
+
|
418
|
+
/**
|
419
|
+
* Internal method
|
420
|
+
*
|
421
|
+
* @param broadPhase
|
422
|
+
* @param transform1
|
423
|
+
* @param transform2
|
424
|
+
*/
|
425
|
+
protected void synchronize(BroadPhase broadPhase, final Transform transform1,
|
426
|
+
final Transform transform2) {
|
427
|
+
if (m_proxyCount == 0) {
|
428
|
+
return;
|
429
|
+
}
|
430
|
+
|
431
|
+
for (int i = 0; i < m_proxyCount; ++i) {
|
432
|
+
FixtureProxy proxy = m_proxies[i];
|
433
|
+
|
434
|
+
// Compute an AABB that covers the swept shape (may miss some rotation effect).
|
435
|
+
final AABB aabb1 = pool1;
|
436
|
+
final AABB aab = pool2;
|
437
|
+
m_shape.computeAABB(aabb1, transform1, proxy.childIndex);
|
438
|
+
m_shape.computeAABB(aab, transform2, proxy.childIndex);
|
439
|
+
|
440
|
+
proxy.aabb.lowerBound.x
|
441
|
+
= aabb1.lowerBound.x < aab.lowerBound.x ? aabb1.lowerBound.x : aab.lowerBound.x;
|
442
|
+
proxy.aabb.lowerBound.y
|
443
|
+
= aabb1.lowerBound.y < aab.lowerBound.y ? aabb1.lowerBound.y : aab.lowerBound.y;
|
444
|
+
proxy.aabb.upperBound.x
|
445
|
+
= aabb1.upperBound.x > aab.upperBound.x ? aabb1.upperBound.x : aab.upperBound.x;
|
446
|
+
proxy.aabb.upperBound.y
|
447
|
+
= aabb1.upperBound.y > aab.upperBound.y ? aabb1.upperBound.y : aab.upperBound.y;
|
448
|
+
displacement.x = transform2.p.x - transform1.p.x;
|
449
|
+
displacement.y = transform2.p.y - transform1.p.y;
|
450
|
+
|
451
|
+
broadPhase.moveProxy(proxy.proxyId, proxy.aabb, displacement);
|
452
|
+
}
|
453
|
+
}
|
454
|
+
}
|