Jolt Physics
A multi core friendly Game Physics Engine
Loading...
Searching...
No Matches
HeightFieldShape Class Referencefinal

#include <HeightFieldShape.h>

Inheritance diagram for HeightFieldShape:
Shape RefTarget< Shape > NonCopyable

Classes

class  DecodingContext
 
struct  HSGetTrianglesContext
 

Public Member Functions

JPH_OVERRIDE_NEW_DELETE HeightFieldShape ()
 Constructor.
 
 HeightFieldShape (const HeightFieldShapeSettings &inSettings, ShapeResult &outResult)
 
virtual ~HeightFieldShape () override
 
Ref< HeightFieldShapeClone () const
 Clone this shape. Can be used to avoid race conditions. See the documentation of this class for more information.
 
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.
 
uint GetSampleCount () const
 Get the size of the height field. Note that this will always be rounded up to the nearest multiple of GetBlockSize().
 
uint GetBlockSize () const
 Get the size of a block.
 
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.
 
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 float GetInnerRadius () const override
 
virtual MassProperties GetMassProperties () const override
 Calculate the mass and inertia of this shape.
 
virtual const PhysicsMaterialGetMaterial (const SubShapeID &inSubShapeID) const override
 Get the material assigned to a particular sub shape ID.
 
const PhysicsMaterialGetMaterial (uint inX, uint inY) const
 Overload to get the material at a particular location.
 
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)
 
virtual bool CastRay (const RayCast &inRay, const SubShapeIDCreator &inSubShapeIDCreator, RayCastResult &ioHit) const override
 
virtual void CastRay (const RayCast &inRay, const RayCastSettings &inRayCastSettings, const SubShapeIDCreator &inSubShapeIDCreator, CastRayCollector &ioCollector, const ShapeFilter &inShapeFilter={ }) const override
 
virtual void CollidePoint (Vec3Arg inPoint, const SubShapeIDCreator &inSubShapeIDCreator, CollidePointCollector &ioCollector, const ShapeFilter &inShapeFilter={ }) const override
 
virtual void CollideSoftBodyVertices (Mat44Arg inCenterOfMassTransform, Vec3Arg inScale, const CollideSoftBodyVertexIterator &inVertices, uint inNumVertices, int inCollidingShapeIndex) 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
 
Vec3 GetPosition (uint inX, uint inY) const
 
bool IsNoCollision (uint inX, uint inY) const
 Check if height field at sampled location (inX, inY) has collision (has a hole or not)
 
bool ProjectOntoSurface (Vec3Arg inLocalPosition, Vec3 &outSurfacePosition, SubShapeID &outSubShapeID) const
 
void GetSubShapeCoordinates (const SubShapeID &inSubShapeID, uint &outX, uint &outY, uint &outTriangleIndex) const
 
float GetMinHeightValue () const
 Get the range of height values that this height field can encode. Can be used to determine the allowed range when setting the height values with SetHeights.
 
float GetMaxHeightValue () const
 
void GetHeights (uint inX, uint inY, uint inSizeX, uint inSizeY, float *outHeights, intptr_t inHeightsStride) const
 
void SetHeights (uint inX, uint inY, uint inSizeX, uint inSizeY, const float *inHeights, intptr_t inHeightsStride, TempAllocator &inAllocator, float inActiveEdgeCosThresholdAngle=0.996195f)
 
const PhysicsMaterialListGetMaterialList () const
 Get the current list of materials, the indices returned by GetMaterials() will index into this list.
 
void GetMaterials (uint inX, uint inY, uint inSizeX, uint inSizeY, uint8 *outMaterials, intptr_t inMaterialsStride) const
 
bool SetMaterials (uint inX, uint inY, uint inSizeX, uint inSizeY, const uint8 *inMaterials, intptr_t inMaterialsStride, const PhysicsMaterialList *inMaterialList, TempAllocator &inAllocator)
 
virtual void SaveBinaryState (StreamOut &inStream) const override
 Saves the contents of the shape in binary form to inStream.
 
virtual void SaveMaterialState (PhysicsMaterialList &outMaterials) const override
 
