diff --git a/src/bodies/box2d_collision_object.cpp b/src/bodies/box2d_collision_object.cpp index 47dc3b6..a52b14a 100644 --- a/src/bodies/box2d_collision_object.cpp +++ b/src/bodies/box2d_collision_object.cpp @@ -286,13 +286,13 @@ Vector2 Box2DCollisionObject::get_center_of_mass_local() const { } double Box2DCollisionObject::get_inverse_mass() const { - if (mass_data.mass <= 0) { + if (mass_data.mass <= b2_epsilon) { return 0; } return 1.0 / mass_data.mass; } double Box2DCollisionObject::get_inverse_inertia() const { - if (mass_data.I <= 0) { + if (mass_data.I <= b2_epsilon) { return 0; } return 1.0 / mass_data.I; diff --git a/src/shapes/box2d_shape_convex_polygon.cpp b/src/shapes/box2d_shape_convex_polygon.cpp index 036478d..73190d1 100644 --- a/src/shapes/box2d_shape_convex_polygon.cpp +++ b/src/shapes/box2d_shape_convex_polygon.cpp @@ -59,6 +59,9 @@ float compute_polygon_area(Vector points) { int j = (i + 1) % points.size(); area += points[j][0] * points[i][1] - points[i][0] * points[j][1]; } + if (area <= b2_epsilon) { + area = b2_epsilon; + } return area / 2.0f; } diff --git a/src/spaces/box2d_sweep_test.cpp b/src/spaces/box2d_sweep_test.cpp index 66f3b14..e9a02ad 100644 --- a/src/spaces/box2d_sweep_test.cpp +++ b/src/spaces/box2d_sweep_test.cpp @@ -28,6 +28,9 @@ real_t SweepTestResult::safe_fraction() { b2Vec2 projection = (b2Cross(separation, motion_normal)) * motion_normal; float safe_length = unsafe_length - projection.Length(); + if (motion_length <= b2_epsilon) { + motion_length = b2_epsilon; + } float safe_fraction = safe_length / motion_length; if (safe_fraction <= b2_epsilon) { return 0;