Package com.jme3.bullet.collision.shapes
Class CapsuleCollisionShape
java.lang.Object
com.jme3.bullet.NativePhysicsObject
com.jme3.bullet.collision.shapes.CollisionShape
com.jme3.bullet.collision.shapes.ConvexShape
com.jme3.bullet.collision.shapes.CapsuleCollisionShape
- All Implemented Interfaces:
com.jme3.export.Savable
,com.jme3.util.clone.JmeCloneable
,Cloneable
,Comparable<NativePhysicsObject>
A capsule collision shape based on Bullet's
btCapsuleShapeX
,
btCapsuleShape
, or btCapsuleShapeZ
. These shapes have no
margin and can only be scaled uniformly.- See Also:
-
Field Summary
Fields inherited from class com.jme3.bullet.collision.shapes.ConvexShape
loggerX
Fields inherited from class com.jme3.bullet.collision.shapes.CollisionShape
enableContactFilter, logger, margin, scale
Fields inherited from class com.jme3.bullet.NativePhysicsObject
loggerN
-
Constructor Summary
ModifierConstructorDescriptionprotected
No-argument constructor needed by SavableClassUtil.CapsuleCollisionShape
(float radius, float height) Instantiate a Y-axis capsule shape with the specified radius and height.CapsuleCollisionShape
(float radius, float height, int axisIndex) Instantiate a capsule shape around the specified main (height) axis. -
Method Summary
Modifier and TypeMethodDescriptionboolean
canScale
(com.jme3.math.Vector3f scale) Test whether the specified scale factors can be applied to the shape.void
cloneFields
(com.jme3.util.clone.Cloner cloner, Object original) Callback fromCloner
to convert this shallow-cloned shape into a deep-cloned one, using the specified Cloner and original to resolve copied fields.int
getAxis()
Return the main (height) axis of the capsule.float
Return the height of the cylindrical portion.float
Return the collision margin of the shape.float
Return the radius of the capsule.float
Calculate how far the scaled shape extends from its center.void
read
(com.jme3.export.JmeImporter importer) De-serialize the shape from the specified importer, for example when loading from a J3O file.float
Estimate the volume of the shape, including scale and margin.void
setMargin
(float margin) Alter the collision margin of the shape.Approximate this shape with a HullCollisionShape.float
Return the unscaled volume of the capsule.void
write
(com.jme3.export.JmeExporter exporter) Serialize the shape to the specified exporter, for example when saving to a J3O file.Methods inherited from class com.jme3.bullet.collision.shapes.ConvexShape
isConcave, isConvex, toSplittableShape
Methods inherited from class com.jme3.bullet.collision.shapes.CollisionShape
aabbCenter, aabbScaledVolume, boundingBox, boundingBox, canSplit, copyShapeProperties, getDefaultMargin, getScale, getScaleDp, getShapeType, getShapeType, isContactFilterEnabled, isInfinite, isNonMoving, isPolyhedral, jmeClone, nativeMargin, readShapeProperties, recalculateAabb, setContactFilterEnabled, setDefaultMargin, setNativeId, setScale, setScale, setUserIndex, setUserIndex2, toString, updateScale, userIndex, userIndex2
Methods inherited from class com.jme3.bullet.NativePhysicsObject
compareTo, countTrackers, dumpTrackers, equals, freeUnusedObjects, hasAssignedNativeObject, hashCode, nativeId, reassignNativeId, setNativeIdNotTracked, unassignNativeObject
-
Field Details
-
logger2
message logger for this class
-
-
Constructor Details
-
CapsuleCollisionShape
protected CapsuleCollisionShape()No-argument constructor needed by SavableClassUtil. -
CapsuleCollisionShape
public CapsuleCollisionShape(float radius, float height) Instantiate a Y-axis capsule shape with the specified radius and height.- Parameters:
radius
- the desired unscaled radius (in shape units, ≥0)height
- the desired unscaled height of the cylindrical portion (in shape units, ≥0)
-
CapsuleCollisionShape
public CapsuleCollisionShape(float radius, float height, int axisIndex) Instantiate a capsule shape around the specified main (height) axis.- Parameters:
radius
- the desired radius (in shape units, ≥0)height
- the desired height of the cylindrical portion (in shape units, ≥0)axisIndex
- which local axis to use for the height: 0→X, 1→Y, 2→Z (default=1)
-
-
Method Details
-
getAxis
public int getAxis()Return the main (height) axis of the capsule.- Returns:
- the axis index: 0→X, 1→Y, 2→Z
-
getHeight
public float getHeight()Return the height of the cylindrical portion.- Returns:
- the unscaled height (in shape units, ≥0)
-
getRadius
public float getRadius()Return the radius of the capsule.- Returns:
- the unscaled radius (in shape units, ≥0)
-
unscaledVolume
public float unscaledVolume()Return the unscaled volume of the capsule.- Returns:
- the volume (in shape units cubed, ≥0)
-
canScale
public boolean canScale(com.jme3.math.Vector3f scale) Test whether the specified scale factors can be applied to the shape. For capsule shapes, scaling must be uniform.- Overrides:
canScale
in classCollisionShape
- Parameters:
scale
- the desired scale factor for each local axis (may be null, unaffected)- Returns:
- true if applicable, otherwise false
-
cloneFields
Callback fromCloner
to convert this shallow-cloned shape into a deep-cloned one, using the specified Cloner and original to resolve copied fields.- Specified by:
cloneFields
in interfacecom.jme3.util.clone.JmeCloneable
- Overrides:
cloneFields
in classCollisionShape
- Parameters:
cloner
- the Cloner that's cloning this shape (not null)original
- the instance from which this shape was shallow-cloned (not null, unaffected)
-
getMargin
public float getMargin()Return the collision margin of the shape.- Overrides:
getMargin
in classCollisionShape
- Returns:
- 0
-
maxRadius
public float maxRadius()Calculate how far the scaled shape extends from its center.- Overrides:
maxRadius
in classCollisionShape
- Returns:
- the distance (in physics-space units, ≥0)
-
read
De-serialize the shape from the specified importer, for example when loading from a J3O file.- Specified by:
read
in interfacecom.jme3.export.Savable
- Overrides:
read
in classCollisionShape
- Parameters:
importer
- (not null)- Throws:
IOException
- from the importer
-
scaledVolume
public float scaledVolume()Estimate the volume of the shape, including scale and margin.- Overrides:
scaledVolume
in classConvexShape
- Returns:
- the volume (in physics-space units cubed, ≥0)
-
setMargin
public void setMargin(float margin) Alter the collision margin of the shape. This feature is disabled for capsule shapes.- Overrides:
setMargin
in classCollisionShape
- Parameters:
margin
- the desired margin thickness (in physics-space units)
-
toHullShape
Approximate this shape with a HullCollisionShape.- Overrides:
toHullShape
in classConvexShape
- Returns:
- a new shape
-
write
Serialize the shape to the specified exporter, for example when saving to a J3O file.- Specified by:
write
in interfacecom.jme3.export.Savable
- Overrides:
write
in classCollisionShape
- Parameters:
exporter
- (not null)- Throws:
IOException
- from the exporter
-