virtual void RestoreMaterialState (const PhysicsMaterialRefC *inMaterials, uint inNumMaterials) override
 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 Stats GetStats () const override
 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 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 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 GetWorldSpaceBounds (Mat44Arg inCenterOfMassTransform, Vec3Arg inScale) const
 
AABox GetWorldSpaceBounds (DMat44Arg inCenterOfMassTransform, Vec3Arg inScale) const
 Get world space bounds including convex radius.
 
virtual const ShapeGetLeafShape (const SubShapeID &inSubShapeID, SubShapeID &outRemainder) const
 
virtual uint64 GetSubShapeUserData (const SubShapeID &inSubShapeID) const
 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 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 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 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 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 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.
 
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.
 
- 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 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.
 
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

static bool sDrawTriangleOutlines = false
 
- 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

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

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

A height field shape. Cannot be used as a dynamic object.

Note: If you're using HeightFieldShape and are querying data while modifying the shape you'll have a race condition. In this case it is best to create a new HeightFieldShape using the Clone function. You replace the shape on a body using BodyInterface::SetShape. If a query is still working on the old shape, it will have taken a reference and keep the old shape alive until the query finishes.

Constructor & Destructor Documentation

◆ HeightFieldShape() [1/2]

JPH_OVERRIDE_NEW_DELETE HeightFieldShape::HeightFieldShape ( )
inline

Constructor.

◆ HeightFieldShape() [2/2]

HeightFieldShape::HeightFieldShape ( const HeightFieldShapeSettings inSettings,
ShapeResult outResult 
)

◆ ~HeightFieldShape()

HeightFieldShape::~HeightFieldShape ( )
overridevirtual

Member Function Documentation

◆ CastRay() [1/2]

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

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

Implements Shape.

◆ CastRay() [2/2]

bool HeightFieldShape::CastRay ( const RayCast inRay,
const SubShapeIDCreator inSubShapeIDCreator,
RayCastResult ioHit 
) const
overridevirtual

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

Implements Shape.

◆ Clone()

Ref< HeightFieldShape > HeightFieldShape::Clone ( ) const

Clone this shape. Can be used to avoid race conditions. See the documentation of this class for more information.

◆ CollidePoint()

void HeightFieldShape::CollidePoint ( Vec3Arg  inPoint,
const SubShapeIDCreator inSubShapeIDCreator,
CollidePointCollector ioCollector,
const ShapeFilter inShapeFilter = { } 
) const
overridevirtual

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.

Implements Shape.

◆ CollideSoftBodyVertices()

void HeightFieldShape::CollideSoftBodyVertices ( Mat44Arg  inCenterOfMassTransform,
Vec3Arg  inScale,
const CollideSoftBodyVertexIterator inVertices,
uint  inNumVertices,
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)
inVerticesThe vertices of the soft body
inNumVerticesThe number of vertices in inVertices
inCollidingShapeIndexValue to store in CollideSoftBodyVertexIterator::mCollidingShapeIndex when a collision was found

Implements Shape.

◆ Draw()

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

◆ GetBlockSize()

uint HeightFieldShape::GetBlockSize ( ) const
inline

Get the size of a block.

◆ GetHeights()

void HeightFieldShape::GetHeights ( uint  inX,
uint  inY,
uint  inSizeX,
uint  inSizeY,
float *  outHeights,
intptr_t  inHeightsStride 
) const

Get the height values of a block of data. Note that the height values are decompressed so will be slightly different from what the shape was originally created with.

Parameters
inXStart X position, must be a multiple of mBlockSize and in the range [0, mSampleCount - 1]
inYStart Y position, must be a multiple of mBlockSize and in the range [0, mSampleCount - 1]
inSizeXNumber of samples in X direction, must be a multiple of mBlockSize and in the range [0, mSampleCount - inX]
inSizeYNumber of samples in Y direction, must be a multiple of mBlockSize and in the range [0, mSampleCount - inY]
outHeightsReturned height values, must be at least inSizeX * inSizeY floats. Values are returned in x-major order and can be cNoCollisionValue.
inHeightsStrideStride in floats between two consecutive rows of outHeights (can be negative if the data is upside down).

