Skip to content

Commit

Permalink
ShapeGenerator: add 3 shapes
Browse files Browse the repository at this point in the history
  • Loading branch information
stephengold committed May 9, 2024
1 parent 20d2a42 commit 93f11f2
Showing 1 changed file with 59 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
import com.jme3.bullet.collision.shapes.MultiSphere;
import com.jme3.bullet.collision.shapes.SimplexCollisionShape;
import com.jme3.bullet.collision.shapes.SphereCollisionShape;
import com.jme3.bullet.collision.shapes.SphericalSegment;
import com.jme3.math.FastMath;
import com.jme3.math.Vector3f;
import com.jme3.util.BufferUtils;
Expand Down Expand Up @@ -270,6 +271,17 @@ public CustomFrustum nextCustomFrustum() {
return result;
}

/**
* Generate a hemisphere shape using {@code CustomHemisphere}.
*
* @return a new shape
*/
public CustomHemisphere nextCustomHemisphere() {
float r = nextFloat(0.6f, 1.6f);
CustomHemisphere result = new CustomHemisphere(r);
return result;
}

/**
* Generate a parabolic lemon shape using {@code CustomLemon}.
*
Expand Down Expand Up @@ -316,6 +328,21 @@ public CustomSegment nextCustomSegment() {
return result;
}

/**
* Generate a spherical dome or plano-convex lens.
*
* @return a new shape
*/
public SphericalSegment nextDome() {
float radius = nextFloat(0.7f, 1.7f);
float verticalAngle = nextFloat(0.7f, 2f);
float yMax = radius;
float yMin = radius * FastMath.cos(verticalAngle);
SphericalSegment result = new SphericalSegment(radius, yMax, yMin);

return result;
}

/**
* Generate a (gridiron) football.
*
Expand Down Expand Up @@ -539,6 +566,26 @@ public MinkowskiSum nextSaucer() {
return result;
}

/**
* Generate a spherical segment using {@code SphericalSegment}.
*
* @return a new shape
*/
public SphericalSegment nextSegment() {
float sphereRadius = nextFloat(0.5f, 1.5f);
float y1 = sphereRadius * nextFloat(-1f, 1f);
float y2 = sphereRadius * nextFloat(-1f, 1f);

SphericalSegment result;
if (y1 > y2) {
result = new SphericalSegment(sphereRadius, y1, y2);
} else {
result = new SphericalSegment(sphereRadius, y2, y1);
}

return result;
}

/**
* Generate an instance of the named shape.
*
Expand Down Expand Up @@ -582,6 +629,10 @@ public CollisionShape nextShape(String shapeName) {
result = nextCustomDome();
break;

case "customHemisphere":
result = nextCustomHemisphere();
break;

case "customLemon":
result = nextCustomLemon();
break;
Expand All @@ -602,6 +653,10 @@ public CollisionShape nextShape(String shapeName) {
result = nextCylinderBox();
break;

case "dome":
result = nextDome();
break;

case "ellipsoid":
result = nextCustomEllipsoid();
break;
Expand Down Expand Up @@ -654,6 +709,10 @@ public CollisionShape nextShape(String shapeName) {
result = nextSaucer();
break;

case "segment":
result = nextSegment();
break;

case "sphere":
result = nextSphere();
break;
Expand Down

0 comments on commit 93f11f2

Please sign in to comment.