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

Base class for all shapes (collision volume of a body). Defines a virtual interface for collision detection. More...

#include <Shape.h>

Inheritance diagram for Shape:
RefTarget< Shape > NonCopyable CompoundShape ConvexShape DecoratedShape HeightFieldShape MeshShape SoftBodyShape MutableCompoundShape StaticCompoundShape BoxShape CapsuleShape ConvexHullShape CylinderShape SphereShape TaperedCapsuleShape TriangleShape OffsetCenterOfMassShape RotatedTranslatedShape ScaledShape

Classes

struct  GetTrianglesContext
 An opaque buffer that holds shape specific information during GetTrianglesStart/Next. More...
 
struct  Stats
 Class that holds information about the shape that can be used for logging / data collection purposes. More...
 

Public Types

using ShapeResult = ShapeSettings::ShapeResult
 
using SupportingFace = StaticArray< Vec3, 32 >
 Type definition for a supporting face.
 
using VisitedShapes = UnorderedSet< const Shape * >
 

Public Member Functions

 Shape (EShapeType inType, EShapeSubType inSubType)
 Constructor.
 
 Shape (EShapeType inType, EShapeSubType inSubType, const ShapeSettings &inSettings, ShapeResult &outResult)
 
virtual ~Shape ()=default
 Destructor.
 
EShapeType GetType () const
 Get type.
 
EShapeSubType GetSubType () const
 
uint64 GetUserData () const
 User data (to be used freely by the application)
 
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.
 
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.
 
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.
 
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.
 
virtual AABox GetWorldSpaceBounds (Mat44Arg inCenterOfMassTransform, Vec3Arg inScale) const
 
AABox GetWorldSpaceBounds (DMat44Arg inCenterOfMassTransform, Vec3Arg inScale) const
 Get world space bounds including convex radius.
 
virtual float GetInnerRadius () const =0
 
virtual MassProperties GetMassProperties () const =0
 Calculate the mass and inertia of this shape.
 
virtual const PhysicsMaterialGetMaterial (const SubShapeID &inSubShapeID) const =0
 Get the material assigned to a particular sub shape ID.
 
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.
 
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)
 
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)
 
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)
 
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.
 
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.
 
virtual float GetVolume () const =0
 
virtual bool IsValidScale (Vec3Arg inScale) const
 
- Public Member Functions inherited from RefTarget< Shape >
 RefTarget ()=default
 Constructor.
 
 RefTarget (const RefTarget &)
 
 ~RefTarget ()
 assert no one is referencing us
 
void SetEmbedded () const
 
RefTargetoperator= (const RefTarget &)
 Assignment operator.
 
uint32 GetRefCount () const
 Get current refcount of this object.
 
void AddRef () const
 Add or release a reference to this object.
 
void Release () const
 
- Public Member Functions inherited from NonCopyable
 NonCopyable ()=default
 
 NonCopyable (const NonCopyable &)=delete
 
void operator= (const NonCopyable &)=delete
 

Static Public Attributes

static constexpr int cGetTrianglesMinTrianglesRequested = 32
 This is the minimum amount of triangles that should be requested through GetTrianglesNext.
 
static bool sDrawSubmergedVolumes = false
 Debug helper which draws the intersection between water and the shapes, the center of buoyancy and the submerged volume.
 

Protected Member Functions

virtual void RestoreBinaryState (StreamIn &inStream)
 This function should not be called directly, it is used by sRestoreFromBinaryState.
 

Static Protected Member Functions

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.
 

Binary serialization of the shape. Note that this saves the 'cooked' shape in a format which will not be backwards compatible for newer library versions.

In this case you need to recreate the shape from the ShapeSettings object and save it again. The user is expected to call SaveBinaryState followed by SaveMaterialState and SaveSubShapeState. The stream should be stored as is and the material and shape list should be saved using the applications own serialization system (e.g. by assigning an ID to each pointer). When restoring data, call sRestoreFromBinaryState to get the shape and then call RestoreMaterialState and RestoreSubShapeState to restore the pointers to the external objects. Alternatively you can use SaveWithChildren and sRestoreWithChildren to save and restore the shape and all its child shapes and materials in a single stream.

