| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
#pragma once |
| 6 |
|
| 7 |
#include <Jolt/Physics/Collision/Shape/ConvexShape.h> |
| 8 |
|
| 9 |
JPH_NAMESPACE_BEGIN |
| 10 |
|
| 11 |
|
| 12 |
class JPH_EXPORT TriangleShapeSettings final : public ConvexShapeSettings |
| 13 |
{ |
| 14 |
JPH_DECLARE_SERIALIZABLE_VIRTUAL(JPH_EXPORT, TriangleShapeSettings) |
| 15 |
|
| 16 |
public: |
| 17 |
|
| 18 |
TriangleShapeSettings() = default; |
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
TriangleShapeSettings(Vec3Arg inV1, Vec3Arg inV2, Vec3Arg inV3, float inConvexRadius = 0.0f, const PhysicsMaterial *inMaterial = nullptr) : ConvexShapeSettings(inMaterial), mV1(inV1), mV2(inV2), mV3(inV3), mConvexRadius(inConvexRadius) { } |
| 23 |
|
| 24 |
|
| 25 |
virtual ShapeResult Create() const override; |
| 26 |
|
| 27 |
Vec3 mV1; |
| 28 |
Vec3 mV2; |
| 29 |
Vec3 mV3; |
| 30 |
float mConvexRadius = 0.0f; |
| 31 |
}; |
| 32 |
|
| 33 |
|
| 34 |
class JPH_EXPORT TriangleShape final : public ConvexShape |
| 35 |
{ |
| 36 |
public: |
| 37 |
JPH_OVERRIDE_NEW_DELETE |
| 38 |
|
| 39 |
|
| 40 |
TriangleShape() : ConvexShape(EShapeSubType::Triangle) { } |
| 41 |
TriangleShape(const TriangleShapeSettings &inSettings, ShapeResult &outResult); |
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
TriangleShape(Vec3Arg inV1, Vec3Arg inV2, Vec3Arg inV3, float inConvexRadius = 0.0f, const PhysicsMaterial *inMaterial = nullptr) : ConvexShape(EShapeSubType::Triangle, inMaterial), mV1(inV1), mV2(inV2), mV3(inV3), mConvexRadius(inConvexRadius) { JPH_ASSERT(inConvexRadius >= 0.0f); } |
| 46 |
|
| 47 |
|
| 48 |
inline Vec3 GetVertex1() const { return mV1; } |
| 49 |
inline Vec3 GetVertex2() const { return mV2; } |
| 50 |
inline Vec3 GetVertex3() const { return mV3; } |
| 51 |
|
| 52 |
|
| 53 |
float GetConvexRadius() const { return mConvexRadius; } |
| 54 |
|
| 55 |
|
| 56 |
virtual AABox GetLocalBounds() const override; |
| 57 |
|
| 58 |
|
| 59 |
virtual AABox GetWorldSpaceBounds(Mat44Arg inCenterOfMassTransform, Vec3Arg inScale) const override; |
| 60 |
using Shape::GetWorldSpaceBounds; |
| 61 |
|
| 62 |
|
| 63 |
virtual float GetInnerRadius() const override { return mConvexRadius; } |
| 64 |
|
| 65 |
|
| 66 |
virtual MassProperties GetMassProperties() const override; |
| 67 |
|
| 68 |
|
| 69 |
virtual Vec3 GetSurfaceNormal(const SubShapeID &inSubShapeID, Vec3Arg inLocalSurfacePosition) const override; |
| 70 |
|
| 71 |
|
| 72 |
virtual void GetSupportingFace(const SubShapeID &inSubShapeID, Vec3Arg inDirection, Vec3Arg inScale, Mat44Arg inCenterOfMassTransform, SupportingFace &outVertices) const override; |
| 73 |
|
| 74 |
|
| 75 |
virtual const Support * GetSupportFunction(ESupportMode inMode, SupportBuffer &inBuffer, Vec3Arg inScale) const override; |
| 76 |
|
| 77 |
|
| 78 |
virtual void GetSubmergedVolume(Mat44Arg inCenterOfMassTransform, Vec3Arg inScale, const Plane &inSurface, float &outTotalVolume, float &outSubmergedVolume, Vec3 &outCenterOfBuoyancy JPH_IF_DEBUG_RENDERER(, RVec3Arg inBaseOffset)) const override; |
| 79 |
|
| 80 |
#ifdef JPH_DEBUG_RENDERER |
| 81 |
|
| 82 |
virtual void Draw(DebugRenderer *inRenderer, RMat44Arg inCenterOfMassTransform, Vec3Arg inScale, ColorArg inColor, bool inUseMaterialColors, bool inDrawWireframe) const override; |
| 83 |
#endif |
| 84 |
|
| 85 |
|
| 86 |
virtual bool CastRay(const RayCast &inRay, const SubShapeIDCreator &inSubShapeIDCreator, RayCastResult &ioHit) const override; |
| 87 |
virtual void CastRay(const RayCast &inRay, const RayCastSettings &inRayCastSettings, const SubShapeIDCreator &inSubShapeIDCreator, CastRayCollector &ioCollector, const ShapeFilter &inShapeFilter = { }) const override; |
| 88 |
|
| 89 |
|
| 90 |
virtual void CollidePoint(Vec3Arg inPoint, const SubShapeIDCreator &inSubShapeIDCreator, CollidePointCollector &ioCollector, const ShapeFilter &inShapeFilter = { }) const override; |
| 91 |
|
| 92 |
|
| 93 |
virtual void CollideSoftBodyVertices(Mat44Arg inCenterOfMassTransform, Vec3Arg inScale, const CollideSoftBodyVertexIterator &inVertices, uint inNumVertices, int inCollidingShapeIndex) const override; |
| 94 |
|
| 95 |
|
| 96 |
virtual void GetTrianglesStart(GetTrianglesContext &ioContext, const AABox &inBox, Vec3Arg inPositionCOM, QuatArg inRotation, Vec3Arg inScale) const override; |
| 97 |
|
| 98 |
|
| 99 |
virtual int GetTrianglesNext(GetTrianglesContext &ioContext, int inMaxTrianglesRequested, Float3 *outTriangleVertices, const PhysicsMaterial **outMaterials = nullptr) const override; |
| 100 |
|
| 101 |
|
| 102 |
virtual void SaveBinaryState(StreamOut &inStream) const override; |
| 103 |
|
| 104 |
|
| 105 |
virtual Stats GetStats() const override { return Stats(sizeof(*this), 1); } |
| 106 |
|
| 107 |
|
| 108 |
virtual float GetVolume() const override { return 0; } |
| 109 |
|
| 110 |
|
| 111 |
virtual bool IsValidScale(Vec3Arg inScale) const override; |
| 112 |
|
| 113 |
|
| 114 |
virtual Vec3 MakeScaleValid(Vec3Arg inScale) const override; |
| 115 |
|
| 116 |
|
| 117 |
static void sRegister(); |
| 118 |
|
| 119 |
protected: |
| 120 |
|
| 121 |
virtual void RestoreBinaryState(StreamIn &inStream) override; |
| 122 |
|
| 123 |
private: |
| 124 |
|
| 125 |
static void sCollideConvexVsTriangle(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); |
| 126 |
static void sCollideSphereVsTriangle(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); |
| 127 |
static void sCastConvexVsTriangle(const ShapeCast &inShapeCast, const ShapeCastSettings &inShapeCastSettings, const Shape *inShape, Vec3Arg inScale, const ShapeFilter &inShapeFilter, Mat44Arg inCenterOfMassTransform2, const SubShapeIDCreator &inSubShapeIDCreator1, const SubShapeIDCreator &inSubShapeIDCreator2, CastShapeCollector &ioCollector); |
| 128 |
static void sCastSphereVsTriangle(const ShapeCast &inShapeCast, const ShapeCastSettings &inShapeCastSettings, const Shape *inShape, Vec3Arg inScale, const ShapeFilter &inShapeFilter, Mat44Arg inCenterOfMassTransform2, const SubShapeIDCreator &inSubShapeIDCreator1, const SubShapeIDCreator &inSubShapeIDCreator2, CastShapeCollector &ioCollector); |
| 129 |
|
| 130 |
|
| 131 |
class TSGetTrianglesContext; |
| 132 |
|
| 133 |
|
| 134 |
class TriangleNoConvex; |
| 135 |
class TriangleWithConvex; |
| 136 |
|
| 137 |
Vec3 mV1; |
| 138 |
Vec3 mV2; |
| 139 |
Vec3 mV3; |
| 140 |
float mConvexRadius = 0.0f; |
| 141 |
}; |
| 142 |
|
| 143 |
JPH_NAMESPACE_END |