Jolt Physics
A multi core friendly Game Physics Engine
Loading...
Searching...
No Matches
CompoundShape Class Referenceabstract

Base class for a compound shape. More...

#include <CompoundShape.h>

Inheritance diagram for CompoundShape:
Shape RefTarget< Shape > NonCopyable MutableCompoundShape StaticCompoundShape

Classes

struct  CastRayVisitor
 
struct  CastRayVisitorCollector
 
struct  CastShapeVisitor
 
struct  CollectTransformedShapesVisitor
 
struct  CollideCompoundVsShapeVisitor
 
struct  CollidePointVisitor
 
struct  CollideShapeVsCompoundVisitor
 
struct  GetIntersectingSubShapesVisitor
 
struct  SubShape
 

Public Types

using SubShapes = Array< SubShape >
 
- Public Types inherited from Shape
using ShapeResult = ShapeSettings::ShapeResult
 
using SupportingFace = StaticArray< Vec3, 32 >
 Type definition for a supporting face. More...
 
using VisitedShapes = UnorderedSet< const Shape * >
 
using ShapeToIDMap = StreamUtils::ObjectToIDMap< Shape >
 
using IDToShapeMap = StreamUtils::IDToObjectMap< Shape >
 
using MaterialToIDMap = StreamUtils::ObjectToIDMap< PhysicsMaterial >
 
using IDToMaterialMap = StreamUtils::IDToObjectMap< PhysicsMaterial >
 

Public Member Functions

JPH_OVERRIDE_NEW_DELETE CompoundShape (EShapeSubType inSubType)
 Constructor. More...
 
 CompoundShape (EShapeSubType inSubType, const ShapeSettings &inSettings, ShapeResult &outResult)
 
virtual Vec3 GetCenterOfMass () const override
 All shapes are centered around their center of mass. This function returns the center of mass position that needs to be applied to transform the shape to where it was created. More...
 
virtual bool MustBeStatic () const override
 Check if this shape can only be used to create a static body or if it can also be dynamic/kinematic. More...
 
virtual AABox GetLocalBounds () const override
 Get local bounding box including convex radius, this box is centered around the center of mass rather than the world transform. More...
 
virtual uint GetSubShapeIDBitsRecursive () const override
 Get the max number of sub shape ID bits that are needed to be able to address any leaf shape in this shape. Used mainly for checking that it is smaller or equal than SubShapeID::MaxBits. More...
 
virtual AABox GetWorldSpaceBounds (Mat44Arg inCenterOfMassTransform, Vec3Arg inScale) const override
 
virtual float GetInnerRadius () const override
 
virtual MassProperties GetMassProperties () const override
 Calculate the mass and inertia of this shape. More...
 
virtual const PhysicsMaterialGetMaterial (const SubShapeID &inSubShapeID) const override
 Get the material assigned to a particular sub shape ID. More...
 
virtual uint64 GetSubShapeUserData (const SubShapeID &inSubShapeID) const override
 Get the user data of a particular sub shape ID. More...
 
virtual TransformedShape GetSubShapeTransformedShape (const SubShapeID &inSubShapeID, Vec3Arg inPositionCOM, QuatArg inRotation, Vec3Arg inScale, SubShapeID &outRemainder) const override
 
virtual Vec3 GetSurfaceNormal (const SubShapeID &inSubShapeID, Vec3Arg inLocalSurfacePosition) const override
 
virtual void GetSupportingFace (const SubShapeID &inSubShapeID, Vec3Arg inDirection, Vec3Arg inScale, Mat44Arg inCenterOfMassTransform, SupportingFace &outVertices) const override
 
virtual void GetSubmergedVolume (Mat44Arg inCenterOfMassTransform, Vec3Arg inScale, const Plane &inSurface, float &outTotalVolume, float &outSubmergedVolume, Vec3 &outCenterOfBuoyancy JPH_IF_DEBUG_RENDERER(, RVec3Arg inBaseOffset)) const override
 
virtual void Draw (DebugRenderer *inRenderer, RMat44Arg inCenterOfMassTransform, Vec3Arg inScale, ColorArg inColor, bool inUseMaterialColors, bool inDrawWireframe) const override
 Draw the shape at a particular location with a particular color (debugging purposes) More...
 
virtual void DrawGetSupportFunction (DebugRenderer *inRenderer, RMat44Arg inCenterOfMassTransform, Vec3Arg inScale, ColorArg inColor, bool inDrawSupportDirection) const override
 Draw the results of the GetSupportFunction with the convex radius added back on to show any errors introduced by this process (only relevant for convex shapes) More...
 
