Path: blob/master/thirdparty/jolt_physics/Jolt/Physics/Collision/Shape/TriangleShape.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>78JPH_NAMESPACE_BEGIN910/// Class that constructs a TriangleShape11class JPH_EXPORT TriangleShapeSettings final : public ConvexShapeSettings12{13JPH_DECLARE_SERIALIZABLE_VIRTUAL(JPH_EXPORT, TriangleShapeSettings)1415public:16/// Default constructor for deserialization17TriangleShapeSettings() = default;1819/// Create a triangle with points (inV1, inV2, inV3) (counter clockwise) and convex radius inConvexRadius.20/// Note that the convex radius is currently only used for shape vs shape collision, for all other purposes the triangle is infinitely thin.21TriangleShapeSettings(Vec3Arg inV1, Vec3Arg inV2, Vec3Arg inV3, float inConvexRadius = 0.0f, const PhysicsMaterial *inMaterial = nullptr) : ConvexShapeSettings(inMaterial), mV1(inV1), mV2(inV2), mV3(inV3), mConvexRadius(inConvexRadius) { }2223// See: ShapeSettings24virtual ShapeResult Create() const override;2526Vec3 mV1;27Vec3 mV2;28Vec3 mV3;29float mConvexRadius = 0.0f;30};3132/// A single triangle, not the most efficient way of creating a world filled with triangles but can be used as a query shape for example.33class JPH_EXPORT TriangleShape final : public ConvexShape34{35public:36JPH_OVERRIDE_NEW_DELETE3738/// Constructor39TriangleShape() : ConvexShape(EShapeSubType::Triangle) { }40TriangleShape(const TriangleShapeSettings &inSettings, ShapeResult &outResult);4142/// Create a triangle with points (inV1, inV2, inV3) (counter clockwise) and convex radius inConvexRadius.43/// Note that the convex radius is currently only used for shape vs shape collision, for all other purposes the triangle is infinitely thin.44TriangleShape(Vec3Arg inV1, Vec3Arg inV2, Vec3Arg inV3, float inConvexRadius = 0.0f, const PhysicsMaterial *inMaterial = nullptr) : ConvexShape(EShapeSubType::Triangle, inMaterial), mV1(inV1), mV2(inV2), mV3(inV3), mConvexRadius(inConvexRadius) { JPH_ASSERT(inConvexRadius >= 0.0f); }4546/// Get the vertices of the triangle47inline Vec3 GetVertex1() const { return mV1; }48inline Vec3 GetVertex2() const { return mV2; }49inline Vec3 GetVertex3() const { return mV3; }5051/// Convex radius52float GetConvexRadius() const { return mConvexRadius; }5354// See Shape::GetLocalBounds55virtual AABox GetLocalBounds() const override;5657// See Shape::GetWorldSpaceBounds58virtual AABox GetWorldSpaceBounds(Mat44Arg inCenterOfMassTransform, Vec3Arg inScale) const override;59using Shape::GetWorldSpaceBounds;6061// See Shape::GetInnerRadius62virtual float GetInnerRadius() const override { return mConvexRadius; }6364// See Shape::GetMassProperties65virtual MassProperties GetMassProperties() const override;6667// See Shape::GetSurfaceNormal68virtual Vec3 GetSurfaceNormal(const SubShapeID &inSubShapeID, Vec3Arg inLocalSurfacePosition) const override;6970// See Shape::GetSupportingFace71virtual void GetSupportingFace(const SubShapeID &inSubShapeID, Vec3Arg inDirection, Vec3Arg inScale, Mat44Arg inCenterOfMassTransform, SupportingFace &outVertices) const override;7273// See ConvexShape::GetSupportFunction74virtual const Support * GetSupportFunction(ESupportMode inMode, SupportBuffer &inBuffer, Vec3Arg inScale) const override;7576// See Shape::GetSubmergedVolume77virtual void GetSubmergedVolume(Mat44Arg inCenterOfMassTransform, Vec3Arg inScale, const Plane &inSurface, float &outTotalVolume, float &outSubmergedVolume, Vec3 &outCenterOfBuoyancy JPH_IF_DEBUG_RENDERER(, RVec3Arg inBaseOffset)) const override;7879#ifdef JPH_DEBUG_RENDERER80// See Shape::Draw81virtual void Draw(DebugRenderer *inRenderer, RMat44Arg inCenterOfMassTransform, Vec3Arg inScale, ColorArg inColor, bool inUseMaterialColors, bool inDrawWireframe) const override;82#endif // JPH_DEBUG_RENDERER8384// See Shape::CastRay85virtual bool CastRay(const RayCast &inRay, const SubShapeIDCreator &inSubShapeIDCreator, RayCastResult &ioHit) const override;86virtual void CastRay(const RayCast &inRay, const RayCastSettings &inRayCastSettings, const SubShapeIDCreator &inSubShapeIDCreator, CastRayCollector &ioCollector, const ShapeFilter &inShapeFilter = { }) const override;8788// See: Shape::CollidePoint89virtual void CollidePoint(Vec3Arg inPoint, const SubShapeIDCreator &inSubShapeIDCreator, CollidePointCollector &ioCollector, const ShapeFilter &inShapeFilter = { }) const override;9091// See: Shape::CollideSoftBodyVertices92virtual void CollideSoftBodyVertices(Mat44Arg inCenterOfMassTransform, Vec3Arg inScale, const CollideSoftBodyVertexIterator &inVertices, uint inNumVertices, int inCollidingShapeIndex) const override;9394// See Shape::GetTrianglesStart95virtual void GetTrianglesStart(GetTrianglesContext &ioContext, const AABox &inBox, Vec3Arg inPositionCOM, QuatArg inRotation, Vec3Arg inScale) const override;9697// See Shape::GetTrianglesNext98virtual int GetTrianglesNext(GetTrianglesContext &ioContext, int inMaxTrianglesRequested, Float3 *outTriangleVertices, const PhysicsMaterial **outMaterials = nullptr) const override;99100// See Shape101virtual void SaveBinaryState(StreamOut &inStream) const override;102103// See Shape::GetStats104virtual Stats GetStats() const override { return Stats(sizeof(*this), 1); }105106// See Shape::GetVolume107virtual float GetVolume() const override { return 0; }108109// See Shape::IsValidScale110virtual bool IsValidScale(Vec3Arg inScale) const override;111112// See Shape::MakeScaleValid113virtual Vec3 MakeScaleValid(Vec3Arg inScale) const override;114115// Register shape functions with the registry116static void sRegister();117118protected:119// See: Shape::RestoreBinaryState120virtual void RestoreBinaryState(StreamIn &inStream) override;121122private:123// Helper functions called by CollisionDispatch124static void sCollideConvexVsTriangle(const Shape *inShape1, const Shape *inShape2, Vec3Arg inScale1, Vec3Arg inScale2, Mat44Arg inCenterOfMassTransform1, Mat44Arg inCenterOfMassTransform2, const SubShapeIDCreator &inSubShapeIDCreator1, const SubShapeIDCreator &inSubShapeIDCreator2, const CollideShapeSettings &inCollideShapeSettings, CollideShapeCollector &ioCollector, const ShapeFilter &inShapeFilter);125static void sCollideSphereVsTriangle(const Shape *inShape1, const Shape *inShape2, Vec3Arg inScale1, Vec3Arg inScale2, Mat44Arg inCenterOfMassTransform1, Mat44Arg inCenterOfMassTransform2, const SubShapeIDCreator &inSubShapeIDCreator1, const SubShapeIDCreator &inSubShapeIDCreator2, const CollideShapeSettings &inCollideShapeSettings, CollideShapeCollector &ioCollector, const ShapeFilter &inShapeFilter);126static void sCastConvexVsTriangle(const ShapeCast &inShapeCast, const ShapeCastSettings &inShapeCastSettings, const Shape *inShape, Vec3Arg inScale, const ShapeFilter &inShapeFilter, Mat44Arg inCenterOfMassTransform2, const SubShapeIDCreator &inSubShapeIDCreator1, const SubShapeIDCreator &inSubShapeIDCreator2, CastShapeCollector &ioCollector);127static void sCastSphereVsTriangle(const ShapeCast &inShapeCast, const ShapeCastSettings &inShapeCastSettings, const Shape *inShape, Vec3Arg inScale, const ShapeFilter &inShapeFilter, Mat44Arg inCenterOfMassTransform2, const SubShapeIDCreator &inSubShapeIDCreator1, const SubShapeIDCreator &inSubShapeIDCreator2, CastShapeCollector &ioCollector);128129// Context for GetTrianglesStart/Next130class TSGetTrianglesContext;131132// Classes for GetSupportFunction133class TriangleNoConvex;134class TriangleWithConvex;135136Vec3 mV1;137Vec3 mV2;138Vec3 mV3;139float mConvexRadius = 0.0f;140};141142JPH_NAMESPACE_END143144145