diff options
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(); |