From 8794bcef8027f60cd38618a08df668314467334b Mon Sep 17 00:00:00 2001 From: Stephen Gold Date: Wed, 24 Jan 2024 14:17:00 -0800 Subject: [PATCH] ShapeGenerator: add 7 named custom shapes --- .../minie/test/shape/ShapeGenerator.java | 129 ++++++++++++++++++ 1 file changed, 129 insertions(+) diff --git a/apps/src/main/java/jme3utilities/minie/test/shape/ShapeGenerator.java b/apps/src/main/java/jme3utilities/minie/test/shape/ShapeGenerator.java index 737aa9a3..e5e4d1f4 100644 --- a/apps/src/main/java/jme3utilities/minie/test/shape/ShapeGenerator.java +++ b/apps/src/main/java/jme3utilities/minie/test/shape/ShapeGenerator.java @@ -29,6 +29,13 @@ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE */ package jme3utilities.minie.test.shape; +import com.github.stephengold.shapes.custom.CustomBox; +import com.github.stephengold.shapes.custom.CustomCone; +import com.github.stephengold.shapes.custom.CustomCylinder; +import com.github.stephengold.shapes.custom.CustomEllipsoid; +import com.github.stephengold.shapes.custom.CustomFrustum; +import com.github.stephengold.shapes.custom.CustomHalfCylinder; +import com.github.stephengold.shapes.custom.CustomHemisphere; import com.jme3.bullet.collision.shapes.BoxCollisionShape; import com.jme3.bullet.collision.shapes.CapsuleCollisionShape; import com.jme3.bullet.collision.shapes.CollisionShape; @@ -135,6 +142,46 @@ public MinkowskiSum nextConeBox() { return result; } + /** + * Generate a box shape using {@code CustomBox}. + * + * @return a new shape + */ + public CustomBox nextCustomBox() { + float rx = nextFloat(0.5f, 1.5f); + float ry = nextFloat(0.5f, 1.5f); + float rz = nextFloat(0.5f, 1.5f); + CustomBox result = new CustomBox(rx, ry, rz); + + return result; + } + + /** + * Generate a cone shape using {@code CustomCone}. + * + * @return a new shape + */ + public CustomCone nextCustomCone() { + float baseRadius = nextFloat(0.5f, 1.5f); + float height = nextFloat(0.5f, 2.5f); + CustomCone result = new CustomCone(baseRadius, height); + + return result; + } + + /** + * Generate a cylinder shape using {@code CustomCylinder}. + * + * @return a new shape + */ + public CustomCylinder nextCustomCylinder() { + float baseRadius = nextFloat(0.5f, 1.5f); + float height = nextFloat(1f, 4f); + CustomCylinder result = new CustomCylinder(baseRadius, height); + + return result; + } + /** * Generate a cylinder shape. * @@ -165,6 +212,37 @@ public MinkowskiSum nextCylinderBox() { return result; } + + /** + * Generate an ellipsoid shape using {@code CustomEllipsoid}. + * + * @return a new shape + */ + public CustomEllipsoid nextCustomEllipsoid() { + float a = nextFloat(1f, 2f); + float b = nextFloat(0.6f, 1.6f); + float c = nextFloat(0.4f, 1.4f); + float inertiaFactor = nextFloat(0.1f, 1 / 3f); + CustomEllipsoid result + = new CustomEllipsoid(a, b, c, inertiaFactor); + + return result; + } + + /** + * Generate an ellipsoid shape using {@code CustomFrustum}. + * + * @return a new shape + */ + public CustomFrustum nextCustomFrustum() { + float a = nextFloat(1f, 2f); + float b = nextFloat(0.01f, 1.6f); + float height = nextFloat(0.6f, 4f); + CustomFrustum result = new CustomFrustum(a, b, height); + + return result; + } + /** * Generate a (gridiron) football. * @@ -210,6 +288,19 @@ public CompoundCollisionShape nextFrame() { return result; } + /** + * Generate a half-cylinder shape. + * + * @return a new shape + */ + public CustomHalfCylinder nextHalfCylinder() { + float baseRadius = nextFloat(0.5f, 1.5f); + float height = nextFloat(0.5f, 3f); + CustomHalfCylinder result = new CustomHalfCylinder(baseRadius, height); + + return result; + } + /** * Approximate a Z-axis half-pipe shape. * @@ -224,7 +315,17 @@ public CompoundCollisionShape nextHalfPipe() { CompoundCollisionShape result = CompoundTestShapes .makePipe(innerRadius, thickness, length, arc, numChildren); + return result; + } + /** + * Generate a hemisphere shape. + * + * @return a new shape + */ + public CustomHemisphere nextHemisphere() { + float r = nextFloat(0.6f, 1.6f); + CustomHemisphere result = new CustomHemisphere(r); return result; } @@ -393,6 +494,18 @@ public CollisionShape nextShape(String shapeName) { result = nextConeBox(); break; + case "customBox": + result = nextCustomBox(); + break; + + case "customCone": + result = nextCustomCone(); + break; + + case "customCylinder": + result = nextCustomCylinder(); + break; + case "cylinder": result = nextCylinder(); break; @@ -401,6 +514,14 @@ public CollisionShape nextShape(String shapeName) { result = nextCylinderBox(); break; + case "ellipsoid": + result = nextCustomEllipsoid(); + break; + + case "frustum": + result = nextCustomFrustum(); + break; + case "football": result = nextFootball(); break; @@ -413,6 +534,14 @@ public CollisionShape nextShape(String shapeName) { result = nextHalfPipe(); break; + case "halfCylinder": + result = nextHalfCylinder(); + break; + + case "hemisphere": + result = nextHemisphere(); + break; + case "hull": result = nextHull(); break;