Jolt Physics
A multi core friendly Game Physics Engine
Loading...
Searching...
No Matches
TaperedCapsuleShape.h
Go to the documentation of this file.
1// Jolt Physics Library (https://github.com/jrouwe/JoltPhysics)
2// SPDX-FileCopyrightText: 2021 Jorrit Rouwe
3// SPDX-License-Identifier: MIT
4
5#pragma once
6
8#ifdef JPH_DEBUG_RENDERER
10#endif // JPH_DEBUG_RENDERER
11
13
16{
18
19public:
22
24 TaperedCapsuleShapeSettings(float inHalfHeightOfTaperedCylinder, float inTopRadius, float inBottomRadius, const PhysicsMaterial *inMaterial = nullptr);
25
27 bool IsValid() const { return mTopRadius > 0.0f && mBottomRadius > 0.0f && mHalfHeightOfTaperedCylinder >= 0.0f; }
28
30 bool IsSphere() const;
31
34 virtual ShapeResult Create() const override;
35
36 float mHalfHeightOfTaperedCylinder = 0.0f;
37 float mTopRadius = 0.0f;
38 float mBottomRadius = 0.0f;
39};
40
43{
44public:
46
49 TaperedCapsuleShape(const TaperedCapsuleShapeSettings &inSettings, ShapeResult &outResult);
50
52 inline float GetTopRadius() const { return mTopRadius; }
53
55 inline float GetBottomRadius() const { return mBottomRadius; }
56
58 inline float GetHalfHeight() const { return 0.5f * (mTopCenter - mBottomCenter); }
59
60 // See Shape::GetCenterOfMass
61 virtual Vec3 GetCenterOfMass() const override { return mCenterOfMass; }
62
63 // See Shape::GetLocalBounds
64 virtual AABox GetLocalBounds() const override;
65
66 // See Shape::GetWorldSpaceBounds
67 virtual AABox GetWorldSpaceBounds(Mat44Arg inCenterOfMassTransform, Vec3Arg inScale) const override;
69
70 // See Shape::GetInnerRadius
71 virtual float GetInnerRadius() const override { return min(mTopRadius, mBottomRadius); }
72
73 // See Shape::GetMassProperties
74 virtual MassProperties GetMassProperties() const override;
75
76 // See Shape::GetSurfaceNormal
77 virtual Vec3 GetSurfaceNormal(const SubShapeID &inSubShapeID, Vec3Arg inLocalSurfacePosition) const override;
78
79 // See Shape::GetSupportingFace
80 virtual void GetSupportingFace(const SubShapeID &inSubShapeID, Vec3Arg inDirection, Vec3Arg inScale, Mat44Arg inCenterOfMassTransform, SupportingFace &outVertices) const override;
81
82 // See ConvexShape::GetSupportFunction
83 virtual const Support * GetSupportFunction(ESupportMode inMode, SupportBuffer &inBuffer, Vec3Arg inScale) const override;
84
85 // See: Shape::CollideSoftBodyVertices
86 virtual void CollideSoftBodyVertices(Mat44Arg inCenterOfMassTransform, Vec3Arg inScale, const CollideSoftBodyVertexIterator &inVertices, uint inNumVertices, int inCollidingShapeIndex) const override;
87
88#ifdef JPH_DEBUG_RENDERER
89 // See Shape::Draw
90 virtual void Draw(DebugRenderer *inRenderer, RMat44Arg inCenterOfMassTransform, Vec3Arg inScale, ColorArg inColor, bool inUseMaterialColors, bool inDrawWireframe) const override;
91#endif // JPH_DEBUG_RENDERER
92
93 // See Shape
94 virtual void SaveBinaryState(StreamOut &inStream) const override;
95
96 // See Shape::GetStats
97 virtual Stats GetStats() const override { return Stats(sizeof(*this), 0); }
98
99 // See Shape::GetVolume
100 virtual float GetVolume() const override { return GetLocalBounds().GetVolume(); } // Volume is approximate!
101
102 // See Shape::IsValidScale
103 virtual bool IsValidScale(Vec3Arg inScale) const override;
104
105 // See Shape::MakeScaleValid
106 virtual Vec3 MakeScaleValid(Vec3Arg inScale) const override;
107
108 // Register shape functions with the registry
109 static void sRegister();
110
111protected:
112 // See: Shape::RestoreBinaryState
113 virtual void RestoreBinaryState(StreamIn &inStream) override;
114
115private:
116 // Class for GetSupportFunction
117 class TaperedCapsule;
118
120 AABox GetInertiaApproximation() const;
121
122 Vec3 mCenterOfMass = Vec3::sZero();
123 float mTopRadius = 0.0f;
124 float mBottomRadius = 0.0f;
125 float mTopCenter = 0.0f;
126 float mBottomCenter = 0.0f;
127 float mConvexRadius = 0.0f;
128 float mSinAlpha = 0.0f;
129 float mTanAlpha = 0.0f;
130
131#ifdef JPH_DEBUG_RENDERER
132 mutable DebugRenderer::GeometryRef mGeometry;
133#endif // JPH_DEBUG_RENDERER
134};
135
#define JPH_EXPORT
Definition Core.h:283
unsigned int uint
Definition Core.h:510
#define JPH_NAMESPACE_END
Definition Core.h:434
#define JPH_NAMESPACE_BEGIN
Definition Core.h:428
#define JPH_OVERRIDE_NEW_DELETE
Macro to override the new and delete functions.
Definition Memory.h:50
#define JPH_DECLARE_SERIALIZABLE_VIRTUAL(linkage, class_name)
Definition SerializableObject.h:109
EShapeSubType
This enumerates all shape types, each shape can return its type through Shape::GetSubType.
Definition Shape.h:76
Axis aligned box.
Definition AABox.h:16
Definition CollideSoftBodyVertexIterator.h:15
Class that holds an RGBA color with 8-bits per component.
Definition Color.h:16
Base class for all convex shapes. Defines a virtual interface.
Definition ConvexShape.h:36
Class that constructs a ConvexShape (abstract)
Definition ConvexShape.h:18
Definition DebugRenderer.h:47
Describes the mass and inertia properties of a body. Used during body construction only.
Definition MassProperties.h:16
Holds a 4x4 matrix of floats, but supports also operations on the 3x3 upper left part of the matrix.
Definition Mat44.h:13
Definition PhysicsMaterial.h:23
virtual AABox GetWorldSpaceBounds(Mat44Arg inCenterOfMassTransform, Vec3Arg inScale) const
Definition Shape.h:221
virtual ShapeResult Create() const =0
Create a shape according to the settings specified by this object.
Simple binary input stream.
Definition StreamIn.h:13
Simple binary output stream.
Definition StreamOut.h:13
A sub shape id contains a path to an element (usually a triangle or other primitive type) of a compou...
Definition SubShapeID.h:23
Definition TaperedCapsuleShape.cpp:137
A capsule with different top and bottom radii.
Definition TaperedCapsuleShape.h:43
float GetHalfHeight() const
Get half height between the top and bottom sphere center.
Definition TaperedCapsuleShape.h:58
float GetBottomRadius() const
Get bottom radius of the tapered capsule.
Definition TaperedCapsuleShape.h:55
JPH_OVERRIDE_NEW_DELETE TaperedCapsuleShape()
Constructor.
Definition TaperedCapsuleShape.h:48
float GetTopRadius() const
Get top radius of the tapered capsule.
Definition TaperedCapsuleShape.h:52
virtual Stats GetStats() const override
Get stats of this shape. Use for logging / data collection purposes only. Does not add values from ch...
Definition TaperedCapsuleShape.h:97
virtual Vec3 GetCenterOfMass() const override
All shapes are centered around their center of mass. This function returns the center of mass positio...
Definition TaperedCapsuleShape.h:61
virtual float GetVolume() const override
Definition TaperedCapsuleShape.h:100
virtual float GetInnerRadius() const override
Definition TaperedCapsuleShape.h:71
Class that constructs a TaperedCapsuleShape.
Definition TaperedCapsuleShape.h:16
TaperedCapsuleShapeSettings()=default
Default constructor for deserialization.
bool IsValid() const
Check if the settings are valid.
Definition TaperedCapsuleShape.h:27
Definition Vec3.h:17
static JPH_INLINE Vec3 sZero()
Vector with all zeros.
Definition Vec3.inl:125
Class that holds information about the shape that can be used for logging / data collection purposes.
Definition Shape.h:407