diff --git a/src/body_operations.cpp b/src/body_operations.cpp index 163051ea..b654c76a 100644 --- a/src/body_operations.cpp +++ b/src/body_operations.cpp @@ -160,9 +160,11 @@ void bodies::computeBoundingSphere(const std::vector& bodie unsigned int vertex_count = 0; for (auto body : bodies) { - const bodies::ConvexMesh* conv = dynamic_cast(body); - if (!conv) + if (!body || body->getType() != MESH) continue; + // MESH type implies bodies::ConvexMesh + const bodies::ConvexMesh* conv = static_cast(body); + for (unsigned int j = 0; j < conv->getScaledVertices().size(); j++, vertex_count++) { sum += conv->getPose() * conv->getScaledVertices()[j]; @@ -174,9 +176,11 @@ void bodies::computeBoundingSphere(const std::vector& bodie double max_dist_squared = 0.0; for (auto body : bodies) { - const bodies::ConvexMesh* conv = dynamic_cast(body); - if (!conv) + if (!body || body->getType() != MESH) continue; + // MESH type implies bodies::ConvexMesh + const bodies::ConvexMesh* conv = static_cast(body); + for (unsigned int j = 0; j < conv->getScaledVertices().size(); j++) { double dist = (conv->getPose() * conv->getScaledVertices()[j] - sphere.center).squaredNorm(); diff --git a/test/test_bounding_sphere.cpp b/test/test_bounding_sphere.cpp index 06e599c0..8521f123 100644 --- a/test/test_bounding_sphere.cpp +++ b/test/test_bounding_sphere.cpp @@ -175,8 +175,8 @@ TEST(ConeBoundingSphere, Cone4) TEST(MeshBoundingSphere, Mesh1) { shapes::Shape* shape = new shapes::Mesh(8, 12); - shapes::Mesh* m = dynamic_cast(shape); - EXPECT_TRUE(m); + EXPECT_EQ(shape->type, shapes::MESH); + shapes::Mesh* m = static_cast(shape); // box mesh