From 106142dfa4cdbf0579f8d07f23ca3c4897a5cc95 Mon Sep 17 00:00:00 2001 From: Sven Göthel Date: Mon, 15 Jan 2024 23:31:20 +0100 Subject: AABBox: Add intersects(AABBox), contains(AABBox), scale(float, float, float) and scale2(float, float, float) --- src/jogl/classes/com/jogamp/math/geom/AABBox.java | 59 +++++++++++++++++++++++ 1 file changed, 59 insertions(+) (limited to 'src/jogl/classes/com/jogamp/math/geom/AABBox.java') diff --git a/src/jogl/classes/com/jogamp/math/geom/AABBox.java b/src/jogl/classes/com/jogamp/math/geom/AABBox.java index 6dd95e2ed..49578337c 100644 --- a/src/jogl/classes/com/jogamp/math/geom/AABBox.java +++ b/src/jogl/classes/com/jogamp/math/geom/AABBox.java @@ -422,6 +422,26 @@ public class AABBox { ztr.z() ); } + /** Returns whether this AABBox intersects (partially contains) given AABBox. */ + public final boolean intersects(final AABBox o) { + return !( tr.x() < o.bl.x() || + tr.y() < o.bl.y() || + tr.z() < o.bl.z() || + bl.x() > o.tr.x() || + bl.y() > o.tr.y() || + bl.z() > o.tr.z()); + } + + /** Returns whether this AABBox fully contains given AABBox. */ + public final boolean contains(final AABBox o) { + return tr.x() >= o.tr.x() && + tr.y() >= o.tr.y() && + tr.z() >= o.tr.z() && + bl.x() <= o.bl.x() && + bl.y() <= o.bl.y() && + bl.z() <= o.bl.z(); + } + /** * Check if there is a common region between this AABBox and the passed * 2D region irrespective of z range @@ -729,6 +749,27 @@ public class AABBox { return this; } + /** + * Scale this AABBox by constants around fixed center + *

+ * high and low is recomputed by scaling its distance to fixed center. + *

+ * @param sX horizontal scale factor + * @param sY vertical scale factor + * @param sZ Z-axis scale factor + * @return this AABBox for chaining + * @see #scale2(float, float[]) + */ + public final AABBox scale(final float sX, final float sY, final float sZ) { + final Vec3f tmp = new Vec3f(); + tmp.set(tr).sub(center).scale(sX, sY, sZ); + tr.set(center).add(tmp); + + tmp.set(bl).sub(center).scale(sX, sY, sZ); + bl.set(center).add(tmp); + + return this; + } /** * Scale this AABBox by a constant, recomputing center @@ -746,6 +787,24 @@ public class AABBox { return this; } + /** + * Scale this AABBox by constants, recomputing center + *

+ * high and low is scaled and center recomputed. + *

+ * @param sX horizontal scale factor + * @param sY vertical scale factor + * @param sZ Z-axis scale factor + * @return this AABBox for chaining + * @see #scale(float, float[]) + */ + public final AABBox scale2(final float sX, final float sY, final float sZ) { + tr.scale(sX, sY, sZ); + bl.scale(sX, sY, sZ); + computeCenter(); + return this; + } + /** * Translate this AABBox by a float[3] vector * @param dx the translation x-component -- cgit v1.2.3