mirror of https://github.com/godotengine/godot
Avoid division by zero when calculating inertias for bodies with colliders without areas.
(cherry picked from commit e347baddf3)
This commit is contained in:
parent
3b29aac348
commit
1f2e0c67b0
|
|
@ -70,17 +70,19 @@ void BodySW::update_inertias() {
|
|||
// We have to recompute the center of mass.
|
||||
center_of_mass_local.zero();
|
||||
|
||||
for (int i = 0; i < get_shape_count(); i++) {
|
||||
real_t area = get_shape_area(i);
|
||||
if (total_area != 0.0) {
|
||||
for (int i = 0; i < get_shape_count(); i++) {
|
||||
real_t area = get_shape_area(i);
|
||||
|
||||
real_t mass = area * this->mass / total_area;
|
||||
real_t mass = area * this->mass / total_area;
|
||||
|
||||
// NOTE: we assume that the shape origin is also its center of mass.
|
||||
center_of_mass_local += mass * get_shape_transform(i).origin;
|
||||
// NOTE: we assume that the shape origin is also its center of mass.
|
||||
center_of_mass_local += mass * get_shape_transform(i).origin;
|
||||
}
|
||||
|
||||
center_of_mass_local /= mass;
|
||||
}
|
||||
|
||||
center_of_mass_local /= mass;
|
||||
|
||||
// Recompute the inertia tensor.
|
||||
Basis inertia_tensor;
|
||||
inertia_tensor.set_zero();
|
||||
|
|
@ -92,12 +94,15 @@ void BodySW::update_inertias() {
|
|||
continue;
|
||||
}
|
||||
|
||||
real_t area = get_shape_area(i);
|
||||
if (area == 0.0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
inertia_set = true;
|
||||
|
||||
const ShapeSW *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 New Issue