virtual void DrawGetSupportingFace (DebugRenderer *inRenderer, RMat44Arg inCenterOfMassTransform, Vec3Arg inScale) const override
 Draw the results of the GetSupportingFace function to show any errors introduced by this process (only relevant for convex shapes) More...
 
virtual void CollideSoftBodyVertices (Mat44Arg inCenterOfMassTransform, Vec3Arg inScale, SoftBodyVertex *ioVertices, uint inNumVertices, float inDeltaTime, Vec3Arg inDisplacementDueToGravity, int inCollidingShapeIndex) const override
 
virtual void TransformShape (Mat44Arg inCenterOfMassTransform, TransformedShapeCollector &ioCollector) const override
 
virtual void GetTrianglesStart (GetTrianglesContext &ioContext, const AABox &inBox, Vec3Arg inPositionCOM, QuatArg inRotation, Vec3Arg inScale) const override
 
virtual int GetTrianglesNext (GetTrianglesContext &ioContext, int inMaxTrianglesRequested, Float3 *outTriangleVertices, const PhysicsMaterial **outMaterials=nullptr) const override
 
virtual int GetIntersectingSubShapes (const AABox &inBox, uint *outSubShapeIndices, int inMaxSubShapeIndices) const =0
 
virtual int GetIntersectingSubShapes (const OrientedBox &inBox, uint *outSubShapeIndices, int inMaxSubShapeIndices) const =0
 
const SubShapesGetSubShapes () const
 Access to the sub shapes of this compound. More...
 
uint GetNumSubShapes () const
 Get the total number of sub shapes. More...
 
const SubShapeGetSubShape (uint inIdx) const
 Access to a particular sub shape. More...
 
uint32 GetCompoundUserData (uint inIdx) const
 Get the user data associated with a shape in this compound. More...
 
void SetCompoundUserData (uint inIdx, uint32 inUserData)
 Set the user data associated with a shape in this compound. More...
 
bool IsSubShapeIDValid (SubShapeID inSubShapeID) const
 
uint32 GetSubShapeIndexFromID (SubShapeID inSubShapeID, SubShapeID &outRemainder) const
 
SubShapeIDCreator GetSubShapeIDFromIndex (int inIdx, const SubShapeIDCreator &inParentSubShapeID) const
 Convert a sub shape index to a sub shape ID. More...
 
virtual void SaveBinaryState (StreamOut &inStream) const override
 Saves the contents of the shape in binary form to inStream. More...
 
virtual void SaveSubShapeState (ShapeList &outSubShapes) const override
 Outputs the shape references that this shape has to outSubShapes. More...
 
virtual void RestoreSubShapeState (const ShapeRefC *inSubShapes, uint inNumShapes) override
 Restore the shape references after calling sRestoreFromBinaryState. Note that the exact same shapes need to be provided in the same order as returned by SaveSubShapeState. More...
 
virtual Stats GetStatsRecursive (VisitedShapes &ioVisitedShapes) const override
 Volume of this shape (m^3). Note that for compound shapes the volume may be incorrect since child shapes can overlap which is not accounted for. More...
 
virtual float GetVolume () const override
 
virtual bool IsValidScale (Vec3Arg inScale) const override
 
virtual Vec3 MakeScaleValid (Vec3Arg inScale) const override
 
virtual AABox GetWorldSpaceBounds (Mat44Arg inCenterOfMassTransform, Vec3Arg inScale) const
 
AABox GetWorldSpaceBounds (DMat44Arg inCenterOfMassTransform, Vec3Arg inScale) const
 Get world space bounds including convex radius. More...
 
- Public Member Functions inherited from Shape
 Shape (EShapeType inType, EShapeSubType inSubType)
 Constructor. More...
 
 Shape (EShapeType inType, EShapeSubType inSubType, const ShapeSettings &inSettings, ShapeResult &outResult)
 
virtual ~Shape ()=default
 Destructor. More...
 
EShapeType GetType () const
 Get type. More...
 
EShapeSubType GetSubType () const
 
uint64 GetUserData () const
 User data (to be used freely by the application) More...
 
void SetUserData (uint64 inUserData)
 
virtual bool MustBeStatic () const
 Check if this shape can only be used to create a static body or if it can also be dynamic/kinematic. More...
 
virtual Vec3 GetCenterOfMass () const
 All shapes are centered around their center of mass. This function returns the center of mass position that needs to be applied to transform the shape to where it was created. More...
 
virtual AABox GetLocalBounds () const =0
 Get local bounding box including convex radius, this box is centered around the center of mass rather than the world transform. More...
 
virtual uint GetSubShapeIDBitsRecursive () const =0
 Get the max number of sub shape ID bits that are needed to be able to address any leaf shape in this shape. Used mainly for checking that it is smaller or equal than SubShapeID::MaxBits. More...
 
