| 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 CylinderShapeSettings final : public ConvexShapeSettings |
| 14 |
{ |
| 15 |
JPH_DECLARE_SERIALIZABLE_VIRTUAL(JPH_EXPORT, CylinderShapeSettings) |
| 16 |
|
| 17 |
public: |
| 18 |
|
| 19 |
CylinderShapeSettings() = default; |
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
CylinderShapeSettings(float inHalfHeight, float inRadius, float inConvexRadius = cDefaultConvexRadius, const PhysicsMaterial *inMaterial = nullptr) : ConvexShapeSettings(inMaterial), mHalfHeight(inHalfHeight), mRadius(inRadius), mConvexRadius(inConvexRadius) { } |
| 24 |
|
| 25 |
|
| 26 |
virtual ShapeResult Create() const override; |
| 27 |
|
| 28 |
float mHalfHeight = 0.0f; |
| 29 |
float mRadius = 0.0f; |
| 30 |
float mConvexRadius = 0.0f; |
| 31 |
}; |
| 32 |
|
| 33 |
|
| 34 |
class JPH_EXPORT CylinderShape final : public ConvexShape |
| 35 |
{ |
| 36 |
public: |
| 37 |
JPH_OVERRIDE_NEW_DELETE |
| 38 |
|
| 39 |
|
| 40 |
CylinderShape() : ConvexShape(EShapeSubType::Cylinder) { } |
| 41 |
CylinderShape(const CylinderShapeSettings &inSettings, ShapeResult &outResult); |
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
CylinderShape(float inHalfHeight, float inRadius, float inConvexRadius = cDefaultConvexRadius, const PhysicsMaterial *inMaterial = nullptr); |
| 46 |
|
| 47 |
|
| 48 |
float GetHalfHeight() const { return mHalfHeight; } |
| 49 |
|
| 50 |
|
| 51 |
float GetRadius() const { return mRadius; } |
| 52 |
|
| 53 |
|
| 54 |
virtual AABox GetLocalBounds() const override; |
| 55 |
|
| 56 |
|
| 57 |
virtual float GetInnerRadius() const override { return min(mHalfHeight, mRadius); } |
| 58 |
|
| 59 |
|
| 60 |
virtual MassProperties GetMassProperties() const override; |
| 61 |
|
| 62 |
|
| 63 |
virtual Vec3 GetSurfaceNormal(const SubShapeID &inSubShapeID, Vec3Arg inLocalSurfacePosition) const override; |
| 64 |
|
| 65 |
|
| 66 |
virtual void GetSupportingFace(const SubShapeID &inSubShapeID, Vec3Arg inDirection, Vec3Arg inScale, Mat44Arg inCenterOfMassTransform, SupportingFace &outVertices) const override; |
| 67 |
|
| 68 |
|
| 69 |
virtual const Support * GetSupportFunction(ESupportMode inMode, SupportBuffer &inBuffer, Vec3Arg inScale) const override; |
| 70 |
|
| 71 |
#ifdef JPH_DEBUG_RENDERER |
| 72 |
|
| 73 |
virtual void Draw(DebugRenderer *inRenderer, RMat44Arg inCenterOfMassTransform, Vec3Arg inScale, ColorArg inColor, bool inUseMaterialColors, bool inDrawWireframe) const override; |
| 74 |
#endif |
| 75 |
|
| 76 |
|
| 77 |
using ConvexShape::CastRay; |
| 78 |
virtual bool CastRay(const RayCast &inRay, const SubShapeIDCreator &inSubShapeIDCreator, RayCastResult &ioHit) const override; |
| 79 |
|
| 80 |
|
| 81 |
virtual void CollidePoint(Vec3Arg inPoint, const SubShapeIDCreator &inSubShapeIDCreator, CollidePointCollector &ioCollector, const ShapeFilter &inShapeFilter = { }) const override; |
| 82 |
|
| 83 |
|
| 84 |
virtual void CollideSoftBodyVertices(Mat44Arg inCenterOfMassTransform, Vec3Arg inScale, const CollideSoftBodyVertexIterator &inVertices, uint inNumVertices, int inCollidingShapeIndex) const override; |
| 85 |
|
| 86 |
|
| 87 |
virtual void GetTrianglesStart(GetTrianglesContext &ioContext, const AABox &inBox, Vec3Arg inPositionCOM, QuatArg inRotation, Vec3Arg inScale) const override; |
| 88 |
|
| 89 |
|
| 90 |
virtual int GetTrianglesNext(GetTrianglesContext &ioContext, int inMaxTrianglesRequested, Float3 *outTriangleVertices, const PhysicsMaterial **outMaterials = nullptr) const override; |
| 91 |
|
| 92 |
|
| 93 |
virtual void SaveBinaryState(StreamOut &inStream) const override; |
| 94 |
|
| 95 |
|
| 96 |
virtual Stats GetStats() const override { return Stats(sizeof(*this), 0); } |
| 97 |
|
| 98 |
|
| 99 |
virtual float GetVolume() const override { return 2.0f * JPH_PI * mHalfHeight * Square(mRadius); } |
| 100 |
|
| 101 |
|
| 102 |
float GetConvexRadius() const { return mConvexRadius; } |
| 103 |
|
| 104 |
|
| 105 |
virtual bool IsValidScale(Vec3Arg inScale) const override; |
| 106 |
|
| 107 |
|
| 108 |
virtual Vec3 MakeScaleValid(Vec3Arg inScale) const override; |
| 109 |
|
| 110 |
|
| 111 |
static void sRegister(); |
| 112 |
|
| 113 |
protected: |
| 114 |
|
| 115 |
virtual void RestoreBinaryState(StreamIn &inStream) override; |
| 116 |
|
| 117 |
private: |
| 118 |
|
| 119 |
class Cylinder; |
| 120 |
|
| 121 |
float mHalfHeight = 0.0f; |
| 122 |
float mRadius = 0.0f; |
| 123 |
float mConvexRadius = 0.0f; |
| 124 |
}; |
| 125 |
|
| 126 |
JPH_NAMESPACE_END |