use convexHull for ellipsoidal "spheres"

This commit is contained in:
Andrew Meadows 2016-11-03 17:56:38 -07:00
parent 4b1034a5e6
commit 0d2cec290d
2 changed files with 13 additions and 8 deletions
libraries
physics/src
shared/src

View file

@ -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: {

View file

@ -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);