Skip to content

Commit

Permalink
ShapeGenerator: add 7 named custom shapes
Browse files Browse the repository at this point in the history
  • Loading branch information
stephengold committed Jan 24, 2024
1 parent ff25a46 commit 8794bce
Showing 1 changed file with 129 additions and 0 deletions.
129 changes: 129 additions & 0 deletions apps/src/main/java/jme3utilities/minie/test/shape/ShapeGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
*
Expand Down Expand Up @@ -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.
*
Expand Down Expand Up @@ -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.
*
Expand All @@ -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;
}

Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down

0 comments on commit 8794bce

Please sign in to comment.