| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
#pragma once |
| 6 |
|
| 7 |
#include <Jolt/Physics/Collision/Shape/ConvexShape.h> |
| 8 |
#ifdef JPH_DEBUG_RENDERER |
| 9 |
#include <Jolt/Renderer/DebugRenderer.h> |
| 10 |
#endif |
| 11 |
|
| 12 |
JPH_NAMESPACE_BEGIN |
| 13 |
|
| 14 |
|
| 15 |
class JPH_EXPORT TaperedCapsuleShapeSettings final : public ConvexShapeSettings |
| 16 |
{ |
| 17 |
JPH_DECLARE_SERIALIZABLE_VIRTUAL(JPH_EXPORT, TaperedCapsuleShapeSettings) |
| 18 |
|
| 19 |
public: |
| 20 |
|
| 21 |
TaperedCapsuleShapeSettings() = default; |
| 22 |
|
| 23 |
|
| 24 |
TaperedCapsuleShapeSettings(float inHalfHeightOfTaperedCylinder, float inTopRadius, float inBottomRadius, const PhysicsMaterial *inMaterial = nullptr); |
| 25 |
|
| 26 |
|
| 27 |
bool IsValid() const { return mTopRadius > 0.0f && mBottomRadius > 0.0f && mHalfHeightOfTaperedCylinder >= 0.0f; } |
| 28 |
|
| 29 |
|
| 30 |
bool IsSphere() const; |
| 31 |
|
| 32 |
|
| 33 |
virtual ShapeResult Create() const override; |
| 34 |
|
| 35 |
float mHalfHeightOfTaperedCylinder = 0.0f; |
| 36 |
float mTopRadius = 0.0f; |
| 37 |
float mBottomRadius = 0.0f; |
| 38 |
}; |
| 39 |
|
| 40 |
|
| 41 |
class JPH_EXPORT TaperedCapsuleShape final : public ConvexShape |
| 42 |
{ |
| 43 |
public: |
| 44 |
JPH_OVERRIDE_NEW_DELETE |
| 45 |
|
| 46 |
|
| 47 |
TaperedCapsuleShape() : ConvexShape(EShapeSubType::TaperedCapsule) { } |
| 48 |
TaperedCapsuleShape(const TaperedCapsuleShapeSettings &inSettings, ShapeResult &outResult); |
| 49 |
|
| 50 |
|
| 51 |
inline float GetTopRadius() const { return mTopRadius; } |
| 52 |
|
| 53 |
|
| 54 |
inline float GetBottomRadius() const { return mBottomRadius; } |
| 55 |
|
| 56 |
|
| 57 |
inline float GetHalfHeight() const { return 0.5f * (mTopCenter - mBottomCenter); } |
| 58 |
|
| 59 |
|
| 60 |
virtual Vec3 GetCenterOfMass() const override { return mCenterOfMass; } |
| 61 |
|
| 62 |
|
| 63 |
virtual AABox GetLocalBounds() const override; |
| 64 |
|
| 65 |
|
| 66 |
virtual AABox GetWorldSpaceBounds(Mat44Arg inCenterOfMassTransform, Vec3Arg inScale) const override; |
| 67 |
using Shape::GetWorldSpaceBounds; |
| 68 |
|
| 69 |
|
| 70 |
virtual float GetInnerRadius() const override { return min(mTopRadius, mBottomRadius); } |
| 71 |
|
| 72 |
|
| 73 |
virtual MassProperties GetMassProperties() const override; |
| 74 |
|
| 75 |
|
| 76 |
virtual Vec3 GetSurfaceNormal(const SubShapeID &inSubShapeID, Vec3Arg inLocalSurfacePosition) const override; |
| 77 |
|
| 78 |
|
| 79 |
virtual void GetSupportingFace(const SubShapeID &inSubShapeID, Vec3Arg inDirection, Vec3Arg inScale, Mat44Arg inCenterOfMassTransform, SupportingFace &outVertices) const override; |
| 80 |
|
| 81 |
|
| 82 |
virtual const Support * GetSupportFunction(ESupportMode inMode, SupportBuffer &inBuffer, Vec3Arg inScale) const override; |
| 83 |
|
| 84 |
|
| 85 |
virtual void CollideSoftBodyVertices(Mat44Arg inCenterOfMassTransform, Vec3Arg inScale, const CollideSoftBodyVertexIterator &inVertices, uint inNumVertices, int inCollidingShapeIndex) const override; |
| 86 |
|
| 87 |
#ifdef JPH_DEBUG_RENDERER |
| 88 |
|
| 89 |
virtual void Draw(DebugRenderer *inRenderer, RMat44Arg inCenterOfMassTransform, Vec3Arg inScale, ColorArg inColor, bool inUseMaterialColors, bool inDrawWireframe) const override; |
| 90 |
#endif |
| 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 GetLocalBounds().GetVolume(); } |
| 100 |
|
| 101 |
|
| 102 |
virtual bool IsValidScale(Vec3Arg inScale) const override; |
| 103 |
|
| 104 |
|
| 105 |
virtual Vec3 MakeScaleValid(Vec3Arg inScale) const override; |
| 106 |
|
| 107 |
|
| 108 |
static void sRegister(); |
| 109 |
|
| 110 |
protected: |
| 111 |
|
| 112 |
virtual void RestoreBinaryState(StreamIn &inStream) override; |
| 113 |
|
| 114 |
private: |
| 115 |
|
| 116 |
class TaperedCapsule; |
| 117 |
|
| 118 |
|
| 119 |
AABox GetInertiaApproximation() const; |
| 120 |
|
| 121 |
Vec3 mCenterOfMass = Vec3::sZero(); |
| 122 |
float mTopRadius = 0.0f; |
| 123 |
float mBottomRadius = 0.0f; |
| 124 |
float mTopCenter = 0.0f; |
| 125 |
float mBottomCenter = 0.0f; |
| 126 |
float mConvexRadius = 0.0f; |
| 127 |
float mSinAlpha = 0.0f; |
| 128 |
float mTanAlpha = 0.0f; |
| 129 |
|
| 130 |
#ifdef JPH_DEBUG_RENDERER |
| 131 |
mutable DebugRenderer::GeometryRef mGeometry; |
| 132 |
#endif |
| 133 |
}; |
| 134 |
|
| 135 |
JPH_NAMESPACE_END |