Jolt Physics
A multi core friendly Game Physics Engine
|
Base class for shapes that decorate another shape with extra functionality (e.g. scale, translation etc.) More...
#include <DecoratedShape.h>
Public Member Functions | |
JPH_OVERRIDE_NEW_DELETE | DecoratedShape (EShapeSubType inSubType) |
Constructor. | |
DecoratedShape (EShapeSubType inSubType, const Shape *inInnerShape) | |
DecoratedShape (EShapeSubType inSubType, const DecoratedShapeSettings &inSettings, ShapeResult &outResult) | |
const Shape * | GetInnerShape () const |
Access to the decorated inner shape. | |
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. | |
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. | |
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. | |
virtual const Shape * | GetLeafShape (const SubShapeID &inSubShapeID, SubShapeID &outRemainder) const override |
virtual const PhysicsMaterial * | GetMaterial (const SubShapeID &inSubShapeID) const override |
Get the material assigned to a particular sub shape ID. | |
virtual void | GetSupportingFace (const SubShapeID &inSubShapeID, Vec3Arg inDirection, Vec3Arg inScale, Mat44Arg inCenterOfMassTransform, SupportingFace &outVertices) const override |
virtual uint64 | GetSubShapeUserData (const SubShapeID &inSubShapeID) const override |
Get the user data of a particular sub shape ID. Corresponds with the value stored in Shape::GetUserData of the leaf shape pointed to by inSubShapeID. | |
virtual void | SaveSubShapeState (ShapeList &outSubShapes) const override |
Outputs the shape references that this shape has to outSubShapes. | |
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. | |
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. | |
virtual bool | IsValidScale (Vec3Arg inScale) const override |
virtual Vec3 | MakeScaleValid (Vec3Arg inScale) const override |
Public Member Functions inherited from Shape | |
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 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 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 Vec3 | GetSurfaceNormal (const SubShapeID &inSubShapeID, Vec3Arg inLocalSurfacePosition) const =0 |
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, const CollideSoftBodyVertexIterator &inVertices, uint inNumVertices, 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 float | GetVolume () const =0 |
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. | |
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. | |
Public Member Functions inherited from RefTarget< Shape > | |
RefTarget ()=default | |
Constructor. | |
RefTarget (const RefTarget &) | |
~RefTarget () | |
assert no one is referencing us | |
void | SetEmbedded () const |
RefTarget & | operator= (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 |
Protected Attributes | |
RefConst< Shape > | mInnerShape |
Protected Attributes inherited from RefTarget< Shape > | |
atomic< uint32 > | mRefCount |
Current reference count. | |
Additional Inherited Members | |
Public Types inherited from Shape | |
using | ShapeResult = ShapeSettings::ShapeResult |
using | SupportingFace = StaticArray< Vec3, 32 > |
Type definition for a supporting face. | |
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 > |
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. | |
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. | |
Static Public Member Functions inherited from RefTarget< Shape > | |
static int | sInternalGetRefCountOffset () |
INTERNAL HELPER FUNCTION USED BY SERIALIZATION. | |
Static Public Attributes inherited from Shape | |
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 inherited from Shape | |
virtual void | RestoreBinaryState (StreamIn &inStream) |
This function should not be called directly, it is used by sRestoreFromBinaryState. | |
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. | |
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. | |
Base class for shapes that decorate another shape with extra functionality (e.g. scale, translation etc.)
|
inlineexplicit |
Constructor.
|
inline |
DecoratedShape::DecoratedShape | ( | EShapeSubType | inSubType, |
const DecoratedShapeSettings & | inSettings, | ||
ShapeResult & | outResult | ||
) |
|
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.
Reimplemented in OffsetCenterOfMassShape, RotatedTranslatedShape, and ScaledShape.
|
inline |
Access to the decorated inner shape.
|
inlineoverridevirtual |
Get the leaf shape for a particular sub shape ID.
inSubShapeID | The full sub shape ID that indicates the path to the leaf shape |
outRemainder | What remains of the sub shape ID after removing the path to the leaf shape (could e.g. refer to a triangle within a MeshShape) |
Reimplemented from Shape.
|
overridevirtual |
Get the material assigned to a particular sub shape ID.
Implements Shape.
|
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.
ioVisitedShapes | is used to track which shapes have already been visited, to avoid calculating the wrong memory size. |
Reimplemented from Shape.
|
inlineoverridevirtual |
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.
|
overridevirtual |
Get the user data of a particular sub shape ID. Corresponds with the value stored in Shape::GetUserData of the leaf shape pointed to by inSubShapeID.
Reimplemented from Shape.
|
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.
inSubShapeID | Sub shape ID of target shape |
inDirection | Direction that the face should be facing (in local space to this shape) |
inCenterOfMassTransform | Transform to transform outVertices with |
inScale | Scale in local space of the shape (scales relative to its center of mass) |
outVertices | Resulting 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.
Reimplemented in OffsetCenterOfMassShape, RotatedTranslatedShape, and ScaledShape.
|
inlineoverridevirtual |
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:
Reimplemented from Shape.
Reimplemented in RotatedTranslatedShape, and ScaledShape.
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.
inScale | Local space scale for this shape. |
Reimplemented from Shape.
Reimplemented in RotatedTranslatedShape, and ScaledShape.
|
inlineoverridevirtual |
Check if this shape can only be used to create a static body or if it can also be dynamic/kinematic.
Reimplemented from Shape.
|
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.
|
overridevirtual |
Outputs the shape references that this shape has to outSubShapes.
Reimplemented from Shape.