From 25e346070eed819f5d08864a3fe37b7a0189d0ba Mon Sep 17 00:00:00 2001 From: Matthew Kosarek Date: Thu, 22 Apr 2021 20:11:32 -0400 Subject: Realized ellipse interactions were not easy, going to try and at least finish rectangle and circles before end of month --- frontend/2d/_collisions/pill_pill/dist/output.wasm | Bin 41813 -> 42555 bytes frontend/2d/_collisions/pill_pill/main.cpp | 37 +++++++++++++++++++++ 2 files changed, 37 insertions(+) (limited to 'frontend/2d/_collisions/pill_pill') diff --git a/frontend/2d/_collisions/pill_pill/dist/output.wasm b/frontend/2d/_collisions/pill_pill/dist/output.wasm index df92665..c616709 100755 Binary files a/frontend/2d/_collisions/pill_pill/dist/output.wasm and b/frontend/2d/_collisions/pill_pill/dist/output.wasm 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(); -- cgit v1.2.1