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
19
21
23 TaperedCapsuleShapeSettings(float inHalfHeightOfTaperedCylinder, float inTopRadius, float inBottomRadius, const PhysicsMaterial *inMaterial = nullptr);
24
26 bool IsValid() const { return mTopRadius > 0.0f && mBottomRadius > 0.0f && mHalfHeightOfTaperedCylinder >= 0.0f; }
27
29 bool IsSphere() const;
30
31 // See: ShapeSettings
32 virtual ShapeResult Create() const override;
33
34 float mHalfHeightOfTaperedCylinder = 0.0f;
35 float mTopRadius = 0.0f;
36 float mBottomRadius = 0.0f;
37};
38
40class TaperedCapsuleShape final : public ConvexShape
41{
42public:
44
47 TaperedCapsuleShape(const TaperedCapsuleShapeSettings &inSettings, ShapeResult &outResult);
48
49 // See Shape::GetCenterOfMass
50 virtual Vec3 GetCenterOfMass() const override { return mCenterOfMass; }
51
52 // See Shape::GetLocalBounds
53 virtual AABox GetLocalBounds() const override;
54
55 // See Shape::GetWorldSpaceBounds
56 virtual AABox GetWorldSpaceBounds(Mat44Arg inCenterOfMassTransform, Vec3Arg inScale) const override;
58
59 // See Shape::GetInnerRadius
60 virtual float GetInnerRadius() const override { return min(mTopRadius, mBottomRadius); }
61
62 // See Shape::GetMassProperties
63 virtual MassProperties GetMassProperties() const override;
64
65 // See Shape::GetSurfaceNormal
66 virtual Vec3 GetSurfaceNormal(const SubShapeID &inSubShapeID, Vec3Arg inLocalSurfacePosition) const override;
67
68 // See Shape::GetSupportingFace
69 virtual void GetSupportingFace(const SubShapeID &inSubShapeID, Vec3Arg inDirection, Vec3Arg inScale, Mat44Arg inCenterOfMassTransform, SupportingFace &outVertices) const override;
70
71 // See ConvexShape::GetSupportFunction
72 virtual const Support * GetSupportFunction(ESupportMode inMode, SupportBuffer &inBuffer, Vec3Arg inScale) const override;
73
74#ifdef JPH_DEBUG_RENDERER
75 // See Shape::Draw
76 virtual void Draw(DebugRenderer *inRenderer, RMat44Arg inCenterOfMassTransform, Vec3Arg inScale, ColorArg inColor, bool inUseMaterialColors, bool inDrawWireframe) const override;
77#endif // JPH_DEBUG_RENDERER
78
79 // See Shape::TransformShape
80 virtual void TransformShape(Mat44Arg inCenterOfMassTransform, TransformedShapeCollector &ioCollector) const override;
81
82 // See Shape
83 virtual void SaveBinaryState(StreamOut &inStream) const override;
84
85 // See Shape::GetStats
86 virtual Stats GetStats() const override { return Stats(sizeof(*this), 0); }
87
88 // See Shape::GetVolume
89 virtual float GetVolume() const override { return GetLocalBounds().GetVolume(); } // Volume is approximate!
90
91 // See Shape::IsValidScale
92 virtual bool IsValidScale(Vec3Arg inScale) const override;
93
94 // Register shape functions with the registry
95 static void sRegister();
96
97protected:
98 // See: Shape::RestoreBinaryState
99 virtual void RestoreBinaryState(StreamIn &inStream) override;
100
101private:
102 // Class for GetSupportFunction
103 class TaperedCapsule;
104
106 AABox GetInertiaApproximation() const;
107
108 Vec3 mCenterOfMass = Vec3::sZero();
109 float mTopRadius = 0.0f;
110 float mBottomRadius = 0.0f;
111 float mTopCenter = 0.0f;
112 float mBottomCenter = 0.0f;
113 float mConvexRadius = 0.0f;
114 float mSinAlpha = 0.0f;
115 float mTanAlpha = 0.0f;
116
117#ifdef JPH_DEBUG_RENDERER
118 mutable DebugRenderer::GeometryRef mGeometry;
119#endif // JPH_DEBUG_RENDERER
120};
121
#define JPH_NAMESPACE_END
Definition: Core.h:240
#define JPH_NAMESPACE_BEGIN
Definition: Core.h:234
#define JPH_OVERRIDE_NEW_DELETE
Macro to override the new and delete functions.
Definition: Memory.h:29
#define JPH_DECLARE_SERIALIZABLE_VIRTUAL(class_name)
Definition: SerializableObject.h:100
EShapeSubType
This enumerates all shape types, each shape can return its type through Shape::GetSubType.
Definition: Shape.h:71
Axis aligned box.
Definition: AABox.h:16
float GetVolume() const
Get volume of bounding box.
Definition: AABox.h:130
Virtual interface that allows collecting multiple collision results.
Definition: CollisionCollector.h:45
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
ESupportMode
How the GetSupport function should behave.
Definition: ConvexShape.h:92
Class that constructs a ConvexShape (abstract)
Definition: ConvexShape.h:18
Simple triangle renderer for debugging purposes.
Definition: DebugRenderer.h:25
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
ShapeSettings::ShapeResult ShapeResult
Definition: Shape.h:174
StaticArray< Vec3, 32 > SupportingFace
Type definition for a supporting face.
Definition: Shape.h:235
virtual AABox GetWorldSpaceBounds(Mat44Arg inCenterOfMassTransform, Vec3Arg inScale) const
Definition: Shape.h:206
Simple binary input stream.
Definition: StreamIn.h:11
Simple binary output stream.
Definition: StreamOut.h:11
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:136
A capsule with different top and bottom radii.
Definition: TaperedCapsuleShape.h:41
virtual AABox GetWorldSpaceBounds(Mat44Arg inCenterOfMassTransform, Vec3Arg inScale) const override
Definition: TaperedCapsuleShape.cpp:286
JPH_OVERRIDE_NEW_DELETE TaperedCapsuleShape()
Constructor.
Definition: TaperedCapsuleShape.h:46
virtual void TransformShape(Mat44Arg inCenterOfMassTransform, TransformedShapeCollector &ioCollector) const override
Definition: TaperedCapsuleShape.cpp:335
static void sRegister()
Definition: TaperedCapsuleShape.cpp:377
virtual void SaveBinaryState(StreamOut &inStream) const override
Saves the contents of the shape in binary form to inStream.
Definition: TaperedCapsuleShape.cpp:344
virtual const Support * GetSupportFunction(ESupportMode inMode, SupportBuffer &inBuffer, Vec3Arg inScale) const override
Definition: TaperedCapsuleShape.cpp:178
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:86
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:50
virtual float GetVolume() const override
Definition: TaperedCapsuleShape.h:89
virtual float GetInnerRadius() const override
Definition: TaperedCapsuleShape.h:60
virtual void GetSupportingFace(const SubShapeID &inSubShapeID, Vec3Arg inDirection, Vec3Arg inScale, Mat44Arg inCenterOfMassTransform, SupportingFace &outVertices) const override
Definition: TaperedCapsuleShape.cpp:212
virtual bool IsValidScale(Vec3Arg inScale) const override
Definition: TaperedCapsuleShape.cpp:372
virtual void RestoreBinaryState(StreamIn &inStream) override
This function should not be called directly, it is used by sRestoreFromBinaryState.
Definition: TaperedCapsuleShape.cpp:358
virtual AABox GetLocalBounds() const override
Get local bounding box including convex radius, this box is centered around the center of mass rather...
Definition: TaperedCapsuleShape.cpp:280
virtual Vec3 GetSurfaceNormal(const SubShapeID &inSubShapeID, Vec3Arg inLocalSurfacePosition) const override
Definition: TaperedCapsuleShape.cpp:256
virtual void Draw(DebugRenderer *inRenderer, RMat44Arg inCenterOfMassTransform, Vec3Arg inScale, ColorArg inColor, bool inUseMaterialColors, bool inDrawWireframe) const override
Draw the shape at a particular location with a particular color (debugging purposes)
Definition: TaperedCapsuleShape.cpp:303
virtual MassProperties GetMassProperties() const override
Calculate the mass and inertia of this shape.
Definition: TaperedCapsuleShape.cpp:247
Class that constructs a TaperedCapsuleShape.
Definition: TaperedCapsuleShape.h:16
Definition: Vec3.h:16
static JPH_INLINE Vec3 sZero()
Vector with all zeros.
Definition: Vec3.inl:107
Class that holds information about the shape that can be used for logging / data collection purposes.
Definition: Shape.h:377