From 0d2cec290d3b20add7c35c196982571e8be39929 Mon Sep 17 00:00:00 2001 From: Andrew Meadows Date: Thu, 3 Nov 2016 17:56:38 -0700 Subject: [PATCH] use convexHull for ellipsoidal "spheres" --- libraries/physics/src/ShapeFactory.cpp | 14 ++++++++++++-- libraries/shared/src/ShapeInfo.cpp | 7 +------ 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/libraries/physics/src/ShapeFactory.cpp b/libraries/physics/src/ShapeFactory.cpp index 9b9ee0e299..100dab0fd1 100644 --- a/libraries/physics/src/ShapeFactory.cpp +++ b/libraries/physics/src/ShapeFactory.cpp @@ -256,8 +256,18 @@ const btCollisionShape* ShapeFactory::createShapeFromInfo(const ShapeInfo& info) } break; case SHAPE_TYPE_SPHERE: { - float radius = info.getHalfExtents().x; - shape = new btSphereShape(radius); + glm::vec3 halfExtents = info.getHalfExtents(); + float radius = halfExtents.x; + if (radius == halfExtents.y && radius == halfExtents.z) { + shape = new btSphereShape(radius); + } else { + ShapeInfo::PointList points; + points.reserve(NUM_UNIT_SPHERE_DIRECTIONS); + for (uint32_t i = 0; i < NUM_UNIT_SPHERE_DIRECTIONS; ++i) { + points.push_back(bulletToGLM(_unitSphereDirections[i]) * halfExtents); + } + shape = createConvexHull(points); + } } break; case SHAPE_TYPE_CAPSULE_Y: { diff --git a/libraries/shared/src/ShapeInfo.cpp b/libraries/shared/src/ShapeInfo.cpp index 424c2bfa22..1dc0753b8d 100644 --- a/libraries/shared/src/ShapeInfo.cpp +++ b/libraries/shared/src/ShapeInfo.cpp @@ -33,13 +33,8 @@ void ShapeInfo::setParams(ShapeType type, const glm::vec3& halfExtents, QString _halfExtents = glm::vec3(0.0f); break; case SHAPE_TYPE_BOX: + case SHAPE_TYPE_SPHERE: break; - case SHAPE_TYPE_SPHERE: { - // sphere radius is max of halfExtents - float radius = glm::max(glm::max(halfExtents.x, halfExtents.y), halfExtents.z); - _halfExtents = glm::vec3(radius); - break; - } case SHAPE_TYPE_COMPOUND: case SHAPE_TYPE_STATIC_MESH: _url = QUrl(url);