Path: blob/master/thirdparty/jolt_physics/Jolt/Physics/Collision/Shape/EmptyShape.h
9913 views
// Jolt Physics Library (https://github.com/jrouwe/JoltPhysics)1// SPDX-FileCopyrightText: 2024 Jorrit Rouwe2// SPDX-License-Identifier: MIT34#pragma once56#include <Jolt/Physics/Collision/Shape/Shape.h>7#include <Jolt/Physics/Collision/PhysicsMaterial.h>89JPH_NAMESPACE_BEGIN1011/// Class that constructs an EmptyShape12class JPH_EXPORT EmptyShapeSettings final : public ShapeSettings13{14JPH_DECLARE_SERIALIZABLE_VIRTUAL(JPH_EXPORT, EmptyShapeSettings)1516public:17EmptyShapeSettings() = default;18explicit EmptyShapeSettings(Vec3Arg inCenterOfMass) : mCenterOfMass(inCenterOfMass) { }1920ShapeResult Create() const override;2122Vec3 mCenterOfMass = Vec3::sZero(); ///< Determines the center of mass for this shape23};2425/// An empty shape that has no volume and collides with nothing.26///27/// Possible use cases:28/// - 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.29/// - If you need a kinematic body to attach a constraint to, but you don't want the body to collide with anything.30///31/// Note that, if possible, you should also put your body in an ObjectLayer that doesn't collide with anything.32/// This ensures that collisions will be filtered out at broad phase level instead of at narrow phase level, this is more efficient.33class JPH_EXPORT EmptyShape final : public Shape34{35public:36// Constructor37EmptyShape() : Shape(EShapeType::Empty, EShapeSubType::Empty) { }38explicit EmptyShape(Vec3Arg inCenterOfMass) : Shape(EShapeType::Empty, EShapeSubType::Empty), mCenterOfMass(inCenterOfMass) { }39EmptyShape(const EmptyShapeSettings &inSettings, ShapeResult &outResult) : Shape(EShapeType::Empty, EShapeSubType::Empty, inSettings, outResult), mCenterOfMass(inSettings.mCenterOfMass) { outResult.Set(this); }4041// See: Shape42Vec3 GetCenterOfMass() const override { return mCenterOfMass; }43AABox GetLocalBounds() const override { return { Vec3::sZero(), Vec3::sZero() }; }44uint GetSubShapeIDBitsRecursive() const override { return 0; }45float GetInnerRadius() const override { return 0.0f; }46MassProperties GetMassProperties() const override;47const PhysicsMaterial * GetMaterial([[maybe_unused]] const SubShapeID &inSubShapeID) const override { return PhysicsMaterial::sDefault; }48virtual Vec3 GetSurfaceNormal(const SubShapeID &inSubShapeID, Vec3Arg inLocalSurfacePosition) const override { return Vec3::sZero(); }49virtual void GetSubmergedVolume(Mat44Arg inCenterOfMassTransform, Vec3Arg inScale, const Plane &inSurface, float &outTotalVolume, float &outSubmergedVolume, Vec3 &outCenterOfBuoyancy50#ifdef JPH_DEBUG_RENDERER // Not using JPH_IF_DEBUG_RENDERER for Doxygen51, RVec3Arg inBaseOffset52#endif53) const override { outTotalVolume = 0.0f; outSubmergedVolume = 0.0f; outCenterOfBuoyancy = Vec3::sZero(); }54#ifdef JPH_DEBUG_RENDERER55virtual 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;56#endif // JPH_DEBUG_RENDERER57virtual bool CastRay([[maybe_unused]] const RayCast &inRay, [[maybe_unused]] const SubShapeIDCreator &inSubShapeIDCreator, [[maybe_unused]] RayCastResult &ioHit) const override { return false; }58virtual 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 */ }59virtual void CollidePoint([[maybe_unused]] Vec3Arg inPoint, [[maybe_unused]] const SubShapeIDCreator &inSubShapeIDCreator, [[maybe_unused]] CollidePointCollector &ioCollector, [[maybe_unused]] const ShapeFilter &inShapeFilter = { }) const override { /* Do nothing */ }60virtual 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 */ }61virtual 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 */ }62virtual int GetTrianglesNext([[maybe_unused]] GetTrianglesContext &ioContext, [[maybe_unused]] int inMaxTrianglesRequested, [[maybe_unused]] Float3 *outTriangleVertices, [[maybe_unused]] const PhysicsMaterial **outMaterials = nullptr) const override { return 0; }63Stats GetStats() const override { return { sizeof(*this), 0 }; }64float GetVolume() const override { return 0.0f; }65bool IsValidScale([[maybe_unused]] Vec3Arg inScale) const override { return true; }6667// Register shape functions with the registry68static void sRegister();6970private:71Vec3 mCenterOfMass = Vec3::sZero();72};7374JPH_NAMESPACE_END757677