using ShapeToIDMap = StreamUtils::ObjectToIDMap< Shape >
 
using IDToShapeMap = StreamUtils::IDToObjectMap< Shape >
 
using MaterialToIDMap = StreamUtils::ObjectToIDMap< PhysicsMaterial >
 
using IDToMaterialMap = StreamUtils::IDToObjectMap< PhysicsMaterial >
 
virtual void SaveBinaryState (StreamOut &inStream) const
 Saves the contents of the shape in binary form to inStream.
 
virtual void SaveMaterialState (PhysicsMaterialList &outMaterials) const
 Outputs the material references that this shape has to outMaterials.
 
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.
 
virtual void SaveSubShapeState (ShapeList &outSubShapes) const
 Outputs the shape references that this shape has to outSubShapes.
 
virtual void RestoreSubShapeState (const ShapeRefC *inSubShapes, uint inNumShapes)
 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.
 
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.
 
static ShapeResult sRestoreFromBinaryState (StreamIn &inStream)
 Creates a Shape of the correct type and restores its contents from the binary stream inStream.
 
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.
 

Additional Inherited Members

- Static Public Member Functions inherited from RefTarget< Shape >
static int sInternalGetRefCountOffset ()
 INTERNAL HELPER FUNCTION USED BY SERIALIZATION.
 
- Protected Attributes inherited from RefTarget< Shape >
atomic< uint32mRefCount
 Current reference count.
 
- 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.
 

Detailed Description

Base class for all shapes (collision volume of a body). Defines a virtual interface for collision detection.

Member Typedef Documentation

◆ IDToMaterialMap

◆ IDToShapeMap

◆ MaterialToIDMap

◆ ShapeResult

◆ ShapeToIDMap

◆ SupportingFace

Type definition for a supporting face.

◆ VisitedShapes

Constructor & Destructor Documentation

◆ Shape() [1/2]

Shape::Shape ( EShapeType  inType,
EShapeSubType  inSubType 
)
inline

Constructor.

◆ Shape() [2/2]

Shape::Shape ( EShapeType  inType,
EShapeSubType  inSubType,
const ShapeSettings inSettings,
ShapeResult outResult 
)
inline

◆ ~Shape()

virtual Shape::~Shape ( )
virtualdefault

Destructor.

Member Function Documentation

◆ CastRay() [1/2]

virtual void Shape::CastRay ( const RayCast inRay,
const RayCastSettings inRayCastSettings,
const SubShapeIDCreator inSubShapeIDCreator,
CastRayCollector ioCollector,
const ShapeFilter inShapeFilter = { } 
) const
pure virtual

Cast a ray against this shape. Allows returning multiple hits through ioCollector. Note that this version is more flexible but also slightly slower than the CastRay function that returns only a single hit. If you want the surface normal of the hit use GetSurfaceNormal(collected sub shape ID, inRay.GetPointOnRay(collected faction)).

Implemented in BoxShape, CapsuleShape, ConvexHullShape, ConvexShape, CylinderShape, HeightFieldShape, MeshShape, MutableCompoundShape, OffsetCenterOfMassShape, RotatedTranslatedShape, ScaledShape, SphereShape, StaticCompoundShape, TriangleShape, and SoftBodyShape.

◆ CastRay() [2/2]

virtual bool Shape::CastRay ( const RayCast inRay,
const SubShapeIDCreator inSubShapeIDCreator,
RayCastResult ioHit 
) const
pure virtual

