From c5fa405e2ab4be33ef7b2fcd8e3b618d729faa77 Mon Sep 17 00:00:00 2001 From: squid233 <60126026+squid233@users.noreply.github.com> Date: Sat, 27 Jul 2024 19:36:42 +0800 Subject: [PATCH] Cleanup code --- .../util/shape/SingleVoxelShape.java | 18 ++---------------- .../java/freeworld/math/Intersectiond.java | 19 +++++++++++++++++-- 2 files changed, 19 insertions(+), 18 deletions(-) diff --git a/modules/freeworld.core/src/main/java/freeworld/util/shape/SingleVoxelShape.java b/modules/freeworld.core/src/main/java/freeworld/util/shape/SingleVoxelShape.java index dce302d..c0e1019 100644 --- a/modules/freeworld.core/src/main/java/freeworld/util/shape/SingleVoxelShape.java +++ b/modules/freeworld.core/src/main/java/freeworld/util/shape/SingleVoxelShape.java @@ -48,22 +48,8 @@ private RayCastFace rayCastFace(Direction direction, Vector3d origin, Vector3d d Vector3d v2 = box.getPoint(vertexIndices.z()); Vector3d v3 = box.getPoint(vertexIndices.w()); double v = Math.max( - Intersectiond.intersectRayTriangleFront( - origin.x(), origin.y(), origin.z(), - dir.x(), dir.y(), dir.z(), - v0.x(), v0.y(), v0.z(), - v1.x(), v1.y(), v1.z(), - v2.x(), v2.y(), v2.z(), - epsilon - ), - Intersectiond.intersectRayTriangleFront( - origin.x(), origin.y(), origin.z(), - dir.x(), dir.y(), dir.z(), - v2.x(), v2.y(), v2.z(), - v3.x(), v3.y(), v3.z(), - v0.x(), v0.y(), v0.z(), - epsilon - ) + Intersectiond.intersectRayTriangleFront(origin, dir, v0, v1, v2, epsilon), + Intersectiond.intersectRayTriangleFront(origin, dir, v2, v3, v0, epsilon) ); if (v == -1.0) { return RayCastFace.MISSED; diff --git a/modules/freeworld.math/src/main/java/freeworld/math/Intersectiond.java b/modules/freeworld.math/src/main/java/freeworld/math/Intersectiond.java index 9e46ea1..89568d7 100644 --- a/modules/freeworld.math/src/main/java/freeworld/math/Intersectiond.java +++ b/modules/freeworld.math/src/main/java/freeworld/math/Intersectiond.java @@ -4,8 +4,8 @@ * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. + * License as published by the Free Software Foundation; + * only version 2.1 of the License. */ package freeworld.math; @@ -95,4 +95,19 @@ public static double intersectRayTriangleFront( double invDet = 1.0 / det; return (edge2X * qvecX + edge2Y * qvecY + edge2Z * qvecZ) * invDet; } + + public static double intersectRayTriangleFront( + Vector3d origin, Vector3d dir, + Vector3d v0, Vector3d v1, Vector3d v2, + double epsilon + ) { + return intersectRayTriangleFront( + origin.x(), origin.y(), origin.z(), + dir.x(), dir.y(), dir.z(), + v0.x(), v0.y(), v0.z(), + v1.x(), v1.y(), v1.z(), + v2.x(), v2.y(), v2.z(), + epsilon + ); + } }