Debian Codegraph @

thirdparty/jolt_physics/Jolt/Physics/Collision/Shape/SphereShape.h

raw symbols SCIP
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
7 #include <Jolt/Physics/Collision/Shape/ConvexShape.h>
8
9 JPH_NAMESPACE_BEGIN
10
11 /// Class that constructs a SphereShape
12 class JPH_EXPORT SphereShapeSettings final : public ConvexShapeSettings
13 {
14 JPH_DECLARE_SERIALIZABLE_VIRTUAL(JPH_EXPORT, SphereShapeSettings)
15
16 public:
17 /// Default constructor for deserialization
18 SphereShapeSettings() = default;
19
20 /// Create a sphere with radius inRadius
21 SphereShapeSettings(float inRadius, const PhysicsMaterial *inMaterial = nullptr) : ConvexShapeSettings(inMaterial), mRadius(inRadius) { }
22
23 // See: ShapeSettings
24 virtual ShapeResult Create() const override;
25
26 float mRadius = 0.0f;
27 };
28
29 /// A sphere, centered around the origin.
30 /// Note that it is implemented as a point with convex radius.
31 class JPH_EXPORT SphereShape final : public ConvexShape
32 {
33 public:
34 JPH_OVERRIDE_NEW_DELETE
35
36 /// Constructor
37 SphereShape() : ConvexShape(EShapeSubType::Sphere) { }
38 SphereShape(const SphereShapeSettings &inSettings, ShapeResult &outResult);
39
40 /// Create a sphere with radius inRadius
41 SphereShape(float inRadius, const PhysicsMaterial *inMaterial = nullptr) : ConvexShape(EShapeSubType::Sphere, inMaterial), mRadius(inRadius) { JPH_ASSERT(inRadius > 0.0f); }
42
43 /// Radius of the sphere
44 float GetRadius() const { return mRadius; }
45
46 // See Shape::GetLocalBounds
47 virtual AABox GetLocalBounds() const override;
48
49 // See Shape::GetWorldSpaceBounds
50 virtual AABox GetWorldSpaceBounds(Mat44Arg inCenterOfMassTransform, Vec3Arg inScale) const override;
51 using Shape::GetWorldSpaceBounds;
52
53 // See Shape::GetInnerRadius
54 virtual float GetInnerRadius() const override { return mRadius; }
55
56 // See Shape::GetMassProperties
57 virtual MassProperties GetMassProperties() const override;
58
59 // See Shape::GetSurfaceNormal
60 virtual Vec3 GetSurfaceNormal(const SubShapeID &inSubShapeID, Vec3Arg inLocalSurfacePosition) const override;
61
62 // See Shape::GetSupportingFace
63 virtual void GetSupportingFace([[maybe_unused]] const SubShapeID &inSubShapeID, [[maybe_unused]] Vec3Arg inDirection, [[maybe_unused]] Vec3Arg inScale, [[maybe_unused]] Mat44Arg inCenterOfMassTransform, [[maybe_unused]] SupportingFace &outVertices) const override { /* Hit is always a single point, no point in returning anything */ }
64
65 // See ConvexShape::GetSupportFunction
66 virtual const Support * GetSupportFunction(ESupportMode inMode, SupportBuffer &inBuffer, Vec3Arg inScale) const override;
67
68 // See Shape::GetSubmergedVolume
69 virtual void GetSubmergedVolume(Mat44Arg inCenterOfMassTransform, Vec3Arg inScale, const Plane &inSurface, float &outTotalVolume, float &outSubmergedVolume, Vec3 &outCenterOfBuoyancy JPH_IF_DEBUG_RENDERER(, RVec3Arg inBaseOffset)) const override;
70
71 #ifdef JPH_DEBUG_RENDERER
72 // See Shape::Draw
73 virtual void Draw(DebugRenderer *inRenderer, RMat44Arg inCenterOfMassTransform, Vec3Arg inScale, ColorArg inColor, bool inUseMaterialColors, bool inDrawWireframe) const override;
74 #endif // JPH_DEBUG_RENDERER
75
76 // See Shape::CastRay
77 virtual bool CastRay(const RayCast &inRay, const SubShapeIDCreator &inSubShapeIDCreator, RayCastResult &ioHit) const override;
78 virtual void CastRay(const RayCast &inRay, const RayCastSettings &inRayCastSettings, const SubShapeIDCreator &inSubShapeIDCreator, CastRayCollector &ioCollector, const ShapeFilter &inShapeFilter = { }) const override;
79
80 // See: Shape::CollidePoint
81 virtual void CollidePoint(Vec3Arg inPoint, const SubShapeIDCreator &inSubShapeIDCreator, CollidePointCollector &ioCollector, const ShapeFilter &inShapeFilter = { }) const override;
82
83 // See: Shape::CollideSoftBodyVertices
84 virtual void CollideSoftBodyVertices(Mat44Arg inCenterOfMassTransform, Vec3Arg inScale, const CollideSoftBodyVertexIterator &inVertices, uint inNumVertices, int inCollidingShapeIndex) const override;
85
86 // See Shape::GetTrianglesStart
87 virtual void GetTrianglesStart(GetTrianglesContext &ioContext, const AABox &inBox, Vec3Arg inPositionCOM, QuatArg inRotation, Vec3Arg inScale) const override;
88
89 // See Shape::GetTrianglesNext
90 virtual int GetTrianglesNext(GetTrianglesContext &ioContext, int inMaxTrianglesRequested, Float3 *outTriangleVertices, const PhysicsMaterial **outMaterials = nullptr) const override;
91
92 // See Shape
93 virtual void SaveBinaryState(StreamOut &inStream) const override;
94
95 // See Shape::GetStats
96 virtual Stats GetStats() const override { return Stats(sizeof(*this), 0); }
97
98 // See Shape::GetVolume
99 virtual float GetVolume() const override { return 4.0f / 3.0f * JPH_PI * Cubed(mRadius); }
100
101 // See Shape::IsValidScale
102 virtual bool IsValidScale(Vec3Arg inScale) const override;
103
104 // See Shape::MakeScaleValid
105 virtual Vec3 MakeScaleValid(Vec3Arg inScale) const override;
106
107 // Register shape functions with the registry
108 static void sRegister();
109
110 protected:
111 // See: Shape::RestoreBinaryState
112 virtual void RestoreBinaryState(StreamIn &inStream) override;
113
114 private:
115 // Get the radius of this sphere scaled by inScale
116 inline float GetScaledRadius(Vec3Arg inScale) const;
117
118 // Classes for GetSupportFunction
119 class SphereNoConvex;
120 class SphereWithConvex;
121
122 float mRadius = 0.0f;
123 };
124
125 JPH_NAMESPACE_END