From fea8e4f7387b4c632c61e2ee82b9143a3bada81a Mon Sep 17 00:00:00 2001 From: Stephen Gold Date: Sat, 2 Mar 2024 13:27:33 -0800 Subject: [PATCH] apps: add getters for the basic dimensions of custom shapes --- .../stephengold/shapes/custom/CustomBox.java | 23 +++++++++ .../stephengold/shapes/custom/CustomCone.java | 22 +++++++++ .../shapes/custom/CustomCylinder.java | 38 +++++++++++++++ .../shapes/custom/CustomEllipsoid.java | 23 +++++++++ .../shapes/custom/CustomFrustum.java | 32 +++++++++++++ .../shapes/custom/CustomHalfCylinder.java | 22 +++++++++ .../shapes/custom/CustomHemisphere.java | 12 +++++ .../shapes/custom/CustomParaboloid.java | 22 +++++++++ .../shapes/custom/CustomSegment.java | 48 +++++++++++++++++++ 9 files changed, 242 insertions(+) diff --git a/apps/src/main/java/com/github/stephengold/shapes/custom/CustomBox.java b/apps/src/main/java/com/github/stephengold/shapes/custom/CustomBox.java index 20db074..feffa3d 100644 --- a/apps/src/main/java/com/github/stephengold/shapes/custom/CustomBox.java +++ b/apps/src/main/java/com/github/stephengold/shapes/custom/CustomBox.java @@ -32,6 +32,7 @@ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE import com.jme3.math.Vector3f; import java.util.logging.Logger; import jme3utilities.Validate; +import jme3utilities.math.MyVector3f; import jme3utilities.math.MyVolume; /** @@ -119,6 +120,28 @@ public CustomBox(Vector3f halfExtents) { setScale(scale); } // ************************************************************************* + // new methods exposed + + /** + * Copy the half extents of the box. + * + * @param storeResult storage for the result (modified if not null) + * @return the unscaled half extent for each local axis (either storeResult + * or a new vector, not null, all components >0) + */ + public Vector3f getHalfExtents(Vector3f storeResult) { + assert MyVector3f.isAllPositive(unscaledHe) : unscaledHe; + + Vector3f result; + if (storeResult == null) { + result = unscaledHe.clone(); + } else { + result = storeResult.set(unscaledHe); + } + + return result; + } + // ************************************************************************* // CustomConvexShape methods /** diff --git a/apps/src/main/java/com/github/stephengold/shapes/custom/CustomCone.java b/apps/src/main/java/com/github/stephengold/shapes/custom/CustomCone.java index 4cfc905..137984f 100644 --- a/apps/src/main/java/com/github/stephengold/shapes/custom/CustomCone.java +++ b/apps/src/main/java/com/github/stephengold/shapes/custom/CustomCone.java @@ -96,6 +96,28 @@ public CustomCone(float radius, float height) { setScale(scale); } // ************************************************************************* + // new methods exposed + + /** + * Return the height of the cone. + * + * @return the unscaled height (>0) + */ + public float getHeight() { + assert unscaledHeight > 0f : unscaledHeight; + return unscaledHeight; + } + + /** + * Return the radius of the cone's base. + * + * @return the unscaled radius (>0) + */ + public float getRadius() { + assert unscaledRadius > 0f : unscaledRadius; + return unscaledRadius; + } + // ************************************************************************* // CustomConvexShape methods /** diff --git a/apps/src/main/java/com/github/stephengold/shapes/custom/CustomCylinder.java b/apps/src/main/java/com/github/stephengold/shapes/custom/CustomCylinder.java index e5f104a..9bb49fd 100644 --- a/apps/src/main/java/com/github/stephengold/shapes/custom/CustomCylinder.java +++ b/apps/src/main/java/com/github/stephengold/shapes/custom/CustomCylinder.java @@ -96,6 +96,44 @@ public CustomCylinder(float radius, float height) { setScale(scale); } // ************************************************************************* + // new methods exposed + + /** + * Copy the half extents of the cylinder. + * + * @param storeResult storage for the result (modified if not null) + * @return the unscaled half extent for each local axis (either storeResult + * or a new vector, not null, no negative component) + */ + public Vector3f getHalfExtents(Vector3f storeResult) { + Vector3f result = (storeResult == null) ? new Vector3f() : storeResult; + result.x = unscaledRadius; + result.y = 0.5f * unscaledHeight; + result.z = unscaledRadius; + + return result; + } + + /** + * Return the height of the cylinder. + * + * @return the unscaled height (>0) + */ + public float getHeight() { + assert unscaledHeight > 0f : unscaledHeight; + return unscaledHeight; + } + + /** + * Return the radius of the cylinder. + * + * @return the unscaled radius (>0) + */ + public float getRadius() { + assert unscaledRadius > 0f : unscaledRadius; + return unscaledRadius; + } + // ************************************************************************* // CustomConvexShape methods /** diff --git a/apps/src/main/java/com/github/stephengold/shapes/custom/CustomEllipsoid.java b/apps/src/main/java/com/github/stephengold/shapes/custom/CustomEllipsoid.java index 35b10a5..1daa1b6 100644 --- a/apps/src/main/java/com/github/stephengold/shapes/custom/CustomEllipsoid.java +++ b/apps/src/main/java/com/github/stephengold/shapes/custom/CustomEllipsoid.java @@ -33,6 +33,7 @@ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE import java.util.logging.Logger; import jme3utilities.Validate; import jme3utilities.math.MyMath; +import jme3utilities.math.MyVector3f; /** * A collision shape for an axis-aligned ellipsoid. @@ -135,6 +136,28 @@ public CustomEllipsoid(Vector3f halfExtents, float inertiaFactor) { setScale(scale); } // ************************************************************************* + // new methods exposed + + /** + * Copy the half extents of the ellipsoid. + * + * @param storeResult storage for the result (modified if not null) + * @return the unscaled half extent for each local axis (either storeResult + * or a new vector, not null, all components >0) + */ + public Vector3f getHalfExtents(Vector3f storeResult) { + assert MyVector3f.isAllPositive(unscaledHe) : unscaledHe; + + Vector3f result; + if (storeResult == null) { + result = unscaledHe.clone(); + } else { + result = storeResult.set(unscaledHe); + } + + return result; + } + // ************************************************************************* // CustomConvexShape methods /** diff --git a/apps/src/main/java/com/github/stephengold/shapes/custom/CustomFrustum.java b/apps/src/main/java/com/github/stephengold/shapes/custom/CustomFrustum.java index 7b94cfd..92b6906 100644 --- a/apps/src/main/java/com/github/stephengold/shapes/custom/CustomFrustum.java +++ b/apps/src/main/java/com/github/stephengold/shapes/custom/CustomFrustum.java @@ -108,6 +108,38 @@ public CustomFrustum(float a, float b, float height) { setScale(scale); } // ************************************************************************* + // new methods exposed + + /** + * Return the height of the frustum. + * + * @return the unscaled height (>0) + */ + public float getHeight() { + assert unscaledHeight > 0f : unscaledHeight; + return unscaledHeight; + } + + /** + * Return the radius of the "A" base. + * + * @return the unscaled radius (>0) + */ + public float getA() { + assert unscaledA > 0f : unscaledA; + return unscaledA; + } + + /** + * Return the radius of the "B" base. + * + * @return the unscaled radius (>0) + */ + public float getB() { + assert unscaledB > 0f : unscaledB; + return unscaledB; + } + // ************************************************************************* // CustomConvexShape methods /** diff --git a/apps/src/main/java/com/github/stephengold/shapes/custom/CustomHalfCylinder.java b/apps/src/main/java/com/github/stephengold/shapes/custom/CustomHalfCylinder.java index f09526d..813c7eb 100644 --- a/apps/src/main/java/com/github/stephengold/shapes/custom/CustomHalfCylinder.java +++ b/apps/src/main/java/com/github/stephengold/shapes/custom/CustomHalfCylinder.java @@ -105,6 +105,28 @@ public CustomHalfCylinder(float radius, float height) { setScale(scale); } // ************************************************************************* + // new methods exposed + + /** + * Return the height of the half cylinder. + * + * @return the unscaled height (>0) + */ + public float getHeight() { + assert unscaledHeight > 0f : unscaledHeight; + return unscaledHeight; + } + + /** + * Return the radius of the parent cylinder. + * + * @return the unscaled radius (>0) + */ + public float getRadius() { + assert unscaledRadius > 0f : unscaledRadius; + return unscaledRadius; + } + // ************************************************************************* // CustomConvexShape methods /** diff --git a/apps/src/main/java/com/github/stephengold/shapes/custom/CustomHemisphere.java b/apps/src/main/java/com/github/stephengold/shapes/custom/CustomHemisphere.java index 0308adc..fc13729 100644 --- a/apps/src/main/java/com/github/stephengold/shapes/custom/CustomHemisphere.java +++ b/apps/src/main/java/com/github/stephengold/shapes/custom/CustomHemisphere.java @@ -87,6 +87,18 @@ public CustomHemisphere(float radius) { setScale(scale); } // ************************************************************************* + // new methods exposed + + /** + * Return the radius of the hemisphere. + * + * @return the unscaled radius (>0) + */ + public float getRadius() { + assert unscaledRadius > 0f : unscaledRadius; + return unscaledRadius; + } + // ************************************************************************* // CustomConvexShape methods /** diff --git a/apps/src/main/java/com/github/stephengold/shapes/custom/CustomParaboloid.java b/apps/src/main/java/com/github/stephengold/shapes/custom/CustomParaboloid.java index 81bf0fe..24b02cf 100644 --- a/apps/src/main/java/com/github/stephengold/shapes/custom/CustomParaboloid.java +++ b/apps/src/main/java/com/github/stephengold/shapes/custom/CustomParaboloid.java @@ -100,6 +100,28 @@ public CustomParaboloid(float radius, float height) { setScale(scale); } // ************************************************************************* + // new methods exposed + + /** + * Return the height of the paraboloid. + * + * @return the unscaled height (>0) + */ + public float getHeight() { + assert unscaledHeight > 0f : unscaledHeight; + return unscaledHeight; + } + + /** + * Return the radius of the paraboloid. + * + * @return the unscaled radius (>0) + */ + public float getRadius() { + assert unscaledRadius > 0f : unscaledRadius; + return unscaledRadius; + } + // ************************************************************************* // CustomConvexShape methods /** diff --git a/apps/src/main/java/com/github/stephengold/shapes/custom/CustomSegment.java b/apps/src/main/java/com/github/stephengold/shapes/custom/CustomSegment.java index afbe3ef..cea887e 100644 --- a/apps/src/main/java/com/github/stephengold/shapes/custom/CustomSegment.java +++ b/apps/src/main/java/com/github/stephengold/shapes/custom/CustomSegment.java @@ -132,6 +132,54 @@ public CustomSegment(float radius, float yMax, float yMin) { setScale(scale); } // ************************************************************************* + // new methods exposed + + /** + * Return the height of the segment. + * + * @return the unscaled height (≥0) + */ + public float getHeight() { + float result = unscaledYMax - unscaledYMin; + + assert result >= 0f : result; + return result; + } + + /** + * Return the radius of the parent sphere. + * + * @return the unscaled radius (>0) + */ + public float sphereRadius() { + assert unscaledRadius > 0f : unscaledRadius; + return unscaledRadius; + } + + /** + * Return the Y offset of the upper base from the center of the parent + * sphere. + * + * @return the unscaled offset (≥-radius, ≤radius) + */ + public float yMax() { + assert unscaledYMax >= -unscaledRadius; + assert unscaledYMax <= unscaledRadius; + return unscaledYMax; + } + + /** + * Return the Y offset of the lower base from the center of the parent + * sphere. + * + * @return the unscaled offset (≥-radius, ≤radius) + */ + public float yMin() { + assert unscaledYMin >= -unscaledRadius; + assert unscaledYMin <= unscaledRadius; + return unscaledYMin; + } + // ************************************************************************* // CustomConvexShape methods /**