Path: blob/master/thirdparty/jolt_physics/Jolt/Physics/Collision/Shape/TaperedCapsuleShape.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#ifdef JPH_DEBUG_RENDERER8#include <Jolt/Renderer/DebugRenderer.h>9#endif // JPH_DEBUG_RENDERER1011JPH_NAMESPACE_BEGIN1213/// Class that constructs a TaperedCapsuleShape14class JPH_EXPORT TaperedCapsuleShapeSettings final : public ConvexShapeSettings15{16JPH_DECLARE_SERIALIZABLE_VIRTUAL(JPH_EXPORT, TaperedCapsuleShapeSettings)1718public:19/// Default constructor for deserialization20TaperedCapsuleShapeSettings() = default;2122/// Create a tapered capsule centered around the origin with one sphere cap at (0, -inHalfHeightOfTaperedCylinder, 0) with radius inBottomRadius and the other at (0, inHalfHeightOfTaperedCylinder, 0) with radius inTopRadius23TaperedCapsuleShapeSettings(float inHalfHeightOfTaperedCylinder, float inTopRadius, float inBottomRadius, const PhysicsMaterial *inMaterial = nullptr);2425/// Check if the settings are valid26bool IsValid() const { return mTopRadius > 0.0f && mBottomRadius > 0.0f && mHalfHeightOfTaperedCylinder >= 0.0f; }2728/// Checks if the settings of this tapered capsule make this shape a sphere29bool IsSphere() const;3031// See: ShapeSettings32virtual ShapeResult Create() const override;3334float mHalfHeightOfTaperedCylinder = 0.0f;35float mTopRadius = 0.0f;36float mBottomRadius = 0.0f;37};3839/// A capsule with different top and bottom radii40class JPH_EXPORT TaperedCapsuleShape final : public ConvexShape41{42public:43JPH_OVERRIDE_NEW_DELETE4445/// Constructor46TaperedCapsuleShape() : ConvexShape(EShapeSubType::TaperedCapsule) { }47TaperedCapsuleShape(const TaperedCapsuleShapeSettings &inSettings, ShapeResult &outResult);4849/// Get top radius of the tapered capsule50inline float GetTopRadius() const { return mTopRadius; }5152/// Get bottom radius of the tapered capsule53inline float GetBottomRadius() const { return mBottomRadius; }5455/// Get half height between the top and bottom sphere center56inline float GetHalfHeight() const { return 0.5f * (mTopCenter - mBottomCenter); }5758// See Shape::GetCenterOfMass59virtual Vec3 GetCenterOfMass() const override { return mCenterOfMass; }6061// See Shape::GetLocalBounds62virtual AABox GetLocalBounds() const override;6364// See Shape::GetWorldSpaceBounds65virtual AABox GetWorldSpaceBounds(Mat44Arg inCenterOfMassTransform, Vec3Arg inScale) const override;66using Shape::GetWorldSpaceBounds;6768// See Shape::GetInnerRadius69virtual float GetInnerRadius() const override { return min(mTopRadius, mBottomRadius); }7071// See Shape::GetMassProperties72virtual MassProperties GetMassProperties() const override;7374// See Shape::GetSurfaceNormal75virtual Vec3 GetSurfaceNormal(const SubShapeID &inSubShapeID, Vec3Arg inLocalSurfacePosition) const override;7677// See Shape::GetSupportingFace78virtual void GetSupportingFace(const SubShapeID &inSubShapeID, Vec3Arg inDirection, Vec3Arg inScale, Mat44Arg inCenterOfMassTransform, SupportingFace &outVertices) const override;7980// See ConvexShape::GetSupportFunction81virtual const Support * GetSupportFunction(ESupportMode inMode, SupportBuffer &inBuffer, Vec3Arg inScale) const override;8283// See: Shape::CollideSoftBodyVertices84virtual void CollideSoftBodyVertices(Mat44Arg inCenterOfMassTransform, Vec3Arg inScale, const CollideSoftBodyVertexIterator &inVertices, uint inNumVertices, int inCollidingShapeIndex) const override;8586#ifdef JPH_DEBUG_RENDERER87// See Shape::Draw88virtual void Draw(DebugRenderer *inRenderer, RMat44Arg inCenterOfMassTransform, Vec3Arg inScale, ColorArg inColor, bool inUseMaterialColors, bool inDrawWireframe) const override;89#endif // JPH_DEBUG_RENDERER9091// 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 GetLocalBounds().GetVolume(); } // Volume is approximate!99100// See Shape::IsValidScale101virtual bool IsValidScale(Vec3Arg inScale) const override;102103// See Shape::MakeScaleValid104virtual Vec3 MakeScaleValid(Vec3Arg inScale) const override;105106// Register shape functions with the registry107static void sRegister();108109protected:110// See: Shape::RestoreBinaryState111virtual void RestoreBinaryState(StreamIn &inStream) override;112113private:114// Class for GetSupportFunction115class TaperedCapsule;116117/// Returns box that approximates the inertia118AABox GetInertiaApproximation() const;119120Vec3 mCenterOfMass = Vec3::sZero();121float mTopRadius = 0.0f;122float mBottomRadius = 0.0f;123float mTopCenter = 0.0f;124float mBottomCenter = 0.0f;125float mConvexRadius = 0.0f;126float mSinAlpha = 0.0f;127float mTanAlpha = 0.0f;128129#ifdef JPH_DEBUG_RENDERER130mutable DebugRenderer::GeometryRef mGeometry;131#endif // JPH_DEBUG_RENDERER132};133134JPH_NAMESPACE_END135136137