Search code examples
bulletphysicsbullet

Is btSphereShape cheaper for calculations than btBoxShape?


Always thought sphere is the cheapest collision primitive but it looks like Bullet creates a convex body for the sphere, don't it? So is the btSphereShape actually cheaper than the btBoxShape for collision computations or much more expensive?


Solution

  • This is not a complete answer. (A complete one should do a profile test.)

    From the official wiki, they are not so different in performance
    (both shape are grouped in to the same tier - Primitives) :-

    Using convex collision shapes such as convex hulls and primitives such as a sphere, box and cylinder makes the collision algorithms much more simple and efficient.

    In the same page, it implies that Sphere is the fastest shape :-

    btSphereShape : A very fast and simple shape.
    btBoxShape : A cuboid shape, the length in each dimension can be chosen arbitrarily.

    Response to each mini questions

    OP: btSphereShape actually cheaper .... , (because it is inherited) from btConvexInternalShape.

    Yes, but the class hierchy is not the reason.
    Both sphere and box are inherited from the btConvexInternalShape.
    Sphere are just easy to calculate.

    OP: ... Bullet creates a convex body for the sphere ... (so) the btSphereShape actually cheaper

    Primitive shape uses special highly-customized algorithm, so it is cheaper than general convex. For an evidence, see btSphereSphereCollisionAlgorithm (cheap) vs btConvexConvexAlgorithm (expensive) .

    General guide

    In practice, you should select the one that match your need. (except your application is really physics-intensive)

    • As I browse the forum for a long time, there are no one mention/complain about difference in performance of Box vs Sphere.

    • I have also used both of them for a few years and see no difference in practice.

    You may be also interested in collision-shape algorithm (a popular collision detection website).
    I believe Bullet use one of such algorithms.