Jolt Physics
A multi core friendly Game Physics Engine
Loading...
Searching...
No Matches
ConvexHullBuilder2D.h
Go to the documentation of this file.
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
8
9//#define JPH_CONVEX_BUILDER_2D_DEBUG
10
12
15{
16public:
19
22 explicit ConvexHullBuilder2D(const Positions &inPositions);
23
26
28 enum class EResult
29 {
30 Success,
31 MaxVerticesReached,
32 };
33
41 EResult Initialize(int inIdx1, int inIdx2, int inIdx3, int inMaxVertices, float inTolerance, Edges &outEdges);
42
43private:
44#ifdef JPH_CONVEX_BUILDER_2D_DEBUG
46 static constexpr Real cDrawScale = 10;
47#endif
48
49 class Edge;
50
52 void FreeEdges();
53
57 void AssignPointToEdge(int inPositionIdx, const Array<Edge *> &inEdges) const;
58
59#ifdef JPH_CONVEX_BUILDER_2D_DEBUG
61 void DrawState();
62#endif
63
64#ifdef JPH_ENABLE_ASSERTS
66 void ValidateEdges() const;
67#endif
68
69 using ConflictList = Array<int>;
70
72 class Edge
73 {
74 public:
76
78 explicit Edge(int inStartIdx) : mStartIdx(inStartIdx) { }
79
81 void CalculateNormalAndCenter(const Vec3 *inPositions);
82
84 inline bool IsFacing(Vec3Arg inPosition) const { return mNormal.Dot(inPosition - mCenter) > 0.0f; }
85
86 Vec3 mNormal;
87 Vec3 mCenter;
88 ConflictList mConflictList;
89 Edge * mPrevEdge = nullptr;
90 Edge * mNextEdge = nullptr;
91 int mStartIdx;
92 float mFurthestPointDistanceSq = 0.0f;
93 };
94
95 const Positions & mPositions;
96 Edge * mFirstEdge = nullptr;
97 int mNumEdges = 0;
98
99#ifdef JPH_CONVEX_BUILDER_2D_DEBUG
100 RVec3 mOffset;
101 Vec3 mDelta;
102#endif
103};
104
#define JPH_EXPORT
Definition: Core.h:236
#define JPH_NAMESPACE_END
Definition: Core.h:378
#define JPH_NAMESPACE_BEGIN
Definition: Core.h:372
#define JPH_OVERRIDE_NEW_DELETE
Macro to override the new and delete functions.
Definition: Memory.h:31
float Real
Definition: Real.h:27
A convex hull builder that tries to create 2D hulls as accurately as possible. Used for offline proce...
Definition: ConvexHullBuilder2D.h:15
EResult
Result enum that indicates how the hull got created.
Definition: ConvexHullBuilder2D.h:29
Class that makes another class non-copyable. Usage: Inherit from NonCopyable.
Definition: NonCopyable.h:11
Definition: Vec3.h:17