summaryrefslogtreecommitdiff
path: root/2d/_collisions/polygon_polygon/main.cpp
diff options
context:
space:
mode:
Diffstat (limited to '2d/_collisions/polygon_polygon/main.cpp')
-rw-r--r--2d/_collisions/polygon_polygon/main.cpp23
1 files changed, 22 insertions, 1 deletions
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 <cmath>
#include <cfloat>
+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;
+}