◆ GetInnerRadius()

virtual float HeightFieldShape::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.

◆ GetLocalBounds()

AABox HeightFieldShape::GetLocalBounds ( ) const
overridevirtual

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 HeightFieldShape::GetMassProperties ( ) const
overridevirtual

Calculate the mass and inertia of this shape.

Implements Shape.

◆ GetMaterial() [1/2]

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

Get the material assigned to a particular sub shape ID.

Implements Shape.

◆ GetMaterial() [2/2]

const PhysicsMaterial * HeightFieldShape::GetMaterial ( uint  inX,
uint  inY 
) const

Overload to get the material at a particular location.

◆ GetMaterialList()

const PhysicsMaterialList & HeightFieldShape::GetMaterialList ( ) const
inline

Get the current list of materials, the indices returned by GetMaterials() will index into this list.

◆ GetMaterials()

void HeightFieldShape::GetMaterials ( uint  inX,
uint  inY,
uint  inSizeX,
uint  inSizeY,
uint8 outMaterials,
intptr_t  inMaterialsStride 
) const

Get the material indices of a block of data.

Parameters
inXStart X position, must in the range [0, mSampleCount - 1]
inYStart Y position, must in the range [0, mSampleCount - 1]
inSizeXNumber of samples in X direction
inSizeYNumber of samples in Y direction
outMaterialsReturned material indices, must be at least inSizeX * inSizeY uint8s. Values are returned in x-major order.
inMaterialsStrideStride in uint8s between two consecutive rows of outMaterials (can be negative if the data is upside down).

◆ GetMaxHeightValue()

float HeightFieldShape::GetMaxHeightValue ( ) const
inline

◆ GetMinHeightValue()

float HeightFieldShape::GetMinHeightValue ( ) const
inline

Get the range of height values that this height field can encode. Can be used to determine the allowed range when setting the height values with SetHeights.

◆ GetPosition()

Vec3 HeightFieldShape::GetPosition ( uint  inX,
uint  inY 
) const

Get height field position at sampled location (inX, inY). where inX and inY are integers in the range inX e [0, mSampleCount - 1] and inY e [0, mSampleCount - 1].

◆ GetSampleCount()

uint HeightFieldShape::GetSampleCount ( ) const
inline

Get the size of the height field. Note that this will always be rounded up to the nearest multiple of GetBlockSize().

◆ GetStats()

Shape::Stats HeightFieldShape::GetStats ( ) const
overridevirtual

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

Implements Shape.

◆ GetSubmergedVolume()

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

◆ GetSubShapeCoordinates()

void HeightFieldShape::GetSubShapeCoordinates ( const SubShapeID inSubShapeID,
uint outX,
uint outY,
uint outTriangleIndex 
) const

Returns the coordinates of the triangle that a sub shape ID represents

Parameters
inSubShapeIDThe sub shape ID to decode
outXX coordinate of the triangle (in the range [0, mSampleCount - 2])
outYY coordinate of the triangle (in the range [0, mSampleCount - 2])
outTriangleIndexTriangle within the quad (0 = lower triangle or 1 = upper triangle)

◆ GetSubShapeIDBitsRecursive()

virtual uint HeightFieldShape::GetSubShapeIDBitsRecursive ( ) const
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.

◆ GetSupportingFace()

void HeightFieldShape::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 HeightFieldShape::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()

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

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

void HeightFieldShape::GetTrianglesStart ( GetTrianglesContext ioContext,
const AABox inBox,
Vec3Arg  inPositionCOM,
QuatArg  inRotation,
Vec3Arg  inScale 
) const
overridevirtual

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

virtual float HeightFieldShape::GetVolume ( ) const
inlineoverridevirtual

Implements Shape.

◆ IsNoCollision()

bool HeightFieldShape::IsNoCollision ( uint  inX,
uint  inY 
) const

Check if height field at sampled location (inX, inY) has collision (has a hole or not)

◆ MustBeStatic()

