aboutsummaryrefslogtreecommitdiff
path: root/Client/Source/Phy2D/Dynamic/Arbiter.h
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2021-11-30 22:25:37 +0800
committerchai <chaifix@163.com>2021-11-30 22:25:37 +0800
commit9e0e01b7f4375063f06e494113187d48614628e0 (patch)
tree21a4901612ad92c121f4c887a33b1bbbe87c6b00 /Client/Source/Phy2D/Dynamic/Arbiter.h
+init
Diffstat (limited to 'Client/Source/Phy2D/Dynamic/Arbiter.h')
-rw-r--r--Client/Source/Phy2D/Dynamic/Arbiter.h91
1 files changed, 91 insertions, 0 deletions
diff --git a/Client/Source/Phy2D/Dynamic/Arbiter.h b/Client/Source/Phy2D/Dynamic/Arbiter.h
new file mode 100644
index 0000000..b02b413
--- /dev/null
+++ b/Client/Source/Phy2D/Dynamic/Arbiter.h
@@ -0,0 +1,91 @@
+#pragma once
+
+#include "../Common/Math.h"
+
+namespace Phy2D
+{
+
+ struct Body;
+
+ union FeaturePair
+ {
+ struct Edges
+ {
+ char inEdge1;
+ char outEdge1;
+ char inEdge2;
+ char outEdge2;
+ } e;
+ int value;
+ };
+
+ struct Contact
+ {
+ Contact() : Pn(0.0f), Pt(0.0f), Pnb(0.0f) {}
+
+ Vec2 position;
+ Vec2 normal;
+ Vec2 r1, r2;
+ number separation;
+ number Pn; // accumulated normal impulse
+ number Pt; // accumulated tangent impulse
+ number Pnb; // accumulated normal impulse for position bias
+ number massNormal, massTangent;
+ number bias;
+ FeaturePair feature;
+ };
+
+ struct ArbiterKey
+ {
+ ArbiterKey(Body* b1, Body* b2)
+ {
+ if (b1 < b2)
+ {
+ body1 = b1; body2 = b2;
+ }
+ else
+ {
+ body1 = b2; body2 = b1;
+ }
+ }
+
+ Body* body1;
+ Body* body2;
+ };
+
+ struct Arbiter
+ {
+ enum { MAX_POINTS = 2 };
+
+ Arbiter(Body* b1, Body* b2);
+
+ void Update(Contact* contacts, int numContacts);
+
+ void PreStep(number inv_dt);
+ void ApplyImpulse();
+
+ Contact contacts[MAX_POINTS];
+ int numContacts;
+
+ Body* body1;
+ Body* body2;
+
+ // Combined friction
+ number friction;
+ };
+
+ // This is used by std::set
+ inline bool operator < (const ArbiterKey& a1, const ArbiterKey& a2)
+ {
+ if (a1.body1 < a2.body1)
+ return true;
+
+ if (a1.body1 == a2.body1 && a1.body2 < a2.body2)
+ return true;
+
+ return false;
+ }
+
+ int Collide(Contact* contacts, Body* body1, Body* body2);
+
+} \ No newline at end of file