Jolt Physics
A multi core friendly Game Physics Engine
Loading...
Searching...
No Matches
TransformedShape Class Reference

#include <TransformedShape.h>

Public Types

using GetTrianglesContext = Shape::GetTrianglesContext
 Use the context from Shape.
 

Public Member Functions

JPH_OVERRIDE_NEW_DELETE TransformedShape ()=default
 Constructor.
 
 TransformedShape (RVec3Arg inPositionCOM, QuatArg inRotation, const Shape *inShape, const BodyID &inBodyID, const SubShapeIDCreator &inSubShapeIDCreator=SubShapeIDCreator())
 
bool CastRay (const RRayCast &inRay, RayCastResult &ioHit) const
 
void CastRay (const RRayCast &inRay, const RayCastSettings &inRayCastSettings, CastRayCollector &ioCollector, const ShapeFilter &inShapeFilter={ }) const
 
void CollidePoint (RVec3Arg inPoint, CollidePointCollector &ioCollector, const ShapeFilter &inShapeFilter={ }) const
 
void CollideShape (const Shape *inShape, Vec3Arg inShapeScale, RMat44Arg inCenterOfMassTransform, const CollideShapeSettings &inCollideShapeSettings, RVec3Arg inBaseOffset, CollideShapeCollector &ioCollector, const ShapeFilter &inShapeFilter={ }) const
 
void CastShape (const RShapeCast &inShapeCast, const ShapeCastSettings &inShapeCastSettings, RVec3Arg inBaseOffset, CastShapeCollector &ioCollector, const ShapeFilter &inShapeFilter={ }) const
 
void CollectTransformedShapes (const AABox &inBox, TransformedShapeCollector &ioCollector, const ShapeFilter &inShapeFilter={ }) const
 
void GetTrianglesStart (GetTrianglesContext &ioContext, const AABox &inBox, RVec3Arg inBaseOffset) const
 
int GetTrianglesNext (GetTrianglesContext &ioContext, int inMaxTrianglesRequested, Float3 *outTriangleVertices, const PhysicsMaterial **outMaterials=nullptr) const
 
Vec3 GetShapeScale () const
 Get/set the scale of the shape as a Vec3.
 
void SetShapeScale (Vec3Arg inScale)
 
RMat44 GetCenterOfMassTransform () const
 Calculates the transform for this shapes's center of mass (excluding scale)
 
RMat44 GetInverseCenterOfMassTransform () const
 Calculates the inverse of the transform for this shape's center of mass (excluding scale)
 
void SetWorldTransform (RVec3Arg inPosition, QuatArg inRotation, Vec3Arg inScale)
 Sets the world transform (including scale) of this transformed shape (not from the center of mass but in the space the shape was created)
 
void SetWorldTransform (RMat44Arg inTransform)
 Sets the world transform (including scale) of this transformed shape (not from the center of mass but in the space the shape was created)
 
RMat44 GetWorldTransform () const
 Calculates the world transform including scale of this shape (not from the center of mass but in the space the shape was created)
 
AABox GetWorldSpaceBounds () const
 Get the world space bounding box for this transformed shape.
 
SubShapeID MakeSubShapeIDRelativeToShape (const SubShapeID &inSubShapeID) const
 Make inSubShapeID relative to mShape. When mSubShapeIDCreator is not empty, this is needed in order to get the correct path to the sub shape.
 
Vec3 GetWorldSpaceSurfaceNormal (const SubShapeID &inSubShapeID, RVec3Arg inPosition) const
 
void GetSupportingFace (const SubShapeID &inSubShapeID, Vec3Arg inDirection, RVec3Arg inBaseOffset, Shape::SupportingFace &outVertices) const
 
const PhysicsMaterialGetMaterial (const SubShapeID &inSubShapeID) const
 Get material of a particular sub shape.
 
uint64 GetSubShapeUserData (const SubShapeID &inSubShapeID) const
 Get the user data of a particular sub shape.
 
TransformedShape GetSubShapeTransformedShape (const SubShapeID &inSubShapeID, SubShapeID &outRemainder) const
 

Static Public Member Functions

static BodyID sGetBodyID (const TransformedShape *inTS)
 Helper function to return the body id from a transformed shape. If the transformed shape is null an invalid body ID will be returned.
 

Public Attributes

RVec3 mShapePositionCOM
 Center of mass world position of the shape.
 
Quat mShapeRotation
 Rotation of the shape.
 
RefConst< ShapemShape
 The shape itself.
 
Float3 mShapeScale { 1, 1, 1 }
 Not stored as Vec3 to get a nicely packed structure.
 
BodyID mBodyID
 Optional body ID from which this shape comes.
 
