Skip to content

Commit 32ba953

Browse files
committed
Update to "Implement the islands computation"
DanielChappuis/reactphysics3d@f1d29b5123f649aa e8bb042b13383cec04ae93cb
1 parent 6e8e567 commit 32ba953

File tree

9 files changed

+602
-6
lines changed

9 files changed

+602
-6
lines changed

src/main/java/org/spout/physics/ReactDefaults.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public class ReactDefaults {
5757
/**
5858
* True if the deactivation (sleeping) of inactive bodies is enabled. Default: true
5959
*/
60-
public static final boolean DEACTIVATION_ENABLED = true;
60+
public static final boolean SLEEPING_ENABLED = true;
6161
/**
6262
* Object margin for collision detection in meters (for the GJK-EPA Algorithm). Default: 0.04
6363
*/

src/main/java/org/spout/physics/body/Body.java

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@
3131
*/
3232
public class Body {
3333
protected final int mID;
34+
protected boolean mIsAlreadyInIsland;
35+
protected boolean mIsAllowedToSleep;
36+
protected boolean mIsSleeping;
3437

3538
/**
3639
* Construct a new body from its ID.
@@ -50,6 +53,60 @@ public int getID() {
5053
return mID;
5154
}
5255

56+
/**
57+
* Returns true if the body has already been added in an island (for the sleeping technique).
58+
*
59+
* @return Whether or not the body is already in an island
60+
*/
61+
public boolean isAlreadyInIsland() {
62+
return mIsAlreadyInIsland;
63+
}
64+
65+
/**
66+
* Sets the value of to know if the body has already been added into an island.
67+
*
68+
* @param isAlreadyInIsland Whether or not the body is in an island
69+
*/
70+
public void setIsAlreadyInIsland(boolean isAlreadyInIsland) {
71+
mIsAlreadyInIsland = isAlreadyInIsland;
72+
}
73+
74+
/**
75+
* Returns whether or not the body is allowed to sleep.
76+
*
77+
* @return Whether or not the body can sleep
78+
*/
79+
public boolean isAllowedToSleep() {
80+
return mIsAllowedToSleep;
81+
}
82+
83+
/**
84+
* Set whether or not the body is allowed to go to sleep.
85+
*
86+
* @param isAllowedToSleep Whether or not the body should be able to sleep
87+
*/
88+
public void setIsAllowedToSleep(boolean isAllowedToSleep) {
89+
mIsAllowedToSleep = isAllowedToSleep;
90+
}
91+
92+
/**
93+
* Returns whether or not the body is sleeping.
94+
*
95+
* @return Whether or not the body is sleeping
96+
*/
97+
public boolean isSleeping() {
98+
return mIsSleeping;
99+
}
100+
101+
/**
102+
* Set the variable to know whether or not the body is sleeping.
103+
*
104+
* @param isSleeping Whether or not the body is sleeping
105+
*/
106+
public void setIsSleeping(boolean isSleeping) {
107+
mIsSleeping = isSleeping;
108+
}
109+
53110
/**
54111
* Returns true this body's ID is smaller than the other body's ID, false if not.
55112
*

src/main/java/org/spout/physics/body/CollisionBody.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

2929
import org.spout.physics.collision.shape.AABB;
3030
import org.spout.physics.collision.shape.CollisionShape;
31+
import org.spout.physics.engine.ContactManifold.ContactManifoldListElement;
3132
import org.spout.physics.math.Transform;
3233

3334
/**
@@ -43,6 +44,7 @@ public class CollisionBody extends Body {
4344
protected boolean mIsCollisionEnabled;
4445
protected final AABB mAabb = new AABB();
4546
protected boolean mHasMoved;
47+
protected ContactManifoldListElement mContactManifoldsList;
4648

4749
/**
4850
* Constructs a new collision body from its transform, collision shape, and ID.
@@ -65,6 +67,7 @@ public CollisionBody(Transform transform, CollisionShape collisionShape, int id)
6567
mInterpolationFactor = 0;
6668
mOldTransform = transform;
6769
mCollisionShape.updateAABB(mAabb, transform);
70+
mContactManifoldsList = null;
6871
}
6972

7073
/**
@@ -220,4 +223,29 @@ public void updateAABB() {
220223
mCollisionShape.updateAABB(mAabb, mTransform);
221224
}
222225
}
226+
227+
/**
228+
* Returns the first element of the linked list of contact manifolds involving this body.
229+
*
230+
* @return The first element of the list
231+
*/
232+
public ContactManifoldListElement getContactManifoldsLists() {
233+
return mContactManifoldsList;
234+
}
235+
236+
/**
237+
* Sets the first element in the contact element list, discarding the entire list.
238+
*
239+
* @param contactManifoldsList The first element in the list
240+
*/
241+
public void setContactManifoldsList(ContactManifoldListElement contactManifoldsList) {
242+
mContactManifoldsList = contactManifoldsList;
243+
}
244+
245+
/**
246+
* Resets the contact manifold lists.
247+
*/
248+
public void resetContactManifoldsList() {
249+
mContactManifoldsList = null;
250+
}
223251
}

src/main/java/org/spout/physics/body/RigidBody.java

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
package org.spout.physics.body;
2828

2929
import org.spout.physics.collision.shape.CollisionShape;
30+
import org.spout.physics.constraint.Constraint;
31+
import org.spout.physics.constraint.Constraint.JointListElement;
3032
import org.spout.physics.engine.Material;
3133
import org.spout.physics.math.Matrix3x3;
3234
import org.spout.physics.math.Transform;
@@ -49,6 +51,7 @@ public class RigidBody extends CollisionBody {
4951
private final Vector3 mAngularVelocity = new Vector3();
5052
private float mLinearDamping;
5153
private float mAngularDamping;
54+
private JointListElement mJointsList;
5255

5356
/**
5457
* Constructs a new rigid body from its transform, mass, local inertia tensor, collision shape and ID.
@@ -68,6 +71,7 @@ public RigidBody(Transform transform, float mass, Matrix3x3 inertiaTensorLocal,
6871
mIsGravityEnabled = true;
6972
mLinearDamping = 0;
7073
mAngularDamping = 0;
74+
mJointsList = null;
7175
}
7276

7377
/**
@@ -297,4 +301,49 @@ public void setAngularDamping(float angularDamping) {
297301
}
298302
mAngularDamping = angularDamping;
299303
}
304+
305+
/**
306+
* Returns the first element of the linked list of joints involving this body.
307+
*
308+
* @return The first element of the list
309+
*/
310+
public JointListElement getJointsList() {
311+
return mJointsList;
312+
}
313+
314+
/**
315+
* Sets the first element in the joint list, discarding the entire list.
316+
*
317+
* @param jointsList The first element in the list
318+
*/
319+
public void setJointsList(JointListElement jointsList) {
320+
mJointsList = jointsList;
321+
}
322+
323+
/**
324+
* Removes a joint from the joints list.
325+
*
326+
* @param joint The joint to remove
327+
*/
328+
public void removeJointFromJointsList(Constraint joint) {
329+
if (joint == null) {
330+
throw new IllegalArgumentException("Joint cannot be null");
331+
}
332+
if (mJointsList == null) {
333+
throw new IllegalStateException("The joint list is already empty");
334+
}
335+
if (mJointsList.getJoint() == joint) {
336+
final JointListElement elementToRemove = mJointsList;
337+
mJointsList = elementToRemove.getNext();
338+
} else {
339+
final JointListElement currentElement = mJointsList;
340+
while (currentElement.getNext() != null) {
341+
if (currentElement.getNext().getJoint() == joint) {
342+
final JointListElement elementToRemove = currentElement.getNext();
343+
currentElement.setNext(elementToRemove.getNext());
344+
break;
345+
}
346+
}
347+
}
348+
}
300349
}

src/main/java/org/spout/physics/constraint/Constraint.java

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ public abstract class Constraint {
4242
protected int mIndexBody2;
4343
protected final JointsPositionCorrectionTechnique mPositionCorrectionTechnique;
4444
protected final boolean mIsCollisionEnabled;
45+
protected boolean mIsAlreadyInIsland;
4546

4647
/**
4748
* Constructs a new constraint from the provided constraint info.
@@ -61,6 +62,7 @@ public Constraint(ConstraintInfo constraintInfo) {
6162
mType = constraintInfo.getType();
6263
mPositionCorrectionTechnique = constraintInfo.getPositionCorrectionTechnique();
6364
mIsCollisionEnabled = constraintInfo.isCollisionEnabled();
65+
mIsAlreadyInIsland = false;
6466
}
6567

6668
/**
@@ -136,6 +138,24 @@ public boolean isCollisionEnabled() {
136138
return mIsCollisionEnabled;
137139
}
138140

141+
/**
142+
* Returns true if the joint has already been added into an island.
143+
*
144+
* @return Whether or not the joint is already in an island
145+
*/
146+
public boolean isAlreadyInIsland() {
147+
return mIsAlreadyInIsland;
148+
}
149+
150+
/**
151+
* Sets whether or not this joint has already been added into an island.
152+
*
153+
* @param isAlreadyInIsland Whether or not the joint is already in an island
154+
*/
155+
public void setIsAlreadyInIsland(boolean isAlreadyInIsland) {
156+
mIsAlreadyInIsland = isAlreadyInIsland;
157+
}
158+
139159
/**
140160
* An enumeration of the possible constraint types (contact).
141161
*/
@@ -266,4 +286,59 @@ public void setPositionCorrectionTechnique(JointsPositionCorrectionTechnique pos
266286
this.positionCorrectionTechnique = positionCorrectionTechnique;
267287
}
268288
}
289+
290+
/**
291+
* This structure represents a single element of a linked list of joints.
292+
*/
293+
public static class JointListElement {
294+
private Constraint joint;
295+
private JointListElement next;
296+
297+
/**
298+
* Constructs a new joint list element from the initial joint and next list element.
299+
*
300+
* @param initJoint The joint
301+
* @param initNext The next element
302+
*/
303+
public JointListElement(Constraint initJoint, JointListElement initNext) {
304+
joint = initJoint;
305+
next = initNext;
306+
}
307+
308+
/**
309+
* Returns the joint in this list element.
310+
*
311+
* @return The joint
312+
*/
313+
public Constraint getJoint() {
314+
return joint;
315+
}
316+
317+
/**
318+
* Sets the joint in this list element.
319+
*
320+
* @param joint The joint
321+
*/
322+
public void setJoint(Constraint joint) {
323+
this.joint = joint;
324+
}
325+
326+
/**
327+
* Returns the next element in the list.
328+
*
329+
* @return The next element
330+
*/
331+
public JointListElement getNext() {
332+
return next;
333+
}
334+
335+
/**
336+
* Sets the next element in the list.
337+
*
338+
* @param next The next element
339+
*/
340+
public void setNext(JointListElement next) {
341+
this.next = next;
342+
}
343+
}
269344
}

0 commit comments

Comments
 (0)