Cast a ray against this shape, returns true if it finds a hit closer than ioHit.mFraction and updates that fraction. Otherwise ioHit is left untouched and the function returns false. Note that the ray should be relative to the center of mass of this shape (i.e. subtract Shape::GetCenterOfMass() from RayCast::mOrigin if you want to cast against the shape in the space it was created). Convex objects will be treated as solid (meaning if the ray starts inside, you'll get a hit fraction of 0) and back face hits against triangles are returned. If you want the surface normal of the hit use GetSurfaceNormal(ioHit.mSubShapeID2, inRay.GetPointOnRay(ioHit.mFraction)).

Implemented in BoxShape, CapsuleShape, CapsuleShape, ConvexHullShape, ConvexShape, CylinderShape, CylinderShape, HeightFieldShape, MeshShape, MutableCompoundShape, OffsetCenterOfMassShape, RotatedTranslatedShape, ScaledShape, SphereShape, StaticCompoundShape, TriangleShape, and SoftBodyShape.

◆ CollectTransformedShapes()

void Shape::CollectTransformedShapes ( const AABox inBox,
Vec3Arg  inPositionCOM,
QuatArg  inRotation,
Vec3Arg  inScale,
const SubShapeIDCreator inSubShapeIDCreator,
TransformedShapeCollector ioCollector,
const ShapeFilter inShapeFilter 
) const
virtual

Collect the leaf transformed shapes of all leaf shapes of this shape. inBox is the world space axis aligned box which leaf shapes should collide with. inPositionCOM/inRotation/inScale describes the transform of this shape. inSubShapeIDCeator represents the current sub shape ID of this shape.

Reimplemented in MutableCompoundShape, OffsetCenterOfMassShape, RotatedTranslatedShape, ScaledShape, and StaticCompoundShape.

◆ CollidePoint()

virtual void Shape::CollidePoint ( Vec3Arg  inPoint,
const SubShapeIDCreator inSubShapeIDCreator,
CollidePointCollector ioCollector,
const ShapeFilter inShapeFilter = { } 
) const
pure virtual

Check if inPoint is inside this shape. For this tests all shapes are treated as if they were solid. Note that inPoint should be relative to the center of mass of this shape (i.e. subtract Shape::GetCenterOfMass() from inPoint if you want to test against the shape in the space it was created). For a mesh shape, this test will only provide sensible information if the mesh is a closed manifold. For each shape that collides, ioCollector will receive a hit.

Implemented in BoxShape, CapsuleShape, ConvexHullShape, ConvexShape, CylinderShape, HeightFieldShape, MeshShape, MutableCompoundShape, OffsetCenterOfMassShape, RotatedTranslatedShape, ScaledShape, SphereShape, StaticCompoundShape, TriangleShape, and SoftBodyShape.

◆ CollideSoftBodyVertices()

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

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.
inScaleThe scale to use for this shape
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

Implemented in BoxShape, CapsuleShape, CompoundShape, ConvexHullShape, CylinderShape, HeightFieldShape, MeshShape, OffsetCenterOfMassShape, RotatedTranslatedShape, ScaledShape, SphereShape, TaperedCapsuleShape, TriangleShape, and SoftBodyShape.

◆ Draw()

virtual void Shape::Draw ( DebugRenderer inRenderer,
RMat44Arg  inCenterOfMassTransform,
Vec3Arg  inScale,
ColorArg  inColor,
bool  inUseMaterialColors,
bool  inDrawWireframe 
) const
pure virtual

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

Implemented in BoxShape, CapsuleShape, CompoundShape, ConvexHullShape, CylinderShape, HeightFieldShape, MeshShape, OffsetCenterOfMassShape, RotatedTranslatedShape, ScaledShape, SphereShape, TaperedCapsuleShape, TriangleShape, and SoftBodyShape.

◆ DrawGetSupportFunction()

virtual void Shape::DrawGetSupportFunction ( DebugRenderer inRenderer,
RMat44Arg  inCenterOfMassTransform,
Vec3Arg  inScale,
ColorArg  inColor,
bool  inDrawSupportDirection 
) const
inlinevirtual

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 in CompoundShape, ConvexShape, OffsetCenterOfMassShape, RotatedTranslatedShape, and ScaledShape.

◆ DrawGetSupportingFace()

virtual void Shape::DrawGetSupportingFace ( DebugRenderer inRenderer,
RMat44Arg  inCenterOfMassTransform,
Vec3Arg  inScale 
) const
inlinevirtual

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

Reimplemented in CompoundShape, ConvexShape, OffsetCenterOfMassShape, RotatedTranslatedShape, and ScaledShape.

◆ GetCenterOfMass()

virtual Vec3 Shape::GetCenterOfMass ( ) const
inlinevirtual

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 in CompoundShape, ConvexHullShape, DecoratedShape, OffsetCenterOfMassShape, RotatedTranslatedShape, ScaledShape, TaperedCapsuleShape, and SoftBodyShape.

◆ GetInnerRadius()

virtual float Shape::GetInnerRadius ( ) const
pure virtual

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.

Implemented in BoxShape, CapsuleShape, CompoundShape, ConvexHullShape, CylinderShape, HeightFieldShape, MeshShape, OffsetCenterOfMassShape, RotatedTranslatedShape, ScaledShape, SphereShape, TaperedCapsuleShape, TriangleShape, and SoftBodyShape.

◆ GetLocalBounds()

virtual AABox Shape::GetLocalBounds ( ) const
pure virtual

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

Implemented in BoxShape, CapsuleShape, CompoundShape, ConvexHullShape, CylinderShape, HeightFieldShape, MeshShape, OffsetCenterOfMassShape, RotatedTranslatedShape, ScaledShape, SphereShape, TaperedCapsuleShape, TriangleShape, and SoftBodyShape.

◆ GetMassProperties()

virtual MassProperties Shape::GetMassProperties ( ) const
pure virtual

◆ GetMaterial()

virtual const PhysicsMaterial * Shape::GetMaterial ( const SubShapeID inSubShapeID) const
pure virtual

Get the material assigned to a particular sub shape ID.

Implemented in CompoundShape, ConvexShape, DecoratedShape, HeightFieldShape, MeshShape, and SoftBodyShape.

◆ GetStats()

virtual Stats Shape::GetStats ( ) const
pure virtual

Get stats of this shape. Use for logging / data collection purposes only. Does not add values from child shapes, use GetStatsRecursive for this.

Implemented in BoxShape, CapsuleShape, ConvexHullShape, CylinderShape, HeightFieldShape, MeshShape, MutableCompoundShape, OffsetCenterOfMassShape, RotatedTranslatedShape, ScaledShape, SphereShape, StaticCompoundShape, TaperedCapsuleShape, TriangleShape, and SoftBodyShape.

◆ GetStatsRecursive()

Shape::Stats Shape::GetStatsRecursive ( VisitedShapes ioVisitedShapes) const
virtual

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 in CompoundShape, and DecoratedShape.

◆ GetSubmergedVolume()

virtual void Shape::GetSubmergedVolume ( Mat44Arg  inCenterOfMassTransform,
Vec3Arg  inScale,
const Plane inSurface,
float &  outTotalVolume,
float &  outSubmergedVolume,
Vec3 outCenterOfBuoyancy,
RVec3Arg  inBaseOffset 
) const
pure virtual

Gets the properties needed to do buoyancy calculations for a body using this shape

Parameters
inCenterOfMassTransformTransform that takes this shape (centered around center of mass) to world space (or a desired other space)
inScaleScale in local space of the shape
inSurfaceThe surface plane of the liquid relative to inCenterOfMassTransform
outTotalVolumeOn return this contains the total volume of the shape
outSubmergedVolumeOn return this contains the submerged volume of the shape
outCenterOfBuoyancyOn return this contains the world space center of mass of the submerged volume
inBaseOffsetThe offset to transform inCenterOfMassTransform to world space (in double precision mode this can be used to shift the whole operation closer to the origin). Only used for debug drawing.

Implemented in SoftBodyShape.

◆ GetSubShapeIDBitsRecursive()

virtual uint Shape::GetSubShapeIDBitsRecursive ( ) const
pure virtual

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.

Implemented in CompoundShape, ConvexShape, DecoratedShape, HeightFieldShape, MeshShape, and SoftBodyShape.

◆ GetSubShapeTransformedShape()

TransformedShape Shape::GetSubShapeTransformedShape ( const SubShapeID inSubShapeID,
Vec3Arg  inPositionCOM,
QuatArg  inRotation,
Vec3Arg  inScale,
SubShapeID outRemainder 
) const
virtual

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 of this shape
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 in CompoundShape, OffsetCenterOfMassShape, RotatedTranslatedShape, and ScaledShape.

◆ GetSubShapeUserData()

virtual uint64 Shape::GetSubShapeUserData ( const SubShapeID inSubShapeID) const
inlinevirtual

Get the user data of a particular sub shape ID.

Reimplemented in CompoundShape, and DecoratedShape.

◆ GetSubType()

EShapeSubType Shape::GetSubType ( ) const
inline

◆ GetSupportingFace()

virtual void Shape::GetSupportingFace ( const SubShapeID inSubShapeID,
Vec3Arg  inDirection,
Vec3Arg  inScale,
Mat44Arg  inCenterOfMassTransform,
SupportingFace outVertices 
) const
inlinevirtual

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 of this shape
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 in BoxShape, CapsuleShape, CompoundShape, ConvexHullShape, CylinderShape, DecoratedShape, HeightFieldShape, MeshShape, OffsetCenterOfMassShape, RotatedTranslatedShape, ScaledShape, SphereShape, TaperedCapsuleShape, TriangleShape, and SoftBodyShape.

◆ GetSurfaceNormal()

virtual Vec3 Shape::GetSurfaceNormal ( const SubShapeID inSubShapeID,
Vec3Arg  inLocalSurfacePosition 
) const
pure virtual

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).