SubShapeIDCreator mSubShapeIDCreator
 Optional sub shape ID creator for the shape (can be used when expanding compound shapes into multiple transformed shapes)
 

Detailed Description

Temporary data structure that contains a shape and a transform. This structure can be obtained from a body (e.g. after a broad phase query) under lock protection. The lock can then be released and collision detection operations can be safely performed since the class takes a reference on the shape and does not use anything from the body anymore.

Member Typedef Documentation

◆ GetTrianglesContext

Constructor & Destructor Documentation

◆ TransformedShape() [1/2]

JPH_OVERRIDE_NEW_DELETE TransformedShape::TransformedShape ( )
default

Constructor.

◆ TransformedShape() [2/2]

TransformedShape::TransformedShape ( RVec3Arg  inPositionCOM,
QuatArg  inRotation,
const Shape inShape,
const BodyID inBodyID,
const SubShapeIDCreator inSubShapeIDCreator = SubShapeIDCreator() 
)
inline

Member Function Documentation

◆ CastRay() [1/2]

void TransformedShape::CastRay ( const RRayCast inRay,
const RayCastSettings inRayCastSettings,
CastRayCollector ioCollector,
const ShapeFilter inShapeFilter = { } 
) const

Cast a ray, allows collecting multiple hits. 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 GetWorldSpaceSurfaceNormal(collected sub shape ID, inRay.GetPointOnRay(collected fraction)) on this object.

◆ CastRay() [2/2]

JPH_NAMESPACE_BEGIN bool TransformedShape::CastRay ( const RRayCast inRay,
RayCastResult ioHit 
) const

Cast a ray and find the closest hit. Returns true if it finds a hit. Hits further than ioHit.mFraction will not be considered and in this case ioHit will remain unmodified (and the function will return false). 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 are returned. If you want the surface normal of the hit use GetWorldSpaceSurfaceNormal(ioHit.mSubShapeID2, inRay.GetPointOnRay(ioHit.mFraction)) on this object.

◆ CastShape()

void TransformedShape::CastShape ( const RShapeCast inShapeCast,
const ShapeCastSettings inShapeCastSettings,
RVec3Arg  inBaseOffset,
CastShapeCollector ioCollector,
const ShapeFilter inShapeFilter = { } 
) const

Cast a shape and report any hits to ioCollector

Parameters
inShapeCastThe shape cast and its position and direction
inShapeCastSettingsSettings for the shape cast
inBaseOffsetAll hit results will be returned relative to this offset, can be zero to get results in world position, but when you're testing far from the origin you get better precision by picking a position that's closer e.g. mShapePositionCOM or inShapeCast.mCenterOfMassStart.GetTranslation() since floats are most accurate near the origin
ioCollectorCollector that receives the hits
inShapeFilterFilter that allows you to reject collisions

◆ CollectTransformedShapes()

void TransformedShape::CollectTransformedShapes ( const AABox inBox,
TransformedShapeCollector ioCollector,
const ShapeFilter inShapeFilter = { } 
) const

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

◆ CollidePoint()

void TransformedShape::CollidePoint ( RVec3Arg  inPoint,
CollidePointCollector ioCollector,
const ShapeFilter inShapeFilter = { } 
) const

Check if inPoint is inside any shapes. For this tests all shapes are treated as if they were solid. 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

◆ CollideShape()

void TransformedShape::CollideShape ( const Shape inShape,
Vec3Arg  inShapeScale,
RMat44Arg  inCenterOfMassTransform,
const CollideShapeSettings inCollideShapeSettings,
RVec3Arg  inBaseOffset,
CollideShapeCollector ioCollector,
const ShapeFilter inShapeFilter = { } 
) const

Collide a shape and report any hits to ioCollector

Parameters
inShapeShape to test
inShapeScaleScale in local space of shape
inCenterOfMassTransformCenter of mass transform for the shape
inCollideShapeSettingsSettings
inBaseOffsetAll hit results will be returned relative to this offset, can be zero to get results in world position, but when you're testing far from the origin you get better precision by picking a position that's closer e.g. mShapePositionCOM since floats are most accurate near the origin
ioCollectorCollector that receives the hits
inShapeFilterFilter that allows you to reject collisions

◆ GetCenterOfMassTransform()

RMat44 TransformedShape::GetCenterOfMassTransform ( ) const
inline

Calculates the transform for this shapes's center of mass (excluding scale)

◆ GetInverseCenterOfMassTransform()

RMat44 TransformedShape::GetInverseCenterOfMassTransform ( ) const
inline

Calculates the inverse of the transform for this shape's center of mass (excluding scale)

◆ GetMaterial()

const PhysicsMaterial * TransformedShape::GetMaterial ( const SubShapeID inSubShapeID) const
inline

Get material of a particular sub shape.

