From a56ccb7392f9f7d0178c17fcef0bf60a1e7de705 Mon Sep 17 00:00:00 2001 From: Matthew Kosarek Date: Tue, 6 Jul 2021 20:24:05 -0400 Subject: (mkosarek) Done enough with SAT collisions for now --- 2d/_collisions/polygon_polygon/dist/output.wasm | Bin 57746 -> 58079 bytes 2d/_collisions/polygon_polygon/main.cpp | 23 ++++++++++++++++++++++- 2d/_collisions/polygon_polygon/snippet2.cpp | 2 ++ 3 files changed, 24 insertions(+), 1 deletion(-) (limited to '2d/_collisions/polygon_polygon') diff --git a/2d/_collisions/polygon_polygon/dist/output.wasm b/2d/_collisions/polygon_polygon/dist/output.wasm index f4ef9bb..a047d19 100755 Binary files a/2d/_collisions/polygon_polygon/dist/output.wasm and b/2d/_collisions/polygon_polygon/dist/output.wasm differ diff --git a/2d/_collisions/polygon_polygon/main.cpp b/2d/_collisions/polygon_polygon/main.cpp index e85cc25..620edaa 100644 --- a/2d/_collisions/polygon_polygon/main.cpp +++ b/2d/_collisions/polygon_polygon/main.cpp @@ -11,6 +11,8 @@ #include #include +float32 gravityDirection = -1; + struct Impulse { Vector2 force = { 0, 0 }; float32 timeOfApplicationSeconds = 0.25f; @@ -52,7 +54,7 @@ struct Rigidbody { } void applyGravity(float32 deltaTimeSeconds) { - velocity += (Vector2 { 0.f, -9.8f } * deltaTimeSeconds); + velocity += (Vector2 { 0.f, gravityDirection * 100.f } * deltaTimeSeconds); } void update(float32 deltaTimeSeconds) { @@ -204,6 +206,7 @@ struct ConvexPolygon { EM_BOOL onPlayClicked(int eventType, const EmscriptenMouseEvent* mouseEvent, void* userData); EM_BOOL onStopClicked(int eventType, const EmscriptenMouseEvent* mouseEvent, void* userData); +EM_BOOL onGravityReversed(int eventType, const EmscriptenMouseEvent* mouseEvent, void* userData);; void load(); void update(float32 time, void* userData); @@ -218,6 +221,7 @@ int main() { context.init("#gl_canvas"); emscripten_set_click_callback("#gl_canvas_play", NULL, false, onPlayClicked); emscripten_set_click_callback("#gl_canvas_stop", NULL, false, onStopClicked); + emscripten_set_click_callback("#reverse_gravity", NULL, false, onGravityReversed); return 0; } @@ -269,12 +273,19 @@ struct SATResult { struct ProjectionResult { Vector2 minVertex; + Vector2 minAdjacent1; + Vector2 minAdjacent2; + Vector2 maxVertex; + Vector2 maxAdjacent1; + Vector2 maxAdjacent2; Vector2 projection; }; ProjectionResult getProjection(Vector2* vertices, int numVertices, Vector2 axis) { ProjectionResult pr; + pr.minVertex = vertices[0]; + pr.maxVertex = vertices[0]; float32 min = axis.dot(vertices[0]); float32 max = min; @@ -334,6 +345,10 @@ bool runSatForShapesEdges(SATResult* result, ConvexPolygon* first, ConvexPolygon } else { result->overlapPoint = secondProj.maxVertex; } + + // Check if the normal from one of the edges of the overlap point is nearly perpendicular + // to the edge that you have intersected with. If so, let's call the point of intersection + // the middle of the edge. } } @@ -497,3 +512,9 @@ EM_BOOL onStopClicked(int eventType, const EmscriptenMouseEvent* mouseEvent, voi unload(); return true; } + +EM_BOOL onGravityReversed(int eventType, const EmscriptenMouseEvent* mouseEvent, void* userData) { + printf("Reversing gravity\n"); + gravityDirection = -gravityDirection; + return true; +} diff --git a/2d/_collisions/polygon_polygon/snippet2.cpp b/2d/_collisions/polygon_polygon/snippet2.cpp index a279f65..c182060 100644 --- a/2d/_collisions/polygon_polygon/snippet2.cpp +++ b/2d/_collisions/polygon_polygon/snippet2.cpp @@ -29,6 +29,8 @@ struct ProjectionResult { // the collision later. ProjectionResult getProjection(Vector2* vertices, int numVertices, Vector2 axis) { ProjectionResult pr; + pr.minVertex = vertices[0]; + pr.maxVertex = vertices[0]; float32 min = axis.dot(vertices[0]); float32 max = min; -- cgit v1.2.1