Implemented in BoxShape, CapsuleShape, CompoundShape, ConvexHullShape, CylinderShape, HeightFieldShape, MeshShape, OffsetCenterOfMassShape, RotatedTranslatedShape, ScaledShape, SphereShape, TaperedCapsuleShape, TriangleShape, and SoftBodyShape.

◆ GetTrianglesNext()

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

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.

Implemented in BoxShape, CapsuleShape, CompoundShape, ConvexHullShape, ConvexShape, CylinderShape, HeightFieldShape, MeshShape, OffsetCenterOfMassShape, RotatedTranslatedShape, ScaledShape, SphereShape, TriangleShape, and SoftBodyShape.

◆ GetTrianglesStart()

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

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.

Implemented in BoxShape, CapsuleShape, CompoundShape, ConvexHullShape, ConvexShape, CylinderShape, HeightFieldShape, MeshShape, OffsetCenterOfMassShape, RotatedTranslatedShape, ScaledShape, SphereShape, TriangleShape, and SoftBodyShape.

◆ GetType()

EShapeType Shape::GetType ( ) const
inline

Get type.

◆ GetUserData()

uint64 Shape::GetUserData ( ) const
inline

User data (to be used freely by the application)

◆ GetVolume()

◆ GetWorldSpaceBounds() [1/2]

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

