Path: blob/master/thirdparty/jolt_physics/Jolt/Physics/Collision/Shape/CylinderShape.h
9913 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 CylinderShape12class JPH_EXPORT CylinderShapeSettings final : public ConvexShapeSettings13{14JPH_DECLARE_SERIALIZABLE_VIRTUAL(JPH_EXPORT, CylinderShapeSettings)1516public:17/// Default constructor for deserialization18CylinderShapeSettings() = default;1920/// Create a shape centered around the origin with one top at (0, -inHalfHeight, 0) and the other at (0, inHalfHeight, 0) and radius inRadius.21/// (internally the convex radius will be subtracted from the cylinder the total cylinder will not grow with the convex radius, but the edges of the cylinder will be rounded a bit).22CylinderShapeSettings(float inHalfHeight, float inRadius, float inConvexRadius = cDefaultConvexRadius, const PhysicsMaterial *inMaterial = nullptr) : ConvexShapeSettings(inMaterial), mHalfHeight(inHalfHeight), mRadius(inRadius), mConvexRadius(inConvexRadius) { }2324// See: ShapeSettings25virtual ShapeResult Create() const override;2627float mHalfHeight = 0.0f;28float mRadius = 0.0f;29float mConvexRadius = 0.0f;30};3132/// A cylinder33class JPH_EXPORT CylinderShape final : public ConvexShape34{35public:36JPH_OVERRIDE_NEW_DELETE3738/// Constructor39CylinderShape() : ConvexShape(EShapeSubType::Cylinder) { }40CylinderShape(const CylinderShapeSettings &inSettings, ShapeResult &outResult);4142/// Create a shape centered around the origin with one top at (0, -inHalfHeight, 0) and the other at (0, inHalfHeight, 0) and radius inRadius.43/// (internally the convex radius will be subtracted from the cylinder the total cylinder will not grow with the convex radius, but the edges of the cylinder will be rounded a bit).44CylinderShape(float inHalfHeight, float inRadius, float inConvexRadius = cDefaultConvexRadius, const PhysicsMaterial *inMaterial = nullptr);4546/// Get half height of cylinder47float GetHalfHeight() const { return mHalfHeight; }4849/// Get radius of cylinder50float GetRadius() const { return mRadius; }5152// See Shape::GetLocalBounds53virtual AABox GetLocalBounds() const override;5455// See Shape::GetInnerRadius56virtual float GetInnerRadius() const override { return min(mHalfHeight, mRadius); }5758// See Shape::GetMassProperties59virtual MassProperties GetMassProperties() const override;6061// See Shape::GetSurfaceNormal62virtual Vec3 GetSurfaceNormal(const SubShapeID &inSubShapeID, Vec3Arg inLocalSurfacePosition) const override;6364// See Shape::GetSupportingFace65virtual void GetSupportingFace(const SubShapeID &inSubShapeID, Vec3Arg inDirection, Vec3Arg inScale, Mat44Arg inCenterOfMassTransform, SupportingFace &outVertices) const override;6667// See ConvexShape::GetSupportFunction68virtual const Support * GetSupportFunction(ESupportMode inMode, SupportBuffer &inBuffer, Vec3Arg inScale) const override;6970#ifdef JPH_DEBUG_RENDERER71// See Shape::Draw72virtual void Draw(DebugRenderer *inRenderer, RMat44Arg inCenterOfMassTransform, Vec3Arg inScale, ColorArg inColor, bool inUseMaterialColors, bool inDrawWireframe) const override;73#endif // JPH_DEBUG_RENDERER7475// See Shape::CastRay76using ConvexShape::CastRay;77virtual bool CastRay(const RayCast &inRay, const SubShapeIDCreator &inSubShapeIDCreator, RayCastResult &ioHit) const override;7879// See: Shape::CollidePoint80virtual void CollidePoint(Vec3Arg inPoint, const SubShapeIDCreator &inSubShapeIDCreator, CollidePointCollector &ioCollector, const ShapeFilter &inShapeFilter = { }) const override;8182// See: Shape::CollideSoftBodyVertices83virtual void CollideSoftBodyVertices(Mat44Arg inCenterOfMassTransform, Vec3Arg inScale, const CollideSoftBodyVertexIterator &inVertices, uint inNumVertices, int inCollidingShapeIndex) const override;8485// See Shape::GetTrianglesStart86virtual void GetTrianglesStart(GetTrianglesContext &ioContext, const AABox &inBox, Vec3Arg inPositionCOM, QuatArg inRotation, Vec3Arg inScale) const override;8788// See Shape::GetTrianglesNext89virtual int GetTrianglesNext(GetTrianglesContext &ioContext, int inMaxTrianglesRequested, Float3 *outTriangleVertices, const PhysicsMaterial **outMaterials = nullptr) const override;9091// See Shape92virtual void SaveBinaryState(StreamOut &inStream) const override;9394// See Shape::GetStats95virtual Stats GetStats() const override { return Stats(sizeof(*this), 0); }9697// See Shape::GetVolume98virtual float GetVolume() const override { return 2.0f * JPH_PI * mHalfHeight * Square(mRadius); }99100/// Get the convex radius of this cylinder101float GetConvexRadius() const { return mConvexRadius; }102103// See Shape::IsValidScale104virtual bool IsValidScale(Vec3Arg inScale) const override;105106// See Shape::MakeScaleValid107virtual Vec3 MakeScaleValid(Vec3Arg inScale) const override;108109// Register shape functions with the registry110static void sRegister();111112protected:113// See: Shape::RestoreBinaryState114virtual void RestoreBinaryState(StreamIn &inStream) override;115116private:117// Class for GetSupportFunction118class Cylinder;119120float mHalfHeight = 0.0f;121float mRadius = 0.0f;122float mConvexRadius = 0.0f;123};124125JPH_NAMESPACE_END126127128