Skip to content

Commit

Permalink
feat: use our own joml-primitives fork
Browse files Browse the repository at this point in the history
  • Loading branch information
smartcmd committed Feb 3, 2025
1 parent 2bd71c6 commit 27cdeff
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 19 deletions.
10 changes: 0 additions & 10 deletions api/src/main/java/org/allaymc/api/math/MathUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import org.allaymc.api.math.location.Location3fc;
import org.joml.*;
import org.joml.primitives.AABBd;
import org.joml.primitives.AABBdc;
import org.joml.primitives.AABBf;

import java.lang.Math;
Expand Down Expand Up @@ -414,13 +413,4 @@ public static AABBd grow(AABBd aabb, double growth) {
aabb.maxZ += growth;
return aabb;
}

/**
* NOTICE: This is a temporary method due to a bug in JOML-primitives, and will be removed after
* <a href="https://github.com/JOML-CI/joml-primitives/pull/4">this pr</a> got merged.
*/
public static boolean intersectsAABB(AABBdc aabb1, AABBdc aabb2) {
return aabb1.maxX() > aabb2.minX() && aabb1.maxY() > aabb2.minY() && aabb1.maxZ() > aabb2.minZ() &&
aabb1.minX() < aabb2.maxX() && aabb1.minY() < aabb2.maxY() && aabb1.minZ() < aabb2.maxZ();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import lombok.AllArgsConstructor;
import lombok.Getter;
import org.allaymc.api.block.data.BlockFace;
import org.allaymc.api.math.MathUtils;
import org.joml.Vector2d;
import org.joml.Vector3d;
import org.joml.Vector3dc;
Expand Down Expand Up @@ -135,7 +134,7 @@ public VoxelShape translate(Vector3dc vec) {
public boolean intersectsAABB(AABBdc other) {
var aabb = unionAABB();
// TODO: This is a bug in JOML-primitives
if (!MathUtils.intersectsAABB(aabb, other)) return false;
if (!aabb.intersectsAABB(other)) return false;

other.intersection(aabb, aabb);
if (vacancies.stream().anyMatch(vacancy -> vacancy.containsAABB(aabb))) return false;
Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ javapoet = { module = "com.palantir.javapoet:javapoet", version = "0.6.0" }
fastreflect = { group = "com.github.AllayMC", name = "fast-reflection", version = "8733a599fa" }
# Math computing
joml = { group = "org.joml", name = "joml", version = "1.10.8" }
joml-primitives = { group = "org.joml", name = "joml-primitives", version = "1.10.0" }
joml-primitives = { group = "org.allaymc", name = "joml-primitives", version = "404d04f6b7" }
# Netty
netty-epoll = { group = "io.netty", name = "netty-transport-classes-epoll", version.ref = "netty" }
netty-kqueue = { group = "io.netty", name = "netty-transport-classes-kqueue", version.ref = "netty" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import it.unimi.dsi.fastutil.objects.ObjectArrayList;
import lombok.Getter;
import org.allaymc.api.math.MathUtils;
import org.allaymc.api.world.service.AABBOverlapFilter;
import org.allaymc.api.world.service.HasAABB;
import org.allaymc.api.world.service.HasLongId;
Expand All @@ -11,7 +10,7 @@
import org.joml.RayAabIntersection;
import org.joml.primitives.AABBd;
import org.joml.primitives.AABBdc;
import org.joml.primitives.Rayf;
import org.joml.primitives.Rayfc;

import java.util.*;
import java.util.function.Predicate;
Expand Down Expand Up @@ -367,7 +366,7 @@ public void detectOverlaps(AABBdc overlapWith, List<T> result) {
}

public void detectOverlaps(AABBdc overlapWith, AABBOverlapFilter<T> filter, List<T> result) {
traverseTree(aabb -> MathUtils.intersectsAABB(aabb, overlapWith), filter, result);
traverseTree(aabb -> aabb.intersectsAABB(overlapWith), filter, result);
}

public void detectCollisionPairs(List<CollisionPair<T>> result) {
Expand Down Expand Up @@ -400,13 +399,13 @@ public void detectInFrustum(Matrix4fc worldViewProjection, AABBOverlapFilter<T>
traverseTree(aabb -> frustumIntersection.testAab((float) aabb.minX(), (float) aabb.minY(), (float) aabb.minZ(), (float) aabb.maxX(), (float) aabb.maxY(), (float) aabb.maxZ()), filter, result);
}

public void detectRayIntersection(Rayf ray, List<T> result) {
public void detectRayIntersection(Rayfc ray, List<T> result) {
detectRayIntersection(ray, defaultAABBOverlapFilter, result);
}

// TODO: Use Rayfc here
public void detectRayIntersection(Rayf ray, AABBOverlapFilter<T> filter, List<T> result) {
rayIntersection.set(ray.oX, ray.oY, ray.oZ, ray.dX, ray.dY, ray.dZ);
public void detectRayIntersection(Rayfc ray, AABBOverlapFilter<T> filter, List<T> result) {
rayIntersection.set(ray.oX(), ray.oY(), ray.oZ(), ray.dX(), ray.dY(), ray.dZ());
traverseTree(aabb -> rayIntersection.test((float) aabb.minX(), (float) aabb.minY(), (float) aabb.minZ(), (float) aabb.maxX(), (float) aabb.maxY(), (float) aabb.maxZ()), filter, result);
}

Expand Down

0 comments on commit 27cdeff

Please sign in to comment.