Skip to content

Commit

Permalink
removed unnecessary object allocations
Browse files Browse the repository at this point in the history
  • Loading branch information
pateman committed Apr 2, 2019
1 parent 8543061 commit 515a0a7
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/main/java/pl/pateman/dynamicaabbtree/AABBTree.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ public final class AABBTree<T extends Boundable & Identifiable> {
private final CollisionFilter<T> defaultCollisionFilter;
private final Map<AABBTreeObject<T>, Integer> objects;
private final Deque<Integer> freeNodes;
private final FrustumIntersection frustumIntersection;
private final RayAabIntersection rayIntersection;

private int root;
private float fatAABBMargin;
Expand All @@ -40,6 +42,9 @@ public AABBTree(AABBTreeHeuristicFunction<T> insertionHeuristicFunction, float f
defaultAABBOverlapFilter = new DefaultAABBOverlapFilter<>();
defaultCollisionFilter = new DefaultCollisionFilter<>();
this.fatAABBMargin = fatAABBMargin;

frustumIntersection = new FrustumIntersection();
rayIntersection = new RayAabIntersection();
}

private AABBTreeNode<T> allocateNode() {
Expand Down Expand Up @@ -380,7 +385,7 @@ public void detectInFrustum(Matrix4fc worldViewProjection, List<T> result) {
}

public void detectInFrustum(Matrix4fc worldViewProjection, AABBOverlapFilter<T> filter, List<T> result) {
FrustumIntersection frustumIntersection = new FrustumIntersection(worldViewProjection, false);
frustumIntersection.set(worldViewProjection, false);
traverseTree(aabb -> frustumIntersection.testAab(aabb.minX, aabb.minY, aabb.minZ, aabb.maxX, aabb.maxY, aabb.maxZ), filter, result);
}

Expand All @@ -389,8 +394,8 @@ public void detectRayIntersection(Rayf ray, List<T> result) {
}

public void detectRayIntersection(Rayf ray, AABBOverlapFilter<T> filter, List<T> result) {
RayAabIntersection intersection = new RayAabIntersection(ray.oX, ray.oY, ray.oZ, ray.dX, ray.dY, ray.dZ);
traverseTree(aabb -> intersection.test(aabb.minX, aabb.minY, aabb.minZ, aabb.maxX, aabb.maxY, aabb.maxZ), filter, result);
rayIntersection.set(ray.oX, ray.oY, ray.oZ, ray.dX, ray.dY, ray.dZ);
traverseTree(aabb -> rayIntersection.test(aabb.minX, aabb.minY, aabb.minZ, aabb.maxX, aabb.maxY, aabb.maxZ), filter, result);
}

private void traverseTree(Predicate<AABBf> nodeTest, AABBOverlapFilter<T> filter, List<T> result) {
Expand Down

0 comments on commit 515a0a7

Please sign in to comment.