Avoid division by zero when calculating inertias for bodies with colliders without areas.
This commit is contained in:
parent
364ea7f280
commit
e347baddf3
1 changed files with 14 additions and 9 deletions
|
@ -65,6 +65,7 @@ void Body3DSW::update_inertias() {
|
|||
// We have to recompute the center of mass.
|
||||
center_of_mass_local.zero();
|
||||
|
||||
if (total_area != 0.0) {
|
||||
for (int i = 0; i < get_shape_count(); i++) {
|
||||
real_t area = get_shape_area(i);
|
||||
|
||||
|
@ -75,6 +76,7 @@ void Body3DSW::update_inertias() {
|
|||
}
|
||||
|
||||
center_of_mass_local /= mass;
|
||||
}
|
||||
|
||||
// Recompute the inertia tensor.
|
||||
Basis inertia_tensor;
|
||||
|
@ -86,12 +88,15 @@ void Body3DSW::update_inertias() {
|
|||
continue;
|
||||
}
|
||||
|
||||
real_t area = get_shape_area(i);
|
||||
if (area == 0.0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
inertia_set = true;
|
||||
|
||||
const Shape3DSW *shape = get_shape(i);
|
||||
|
||||
real_t area = get_shape_area(i);
|
||||
|
||||
real_t mass = area * this->mass / total_area;
|
||||
|
||||
Basis shape_inertia_tensor = shape->get_moment_of_inertia(mass).to_diagonal_matrix();
|
||||
|
|
Loading…
Reference in a new issue