Skip to content

Commit

Permalink
Use origin.xyz + size.xyz for frustum/box comparisons
Browse files Browse the repository at this point in the history
Closes #2234
  • Loading branch information
jellysquid3 committed Jan 18, 2024
1 parent 27e531f commit 17a17ed
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,8 @@ private static int nearestToZero(int min, int max) {
private static final float CHUNK_SECTION_SIZE = 8.0f /* chunk bounds */ + 1.0f /* maximum model extent */ + 0.125f /* epsilon */;

public static boolean isWithinFrustum(Viewport viewport, RenderSection section) {
return viewport.isBoxVisible(section.getCenterX(), section.getCenterY(), section.getCenterZ(), CHUNK_SECTION_SIZE);
return viewport.isBoxVisible(section.getCenterX(), section.getCenterY(), section.getCenterZ(),
CHUNK_SECTION_SIZE, CHUNK_SECTION_SIZE, CHUNK_SECTION_SIZE);
}

private void init(Visitor visitor,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,19 @@ public Viewport(Frustum frustum, Vector3d position) {
this.blockCoords = BlockPos.ofFloored(position.x, position.y, position.z);
}

public boolean isBoxVisible(int intX, int intY, int intZ, float radius) {
float floatX = (intX - this.transform.intX) - this.transform.fracX;
float floatY = (intY - this.transform.intY) - this.transform.fracY;
float floatZ = (intZ - this.transform.intZ) - this.transform.fracZ;
public boolean isBoxVisible(int intOriginX, int intOriginY, int intOriginZ, float floatSizeX, float floatSizeY, float floatSizeZ) {
float floatOriginX = (intOriginX - this.transform.intX) - this.transform.fracX;
float floatOriginY = (intOriginY - this.transform.intY) - this.transform.fracY;
float floatOriginZ = (intOriginZ - this.transform.intZ) - this.transform.fracZ;

return this.frustum.testAab(
floatX - radius,
floatY - radius,
floatZ - radius,
floatOriginX - floatSizeX,
floatOriginY - floatSizeY,
floatOriginZ - floatSizeZ,

floatX + radius,
floatY + radius,
floatZ + radius
floatOriginX + floatSizeX,
floatOriginY + floatSizeY,
floatOriginZ + floatSizeZ
);
}

Expand Down

0 comments on commit 17a17ed

Please sign in to comment.