flyover / box2d.ts

A TypeScript port of Box2D
https://flyover.github.io/box2d.ts/testbed
MIT License
406 stars 84 forks source link

Differences to original box2d #75

Open Lusito opened 3 years ago

Lusito commented 3 years ago

While I'm trying to look for ways to compare the code to original box2d, I noticed a few places, where the logic is quite different (beyond typescript conversion) and I wonder if that is something you rewrote yourself or if that came from the liquidfun project.

For example b2FindMaxSeparation differs a lot in implementation.

flyover commented 3 years ago

It looks like it's an older version of b2FindMaxSeparation; I must have missed that when porting one of the releases. Thanks for letting me know. Let me know if you find anything else.

Lusito commented 3 years ago

Here's something that seems completely off:

Your b2AABB.Contains method:

        if (lowerBound.x <= aabb.lowerBound.x) {
            return false;
        }
        if (lowerBound.y <= aabb.lowerBound.y) {
            return false;
        }
        if (aabb.upperBound.x <= upperBound.x) {
            return false;
        }
        if (aabb.upperBound.y <= upperBound.y) {
            return false;
        }
        return true;

Box2d Contains method:

    result = true;
    result = result && lowerBound.x <= aabb.lowerBound.x;
    result = result && lowerBound.y <= aabb.lowerBound.y;
    result = result && aabb.upperBound.x <= upperBound.x;
    result = result && aabb.upperBound.y <= upperBound.y;
    return result;

This seems to be the exact opposite.

flyover commented 3 years ago

You're right; fixed. Again, thanks for finding these.

Lusito commented 3 years ago

Is the difference intended in b2ContactFilter.ShouldCollide?

flyover commented 3 years ago

Yes; it allows for reporting collisions between kinematic bodies (enabled by default). It's functionally the same, it just brings the body type check into the contact filter. I brought this up with Erin, but he decided against merging it upstream. https://github.com/erincatto/box2d/pull/349