virtual bool HeightFieldShape::MustBeStatic ( ) const
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.

◆ ProjectOntoSurface()

bool HeightFieldShape::ProjectOntoSurface ( Vec3Arg  inLocalPosition,
Vec3 outSurfacePosition,
SubShapeID outSubShapeID 
) const

Projects inLocalPosition (a point in the space of the shape) along the Y axis onto the surface and returns it in outSurfacePosition. When there is no surface position (because of a hole or because the point is outside the heightfield) the function will return false.

◆ RestoreBinaryState()

void HeightFieldShape::RestoreBinaryState ( StreamIn inStream)
overrideprotectedvirtual

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

Reimplemented from Shape.

◆ RestoreMaterialState()

void HeightFieldShape::RestoreMaterialState ( const PhysicsMaterialRefC inMaterials,
uint  inNumMaterials 
)
overridevirtual

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 from Shape.

◆ SaveBinaryState()

void HeightFieldShape::SaveBinaryState ( StreamOut inStream) const
overridevirtual

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

Reimplemented from Shape.

◆ SaveMaterialState()

void HeightFieldShape::SaveMaterialState ( PhysicsMaterialList outMaterials) const
overridevirtual

◆ SetHeights()

void HeightFieldShape::SetHeights ( uint  inX,
uint  inY,
uint  inSizeX,
uint  inSizeY,
const float *  inHeights,
intptr_t  inHeightsStride,
TempAllocator inAllocator,
float  inActiveEdgeCosThresholdAngle = 0.996195f 
)

Set the height values of a block of data. Note that this requires decompressing and recompressing a border of size mBlockSize in the negative x/y direction so will cause some precision loss. Beware this can create a race condition if you're running collision queries in parallel. See class documentation for more information.

Parameters
inXStart X position, must be a multiple of mBlockSize and in the range [0, mSampleCount - 1]
inYStart Y position, must be a multiple of mBlockSize and in the range [0, mSampleCount - 1]
inSizeXNumber of samples in X direction, must be a multiple of mBlockSize and in the range [0, mSampleCount - inX]
inSizeYNumber of samples in Y direction, must be a multiple of mBlockSize and in the range [0, mSampleCount - inY]
inHeightsThe new height values to set, must be an array of inSizeX * inSizeY floats, can be cNoCollisionValue. Values outside of the range [GetMinHeightValue(), GetMaxHeightValue()] will be clamped.
inHeightsStrideStride in floats between two consecutive rows of inHeights (can be negative if the data is upside down).
inAllocatorAllocator to use for temporary memory
inActiveEdgeCosThresholdAngleCosine of the threshold angle (if the angle between the two triangles is bigger than this, the edge is active, note that a concave edge is always inactive).

◆ SetMaterials()

bool HeightFieldShape::SetMaterials ( uint  inX,
uint  inY,
uint  inSizeX,
uint  inSizeY,
const uint8 inMaterials,
intptr_t  inMaterialsStride,
const PhysicsMaterialList inMaterialList,
TempAllocator inAllocator 
)

Set the material indices of a block of data. Beware this can create a race condition if you're running collision queries in parallel. See class documentation for more information.

Parameters
inXStart X position, must in the range [0, mSampleCount - 1]
inYStart Y position, must in the range [0, mSampleCount - 1]
inSizeXNumber of samples in X direction
inSizeYNumber of samples in Y direction
inMaterialsThe new material indices, must be at least inSizeX * inSizeY uint8s. Values are returned in x-major order.
inMaterialsStrideStride in uint8s between two consecutive rows of inMaterials (can be negative if the data is upside down).
inMaterialListThe material list to use for the new material indices or nullptr if the material list should not be updated
inAllocatorAllocator to use for temporary memory
Returns
True if the material indices were set, false if the total number of materials exceeded 256

◆ sRegister()

void HeightFieldShape::sRegister ( )
static

Member Data Documentation

◆ sDrawTriangleOutlines

JPH_NAMESPACE_BEGIN bool HeightFieldShape::sDrawTriangleOutlines = false
static

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