Debian Codegraph @

thirdparty/jolt_physics/Jolt/Physics/Collision/Shape/TriangleShape.h

raw symbols SCIP
1 // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics)
2 // SPDX-FileCopyrightText: 2021 Jorrit Rouwe
3 // SPDX-License-Identifier: MIT
4
5 #pragma once
6
7 #include <Jolt/Physics/Collision/Shape/ConvexShape.h>
8
9 JPH_NAMESPACE_BEGIN
10
11 /// Class that constructs a TriangleShape
12 class JPH_EXPORT TriangleShapeSettings final : public ConvexShapeSettings
13 {
14 JPH_DECLARE_SERIALIZABLE_VIRTUAL(JPH_EXPORT, TriangleShapeSettings)
15
16 public:
17 /// Default constructor for deserialization
18 TriangleShapeSettings() = default;
19
20 /// Create a triangle with points (inV1, inV2, inV3) (counter clockwise) and convex radius inConvexRadius.
21 /// Note that the convex radius is currently only used for shape vs shape collision, for all other purposes the triangle is infinitely thin.
22 TriangleShapeSettings(Vec3Arg inV1, Vec3Arg inV2, Vec3Arg inV3, float inConvexRadius = 0.0f, const PhysicsMaterial *inMaterial = nullptr) : ConvexShapeSettings(inMaterial), mV1(inV1), mV2(inV2), mV3(inV3), mConvexRadius(inConvexRadius) { }
23
24 // See: ShapeSettings
25 virtual ShapeResult Create() const override;
26
27 Vec3 mV1;
28 Vec3 mV2;
29 Vec3 mV3;
30 float mConvexRadius = 0.0f;
31 };
32
33 /// 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.
34 class JPH_EXPORT TriangleShape final : public ConvexShape
35 {
36 public:
37 JPH_OVERRIDE_NEW_DELETE
38
39 /// Constructor
40 TriangleShape() : ConvexShape(EShapeSubType::Triangle) { }
41 TriangleShape(const TriangleShapeSettings &inSettings, ShapeResult &outResult);
42
43 /// Create a triangle with points (inV1, inV2, inV3) (counter clockwise) and convex radius inConvexRadius.
44 /// Note that the convex radius is currently only used for shape vs shape collision, for all other purposes the triangle is infinitely thin.
45 TriangleShape(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); }
46
47 /// Get the vertices of the triangle
48 inline Vec3 GetVertex1() const { return mV1; }
49 inline Vec3 GetVertex2() const { return mV2; }
50 inline Vec3 GetVertex3() const { return mV3; }
51
52 /// Convex radius
53 float GetConvexRadius() const { return mConvexRadius; }
54
55 // See Shape::GetLocalBounds
56 virtual AABox GetLocalBounds() const override;
57
58 // See Shape::GetWorldSpaceBounds
59 virtual AABox GetWorldSpaceBounds(Mat44Arg inCenterOfMassTransform, Vec3Arg inScale) const override;
60 using Shape::GetWorldSpaceBounds;
61
62 // See Shape::GetInnerRadius
63 virtual float GetInnerRadius() const override { return mConvexRadius; }
64
65 // See Shape::GetMassProperties
66 virtual MassProperties GetMassProperties() const override;
67
68 // See Shape::GetSurfaceNormal
69 virtual Vec3 GetSurfaceNormal(const SubShapeID &inSubShapeID, Vec3Arg inLocalSurfacePosition) const override;
70
71 // See Shape::GetSupportingFace
72 virtual void GetSupportingFace(const SubShapeID &inSubShapeID, Vec3Arg inDirection, Vec3Arg inScale, Mat44Arg inCenterOfMassTransform, SupportingFace &outVertices) const override;
73
74 // See ConvexShape::GetSupportFunction
75 virtual const Support * GetSupportFunction(ESupportMode inMode, SupportBuffer &inBuffer, Vec3Arg inScale) const override;
76
77 // See Shape::GetSubmergedVolume
78 virtual void GetSubmergedVolume(Mat44Arg inCenterOfMassTransform, Vec3Arg inScale, const Plane &inSurface, float &outTotalVolume, float &outSubmergedVolume, Vec3 &outCenterOfBuoyancy JPH_IF_DEBUG_RENDERER(, RVec3Arg inBaseOffset)) const override;
79
80 #ifdef JPH_DEBUG_RENDERER
81 // See Shape::Draw
82 virtual void Draw(DebugRenderer *inRenderer, RMat44Arg inCenterOfMassTransform, Vec3Arg inScale, ColorArg inColor, bool inUseMaterialColors, bool inDrawWireframe) const override;
83 #endif // JPH_DEBUG_RENDERER
84
85 // See Shape::CastRay
86 virtual bool CastRay(const RayCast &inRay, const SubShapeIDCreator &inSubShapeIDCreator, RayCastResult &ioHit) const override;
87 virtual void CastRay(const RayCast &inRay, const RayCastSettings &inRayCastSettings, const SubShapeIDCreator &inSubShapeIDCreator, CastRayCollector &ioCollector, const ShapeFilter &inShapeFilter = { }) const override;
88
89 // See: Shape::CollidePoint
90 virtual void CollidePoint(Vec3Arg inPoint, const SubShapeIDCreator &inSubShapeIDCreator, CollidePointCollector &ioCollector, const ShapeFilter &inShapeFilter = { }) const override;
91
92 // See: Shape::CollideSoftBodyVertices
93 virtual void CollideSoftBodyVertices(Mat44Arg inCenterOfMassTransform, Vec3Arg inScale, const CollideSoftBodyVertexIterator &inVertices, uint inNumVertices, int inCollidingShapeIndex) const override;
94
95 // See Shape::GetTrianglesStart
96 virtual void GetTrianglesStart(GetTrianglesContext &ioContext, const AABox &inBox, Vec3Arg inPositionCOM, QuatArg inRotation, Vec3Arg inScale) const override;
97
98 // See Shape::GetTrianglesNext
99 virtual int GetTrianglesNext(GetTrianglesContext &ioContext, int inMaxTrianglesRequested, Float3 *outTriangleVertices, const PhysicsMaterial **outMaterials = nullptr) const override;
100
101 // See Shape
102 virtual void SaveBinaryState(StreamOut &inStream) const override;
103
104 // See Shape::GetStats
105 virtual Stats GetStats() const override { return Stats(sizeof(*this), 1); }
106
107 // See Shape::GetVolume
108 virtual float GetVolume() const override { return 0; }
109
110 // See Shape::IsValidScale
111 virtual bool IsValidScale(Vec3Arg inScale) const override;
112
113 // See Shape::MakeScaleValid
114 virtual Vec3 MakeScaleValid(Vec3Arg inScale) const override;
115
116 // Register shape functions with the registry
117 static void sRegister();
118
119 protected:
120 // See: Shape::RestoreBinaryState
121 virtual void RestoreBinaryState(StreamIn &inStream) override;
122
123 private:
124 // Helper functions called by CollisionDispatch
125 static 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);
126 static 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);
127 static 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);
128 static 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);
129
130 // Context for GetTrianglesStart/Next
131 class TSGetTrianglesContext;
132
133 // Classes for GetSupportFunction
134 class TriangleNoConvex;
135 class TriangleWithConvex;
136
137 Vec3 mV1;
138 Vec3 mV2;
139 Vec3 mV3;
140 float mConvexRadius = 0.0f;
141 };
142
143 JPH_NAMESPACE_END