virtual AABox GetWorldSpaceBounds (Mat44Arg inCenterOfMassTransform, Vec3Arg inScale) const
 
AABox GetWorldSpaceBounds (DMat44Arg inCenterOfMassTransform, Vec3Arg inScale) const
 Get world space bounds including convex radius. More...
 
virtual float GetInnerRadius () const =0
 
virtual MassProperties GetMassProperties () const =0
 Calculate the mass and inertia of this shape. More...
 
virtual const PhysicsMaterialGetMaterial (const SubShapeID &inSubShapeID) const =0
 Get the material assigned to a particular sub shape ID. More...
 
virtual Vec3 GetSurfaceNormal (const SubShapeID &inSubShapeID, Vec3Arg inLocalSurfacePosition) const =0
 
virtual void GetSupportingFace (const SubShapeID &inSubShapeID, Vec3Arg inDirection, Vec3Arg inScale, Mat44Arg inCenterOfMassTransform, SupportingFace &outVertices) const
 
virtual uint64 GetSubShapeUserData (const SubShapeID &inSubShapeID) const
 Get the user data of a particular sub shape ID. More...
 
virtual TransformedShape GetSubShapeTransformedShape (const SubShapeID &inSubShapeID, Vec3Arg inPositionCOM, QuatArg inRotation, Vec3Arg inScale, SubShapeID &outRemainder) const
 
virtual void GetSubmergedVolume (Mat44Arg inCenterOfMassTransform, Vec3Arg inScale, const Plane &inSurface, float &outTotalVolume, float &outSubmergedVolume, Vec3 &outCenterOfBuoyancy, RVec3Arg inBaseOffset) const =0
 
virtual void Draw (DebugRenderer *inRenderer, RMat44Arg inCenterOfMassTransform, Vec3Arg inScale, ColorArg inColor, bool inUseMaterialColors, bool inDrawWireframe) const =0
 Draw the shape at a particular location with a particular color (debugging purposes) More...
 
virtual void DrawGetSupportFunction (DebugRenderer *inRenderer, RMat44Arg inCenterOfMassTransform, Vec3Arg inScale, ColorArg inColor, bool inDrawSupportDirection) const
 Draw the results of the GetSupportFunction with the convex radius added back on to show any errors introduced by this process (only relevant for convex shapes) More...
 
virtual void DrawGetSupportingFace (DebugRenderer *inRenderer, RMat44Arg inCenterOfMassTransform, Vec3Arg inScale) const
 Draw the results of the GetSupportingFace function to show any errors introduced by this process (only relevant for convex shapes) More...
 
virtual bool CastRay (const RayCast &inRay, const SubShapeIDCreator &inSubShapeIDCreator, RayCastResult &ioHit) const =0
 
virtual void CastRay (const RayCast &inRay, const RayCastSettings &inRayCastSettings, const SubShapeIDCreator &inSubShapeIDCreator, CastRayCollector &ioCollector, const ShapeFilter &inShapeFilter={ }) const =0
 
virtual void CollidePoint (Vec3Arg inPoint, const SubShapeIDCreator &inSubShapeIDCreator, CollidePointCollector &ioCollector, const ShapeFilter &inShapeFilter={ }) const =0
 
virtual void CollideSoftBodyVertices (Mat44Arg inCenterOfMassTransform, Vec3Arg inScale, SoftBodyVertex *ioVertices, uint inNumVertices, float inDeltaTime, Vec3Arg inDisplacementDueToGravity, int inCollidingShapeIndex) const =0
 
virtual void CollectTransformedShapes (const AABox &inBox, Vec3Arg inPositionCOM, QuatArg inRotation, Vec3Arg inScale, const SubShapeIDCreator &inSubShapeIDCreator, TransformedShapeCollector &ioCollector, const ShapeFilter &inShapeFilter) const
 
virtual void TransformShape (Mat44Arg inCenterOfMassTransform, TransformedShapeCollector &ioCollector) const
 
ShapeResult ScaleShape (Vec3Arg inScale) const
 
virtual void GetTrianglesStart (GetTrianglesContext &ioContext, const AABox &inBox, Vec3Arg inPositionCOM, QuatArg inRotation, Vec3Arg inScale) const =0
 
virtual int GetTrianglesNext (GetTrianglesContext &ioContext, int inMaxTrianglesRequested, Float3 *outTriangleVertices, const PhysicsMaterial **outMaterials=nullptr) const =0
 
virtual Stats GetStats () const =0
 Get stats of this shape. Use for logging / data collection purposes only. Does not add values from child shapes, use GetStatsRecursive for this. More...
 
