Skip to content

Commit

Permalink
Made AABB immutable
Browse files Browse the repository at this point in the history
  • Loading branch information
ata4 committed Jul 15, 2014
1 parent 3ee980e commit 2cd62cd
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 27 deletions.
17 changes: 8 additions & 9 deletions src/info/ata4/bspsrc/modules/entity/EntitySource.java
Original file line number Diff line number Diff line change
Expand Up @@ -351,8 +351,6 @@ public void writeDetails() {
if (config.detailMerge) {
Queue<Pair<DBrush, AABB>> detailBrushes = new ArrayDeque<>();
Map<DBrush, Integer> detailBrushIndices = new HashMap<>();
Vector3f vex = new Vector3f(config.detailMergeThresh,
config.detailMergeThresh, config.detailMergeThresh);

// add all detail brushes to queue
for (int i = 0; i < bsp.brushes.size(); i++) {
Expand All @@ -371,9 +369,6 @@ public void writeDetails() {
// get bounding box of the detail brush
AABB bounds = BrushUtils.getBounds(bsp, brush);

// expand bb so it can touch the bbs of other brushes
bounds.expand(vex);

detailBrushes.add(new ImmutablePair<>(brush, bounds));
detailBrushIndices.put(brush, i);
}
Expand All @@ -387,7 +382,7 @@ public void writeDetails() {
detailBrushClump.add(detailBrush1);

// move all touching brushes from the queue to this clump
clumpBrushes(detailBrushes, detailBrushClump, detailBrush1);
clumpBrushes(detailBrushes, detailBrushClump, detailBrush1, config.detailMergeThresh);

// write brush clump as func_detail to VMF
writer.start("entity");
Expand Down Expand Up @@ -444,24 +439,28 @@ public void writeDetails() {
*
* @param src global brush collection
* @param dst clumped brush collection
* @param thresh touching threshold
* @param target search brush
*/
private void clumpBrushes(Collection<Pair<DBrush, AABB>> src, Collection<Pair<DBrush, AABB>> dst, Pair<DBrush, AABB> target) {
private void clumpBrushes(Collection<Pair<DBrush, AABB>> src, Collection<Pair<DBrush, AABB>> dst, Pair<DBrush, AABB> target, float thresh) {
// expand bb so it can touch the bbs of other brushes
AABB targetBounds = target.getRight().expand(thresh);

Iterator<Pair<DBrush, AABB>> iter = src.iterator();
while (iter.hasNext()) {
// get next brush
Pair<DBrush, AABB> other = iter.next();

// is it touching the target brush?
if (other.getRight().intersectsWith(target.getRight())) {
if (other.getRight().intersectsWith(targetBounds)) {
// put it to destination collection
dst.add(other);

// remove it from source
iter.remove();

// also move all brushes that touch this brush
clumpBrushes(src, dst, other);
clumpBrushes(src, dst, other, thresh);

// recreate iterator, since the collection may have been modified
iter = src.iterator();
Expand Down
2 changes: 1 addition & 1 deletion src/info/ata4/bspsrc/modules/geom/BrushUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public static AABB getBounds(BspData bsp, DBrush brush) {
// add bounds of all brush sides
AABB bounds = new AABB();
for (int i = 0; i < brush.numside; i++) {
bounds.include(WindingFactory.fromSide(bsp, brush, i).getBounds());
bounds = bounds.include(WindingFactory.fromSide(bsp, brush, i).getBounds());
}
return bounds;
}
Expand Down
28 changes: 11 additions & 17 deletions src/info/ata4/bspsrc/util/AABB.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
*/
public class AABB {

private Vector3f min;
private Vector3f max;
private final Vector3f min;
private final Vector3f max;

public AABB(Vector3f mins, Vector3f maxs) {
this.min = mins;
Expand All @@ -34,17 +34,9 @@ public Vector3f getMin() {
return min;
}

public void setMin(Vector3f min) {
this.min = min;
}

public Vector3f getMax() {
return max;
}

public void setMax(Vector3f max) {
this.max = max;
}

public Vector3f getSize() {
return max.sub(min);
Expand All @@ -55,15 +47,17 @@ public boolean intersectsWith(AABB that) {
that.max.y > this.min.y && that.min.y < this.max.y &&
that.max.z > this.min.z && that.min.z < this.max.z;
}

public void include(AABB that) {
min = min.min(that.min);
max = max.max(that.max);

public AABB include(AABB that) {
return new AABB(min.min(that.min), max.max(that.max));
}

public AABB expand(Vector3f v) {
return new AABB(min.sub(v), max.add(v));
}

public void expand(Vector3f v) {
min = min.sub(v);
max = max.add(v);
public AABB expand(float e) {
return expand(new Vector3f(e, e, e));
}

@Override
Expand Down

0 comments on commit 2cd62cd

Please sign in to comment.