Get world space bounds including convex radius.

◆ GetWorldSpaceBounds() [2/2]

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 in CapsuleShape, CompoundShape, OffsetCenterOfMassShape, RotatedTranslatedShape, ScaledShape, SphereShape, TaperedCapsuleShape, TriangleShape, CapsuleShape, CompoundShape, OffsetCenterOfMassShape, RotatedTranslatedShape, ScaledShape, SphereShape, TaperedCapsuleShape, and TriangleShape.

◆ IsValidScale()

virtual bool Shape::IsValidScale ( Vec3Arg  inScale) const
inlinevirtual

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 in CapsuleShape, CompoundShape, CylinderShape, OffsetCenterOfMassShape, RotatedTranslatedShape, ScaledShape, SphereShape, TaperedCapsuleShape, and TriangleShape.

◆ MustBeStatic()

virtual bool Shape::MustBeStatic ( ) const
inlinevirtual

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

Reimplemented in CompoundShape, DecoratedShape, HeightFieldShape, MeshShape, and SoftBodyShape.

◆ RestoreBinaryState()

void Shape::RestoreBinaryState ( StreamIn inStream)
protectedvirtual

◆ RestoreMaterialState()

virtual void Shape::RestoreMaterialState ( const PhysicsMaterialRefC inMaterials,
uint  inNumMaterials 
)
inlinevirtual

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.

