diff options
author | Matthew Kosarek <mattkae@protonmail.com> | 2021-05-19 20:22:03 -0400 |
---|---|---|
committer | Matthew Kosarek <mattkae@protonmail.com> | 2021-05-19 20:22:03 -0400 |
commit | e431c58c0e5bde1689ef0be0d02588ee22c99c82 (patch) | |
tree | 21ca931d46a8b5bf779418536e2a5fca52ed42dd /2d | |
parent | a7ac3adcb70bc40e79e31de2bb466201417be12e (diff) |
Ignoring general SAT rotations for now, going to focus on redoing the original demos
Diffstat (limited to '2d')
-rwxr-xr-x | 2d/_collisions/polygon_polygon/dist/output.wasm | bin | 56810 -> 56473 bytes | |||
-rw-r--r-- | 2d/_collisions/polygon_polygon/main.cpp | 11 | ||||
-rwxr-xr-x | 2d/_collisions/rectangle_rectangle/dist/output.wasm | bin | 55607 -> 55719 bytes | |||
-rw-r--r-- | 2d/_collisions/rectangle_rectangle/main.cpp | 8 |
4 files changed, 15 insertions, 4 deletions
diff --git a/2d/_collisions/polygon_polygon/dist/output.wasm b/2d/_collisions/polygon_polygon/dist/output.wasm Binary files differindex e355676..d008042 100755 --- a/2d/_collisions/polygon_polygon/dist/output.wasm +++ b/2d/_collisions/polygon_polygon/dist/output.wasm diff --git a/2d/_collisions/polygon_polygon/main.cpp b/2d/_collisions/polygon_polygon/main.cpp index 916a057..b928f02 100644 --- a/2d/_collisions/polygon_polygon/main.cpp +++ b/2d/_collisions/polygon_polygon/main.cpp @@ -331,12 +331,13 @@ void resolveCollision(Rigidbody* first, Rigidbody* second, IntersectionResult* i float32 linearDenomPart = collisionNormal.dot(collisionNormal * (1.f / first->mass + 1.f / second->mass)); float32 rotationalDenomPart = (firstPerpNorm * firstPerpNorm) / first->momentOfInertia + (sndPerpNorm * sndPerpNorm) / second->momentOfInertia; - float32 impulseMagnitude = numerator / (linearDenomPart + rotationalDenomPart); + // @TODO: Most of my 2D rotational work is pretty broken. Let's ignore it for the time being; + float32 impulseMagnitude = numerator / (linearDenomPart);// + rotationalDenomPart); first->velocity = first->velocity + (collisionNormal * (impulseMagnitude / first->mass)); second->velocity = second->velocity - (collisionNormal * (impulseMagnitude / second->mass)); - first->rotationalVelocity = first->rotationalVelocity + firstPerp.dot(collisionNormal * impulseMagnitude) / first->momentOfInertia; - second->rotationalVelocity = second->rotationalVelocity - secondPerp.dot(collisionNormal * impulseMagnitude) / second->momentOfInertia; + // first->rotationalVelocity = first->rotationalVelocity + firstPerp.dot(collisionNormal * impulseMagnitude) / first->momentOfInertia; + // second->rotationalVelocity = second->rotationalVelocity - secondPerp.dot(collisionNormal * impulseMagnitude) / second->momentOfInertia; } void update(float32 deltaTimeSeconds, void* userData) { @@ -393,15 +394,19 @@ void update(float32 deltaTimeSeconds, void* userData) { for (int p = 0; p < 4; p++) { ConvexPolygon* polygon = &polygons[p]; if (polygon->body.position.x <= 0.f) { + polygon->body.position.x = 0.f; polygon->body.velocity = polygon->body.velocity - Vector2 { 1.f, 0.f } * (2 * (polygon->body.velocity.dot(Vector2 { 1.f, 0.f }))); } if (polygon->body.position.y <= 0.f) { + polygon->body.position.y = 0.f; polygon->body.velocity = polygon->body.velocity - Vector2 { 0.f, 1.f } * (2 * (polygon->body.velocity.dot(Vector2 { 0.f, 1.f }))); } if (polygon->body.position.x >= 640.f) { + polygon->body.position.x = 640.f; polygon->body.velocity = polygon->body.velocity - Vector2 { -1.f, 0.f } * (2 * (polygon->body.velocity.dot(Vector2{ -1.f, 0.f }))); } if (polygon->body.position.y >= 480.f) { + polygon->body.position.y = 480.f; polygon->body.velocity = polygon->body.velocity - Vector2 { 0.f, -1.f } * (2 * (polygon->body.velocity.dot(Vector2 { 0.f, -1.f }))) ; } } diff --git a/2d/_collisions/rectangle_rectangle/dist/output.wasm b/2d/_collisions/rectangle_rectangle/dist/output.wasm Binary files differindex 5a17a67..f61e371 100755 --- a/2d/_collisions/rectangle_rectangle/dist/output.wasm +++ b/2d/_collisions/rectangle_rectangle/dist/output.wasm diff --git a/2d/_collisions/rectangle_rectangle/main.cpp b/2d/_collisions/rectangle_rectangle/main.cpp index 99dafe5..689ea11 100644 --- a/2d/_collisions/rectangle_rectangle/main.cpp +++ b/2d/_collisions/rectangle_rectangle/main.cpp @@ -398,19 +398,25 @@ void update(float32 deltaTimeSeconds, void* userData) { } } - // Check collisions with walls + // Check collisions with walls. + // @NOTE: Setting the position backwards by a small amount _could_ move it into another object, but we are ignoring that circumstance + // for now, as it is very unlikely. for (int r = 0; r < 4; r++) { Rectangle* rect = &rectangleList[r]; if (rect->body.position.x <= 0.f) { + rect->body.position.x = 0.f; rect->body.velocity = rect->body.velocity - Vector2 { 1.f, 0.f } * (2 * (rect->body.velocity.dot(Vector2 { 1.f, 0.f }))); } if (rect->body.position.y <= 0.f) { + rect->body.position.y = 0.f; rect->body.velocity = rect->body.velocity - Vector2 { 0.f, 1.f } * (2 * (rect->body.velocity.dot(Vector2 { 0.f, 1.f }))); } if (rect->body.position.x >= 640.f) { + rect->body.position.x = 640.f; rect->body.velocity = rect->body.velocity - Vector2 { -1.f, 0.f } * (2 * (rect->body.velocity.dot(Vector2{ -1.f, 0.f }))); } if (rect->body.position.y >= 480.f) { + rect->body.position.y = 480.f; rect->body.velocity = rect->body.velocity - Vector2 { 0.f, -1.f } * (2 * (rect->body.velocity.dot(Vector2 { 0.f, -1.f }))) ; } } |