Skip to content

Commit

Permalink
ShapeGenerator: add 4 named shapes that use the MinkowskiSum class
Browse files Browse the repository at this point in the history
  • Loading branch information
stephengold committed Jan 24, 2024
1 parent 7651996 commit 527a24b
Showing 1 changed file with 78 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright (c) 2020-2022, Stephen Gold and Yanis Boudiaf
Copyright (c) 2020-2024 Stephen Gold and Yanis Boudiaf
All rights reserved.
Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -36,6 +36,7 @@ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
import com.jme3.bullet.collision.shapes.ConeCollisionShape;
import com.jme3.bullet.collision.shapes.CylinderCollisionShape;
import com.jme3.bullet.collision.shapes.HullCollisionShape;
import com.jme3.bullet.collision.shapes.MinkowskiSum;
import com.jme3.bullet.collision.shapes.MultiSphere;
import com.jme3.bullet.collision.shapes.SimplexCollisionShape;
import com.jme3.bullet.collision.shapes.SphereCollisionShape;
Expand Down Expand Up @@ -119,6 +120,21 @@ public ConeCollisionShape nextCone() {
return result;
}

/**
* Generate a cone+box shape.
*
* @return a new Minkowski-sum shape
*/
public MinkowskiSum nextConeBox() {
BoxCollisionShape box = nextBox();
float baseRadius = nextFloat(0.3f, 1f);
float height = nextFloat(0.5f, 1.5f);
ConeCollisionShape cone = new ConeCollisionShape(baseRadius, height);
MinkowskiSum result = new MinkowskiSum(cone, box);

return result;
}

/**
* Generate a cylinder shape.
*
Expand All @@ -134,6 +150,21 @@ public CylinderCollisionShape nextCylinder() {
return result;
}

/**
* Generate a cylinder+box shape.
*
* @return a new Minkowski-sum shape
*/
public MinkowskiSum nextCylinderBox() {
BoxCollisionShape box = nextBox();
float baseRadius = nextFloat(0.3f, 1.5f);
float height = CollisionShape.getDefaultMargin();
CylinderCollisionShape cylinder = new CylinderCollisionShape(
baseRadius, height, MyVector3f.yAxis);
MinkowskiSum result = new MinkowskiSum(cylinder, box);

return result;
}
/**
* Generate a (gridiron) football.
*
Expand Down Expand Up @@ -305,6 +336,36 @@ public MultiSphere nextMultiSphere() {
return result;
}

/**
* Generate a rounded disc shape.
*
* @return a new Minkowski-sum shape
*/
public MinkowskiSum nextRoundedDisc() {
float baseRadius = nextFloat(0.3f, 1.5f);
float height = nextFloat(0.5f, 1f);
CylinderCollisionShape thinDisc = new CylinderCollisionShape(
baseRadius, 0.04f, MyVector3f.yAxis);
SphereCollisionShape sphere = new SphereCollisionShape(height / 2f);
MinkowskiSum result = new MinkowskiSum(thinDisc, sphere);

return result;
}

/**
* Generate a flying-saucer shape.
*
* @return a new Minkowski-sum shape
*/
public MinkowskiSum nextSaucer() {
float baseRadius = nextFloat(0.3f, 1f);
float height = nextFloat(0.3f, 1f);
ConeCollisionShape cone = new ConeCollisionShape(baseRadius, height);
MinkowskiSum result = new MinkowskiSum(cone, cone);

return result;
}

/**
* Generate an instance of the named shape.
*
Expand All @@ -328,10 +389,18 @@ public CollisionShape nextShape(String shapeName) {
result = nextCone();
break;

case "coneBox":
result = nextConeBox();
break;

case "cylinder":
result = nextCylinder();
break;

case "cylinderBox":
result = nextCylinderBox();
break;

case "football":
result = nextFootball();
break;
Expand Down Expand Up @@ -360,6 +429,14 @@ public CollisionShape nextShape(String shapeName) {
result = nextMultiSphere();
break;

case "roundedDisc":
result = nextRoundedDisc();
break;

case "saucer":
result = nextSaucer();
break;

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

0 comments on commit 527a24b

Please sign in to comment.