virtual Stats GetStatsRecursive (VisitedShapes &ioVisitedShapes) const
 Volume of this shape (m^3). Note that for compound shapes the volume may be incorrect since child shapes can overlap which is not accounted for. More...
 
virtual float GetVolume () const =0
 
virtual bool IsValidScale (Vec3Arg inScale) const
 
virtual Vec3 MakeScaleValid (Vec3Arg inScale) const
 
virtual void SaveMaterialState (PhysicsMaterialList &outMaterials) const
 Outputs the material references that this shape has to outMaterials. More...
 
virtual void RestoreMaterialState (const PhysicsMaterialRefC *inMaterials, uint inNumMaterials)
 Restore the material references after calling sRestoreFromBinaryState. Note that the exact same materials need to be provided in the same order as returned by SaveMaterialState. More...
 
void SaveWithChildren (StreamOut &inStream, ShapeToIDMap &ioShapeMap, MaterialToIDMap &ioMaterialMap) const
 Save this shape, all its children and its materials. Pass in an empty map in ioShapeMap / ioMaterialMap or reuse the same map while saving multiple shapes to the same stream in order to avoid writing duplicates. More...
 
- Public Member Functions inherited from RefTarget< Shape >
 RefTarget ()=default
 Constructor. More...
 
 RefTarget (const RefTarget &)
 
 ~RefTarget ()
 assert no one is referencing us More...
 
void SetEmbedded () const
 
RefTargetoperator= (const RefTarget &)
 Assignment operator. More...
 
uint32 GetRefCount () const
 Get current refcount of this object. More...
 
void AddRef () const
 Add or release a reference to this object. More...
 
void Release () const
 
- Public Member Functions inherited from NonCopyable
 NonCopyable ()=default
 
 NonCopyable (const NonCopyable &)=delete
 
void operator= (const NonCopyable &)=delete
 

Static Public Member Functions

static void sRegister ()
 
- Static Public Member Functions inherited from Shape
static ShapeResult sRestoreFromBinaryState (StreamIn &inStream)
 Creates a Shape of the correct type and restores its contents from the binary stream inStream. More...
 
static ShapeResult sRestoreWithChildren (StreamIn &inStream, IDToShapeMap &ioShapeMap, IDToMaterialMap &ioMaterialMap)
 Restore a shape, all its children and materials. Pass in an empty map in ioShapeMap / ioMaterialMap or reuse the same map while reading multiple shapes from the same stream in order to restore duplicates. More...
 
- Static Public Member Functions inherited from RefTarget< Shape >
static int sInternalGetRefCountOffset ()
 INTERNAL HELPER FUNCTION USED BY SERIALIZATION. More...
 

Protected Member Functions

virtual void RestoreBinaryState (StreamIn &inStream) override
 This function should not be called directly, it is used by sRestoreFromBinaryState. More...
 
uint GetSubShapeIDBits () const
 Determine amount of bits needed to encode sub shape id. More...
 
void CalculateInnerRadius ()
 Determine the inner radius of this shape. More...
 
virtual void RestoreBinaryState (StreamIn &inStream)
 This function should not be called directly, it is used by sRestoreFromBinaryState. More...
 

Protected Attributes

Vec3 mCenterOfMass { Vec3::sZero() }
 Center of mass of the compound. More...
 
AABox mLocalBounds
 
SubShapes mSubShapes
 
float mInnerRadius = FLT_MAX
 Smallest radius of GetInnerRadius() of child shapes. More...
 
- Protected Attributes inherited from RefTarget< Shape >
atomic< uint32mRefCount
 Current reference count. More...
 

Additional Inherited Members

- Static Public Attributes inherited from Shape
static constexpr int cGetTrianglesMinTrianglesRequested = 32
 This is the minimum amount of triangles that should be requested through GetTrianglesNext. More...
 
static bool sDrawSubmergedVolumes = false
 Debug helper which draws the intersection between water and the shapes, the center of buoyancy and the submerged volume. More...
 
- Static Protected Member Functions inherited from Shape
static void sCollidePointUsingRayCast (const Shape &inShape, Vec3Arg inPoint, const SubShapeIDCreator &inSubShapeIDCreator, CollidePointCollector &ioCollector, const ShapeFilter &inShapeFilter)
 A fallback version of CollidePoint that uses a ray cast and counts the number of hits to determine if the point is inside the shape. Odd number of hits means inside, even number of hits means outside. More...
 
- Static Protected Attributes inherited from RefTarget< Shape >
static constexpr uint32 cEmbedded
 A large value that gets added to the refcount to mark the object as embedded. More...
 

