Debian Codegraph @

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

raw symbols SCIP
1 // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics)
2 // SPDX-FileCopyrightText: 2024 Jorrit Rouwe
3 // SPDX-License-Identifier: MIT
4
5 #pragma once
6
7 #include <Jolt/Physics/Collision/Shape/Shape.h>
8 #include <Jolt/Physics/Collision/PhysicsMaterial.h>
9
10 JPH_NAMESPACE_BEGIN
11
12 /// Class that constructs an EmptyShape
13 class JPH_EXPORT EmptyShapeSettings final : public ShapeSettings
14 {
15 JPH_DECLARE_SERIALIZABLE_VIRTUAL(JPH_EXPORT, EmptyShapeSettings)
16
17 public:
18 EmptyShapeSettings() = default;
19 explicit EmptyShapeSettings(Vec3Arg inCenterOfMass) : mCenterOfMass(inCenterOfMass) { }
20
21 ShapeResult Create() const override;
22
23 Vec3 mCenterOfMass = Vec3::sZero(); ///< Determines the center of mass for this shape
24 };
25
26 /// An empty shape that has no volume and collides with nothing.
27 ///
28 /// Possible use cases:
29 /// - As a placeholder for a shape that will be created later. E.g. if you first need to create a body and only then know what shape it will have.
30 /// - If you need a kinematic body to attach a constraint to, but you don't want the body to collide with anything.
31 ///
32 /// Note that, if possible, you should also put your body in an ObjectLayer that doesn't collide with anything.
33 /// This ensures that collisions will be filtered out at broad phase level instead of at narrow phase level, this is more efficient.
34 class JPH_EXPORT EmptyShape final : public Shape
35 {
36 public:
37 // Constructor
38 EmptyShape() : Shape(EShapeType::Empty, EShapeSubType::Empty) { }
39 explicit EmptyShape(Vec3Arg inCenterOfMass) : Shape(EShapeType::Empty, EShapeSubType::Empty), mCenterOfMass(inCenterOfMass) { }
40 EmptyShape(const EmptyShapeSettings &inSettings, ShapeResult &outResult) : Shape(EShapeType::Empty, EShapeSubType::Empty, inSettings, outResult), mCenterOfMass(inSettings.mCenterOfMass) { outResult.Set(this); }
41
42 // See: Shape
43 Vec3 GetCenterOfMass() const override { return mCenterOfMass; }
44 AABox GetLocalBounds() const override { return { Vec3::sZero(), Vec3::sZero() }; }
45 uint GetSubShapeIDBitsRecursive() const override { return 0; }
46 float GetInnerRadius() const override { return 0.0f; }
47 MassProperties GetMassProperties() const override;
48 const PhysicsMaterial * GetMaterial([[maybe_unused]] const SubShapeID &inSubShapeID) const override { return PhysicsMaterial::sDefault; }
49 virtual Vec3 GetSurfaceNormal(const SubShapeID &inSubShapeID, Vec3Arg inLocalSurfacePosition) const override { return Vec3::sZero(); }
50 virtual void GetSubmergedVolume(Mat44Arg inCenterOfMassTransform, Vec3Arg inScale, const Plane &inSurface, float &outTotalVolume, float &outSubmergedVolume, Vec3 &outCenterOfBuoyancy
51 #ifdef JPH_DEBUG_RENDERER // Not using JPH_IF_DEBUG_RENDERER for Doxygen
52 , RVec3Arg inBaseOffset
53 #endif
54 ) const override { outTotalVolume = 0.0f; outSubmergedVolume = 0.0f; outCenterOfBuoyancy = Vec3::sZero(); }
55 #ifdef JPH_DEBUG_RENDERER
56 virtual void Draw([[maybe_unused]] DebugRenderer *inRenderer, [[maybe_unused]] RMat44Arg inCenterOfMassTransform, [[maybe_unused]] Vec3Arg inScale, [[maybe_unused]] ColorArg inColor, [[maybe_unused]] bool inUseMaterialColors, [[maybe_unused]] bool inDrawWireframe) const override;
57 #endif // JPH_DEBUG_RENDERER
58 virtual bool CastRay([[maybe_unused]] const RayCast &inRay, [[maybe_unused]] const SubShapeIDCreator &inSubShapeIDCreator, [[maybe_unused]] RayCastResult &ioHit) const override { return false; }
59 virtual void CastRay([[maybe_unused]] const RayCast &inRay, [[maybe_unused]] const RayCastSettings &inRayCastSettings, [[maybe_unused]] const SubShapeIDCreator &inSubShapeIDCreator, [[maybe_unused]] CastRayCollector &ioCollector, [[maybe_unused]] const ShapeFilter &inShapeFilter = { }) const override { /* Do nothing */ }
60 virtual void CollidePoint([[maybe_unused]] Vec3Arg inPoint, [[maybe_unused]] const SubShapeIDCreator &inSubShapeIDCreator, [[maybe_unused]] CollidePointCollector &ioCollector, [[maybe_unused]] const ShapeFilter &inShapeFilter = { }) const override { /* Do nothing */ }
61 virtual void CollideSoftBodyVertices([[maybe_unused]] Mat44Arg inCenterOfMassTransform, [[maybe_unused]] Vec3Arg inScale, [[maybe_unused]] const CollideSoftBodyVertexIterator &inVertices, [[maybe_unused]] uint inNumVertices, [[maybe_unused]] int inCollidingShapeIndex) const override { /* Do nothing */ }
62 virtual void GetTrianglesStart([[maybe_unused]] GetTrianglesContext &ioContext, [[maybe_unused]] const AABox &inBox, [[maybe_unused]] Vec3Arg inPositionCOM, [[maybe_unused]] QuatArg inRotation, [[maybe_unused]] Vec3Arg inScale) const override { /* Do nothing */ }
63 virtual int GetTrianglesNext([[maybe_unused]] GetTrianglesContext &ioContext, [[maybe_unused]] int inMaxTrianglesRequested, [[maybe_unused]] Float3 *outTriangleVertices, [[maybe_unused]] const PhysicsMaterial **outMaterials = nullptr) const override { return 0; }
64 Stats GetStats() const override { return { sizeof(*this), 0 }; }
65 float GetVolume() const override { return 0.0f; }
66 bool IsValidScale([[maybe_unused]] Vec3Arg inScale) const override { return true; }
67
68 // Register shape functions with the registry
69 static void sRegister();
70
71 private:
72 Vec3 mCenterOfMass = Vec3::sZero();
73 };
74
75 JPH_NAMESPACE_END