diff options
author | Matthew Kosarek <mattkae@protonmail.com> | 2021-04-22 20:11:32 -0400 |
---|---|---|
committer | Matthew Kosarek <mattkae@protonmail.com> | 2021-04-22 20:11:32 -0400 |
commit | 25e346070eed819f5d08864a3fe37b7a0189d0ba (patch) | |
tree | 68b8f77ef0da3d2562c45be3f9b5fc53dae53ac9 /frontend/2d/_collisions/pill_pill | |
parent | 6d1f2aa2c3dd5db7a6435fe16e03d8df5e016775 (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-x | frontend/2d/_collisions/pill_pill/dist/output.wasm | bin | 41813 -> 42555 bytes | |||
-rw-r--r-- | frontend/2d/_collisions/pill_pill/main.cpp | 37 |
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 Binary files differindex df92665..c616709 100755 --- a/frontend/2d/_collisions/pill_pill/dist/output.wasm +++ b/frontend/2d/_collisions/pill_pill/dist/output.wasm 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(); |