◆ GetShapeScale()

Vec3 TransformedShape::GetShapeScale ( ) const
inline

Get/set the scale of the shape as a Vec3.

◆ GetSubShapeTransformedShape()

TransformedShape TransformedShape::GetSubShapeTransformedShape ( const SubShapeID inSubShapeID,
SubShapeID outRemainder 
) const
inline

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

◆ GetSubShapeUserData()

uint64 TransformedShape::GetSubShapeUserData ( const SubShapeID inSubShapeID) const
inline

Get the user data of a particular sub shape.

◆ GetSupportingFace()

void TransformedShape::GetSupportingFace ( const SubShapeID inSubShapeID,
Vec3Arg  inDirection,
RVec3Arg  inBaseOffset,
Shape::SupportingFace outVertices 
) const
inline

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 world space)
inBaseOffsetThe vertices will be returned relative to this offset, can be zero to get results in world position, but when you're testing far from the origin you get better precision by picking a position that's closer e.g. mShapePositionCOM since floats are most accurate near the origin
outVerticesResulting face. Note the returned face can have a single point if the shape doesn't have polygons to return (e.g. because it's a sphere). The face will be returned in world space.

◆ GetTrianglesNext()

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

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

◆ GetTrianglesStart()

void TransformedShape::GetTrianglesStart ( GetTrianglesContext ioContext,
const AABox inBox,
RVec3Arg  inBaseOffset 
) const

To start iterating over triangles, call this function first. To get the actual triangles call GetTrianglesNext.

Parameters
ioContextA temporary buffer and should remain untouched until the last call to GetTrianglesNext.
inBoxThe world space bounding in which you want to get the triangles.
inBaseOffsetAll hit results will be returned relative to this offset, can be zero to get results in world position, but when you're testing far from the origin you get better precision by picking a position that's closer e.g. inBox.GetCenter() since floats are most accurate near the origin

◆ GetWorldSpaceBounds()

AABox TransformedShape::GetWorldSpaceBounds ( ) const
inline

Get the world space bounding box for this transformed shape.

◆ GetWorldSpaceSurfaceNormal()

Vec3 TransformedShape::GetWorldSpaceSurfaceNormal ( const SubShapeID inSubShapeID,
RVec3Arg  inPosition 
) const
inline

Get surface normal of a particular sub shape and its world space surface position on this body. Note: When you have a CollideShapeResult or ShapeCastResult you should use -mPenetrationAxis.Normalized() as contact normal as GetWorldSpaceSurfaceNormal will only return face normals (and not vertex or edge normals).

◆ GetWorldTransform()

RMat44 TransformedShape::GetWorldTransform ( ) const
inline

Calculates the world transform including scale of this shape (not from the center of mass but in the space the shape was created)

◆ MakeSubShapeIDRelativeToShape()

SubShapeID TransformedShape::MakeSubShapeIDRelativeToShape ( const SubShapeID inSubShapeID) const
inline

Make inSubShapeID relative to mShape. When mSubShapeIDCreator is not empty, this is needed in order to get the correct path to the sub shape.

◆ SetShapeScale()

void TransformedShape::SetShapeScale ( Vec3Arg  inScale)
inline

◆ SetWorldTransform() [1/2]

void TransformedShape::SetWorldTransform ( RMat44Arg  inTransform)
inline

Sets the world transform (including scale) of this transformed shape (not from the center of mass but in the space the shape was created)

◆ SetWorldTransform() [2/2]

void TransformedShape::SetWorldTransform ( RVec3Arg  inPosition,
QuatArg  inRotation,
Vec3Arg  inScale 
)
inline

Sets the world transform (including scale) of this transformed shape (not from the center of mass but in the space the shape was created)

◆ sGetBodyID()

static BodyID TransformedShape::sGetBodyID ( const TransformedShape inTS)
inlinestatic

Helper function to return the body id from a transformed shape. If the transformed shape is null an invalid body ID will be returned.

Member Data Documentation

◆ mBodyID

BodyID TransformedShape::mBodyID

Optional body ID from which this shape comes.

◆ mShape

RefConst<Shape> TransformedShape::mShape

The shape itself.

◆ mShapePositionCOM

RVec3 TransformedShape::mShapePositionCOM

Center of mass world position of the shape.

◆ mShapeRotation

Quat TransformedShape::mShapeRotation

Rotation of the shape.

◆ mShapeScale

Float3 TransformedShape::mShapeScale { 1, 1, 1 }

Not stored as Vec3 to get a nicely packed structure.

◆ mSubShapeIDCreator

SubShapeIDCreator TransformedShape::mSubShapeIDCreator

Optional sub shape ID creator for the shape (can be used when expanding compound shapes into multiple transformed shapes)


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