Path: blob/master/thirdparty/jolt_physics/Jolt/Physics/Collision/Shape/BoxShape.h
9917 views
// Jolt Physics Library (https://github.com/jrouwe/JoltPhysics)1// SPDX-FileCopyrightText: 2021 Jorrit Rouwe2// SPDX-License-Identifier: MIT34#pragma once56#include <Jolt/Physics/Collision/Shape/ConvexShape.h>7#include <Jolt/Physics/PhysicsSettings.h>89JPH_NAMESPACE_BEGIN1011/// Class that constructs a BoxShape12class JPH_EXPORT BoxShapeSettings final : public ConvexShapeSettings13{14JPH_DECLARE_SERIALIZABLE_VIRTUAL(JPH_EXPORT, BoxShapeSettings)1516public:17/// Default constructor for deserialization18BoxShapeSettings() = default;1920/// Create a box with half edge length inHalfExtent and convex radius inConvexRadius.21/// (internally the convex radius will be subtracted from the half extent so the total box will not grow with the convex radius).22BoxShapeSettings(Vec3Arg inHalfExtent, float inConvexRadius = cDefaultConvexRadius, const PhysicsMaterial *inMaterial = nullptr) : ConvexShapeSettings(inMaterial), mHalfExtent(inHalfExtent), mConvexRadius(inConvexRadius) { }2324// See: ShapeSettings25virtual ShapeResult Create() const override;2627Vec3 mHalfExtent = Vec3::sZero(); ///< Half the size of the box (including convex radius)28float mConvexRadius = 0.0f;29};3031/// A box, centered around the origin32class JPH_EXPORT BoxShape final : public ConvexShape33{34public:35JPH_OVERRIDE_NEW_DELETE3637/// Constructor38BoxShape() : ConvexShape(EShapeSubType::Box) { }39BoxShape(const BoxShapeSettings &inSettings, ShapeResult &outResult);4041/// Create a box with half edge length inHalfExtent and convex radius inConvexRadius.42/// (internally the convex radius will be subtracted from the half extent so the total box will not grow with the convex radius).43BoxShape(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); }4445/// Get half extent of box46Vec3 GetHalfExtent() const { return mHalfExtent; }4748// See Shape::GetLocalBounds49virtual AABox GetLocalBounds() const override { return AABox(-mHalfExtent, mHalfExtent); }5051// See Shape::GetInnerRadius52virtual float GetInnerRadius() const override { return mHalfExtent.ReduceMin(); }5354// See Shape::GetMassProperties55virtual MassProperties GetMassProperties() const override;5657// See Shape::GetSurfaceNormal58virtual Vec3 GetSurfaceNormal(const SubShapeID &inSubShapeID, Vec3Arg inLocalSurfacePosition) const override;5960// See Shape::GetSupportingFace61virtual void GetSupportingFace(const SubShapeID &inSubShapeID, Vec3Arg inDirection, Vec3Arg inScale, Mat44Arg inCenterOfMassTransform, SupportingFace &outVertices) const override;6263// See ConvexShape::GetSupportFunction64virtual const Support * GetSupportFunction(ESupportMode inMode, SupportBuffer &inBuffer, Vec3Arg inScale) const override;6566#ifdef JPH_DEBUG_RENDERER67// See Shape::Draw68virtual void Draw(DebugRenderer *inRenderer, RMat44Arg inCenterOfMassTransform, Vec3Arg inScale, ColorArg inColor, bool inUseMaterialColors, bool inDrawWireframe) const override;69#endif // JPH_DEBUG_RENDERER7071// See Shape::CastRay72virtual bool CastRay(const RayCast &inRay, const SubShapeIDCreator &inSubShapeIDCreator, RayCastResult &ioHit) const override;73virtual void CastRay(const RayCast &inRay, const RayCastSettings &inRayCastSettings, const SubShapeIDCreator &inSubShapeIDCreator, CastRayCollector &ioCollector, const ShapeFilter &inShapeFilter = { }) const override;7475// See: Shape::CollidePoint76virtual void CollidePoint(Vec3Arg inPoint, const SubShapeIDCreator &inSubShapeIDCreator, CollidePointCollector &ioCollector, const ShapeFilter &inShapeFilter = { }) const override;7778// See: Shape::CollideSoftBodyVertices79virtual void CollideSoftBodyVertices(Mat44Arg inCenterOfMassTransform, Vec3Arg inScale, const CollideSoftBodyVertexIterator &inVertices, uint inNumVertices, int inCollidingShapeIndex) const override;8081// See Shape::GetTrianglesStart82virtual void GetTrianglesStart(GetTrianglesContext &ioContext, const AABox &inBox, Vec3Arg inPositionCOM, QuatArg inRotation, Vec3Arg inScale) const override;8384// See Shape::GetTrianglesNext85virtual int GetTrianglesNext(GetTrianglesContext &ioContext, int inMaxTrianglesRequested, Float3 *outTriangleVertices, const PhysicsMaterial **outMaterials = nullptr) const override;8687// See Shape88virtual void SaveBinaryState(StreamOut &inStream) const override;8990// See Shape::GetStats91virtual Stats GetStats() const override { return Stats(sizeof(*this), 12); }9293// See Shape::GetVolume94virtual float GetVolume() const override { return GetLocalBounds().GetVolume(); }9596/// Get the convex radius of this box97float GetConvexRadius() const { return mConvexRadius; }9899// Register shape functions with the registry100static void sRegister();101102protected:103// See: Shape::RestoreBinaryState104virtual void RestoreBinaryState(StreamIn &inStream) override;105106private:107// Class for GetSupportFunction108class Box;109110Vec3 mHalfExtent = Vec3::sZero(); ///< Half the size of the box (including convex radius)111float mConvexRadius = 0.0f;112};113114JPH_NAMESPACE_END115116117