Skip to content

Commit

Permalink
apps: add getters for the basic dimensions of custom shapes
Browse files Browse the repository at this point in the history
  • Loading branch information
stephengold committed Mar 2, 2024
1 parent f5d20a1 commit fea8e4f
Show file tree
Hide file tree
Showing 9 changed files with 242 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -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

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 (&ge;-radius, &le;radius)
*/
public float yMin() {
assert unscaledYMin >= -unscaledRadius;
assert unscaledYMin <= unscaledRadius;
return unscaledYMin;
}
// *************************************************************************
// CustomConvexShape methods

/**
Expand Down

0 comments on commit fea8e4f

Please sign in to comment.