Skip to content
This repository has been archived by the owner on Jun 29, 2024. It is now read-only.

Commit

Permalink
try to solve NaN errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Ughuuu committed Aug 3, 2023
1 parent a2b3f1a commit eae8f59
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/bodies/box2d_collision_object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions src/shapes/box2d_shape_convex_polygon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ float compute_polygon_area(Vector<Vector2> 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;
}

Expand Down
3 changes: 3 additions & 0 deletions src/spaces/box2d_sweep_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit eae8f59

Please sign in to comment.