Debian Codegraph @

thirdparty/jolt_physics/Jolt/Physics/Collision/Shape/BoxShape.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 #include <Jolt/Physics/PhysicsSettings.h>
9
10 JPH_NAMESPACE_BEGIN
11
12 /// Class that constructs a BoxShape
13 class JPH_EXPORT BoxShapeSettings final : public ConvexShapeSettings
14 {
15 JPH_DECLARE_SERIALIZABLE_VIRTUAL(JPH_EXPORT, BoxShapeSettings)
16
17 public:
18 /// Default constructor for deserialization
19 BoxShapeSettings() = default;
20
21 /// Create a box with half edge length inHalfExtent and convex radius inConvexRadius.
22 /// (internally the convex radius will be subtracted from the half extent so the total box will not grow with the convex radius).
23 BoxShapeSettings(Vec3Arg inHalfExtent, float inConvexRadius = cDefaultConvexRadius, const PhysicsMaterial *inMaterial = nullptr) : ConvexShapeSettings(inMaterial), mHalfExtent(inHalfExtent), mConvexRadius(inConvexRadius) { }
24
25 // See: ShapeSettings
26 virtual ShapeResult Create() const override;
27
28 Vec3 mHalfExtent = Vec3::sZero(); ///< Half the size of the box (including convex radius)
29 float mConvexRadius = 0.0f;
30 };
31
32 /// A box, centered around the origin
33 class JPH_EXPORT BoxShape final : public ConvexShape
34 {
35 public:
36 JPH_OVERRIDE_NEW_DELETE
37
38 /// Constructor
39 BoxShape() : ConvexShape(EShapeSubType::Box) { }
40 BoxShape(const BoxShapeSettings &inSettings, ShapeResult &outResult);
41
42 /// Create a box with half edge length inHalfExtent and convex radius inConvexRadius.
43 /// (internally the convex radius will be subtracted from the half extent so the total box will not grow with the convex radius).
44 BoxShape(Vec3Arg inHalfExtent, float inConvexRadius = cDefaultConvexRadius, const PhysicsMaterial *inMaterial = nullptr) : ConvexShape(EShapeSubType::Box, inMaterial), mHalfExtent(inHalfExtent), mConvexRadius(inConvexRadius) { JPH_ASSERT(inConvexRadius >= 0.0f); JPH_ASSERT(inHalfExtent.ReduceMin() >= inConvexRadius); }
45
46 /// Get half extent of box
47 Vec3 GetHalfExtent() const { return mHalfExtent; }
48
49 // See Shape::GetLocalBounds
50 virtual AABox GetLocalBounds() const override { return AABox(-mHalfExtent, mHalfExtent); }
51
52 // See Shape::GetInnerRadius
53 virtual float GetInnerRadius() const override { return mHalfExtent.ReduceMin(); }
54
55 // See Shape::GetMassProperties
56 virtual MassProperties GetMassProperties() const override;
57
58 // See Shape::GetSurfaceNormal
59 virtual Vec3 GetSurfaceNormal(const SubShapeID &inSubShapeID, Vec3Arg inLocalSurfacePosition) const override;
60
61 // See Shape::GetSupportingFace
62 virtual void GetSupportingFace(const SubShapeID &inSubShapeID, Vec3Arg inDirection, Vec3Arg inScale, Mat44Arg inCenterOfMassTransform, SupportingFace &outVertices) const override;
63
64 // See ConvexShape::GetSupportFunction
65 virtual const Support * GetSupportFunction(ESupportMode inMode, SupportBuffer &inBuffer, Vec3Arg inScale) const override;
66
67 #ifdef JPH_DEBUG_RENDERER
68 // See Shape::Draw
69 virtual void Draw(DebugRenderer *inRenderer, RMat44Arg inCenterOfMassTransform, Vec3Arg inScale, ColorArg inColor, bool inUseMaterialColors, bool inDrawWireframe) const override;
70 #endif // JPH_DEBUG_RENDERER
71
72 // See Shape::CastRay
73 virtual bool CastRay(const RayCast &inRay, const SubShapeIDCreator &inSubShapeIDCreator, RayCastResult &ioHit) const override;
74 virtual void CastRay(const RayCast &inRay, const RayCastSettings &inRayCastSettings, const SubShapeIDCreator &inSubShapeIDCreator, CastRayCollector &ioCollector, const ShapeFilter &inShapeFilter = { }) const override;
75
76 // See: Shape::CollidePoint
77 virtual void CollidePoint(Vec3Arg inPoint, const SubShapeIDCreator &inSubShapeIDCreator, CollidePointCollector &ioCollector, const ShapeFilter &inShapeFilter = { }) const override;
78
79 // See: Shape::CollideSoftBodyVertices
80 virtual void CollideSoftBodyVertices(Mat44Arg inCenterOfMassTransform, Vec3Arg inScale, const CollideSoftBodyVertexIterator &inVertices, uint inNumVertices, int inCollidingShapeIndex) const override;
81
82 // See Shape::GetTrianglesStart
83 virtual void GetTrianglesStart(GetTrianglesContext &ioContext, const AABox &inBox, Vec3Arg inPositionCOM, QuatArg inRotation, Vec3Arg inScale) const override;
84
85 // See Shape::GetTrianglesNext
86 virtual int GetTrianglesNext(GetTrianglesContext &ioContext, int inMaxTrianglesRequested, Float3 *outTriangleVertices, const PhysicsMaterial **outMaterials = nullptr) const override;
87
88 // See Shape
89 virtual void SaveBinaryState(StreamOut &inStream) const override;
90
91 // See Shape::GetStats
92 virtual Stats GetStats() const override { return Stats(sizeof(*this), 12); }
93
94 // See Shape::GetVolume
95 virtual float GetVolume() const override { return GetLocalBounds().GetVolume(); }
96
97 /// Get the convex radius of this box
98 float GetConvexRadius() const { return mConvexRadius; }
99
100 // Register shape functions with the registry
101 static void sRegister();
102
103 protected:
104 // See: Shape::RestoreBinaryState
105 virtual void RestoreBinaryState(StreamIn &inStream) override;
106
107 private:
108 // Class for GetSupportFunction
109 class Box;
110
111 Vec3 mHalfExtent = Vec3::sZero(); ///< Half the size of the box (including convex radius)
112 float mConvexRadius = 0.0f;
113 };
114
115 JPH_NAMESPACE_END