| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
#pragma once |
| 6 |
|
| 7 |
#include <Jolt/Physics/Collision/Shape/ConvexShape.h> |
| 8 |
#include <Jolt/Physics/PhysicsSettings.h> |
| 9 |
|
| 10 |
JPH_NAMESPACE_BEGIN |
| 11 |
|
| 12 |
|
| 13 |
class JPH_EXPORT BoxShapeSettings final : public ConvexShapeSettings |
| 14 |
{ |
| 15 |
JPH_DECLARE_SERIALIZABLE_VIRTUAL(JPH_EXPORT, BoxShapeSettings) |
| 16 |
|
| 17 |
public: |
| 18 |
|
| 19 |
BoxShapeSettings() = default; |
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
BoxShapeSettings(Vec3Arg inHalfExtent, float inConvexRadius = cDefaultConvexRadius, const PhysicsMaterial *inMaterial = nullptr) : ConvexShapeSettings(inMaterial), mHalfExtent(inHalfExtent), mConvexRadius(inConvexRadius) { } |
| 24 |
|
| 25 |
|
| 26 |
virtual ShapeResult Create() const override; |
| 27 |
|
| 28 |
Vec3 mHalfExtent = Vec3::sZero(); |
| 29 |
float mConvexRadius = 0.0f; |
| 30 |
}; |
| 31 |
|
| 32 |
|
| 33 |
class JPH_EXPORT BoxShape final : public ConvexShape |
| 34 |
{ |
| 35 |
public: |
| 36 |
JPH_OVERRIDE_NEW_DELETE |
| 37 |
|
| 38 |
|
| 39 |
BoxShape() : ConvexShape(EShapeSubType::Box) { } |
| 40 |
BoxShape(const BoxShapeSettings &inSettings, ShapeResult &outResult); |
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
BoxShape(Vec3Arg inHalfExtent, float inConvexRadius = cDefaultConvexRadius, const PhysicsMaterial *inMaterial = nullptr) : ConvexShape(EShapeSubType::Box, inMaterial), mHalfExtent(inHalfExtent), mConvexRadius(inConvexRadius) { JPH_ASSERT(inConvexRadius >= 0.0f); JPH_ASSERT(inHalfExtent.ReduceMin() >= inConvexRadius); } |
| 45 |
|
| 46 |
|
| 47 |
Vec3 GetHalfExtent() const { return mHalfExtent; } |
| 48 |
|
| 49 |
|
| 50 |
virtual AABox GetLocalBounds() const override { return AABox(-mHalfExtent, mHalfExtent); } |
| 51 |
|
| 52 |
|
| 53 |
virtual float GetInnerRadius() const override { return mHalfExtent.ReduceMin(); } |
| 54 |
|
| 55 |
|
| 56 |
virtual MassProperties GetMassProperties() const override; |
| 57 |
|
| 58 |
|
| 59 |
virtual Vec3 GetSurfaceNormal(const SubShapeID &inSubShapeID, Vec3Arg inLocalSurfacePosition) const override; |
| 60 |
|
| 61 |
|
| 62 |
virtual void GetSupportingFace(const SubShapeID &inSubShapeID, Vec3Arg inDirection, Vec3Arg inScale, Mat44Arg inCenterOfMassTransform, SupportingFace &outVertices) const override; |
| 63 |
|
| 64 |
|
| 65 |
virtual const Support * GetSupportFunction(ESupportMode inMode, SupportBuffer &inBuffer, Vec3Arg inScale) const override; |
| 66 |
|
| 67 |
#ifdef JPH_DEBUG_RENDERER |
| 68 |
|
| 69 |
virtual void Draw(DebugRenderer *inRenderer, RMat44Arg inCenterOfMassTransform, Vec3Arg inScale, ColorArg inColor, bool inUseMaterialColors, bool inDrawWireframe) const override; |
| 70 |
#endif |
| 71 |
|
| 72 |
|
| 73 |
virtual bool CastRay(const RayCast &inRay, const SubShapeIDCreator &inSubShapeIDCreator, RayCastResult &ioHit) const override; |
| 74 |
virtual void CastRay(const RayCast &inRay, const RayCastSettings &inRayCastSettings, const SubShapeIDCreator &inSubShapeIDCreator, CastRayCollector &ioCollector, const ShapeFilter &inShapeFilter = { }) const override; |
| 75 |
|
| 76 |
|
| 77 |
virtual void CollidePoint(Vec3Arg inPoint, const SubShapeIDCreator &inSubShapeIDCreator, CollidePointCollector &ioCollector, const ShapeFilter &inShapeFilter = { }) const override; |
| 78 |
|
| 79 |
|
| 80 |
virtual void CollideSoftBodyVertices(Mat44Arg inCenterOfMassTransform, Vec3Arg inScale, const CollideSoftBodyVertexIterator &inVertices, uint inNumVertices, int inCollidingShapeIndex) const override; |
| 81 |
|
| 82 |
|
| 83 |
virtual void GetTrianglesStart(GetTrianglesContext &ioContext, const AABox &inBox, Vec3Arg inPositionCOM, QuatArg inRotation, Vec3Arg inScale) const override; |
| 84 |
|
| 85 |
|
| 86 |
virtual int GetTrianglesNext(GetTrianglesContext &ioContext, int inMaxTrianglesRequested, Float3 *outTriangleVertices, const PhysicsMaterial **outMaterials = nullptr) const override; |
| 87 |
|
| 88 |
|
| 89 |
virtual void SaveBinaryState(StreamOut &inStream) const override; |
| 90 |
|
| 91 |
|
| 92 |
virtual Stats GetStats() const override { return Stats(sizeof(*this), 12); } |
| 93 |
|
| 94 |
|
| 95 |
virtual float GetVolume() const override { return GetLocalBounds().GetVolume(); } |
| 96 |
|
| 97 |
|
| 98 |
float GetConvexRadius() const { return mConvexRadius; } |
| 99 |
|
| 100 |
|
| 101 |
static void sRegister(); |
| 102 |
|
| 103 |
protected: |
| 104 |
|
| 105 |
virtual void RestoreBinaryState(StreamIn &inStream) override; |
| 106 |
|
| 107 |
private: |
| 108 |
|
| 109 |
class Box; |
| 110 |
|
| 111 |
Vec3 mHalfExtent = Vec3::sZero(); |
| 112 |
float mConvexRadius = 0.0f; |
| 113 |
}; |
| 114 |
|
| 115 |
JPH_NAMESPACE_END |