summaryrefslogtreecommitdiff
path: root/frontend/2d/_collisions/pill_pill
diff options
context:
space:
mode:
authorMatthew Kosarek <mattkae@protonmail.com>2021-04-22 20:11:32 -0400
committerMatthew Kosarek <mattkae@protonmail.com>2021-04-22 20:11:32 -0400
commit25e346070eed819f5d08864a3fe37b7a0189d0ba (patch)
tree68b8f77ef0da3d2562c45be3f9b5fc53dae53ac9 /frontend/2d/_collisions/pill_pill
parent6d1f2aa2c3dd5db7a6435fe16e03d8df5e016775 (diff)
Realized ellipse interactions were not easy, going to try and at least finish rectangle and circles before end of month
Diffstat (limited to 'frontend/2d/_collisions/pill_pill')
-rwxr-xr-xfrontend/2d/_collisions/pill_pill/dist/output.wasmbin41813 -> 42555 bytes
-rw-r--r--frontend/2d/_collisions/pill_pill/main.cpp37
2 files changed, 37 insertions, 0 deletions
diff --git a/frontend/2d/_collisions/pill_pill/dist/output.wasm b/frontend/2d/_collisions/pill_pill/dist/output.wasm
index df92665..c616709 100755
--- a/frontend/2d/_collisions/pill_pill/dist/output.wasm
+++ b/frontend/2d/_collisions/pill_pill/dist/output.wasm
Binary files differ
diff --git a/frontend/2d/_collisions/pill_pill/main.cpp b/frontend/2d/_collisions/pill_pill/main.cpp
index aeae066..1aef594 100644
--- a/frontend/2d/_collisions/pill_pill/main.cpp
+++ b/frontend/2d/_collisions/pill_pill/main.cpp
@@ -125,6 +125,14 @@ struct Pill {
}
};
+struct IntersectionResult {
+ bool intersect = false;
+ Vector2 collisionNormal;
+ Vector2 relativeVelocity;
+ Vector2 firstPointOfApplication;
+ Vector2 secondPointOfApplication;
+};
+
EM_BOOL onPlayClicked(int eventType, const EmscriptenMouseEvent* mouseEvent, void* userData);
EM_BOOL onStopClicked(int eventType, const EmscriptenMouseEvent* mouseEvent, void* userData);
@@ -168,12 +176,41 @@ void load() {
mainLoop.run(update);
}
+IntersectionResult getIntersection(Pill* first, Pill* second) {
+ IntersectionResult ir;
+
+ float32 a1 = first->a;
+ float32 b1 = first->b;
+ float32 a1Squared = a1 * a1;
+ float32 b1Squared = b1 * b1;
+ float32 a1Quad = a1Squared * a1Squared;
+ float32 b1Quad = b1Squared * b1Squared;
+
+ float32 a2 = second->a;
+ float32 b2 = second->b;
+ float32 a2Squared = a2 * a2;
+ float32 b2Squared = b2 * b2;
+ float32 a2Quad = a2Squared * a2Squared;
+ float32 b2Quad = b2Squared * b2Squared;
+
+ float32 A = (b1Quad / (a1Quad * b2Squared));
+ float32 B = (2.f * b1Quad) / (a1Squared * b2Squared) + (1.f / a1Squared);
+ float32 C = (b1Quad / b2Squared) - 1.f;
+
+ float32 determinant = (B * B) - (4.f * A * C);
+ printf("%f\n", determinant);
+
+ return ir;
+}
+
void update(float32 deltaTimeSeconds, void* userData) {
// Update
for (int32 pillIdx = 0; pillIdx < 2; pillIdx++) {
pillList[pillIdx].update(deltaTimeSeconds);
}
+ getIntersection(&pillList[0], &pillList[1]);
+
// Render
renderer.render();