Detailed Description

Base class for a compound shape.

Member Typedef Documentation

◆ SubShapes

Constructor & Destructor Documentation

◆ CompoundShape() [1/2]

JPH_OVERRIDE_NEW_DELETE CompoundShape::CompoundShape ( EShapeSubType  inSubType)
inlineexplicit

Constructor.

◆ CompoundShape() [2/2]

CompoundShape::CompoundShape ( EShapeSubType  inSubType,
const ShapeSettings inSettings,
ShapeResult outResult 
)
inline

Member Function Documentation

◆ CalculateInnerRadius()

void CompoundShape::CalculateInnerRadius ( )
inlineprotected

Determine the inner radius of this shape.

◆ CollideSoftBodyVertices()

void CompoundShape::CollideSoftBodyVertices ( Mat44Arg  inCenterOfMassTransform,
Vec3Arg  inScale,
SoftBodyVertex ioVertices,
uint  inNumVertices,
float  inDeltaTime,
Vec3Arg  inDisplacementDueToGravity,
int  inCollidingShapeIndex 
) const
overridevirtual

Collides all vertices of a soft body with this shape and updates SoftBodyVertex::mCollisionPlane, SoftBodyVertex::mCollidingShapeIndex and SoftBodyVertex::mLargestPenetration if a collision with more penetration was found.

Parameters
inCenterOfMassTransformCenter of mass transform for this shape relative to the vertices.
inScaleScale in local space of the shape (scales relative to its center of mass)
ioVerticesThe vertices of the soft body
inNumVerticesThe number of vertices in ioVertices
inDeltaTimeDelta time of this time step (can be used to extrapolate the position using the velocity of the particle)
inDisplacementDueToGravityDisplacement due to gravity during this time step
inCollidingShapeIndexValue to store in SoftBodyVertex::mCollidingShapeIndex when a collision was found

Implements Shape.

◆ Draw()

void CompoundShape::Draw ( DebugRenderer inRenderer,
RMat44Arg  inCenterOfMassTransform,
Vec3Arg  inScale,
ColorArg  inColor,
bool  inUseMaterialColors,
bool  inDrawWireframe 
) const
overridevirtual

Draw the shape at a particular location with a particular color (debugging purposes)

Implements Shape.

◆ DrawGetSupportFunction()

void CompoundShape::DrawGetSupportFunction ( DebugRenderer inRenderer,
RMat44Arg  inCenterOfMassTransform,
Vec3Arg  inScale,
ColorArg  inColor,
bool  inDrawSupportDirection 
) const
overridevirtual

Draw the results of the GetSupportFunction with the convex radius added back on to show any errors introduced by this process (only relevant for convex shapes)

Reimplemented from Shape.

◆ DrawGetSupportingFace()

void CompoundShape::DrawGetSupportingFace ( DebugRenderer inRenderer,
RMat44Arg  inCenterOfMassTransform,
Vec3Arg  inScale 
) const
overridevirtual

Draw the results of the GetSupportingFace function to show any errors introduced by this process (only relevant for convex shapes)

Reimplemented from Shape.

◆ GetCenterOfMass()

virtual Vec3 CompoundShape::GetCenterOfMass ( ) const
inlineoverridevirtual

All shapes are centered around their center of mass. This function returns the center of mass position that needs to be applied to transform the shape to where it was created.

Reimplemented from Shape.

◆ GetCompoundUserData()

uint32 CompoundShape::GetCompoundUserData ( uint  inIdx) const
inline

Get the user data associated with a shape in this compound.

◆ GetInnerRadius()

virtual float CompoundShape::GetInnerRadius ( ) const
inlineoverridevirtual

Returns the radius of the biggest sphere that fits entirely in the shape. In case this shape consists of multiple sub shapes, it returns the smallest sphere of the parts. This can be used as a measure of how far the shape can be moved without risking going through geometry.

Implements Shape.

◆ GetIntersectingSubShapes() [1/2]

virtual int CompoundShape::GetIntersectingSubShapes ( const AABox inBox,
uint outSubShapeIndices,
int  inMaxSubShapeIndices 
) const
pure virtual

Get which sub shape's bounding boxes overlap with an axis aligned box

