From adf076a63077fed8168233629cefc20ebe3c0322 Mon Sep 17 00:00:00 2001 From: Andrew Meadows Date: Mon, 30 Mar 2015 09:56:30 -0700 Subject: [PATCH] optimizations when creating convex hull shapes --- libraries/physics/src/ShapeInfoUtil.cpp | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/libraries/physics/src/ShapeInfoUtil.cpp b/libraries/physics/src/ShapeInfoUtil.cpp index 1073fbae3f..8900c5a0dc 100644 --- a/libraries/physics/src/ShapeInfoUtil.cpp +++ b/libraries/physics/src/ShapeInfoUtil.cpp @@ -136,28 +136,32 @@ btCollisionShape* ShapeInfoUtil::createShapeFromInfo(const ShapeInfo& info) { } break; case SHAPE_TYPE_CONVEX_HULL: { - shape = new btConvexHullShape(); + auto hull = new btConvexHullShape(); const QVector>& points = info.getPoints(); foreach (glm::vec3 point, points[0]) { btVector3 btPoint(point[0], point[1], point[2]); - static_cast(shape)->addPoint(btPoint); + hull->addPoint(btPoint, false); } + hull->recalcLocalAabb(); + shape = hull; } break; case SHAPE_TYPE_COMPOUND: { - shape = new btCompoundShape(); + auto compound = new btCompoundShape(); const QVector>& points = info.getPoints(); - foreach (QVector hullPoints, info.getPoints()) { + btTransform trans; + trans.setIdentity(); + foreach (QVector hullPoints, points) { auto hull = new btConvexHullShape(); foreach (glm::vec3 point, hullPoints) { btVector3 btPoint(point[0], point[1], point[2]); - hull->addPoint(btPoint); + hull->addPoint(btPoint, false); } - btTransform trans; - trans.setIdentity(); - static_cast(shape)->addChildShape (trans, hull); + hull->recalcLocalAabb(); + compound->addChildShape (trans, hull); } + shape = compound; } break; }