Reimplemented in ConvexShape, HeightFieldShape, and MeshShape.

◆ RestoreSubShapeState()

virtual void Shape::RestoreSubShapeState ( const ShapeRefC inSubShapes,
uint  inNumShapes 
)
inlinevirtual

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 in CompoundShape, and DecoratedShape.

◆ SaveBinaryState()

void Shape::SaveBinaryState ( StreamOut inStream) const
virtual

◆ SaveMaterialState()

virtual void Shape::SaveMaterialState ( PhysicsMaterialList outMaterials) const
inlinevirtual

Outputs the material references that this shape has to outMaterials.

◆ SaveSubShapeState()

virtual void Shape::SaveSubShapeState ( ShapeList outSubShapes) const
inlinevirtual

Outputs the shape references that this shape has to outSubShapes.

Reimplemented in CompoundShape, and DecoratedShape.

◆ SaveWithChildren()

void Shape::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.

◆ ScaleShape()

Shape::ShapeResult Shape::ScaleShape ( Vec3Arg  inScale) const

Scale this shape. Note that not all shapes support all scales, this will return a shape that matches the scale as accurately as possible. See Shape::IsValidScale for more information.

Parameters
inScaleThe scale to use for this shape (note: this scale is applied to the entire shape in the space it was created, most other functions apply the scale in the space of the leaf shapes and from the center of mass!)

◆ sCollidePointUsingRayCast()

void Shape::sCollidePointUsingRayCast ( const Shape inShape,
Vec3Arg  inPoint,
const SubShapeIDCreator inSubShapeIDCreator,
CollidePointCollector ioCollector,
const ShapeFilter inShapeFilter 
)
staticprotected

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.

◆ SetUserData()

void Shape::SetUserData ( uint64  inUserData)
inline

◆ sRestoreFromBinaryState()

Shape::ShapeResult Shape::sRestoreFromBinaryState ( StreamIn inStream)
static

Creates a Shape of the correct type and restores its contents from the binary stream inStream.

◆ sRestoreWithChildren()

Shape::ShapeResult Shape::sRestoreWithChildren ( StreamIn inStream,
IDToShapeMap ioShapeMap,
IDToMaterialMap ioMaterialMap 
)
static

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.

◆ TransformShape()

void Shape::TransformShape ( Mat44Arg  inCenterOfMassTransform,
TransformedShapeCollector ioCollector 
) const
virtual

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 in CapsuleShape, CompoundShape, CylinderShape, OffsetCenterOfMassShape, RotatedTranslatedShape, ScaledShape, SphereShape, TaperedCapsuleShape, and TriangleShape.

Member Data Documentation

◆ cGetTrianglesMinTrianglesRequested

constexpr int Shape::cGetTrianglesMinTrianglesRequested = 32
staticconstexpr

This is the minimum amount of triangles that should be requested through GetTrianglesNext.

◆ sDrawSubmergedVolumes

bool Shape::sDrawSubmergedVolumes = false
static

Debug helper which draws the intersection between water and the shapes, the center of buoyancy and the submerged volume.


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