Parameters
inBoxThe axis aligned box to test against (relative to the center of mass of this shape)
outSubShapeIndicesBuffer where to place the indices of the sub shapes that intersect
inMaxSubShapeIndicesHow many indices will fit in the buffer (normally you'd provide a buffer of GetNumSubShapes() indices)
Returns
How many indices were placed in outSubShapeIndices

Implemented in MutableCompoundShape, and StaticCompoundShape.

◆ GetIntersectingSubShapes() [2/2]

virtual int CompoundShape::GetIntersectingSubShapes ( const OrientedBox inBox,
uint outSubShapeIndices,
int  inMaxSubShapeIndices 
) const
pure virtual

Get which sub shape's bounding boxes overlap with an axis aligned box

Parameters
inBoxThe axis aligned box to test against (relative to the center of mass of this shape)
outSubShapeIndicesBuffer where to place the indices of the sub shapes that intersect
inMaxSubShapeIndicesHow many indices will fit in the buffer (normally you'd provide a buffer of GetNumSubShapes() indices)
Returns
How many indices were placed in outSubShapeIndices

Implemented in MutableCompoundShape, and StaticCompoundShape.

◆ GetLocalBounds()

virtual AABox CompoundShape::GetLocalBounds ( ) const
inlineoverridevirtual

Get local bounding box including convex radius, this box is centered around the center of mass rather than the world transform.

Implements Shape.

◆ GetMassProperties()

MassProperties CompoundShape::GetMassProperties ( ) const
overridevirtual

Calculate the mass and inertia of this shape.

Implements Shape.

◆ GetMaterial()

const PhysicsMaterial * CompoundShape::GetMaterial ( const SubShapeID inSubShapeID) const
overridevirtual

Get the material assigned to a particular sub shape ID.

Implements Shape.

◆ GetNumSubShapes()

uint CompoundShape::GetNumSubShapes ( ) const
inline

Get the total number of sub shapes.

◆ GetStatsRecursive()

Shape::Stats CompoundShape::GetStatsRecursive ( VisitedShapes ioVisitedShapes) const
overridevirtual

Volume of this shape (m^3). Note that for compound shapes the volume may be incorrect since child shapes can overlap which is not accounted for.

Get the combined stats of this shape and its children.

Parameters
ioVisitedShapesis used to track which shapes have already been visited, to avoid calculating the wrong memory size.

Reimplemented from Shape.

◆ GetSubmergedVolume()

void CompoundShape::GetSubmergedVolume ( Mat44Arg  inCenterOfMassTransform,
Vec3Arg  inScale,
const Plane inSurface,
float &  outTotalVolume,
float &  outSubmergedVolume,
Vec3 &outCenterOfBuoyancy   JPH_IF_DEBUG_RENDERER, RVec3Arg inBaseOffset 
) const
overridevirtual

◆ GetSubShape()

const SubShape & CompoundShape::GetSubShape ( uint  inIdx) const
inline

Access to a particular sub shape.

◆ GetSubShapeIDBits()

uint CompoundShape::GetSubShapeIDBits ( ) const
inlineprotected

Determine amount of bits needed to encode sub shape id.

◆ GetSubShapeIDBitsRecursive()

uint CompoundShape::GetSubShapeIDBitsRecursive ( ) const
overridevirtual

Get the max number of sub shape ID bits that are needed to be able to address any leaf shape in this shape. Used mainly for checking that it is smaller or equal than SubShapeID::MaxBits.

Implements Shape.

◆ GetSubShapeIDFromIndex()

SubShapeIDCreator CompoundShape::GetSubShapeIDFromIndex ( int  inIdx,
const SubShapeIDCreator inParentSubShapeID 
) const
inline

Convert a sub shape index to a sub shape ID.

Parameters
inIdxIndex of the sub shape of this compound
inParentSubShapeIDParent SubShapeID (describing the path to the compound shape)
Returns
A sub shape ID creator that contains the full path to the sub shape with index inIdx

◆ GetSubShapeIndexFromID()

uint32 CompoundShape::GetSubShapeIndexFromID ( SubShapeID  inSubShapeID,
SubShapeID outRemainder 
) const
inline

Convert SubShapeID to sub shape index

Parameters
inSubShapeIDSub shape id that indicates the leaf shape relative to this shape
outRemainderThis is the sub shape ID for the sub shape of the compound after popping off the index
Returns
The index of the sub shape of this compound

◆ GetSubShapes()

const SubShapes & CompoundShape::GetSubShapes ( ) const
inline

Access to the sub shapes of this compound.

◆ GetSubShapeTransformedShape()

TransformedShape CompoundShape::GetSubShapeTransformedShape ( const SubShapeID inSubShapeID,
Vec3Arg  inPositionCOM,
QuatArg  inRotation,
Vec3Arg  inScale,
SubShapeID outRemainder 
) const
overridevirtual

Get the direct child sub shape and its transform for a sub shape ID.

Parameters
inSubShapeIDSub shape ID that indicates the path to the leaf shape
inPositionCOMThe position of the center of mass of this shape
inRotationThe orientation of this shape
inScaleScale in local space of the shape (scales relative to its center of mass)
outRemainderThe remainder of the sub shape ID after removing the sub shape
Returns
Direct child sub shape and its transform, note that the body ID and sub shape ID will be invalid

Reimplemented from Shape.

◆ GetSubShapeUserData()

uint64 CompoundShape::GetSubShapeUserData ( const SubShapeID inSubShapeID) const
overridevirtual

Get the user data of a particular sub shape ID.

Reimplemented from Shape.

◆ GetSupportingFace()

void CompoundShape::GetSupportingFace ( const SubShapeID inSubShapeID,
Vec3Arg  inDirection,
Vec3Arg  inScale,
Mat44Arg  inCenterOfMassTransform,
SupportingFace outVertices 
) const
overridevirtual

Get the vertices of the face that faces inDirection the most (includes any convex radius). Note that this function can only return faces of convex shapes or triangles, which is why a sub shape ID to get to that leaf must be provided.

Parameters
inSubShapeIDSub shape ID of target shape
inDirectionDirection that the face should be facing (in local space to this shape)
inCenterOfMassTransformTransform to transform outVertices with
inScaleScale in local space of the shape (scales relative to its center of mass)
outVerticesResulting face. The returned face can be empty if the shape doesn't have polygons to return (e.g. because it's a sphere). The face will be returned in world space.

Reimplemented from Shape.

◆ GetSurfaceNormal()

Vec3 CompoundShape::GetSurfaceNormal ( const SubShapeID inSubShapeID,
Vec3Arg  inLocalSurfacePosition 
) const
overridevirtual

Get the surface normal of a particular sub shape ID and point on surface (all vectors are relative to center of mass for this shape). Note: When you have a CollideShapeResult or ShapeCastResult you should use -mPenetrationAxis.Normalized() as contact normal as GetSurfaceNormal will only return face normals (and not vertex or edge normals).

Implements Shape.

◆ GetTrianglesNext()

virtual int CompoundShape::GetTrianglesNext ( GetTrianglesContext ioContext,
int  inMaxTrianglesRequested,
Float3 outTriangleVertices,
const PhysicsMaterial **  outMaterials = nullptr 
) const
inlineoverridevirtual

Call this repeatedly to get all triangles in the box. outTriangleVertices should be large enough to hold 3 * inMaxTriangleRequested entries. outMaterials (if it is not null) should contain inMaxTrianglesRequested entries. The function returns the amount of triangles that it found (which will be <= inMaxTrianglesRequested), or 0 if there are no more triangles. Note that the function can return a value < inMaxTrianglesRequested and still have more triangles to process (triangles can be returned in blocks). Note that the function may return triangles outside of the requested box, only coarse culling is performed on the returned triangles.

Implements Shape.

◆ GetTrianglesStart()

virtual void CompoundShape::GetTrianglesStart ( GetTrianglesContext ioContext,
const AABox inBox,
Vec3Arg  inPositionCOM,
QuatArg  inRotation,
Vec3Arg  inScale 
) const
inlineoverridevirtual

To start iterating over triangles, call this function first. ioContext is a temporary buffer and should remain untouched until the last call to GetTrianglesNext. inBox is the world space bounding in which you want to get the triangles. inPositionCOM/inRotation/inScale describes the transform of this shape. To get the actual triangles call GetTrianglesNext.

Implements Shape.

◆ GetVolume()

float CompoundShape::GetVolume ( ) const
overridevirtual

Implements Shape.

◆ GetWorldSpaceBounds() [1/3]

AABox Shape::GetWorldSpaceBounds ( DMat44Arg  inCenterOfMassTransform,
Vec3Arg  inScale 
) const
inline

Get world space bounds including convex radius.

◆ GetWorldSpaceBounds() [2/3]

virtual AABox Shape::GetWorldSpaceBounds ( Mat44Arg  inCenterOfMassTransform,
Vec3Arg  inScale 
) const
inlinevirtual

Get world space bounds including convex radius. This shape is scaled by inScale in local space first. This function can be overridden to return a closer fitting world space bounding box, by default it will just transform what GetLocalBounds() returns.

Reimplemented from Shape.

◆ GetWorldSpaceBounds() [3/3]

AABox CompoundShape::GetWorldSpaceBounds ( Mat44Arg  inCenterOfMassTransform,
Vec3Arg  inScale 
) const
overridevirtual

Get world space bounds including convex radius. This shape is scaled by inScale in local space first. This function can be overridden to return a closer fitting world space bounding box, by default it will just transform what GetLocalBounds() returns.

Reimplemented from Shape.

◆ IsSubShapeIDValid()

bool CompoundShape::IsSubShapeIDValid ( SubShapeID  inSubShapeID) const
inline

Check if a sub shape ID is still valid for this shape

Parameters
inSubShapeIDSub shape id that indicates the leaf shape relative to this shape
Returns
True if the ID is valid, false if not

◆ IsValidScale()

bool CompoundShape::IsValidScale ( Vec3Arg  inScale) const
overridevirtual

Test if inScale is a valid scale for this shape. Some shapes can only be scaled uniformly, compound shapes cannot handle shapes being rotated and scaled (this would cause shearing), scale can never be zero. When the scale is invalid, the function will return false.

Here's a list of supported scales:

  • SphereShape: Scale must be uniform (signs of scale are ignored).
  • BoxShape: Any scale supported (signs of scale are ignored).
  • TriangleShape: Any scale supported when convex radius is zero, otherwise only uniform scale supported.
  • CapsuleShape: Scale must be uniform (signs of scale are ignored).
  • TaperedCapsuleShape: Scale must be uniform (sign of Y scale can be used to flip the capsule).
  • CylinderShape: Scale must be uniform in XZ plane, Y can scale independently (signs of scale are ignored).
  • RotatedTranslatedShape: Scale must not cause shear in the child shape.
  • CompoundShape: Scale must not cause shear in any of the child shapes.

Reimplemented from Shape.

◆ MakeScaleValid()

Vec3 CompoundShape::MakeScaleValid ( Vec3Arg  inScale) const
overridevirtual

This function will make sure that if you wrap this shape in a ScaledShape that the scale is valid. Note that this involves discarding components of the scale that are invalid, so the resulting scaled shape may be different than the requested scale. Compare the return value of this function with the scale you passed in to detect major inconsistencies and possibly warn the user.

Parameters
inScaleLocal space scale for this shape.
Returns
Scale that can be used to wrap this shape in a ScaledShape. IsValidScale will return true for this scale.

Reimplemented from Shape.

◆ MustBeStatic()

bool CompoundShape::MustBeStatic ( ) const
overridevirtual

Check if this shape can only be used to create a static body or if it can also be dynamic/kinematic.

Reimplemented from Shape.

◆ RestoreBinaryState()

void CompoundShape::RestoreBinaryState ( StreamIn inStream)
overrideprotectedvirtual

This function should not be called directly, it is used by sRestoreFromBinaryState.

Reimplemented from Shape.

Reimplemented in MutableCompoundShape, and StaticCompoundShape.

◆ RestoreSubShapeState()

void CompoundShape::RestoreSubShapeState ( const ShapeRefC inSubShapes,
uint  inNumShapes 
)
overridevirtual

Restore the shape references after calling sRestoreFromBinaryState. Note that the exact same shapes need to be provided in the same order as returned by SaveSubShapeState.

Reimplemented from Shape.

◆ SaveBinaryState()

void CompoundShape::SaveBinaryState ( StreamOut inStream) const
overridevirtual

Saves the contents of the shape in binary form to inStream.

Reimplemented from Shape.

Reimplemented in MutableCompoundShape, and StaticCompoundShape.

◆ SaveSubShapeState()

void CompoundShape::SaveSubShapeState ( ShapeList outSubShapes) const
overridevirtual

Outputs the shape references that this shape has to outSubShapes.

Reimplemented from Shape.

◆ SetCompoundUserData()

void CompoundShape::SetCompoundUserData ( uint  inIdx,
uint32  inUserData 
)
inline

Set the user data associated with a shape in this compound.

◆ sRegister()

void CompoundShape::sRegister ( )
static

◆ TransformShape()

void CompoundShape::TransformShape ( Mat44Arg  inCenterOfMassTransform,
TransformedShapeCollector ioCollector 
) const
overridevirtual

Transforms this shape and all of its children with inTransform, resulting shape(s) are passed to ioCollector. Note that not all shapes support all transforms (especially true for scaling), the resulting shape will try to match the transform as accurately as possible.

Parameters
inCenterOfMassTransformThe transform (rotation, translation, scale) that the center of mass of the shape should get
ioCollectorThe transformed shapes will be passed to this collector

Reimplemented from Shape.

Member Data Documentation

◆ mCenterOfMass

Vec3 CompoundShape::mCenterOfMass { Vec3::sZero() }
protected

Center of mass of the compound.

◆ mInnerRadius

float CompoundShape::mInnerRadius = FLT_MAX
protected

Smallest radius of GetInnerRadius() of child shapes.

◆ mLocalBounds

AABox CompoundShape::mLocalBounds
protected

◆ mSubShapes

SubShapes CompoundShape::mSubShapes
protected

The documentation for this class was generated from the following files: