| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
#pragma once |
| 6 |
|
| 7 |
#include <Jolt/Core/StaticArray.h> |
| 8 |
#include <Jolt/Physics/Collision/Shape/Shape.h> |
| 9 |
#include <Jolt/Physics/Collision/Shape/SubShapeID.h> |
| 10 |
#include <Jolt/Physics/Collision/PhysicsMaterial.h> |
| 11 |
|
| 12 |
JPH_NAMESPACE_BEGIN |
| 13 |
|
| 14 |
class CollideShapeSettings; |
| 15 |
|
| 16 |
|
| 17 |
class JPH_EXPORT ConvexShapeSettings : public ShapeSettings |
| 18 |
{ |
| 19 |
JPH_DECLARE_SERIALIZABLE_ABSTRACT(JPH_EXPORT, ConvexShapeSettings) |
| 20 |
|
| 21 |
public: |
| 22 |
|
| 23 |
ConvexShapeSettings() = default; |
| 24 |
explicit ConvexShapeSettings(const PhysicsMaterial *inMaterial) : mMaterial(inMaterial) { } |
| 25 |
|
| 26 |
|
| 27 |
void SetDensity(float inDensity) { mDensity = inDensity; } |
| 28 |
|
| 29 |
|
| 30 |
RefConst<PhysicsMaterial> mMaterial; |
| 31 |
float mDensity = 1000.0f; |
| 32 |
}; |
| 33 |
|
| 34 |
|
| 35 |
class JPH_EXPORT ConvexShape : public Shape |
| 36 |
{ |
| 37 |
public: |
| 38 |
JPH_OVERRIDE_NEW_DELETE |
| 39 |
|
| 40 |
|
| 41 |
explicit ConvexShape(EShapeSubType inSubType) : Shape(EShapeType::Convex, inSubType) { } |
| 42 |
ConvexShape(EShapeSubType inSubType, const ConvexShapeSettings &inSettings, ShapeResult &outResult) : Shape(EShapeType::Convex, inSubType, inSettings, outResult), mMaterial(inSettings.mMaterial), mDensity(inSettings.mDensity) { } |
| 43 |
ConvexShape(EShapeSubType inSubType, const PhysicsMaterial *inMaterial) : Shape(EShapeType::Convex, inSubType), mMaterial(inMaterial) { } |
| 44 |
|
| 45 |
|
| 46 |
virtual uint GetSubShapeIDBitsRecursive() const override { return 0; } |
| 47 |
|
| 48 |
|
| 49 |
virtual const PhysicsMaterial * GetMaterial([[maybe_unused]] const SubShapeID &inSubShapeID) const override { JPH_ASSERT(inSubShapeID.IsEmpty(), "Invalid subshape ID"); return GetMaterial(); } |
| 50 |
|
| 51 |
|
| 52 |
virtual bool CastRay(const RayCast &inRay, const SubShapeIDCreator &inSubShapeIDCreator, RayCastResult &ioHit) const override; |
| 53 |
virtual void CastRay(const RayCast &inRay, const RayCastSettings &inRayCastSettings, const SubShapeIDCreator &inSubShapeIDCreator, CastRayCollector &ioCollector, const ShapeFilter &inShapeFilter = { }) const override; |
| 54 |
|
| 55 |
|
| 56 |
virtual void CollidePoint(Vec3Arg inPoint, const SubShapeIDCreator &inSubShapeIDCreator, CollidePointCollector &ioCollector, const ShapeFilter &inShapeFilter = { }) const override; |
| 57 |
|
| 58 |
|
| 59 |
virtual void GetTrianglesStart(GetTrianglesContext &ioContext, const AABox &inBox, Vec3Arg inPositionCOM, QuatArg inRotation, Vec3Arg inScale) const override; |
| 60 |
|
| 61 |
|
| 62 |
virtual int GetTrianglesNext(GetTrianglesContext &ioContext, int inMaxTrianglesRequested, Float3 *outTriangleVertices, const PhysicsMaterial **outMaterials = nullptr) const override; |
| 63 |
|
| 64 |
|
| 65 |
virtual void GetSubmergedVolume(Mat44Arg inCenterOfMassTransform, Vec3Arg inScale, const Plane &inSurface, float &outTotalVolume, float &outSubmergedVolume, Vec3 &outCenterOfBuoyancy JPH_IF_DEBUG_RENDERER(, RVec3Arg inBaseOffset)) const override; |
| 66 |
|
| 67 |
|
| 68 |
class Support |
| 69 |
{ |
| 70 |
public: |
| 71 |
|
| 72 |
virtual ~Support() = default; |
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
virtual Vec3 GetSupport(Vec3Arg inDirection) const = 0; |
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
virtual float GetConvexRadius() const = 0; |
| 81 |
}; |
| 82 |
|
| 83 |
|
| 84 |
class alignas(16) SupportBuffer |
| 85 |
{ |
| 86 |
public: |
| 87 |
uint8 mData[4160]; |
| 88 |
}; |
| 89 |
|
| 90 |
|
| 91 |
enum class ESupportMode |
| 92 |
{ |
| 93 |
ExcludeConvexRadius, |
| 94 |
IncludeConvexRadius, |
| 95 |
Default, |
| 96 |
}; |
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
virtual const Support * GetSupportFunction(ESupportMode inMode, SupportBuffer &inBuffer, Vec3Arg inScale) const = 0; |
| 103 |
|
| 104 |
|
| 105 |
void SetMaterial(const PhysicsMaterial *inMaterial) { mMaterial = inMaterial; } |
| 106 |
const PhysicsMaterial * GetMaterial() const { return mMaterial != nullptr? mMaterial : PhysicsMaterial::sDefault; } |
| 107 |
|
| 108 |
|
| 109 |
void SetDensity(float inDensity) { mDensity = inDensity; } |
| 110 |
|
| 111 |
|
| 112 |
float GetDensity() const { return mDensity; } |
| 113 |
|
| 114 |
#ifdef JPH_DEBUG_RENDERER |
| 115 |
|
| 116 |
virtual void DrawGetSupportFunction(DebugRenderer *inRenderer, RMat44Arg inCenterOfMassTransform, Vec3Arg inScale, ColorArg inColor, bool inDrawSupportDirection) const override; |
| 117 |
|
| 118 |
|
| 119 |
virtual void DrawGetSupportingFace(DebugRenderer *inRenderer, RMat44Arg inCenterOfMassTransform, Vec3Arg inScale) const override; |
| 120 |
#endif |
| 121 |
|
| 122 |
|
| 123 |
virtual void SaveBinaryState(StreamOut &inStream) const override; |
| 124 |
virtual void SaveMaterialState(PhysicsMaterialList &outMaterials) const override; |
| 125 |
virtual void RestoreMaterialState(const PhysicsMaterialRefC *inMaterials, uint inNumMaterials) override; |
| 126 |
|
| 127 |
|
| 128 |
static void sRegister(); |
| 129 |
|
| 130 |
protected: |
| 131 |
|
| 132 |
virtual void RestoreBinaryState(StreamIn &inStream) override; |
| 133 |
|
| 134 |
|
| 135 |
static const StaticArray<Vec3, 384> sUnitSphereTriangles; |
| 136 |
|
| 137 |
private: |
| 138 |
|
| 139 |
class CSGetTrianglesContext; |
| 140 |
|
| 141 |
|
| 142 |
static void sCollideConvexVsConvex(const Shape *inShape1, const Shape *inShape2, Vec3Arg inScale1, Vec3Arg inScale2, Mat44Arg inCenterOfMassTransform1, Mat44Arg inCenterOfMassTransform2, const SubShapeIDCreator &inSubShapeIDCreator1, const SubShapeIDCreator &inSubShapeIDCreator2, const CollideShapeSettings &inCollideShapeSettings, CollideShapeCollector &ioCollector, const ShapeFilter &inShapeFilter); |
| 143 |
static void sCastConvexVsConvex(const ShapeCast &inShapeCast, const ShapeCastSettings &inShapeCastSettings, const Shape *inShape, Vec3Arg inScale, const ShapeFilter &inShapeFilter, Mat44Arg inCenterOfMassTransform2, const SubShapeIDCreator &inSubShapeIDCreator1, const SubShapeIDCreator &inSubShapeIDCreator2, CastShapeCollector &ioCollector); |
| 144 |
|
| 145 |
|
| 146 |
RefConst<PhysicsMaterial> mMaterial; |
| 147 |
float mDensity = 1000.0f; |
| 148 |
}; |
| 149 |
|
| 150 |
JPH_NAMESPACE_END |