Path: blob/master/thirdparty/jolt_physics/Jolt/Physics/Collision/Shape/TaperedCylinderShape.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/ConvexShape.h>7#include <Jolt/Physics/PhysicsSettings.h>89JPH_NAMESPACE_BEGIN1011/// Class that constructs a TaperedCylinderShape12class JPH_EXPORT TaperedCylinderShapeSettings final : public ConvexShapeSettings13{14JPH_DECLARE_SERIALIZABLE_VIRTUAL(JPH_EXPORT, TaperedCylinderShapeSettings)1516public:17/// Default constructor for deserialization18TaperedCylinderShapeSettings() = default;1920/// Create a tapered cylinder centered around the origin with bottom at (0, -inHalfHeightOfTaperedCylinder, 0) with radius inBottomRadius and top at (0, inHalfHeightOfTaperedCylinder, 0) with radius inTopRadius21TaperedCylinderShapeSettings(float inHalfHeightOfTaperedCylinder, float inTopRadius, float inBottomRadius, float inConvexRadius = cDefaultConvexRadius, const PhysicsMaterial *inMaterial = nullptr);2223// See: ShapeSettings24virtual ShapeResult Create() const override;2526float mHalfHeight = 0.0f;27float mTopRadius = 0.0f;28float mBottomRadius = 0.0f;29float mConvexRadius = 0.0f;30};3132/// A cylinder with different top and bottom radii33class JPH_EXPORT TaperedCylinderShape final : public ConvexShape34{35public:36JPH_OVERRIDE_NEW_DELETE3738/// Constructor39TaperedCylinderShape() : ConvexShape(EShapeSubType::TaperedCylinder) { }40TaperedCylinderShape(const TaperedCylinderShapeSettings &inSettings, ShapeResult &outResult);4142/// Get top radius of the tapered cylinder43inline float GetTopRadius() const { return mTopRadius; }4445/// Get bottom radius of the tapered cylinder46inline float GetBottomRadius() const { return mBottomRadius; }4748/// Get convex radius of the tapered cylinder49inline float GetConvexRadius() const { return mConvexRadius; }5051/// Get half height of the tapered cylinder52inline float GetHalfHeight() const { return 0.5f * (mTop - mBottom); }5354// See Shape::GetCenterOfMass55virtual Vec3 GetCenterOfMass() const override { return Vec3(0, -0.5f * (mTop + mBottom), 0); }5657// See Shape::GetLocalBounds58virtual AABox GetLocalBounds() const override;5960// See Shape::GetInnerRadius61virtual float GetInnerRadius() const override { return min(mTopRadius, mBottomRadius); }6263// See Shape::GetMassProperties64virtual MassProperties GetMassProperties() const override;6566// See Shape::GetSurfaceNormal67virtual Vec3 GetSurfaceNormal(const SubShapeID &inSubShapeID, Vec3Arg inLocalSurfacePosition) const override;6869// See Shape::GetSupportingFace70virtual void GetSupportingFace(const SubShapeID &inSubShapeID, Vec3Arg inDirection, Vec3Arg inScale, Mat44Arg inCenterOfMassTransform, SupportingFace &outVertices) const override;7172// See ConvexShape::GetSupportFunction73virtual const Support * GetSupportFunction(ESupportMode inMode, SupportBuffer &inBuffer, Vec3Arg inScale) 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#ifdef JPH_DEBUG_RENDERER88// See Shape::Draw89virtual void Draw(DebugRenderer *inRenderer, RMat44Arg inCenterOfMassTransform, Vec3Arg inScale, ColorArg inColor, bool inUseMaterialColors, bool inDrawWireframe) const override;90#endif // JPH_DEBUG_RENDERER9192// See Shape93virtual void SaveBinaryState(StreamOut &inStream) const override;9495// See Shape::GetStats96virtual Stats GetStats() const override { return Stats(sizeof(*this), 0); }9798// See Shape::GetVolume99virtual float GetVolume() const override;100101// See Shape::IsValidScale102virtual bool IsValidScale(Vec3Arg inScale) const override;103104// See Shape::MakeScaleValid105virtual Vec3 MakeScaleValid(Vec3Arg inScale) const override;106107// Register shape functions with the registry108static void sRegister();109110protected:111// See: Shape::RestoreBinaryState112virtual void RestoreBinaryState(StreamIn &inStream) override;113114private:115// Class for GetSupportFunction116class TaperedCylinder;117118// Class for GetTrianglesTart119class TCSGetTrianglesContext;120121// Scale the cylinder122JPH_INLINE void GetScaled(Vec3Arg inScale, float &outTop, float &outBottom, float &outTopRadius, float &outBottomRadius, float &outConvexRadius) const;123124float mTop = 0.0f;125float mBottom = 0.0f;126float mTopRadius = 0.0f;127float mBottomRadius = 0.0f;128float mConvexRadius = 0.0f;129};130131JPH_NAMESPACE_END132133134