Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 39 additions & 5 deletions jme3-bullet/src/main/java/com/jme3/bullet/PhysicsSpace.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,12 @@
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Comparator;
import java.util.concurrent.Callable;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentLinkedQueue;
Expand Down Expand Up @@ -780,15 +782,27 @@ public void addCollisionGroupListener(PhysicsCollisionGroupListener listener, in
public void removeCollisionGroupListener(int collisionGroup) {
collisionGroupListeners.remove(collisionGroup);
}

/**
* Performs a ray collision test and returns the results as a list of
* PhysicsRayTestResults
* PhysicsRayTestResults ordered by it hitFraction (lower to higher)
*/
public List rayTest(Vector3f from, Vector3f to) {
List results = new LinkedList();
List<PhysicsRayTestResult> results = new ArrayList<PhysicsRayTestResult>();
rayTest(from, to, results);
return (List<PhysicsRayTestResult>) results;

return results;
}

/**
* Performs a ray collision test and returns the results as a list of
* PhysicsRayTestResults without performing any sort operation
*/
public List rayTestRaw(Vector3f from, Vector3f to) {
List<PhysicsRayTestResult> results = new ArrayList<PhysicsRayTestResult>();
rayTestRaw(from, to, results);

return results;
}

/**
Expand All @@ -808,13 +822,33 @@ public int GetRayTestFlags() {
return rayTestFlags;
}

private static Comparator<PhysicsRayTestResult> hitFractionComparator = new Comparator<PhysicsRayTestResult>() {
@Override
public int compare(PhysicsRayTestResult r1, PhysicsRayTestResult r2) {
float comp = r1.getHitFraction() - r2.getHitFraction();
return comp > 0 ? 1 : -1;
}
};

/**
* Performs a ray collision test and returns the results as a list of
* PhysicsRayTestResults
* PhysicsRayTestResults ordered by it hitFraction (lower to higher)
*/
public List<PhysicsRayTestResult> rayTest(Vector3f from, Vector3f to, List<PhysicsRayTestResult> results) {
results.clear();
rayTest_native(from, to, physicsSpaceId, results, rayTestFlags);

Collections.sort(results, hitFractionComparator);
return results;
}

/**
* Performs a ray collision test and returns the results as a list of
* PhysicsRayTestResults without performing any sort operation
*/
public List<PhysicsRayTestResult> rayTestRaw(Vector3f from, Vector3f to, List<PhysicsRayTestResult> results) {
results.clear();
rayTest_native(from, to, physicsSpaceId, results, rayTestFlags);
return results;
}

Expand Down