| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
#pragma once |
| 6 |
|
| 7 |
#include <Jolt/Physics/Collision/Shape/Shape.h> |
| 8 |
#include <Jolt/Physics/Collision/Shape/SubShapeID.h> |
| 9 |
#include <Jolt/Physics/Collision/PhysicsMaterial.h> |
| 10 |
|
| 11 |
JPH_NAMESPACE_BEGIN |
| 12 |
|
| 13 |
class CollideShapeSettings; |
| 14 |
|
| 15 |
|
| 16 |
class JPH_EXPORT PlaneShapeSettings final : public ShapeSettings |
| 17 |
{ |
| 18 |
JPH_DECLARE_SERIALIZABLE_VIRTUAL(JPH_EXPORT, PlaneShapeSettings) |
| 19 |
|
| 20 |
public: |
| 21 |
|
| 22 |
PlaneShapeSettings() = default; |
| 23 |
|
| 24 |
|
| 25 |
PlaneShapeSettings(const Plane &inPlane, const PhysicsMaterial *inMaterial = nullptr, float inHalfExtent = cDefaultHalfExtent) : mPlane(inPlane), mMaterial(inMaterial), mHalfExtent(inHalfExtent) { } |
| 26 |
|
| 27 |
|
| 28 |
virtual ShapeResult Create() const override; |
| 29 |
|
| 30 |
Plane mPlane; |
| 31 |
|
| 32 |
RefConst<PhysicsMaterial> mMaterial; |
| 33 |
|
| 34 |
static constexpr float cDefaultHalfExtent = 1000.0f; |
| 35 |
|
| 36 |
float mHalfExtent = cDefaultHalfExtent; |
| 37 |
}; |
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
class JPH_EXPORT PlaneShape final : public Shape |
| 43 |
{ |
| 44 |
public: |
| 45 |
JPH_OVERRIDE_NEW_DELETE |
| 46 |
|
| 47 |
|
| 48 |
PlaneShape() : Shape(EShapeType::Plane, EShapeSubType::Plane) { } |
| 49 |
PlaneShape(const Plane &inPlane, const PhysicsMaterial *inMaterial = nullptr, float inHalfExtent = PlaneShapeSettings::cDefaultHalfExtent) : Shape(EShapeType::Plane, EShapeSubType::Plane), mPlane(inPlane), mMaterial(inMaterial), mHalfExtent(inHalfExtent) { CalculateLocalBounds(); } |
| 50 |
PlaneShape(const PlaneShapeSettings &inSettings, ShapeResult &outResult); |
| 51 |
|
| 52 |
|
| 53 |
const Plane & GetPlane() const { return mPlane; } |
| 54 |
|
| 55 |
|
| 56 |
float GetHalfExtent() const { return mHalfExtent; } |
| 57 |
|
| 58 |
|
| 59 |
virtual bool MustBeStatic() const override { return true; } |
| 60 |
|
| 61 |
|
| 62 |
virtual AABox GetLocalBounds() const override { return mLocalBounds; } |
| 63 |
|
| 64 |
|
| 65 |
virtual uint GetSubShapeIDBitsRecursive() const override { return 0; } |
| 66 |
|
| 67 |
|
| 68 |
virtual float GetInnerRadius() const override { return 0.0f; } |
| 69 |
|
| 70 |
|
| 71 |
virtual MassProperties GetMassProperties() const override; |
| 72 |
|
| 73 |
|
| 74 |
virtual const PhysicsMaterial * GetMaterial(const SubShapeID &inSubShapeID) const override { JPH_ASSERT(inSubShapeID.IsEmpty(), "Invalid subshape ID"); return GetMaterial(); } |
| 75 |
|
| 76 |
|
| 77 |
virtual Vec3 GetSurfaceNormal(const SubShapeID &inSubShapeID, Vec3Arg inLocalSurfacePosition) const override { JPH_ASSERT(inSubShapeID.IsEmpty(), "Invalid subshape ID"); return mPlane.GetNormal(); } |
| 78 |
|
| 79 |
|
| 80 |
virtual void GetSupportingFace(const SubShapeID &inSubShapeID, Vec3Arg inDirection, Vec3Arg inScale, Mat44Arg inCenterOfMassTransform, SupportingFace &outVertices) const override; |
| 81 |
|
| 82 |
#ifdef JPH_DEBUG_RENDERER |
| 83 |
|
| 84 |
virtual void Draw(DebugRenderer *inRenderer, RMat44Arg inCenterOfMassTransform, Vec3Arg inScale, ColorArg inColor, bool inUseMaterialColors, bool inDrawWireframe) const override; |
| 85 |
#endif |
| 86 |
|
| 87 |
|
| 88 |
virtual bool CastRay(const RayCast &inRay, const SubShapeIDCreator &inSubShapeIDCreator, RayCastResult &ioHit) const override; |
| 89 |
virtual void CastRay(const RayCast &inRay, const RayCastSettings &inRayCastSettings, const SubShapeIDCreator &inSubShapeIDCreator, CastRayCollector &ioCollector, const ShapeFilter &inShapeFilter = { }) const override; |
| 90 |
|
| 91 |
|
| 92 |
virtual void CollidePoint(Vec3Arg inPoint, const SubShapeIDCreator &inSubShapeIDCreator, CollidePointCollector &ioCollector, const ShapeFilter &inShapeFilter = { }) const override; |
| 93 |
|
| 94 |
|
| 95 |
virtual void CollideSoftBodyVertices(Mat44Arg inCenterOfMassTransform, Vec3Arg inScale, const CollideSoftBodyVertexIterator &inVertices, uint inNumVertices, int inCollidingShapeIndex) const override; |
| 96 |
|
| 97 |
|
| 98 |
virtual void GetTrianglesStart(GetTrianglesContext &ioContext, const AABox &inBox, Vec3Arg inPositionCOM, QuatArg inRotation, Vec3Arg inScale) const override; |
| 99 |
|
| 100 |
|
| 101 |
virtual int GetTrianglesNext(GetTrianglesContext &ioContext, int inMaxTrianglesRequested, Float3 *outTriangleVertices, const PhysicsMaterial **outMaterials = nullptr) const override; |
| 102 |
|
| 103 |
|
| 104 |
virtual void GetSubmergedVolume(Mat44Arg inCenterOfMassTransform, Vec3Arg inScale, const Plane &inSurface, float &outTotalVolume, float &outSubmergedVolume, Vec3 &outCenterOfBuoyancy JPH_IF_DEBUG_RENDERER(, RVec3Arg inBaseOffset)) const override { JPH_ASSERT(false, "Not supported"); } |
| 105 |
|
| 106 |
|
| 107 |
virtual void SaveBinaryState(StreamOut &inStream) const override; |
| 108 |
virtual void SaveMaterialState(PhysicsMaterialList &outMaterials) const override; |
| 109 |
virtual void RestoreMaterialState(const PhysicsMaterialRefC *inMaterials, uint inNumMaterials) override; |
| 110 |
|
| 111 |
|
| 112 |
virtual Stats GetStats() const override { return Stats(sizeof(*this), 0); } |
| 113 |
|
| 114 |
|
| 115 |
virtual float GetVolume() const override { return 0; } |
| 116 |
|
| 117 |
|
| 118 |
void SetMaterial(const PhysicsMaterial *inMaterial) { mMaterial = inMaterial; } |
| 119 |
const PhysicsMaterial * GetMaterial() const { return mMaterial != nullptr? mMaterial : PhysicsMaterial::sDefault; } |
| 120 |
|
| 121 |
|
| 122 |
static void sRegister(); |
| 123 |
|
| 124 |
protected: |
| 125 |
|
| 126 |
virtual void RestoreBinaryState(StreamIn &inStream) override; |
| 127 |
|
| 128 |
private: |
| 129 |
struct PSGetTrianglesContext; |
| 130 |
|
| 131 |
|
| 132 |
void GetVertices(Vec3 *outVertices) const; |
| 133 |
|
| 134 |
|
| 135 |
void CalculateLocalBounds(); |
| 136 |
|
| 137 |
|
| 138 |
static void sCollideConvexVsPlane(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); |
| 139 |
static void sCastConvexVsPlane(const ShapeCast &inShapeCast, const ShapeCastSettings &inShapeCastSettings, const Shape *inShape, Vec3Arg inScale, const ShapeFilter &inShapeFilter, Mat44Arg inCenterOfMassTransform2, const SubShapeIDCreator &inSubShapeIDCreator1, const SubShapeIDCreator &inSubShapeIDCreator2, CastShapeCollector &ioCollector); |
| 140 |
|
| 141 |
Plane mPlane; |
| 142 |
RefConst<PhysicsMaterial> mMaterial; |
| 143 |
float mHalfExtent; |
| 144 |
AABox mLocalBounds; |
| 145 |
}; |
| 146 |
|
| 147 |
JPH_NAMESPACE_END |