btCompoundShape of convex hulls not rendering in BasicExample

Post Reply
zb10948
Posts: 3
Joined: Fri Sep 10, 2021 4:18 pm

btCompoundShape of convex hulls not rendering in BasicExample

Post by zb10948 »

Hello,

I've been looking into bullet for some simulation of rigid bodies with multiple hulls or collision sections. For start i use infrastructure provided by BasicExample for some POCs. By creating two btConvexHulls and their bodies I get the exact shapes on screen. When I try to do the same via btCompoundShape::addChildShape() and then make a single body, there's nothing in the visualization.

Is this an issue in approach or a limit of a built in visualizer?

Code: Select all

    btTransform t1;
    m_collisionShapes.push_back(collisionModel->meshes[0]->generatedHull);
    createRigidBody(0., t1, collisionModel->meshes[0]->generatedHull);

    btTransform t2;
    t2.setOrigin(btVector3(-0.5, 0, 0));
    m_collisionShapes.push_back(collisionModel->meshes[1]->generatedHull);
    createRigidBody(0., t2, collisionModel->meshes[1]->generatedHull);

Code: Select all

    btCompoundShape * compound = new btCompoundShape();

    btTransform t1;
    compound->addChildShape(t1, collisionModel->meshes[0]->generatedHull);
    
    btTransform t2;
    t2.setOrigin(btVector3(-0.5, 0, 0));
    compound->addChildShape(t2, collisionModel->meshes[1]->generatedHull);
    
    btTransform testmodelTransform;
    m_collisionShapes.push_back(compound);
    createRigidBody(0., testmodelTransform, compound);
User avatar
drleviathan
Posts: 849
Joined: Tue Sep 30, 2014 6:03 pm
Location: San Francisco

Re: btCompoundShape of convex hulls not rendering in BasicExample

Post by drleviathan »

In the btCompoundShape case your testModelTransform is left uninitialized when you pass it to createRigidBody(). Does the problem go away when you initialize it to something reasonable?
zb10948
Posts: 3
Joined: Fri Sep 10, 2021 4:18 pm

Re: btCompoundShape of convex hulls not rendering in BasicExample

Post by zb10948 »

Thank you, it gets displayed now. I wasn't aware I need to call setIdentity() to load the defaults.
User avatar
drleviathan
Posts: 849
Joined: Tue Sep 30, 2014 6:03 pm
Location: San Francisco

Re: btCompoundShape of convex hulls not rendering in BasicExample

Post by drleviathan »

Typically math libraries that have been optimized will NOT initialize object components to default values in the default ctor. This to avoid wasted CPU cycles for the cases where the default values are immediately overwritten. As such they require the Application developer to explicitly initialize.

As I recall, sometime around 2011 or so the Havok physics math library took this to the next level and eliminated the copy ctor and normal math operators that used it. As a consequence code that used to be expressible in one line...

Code: Select all

Vector3 C = A + delta * (B - A)
...could only be done over several lines:

Code: Select all

Vector3 C(B);
C.subtract(A);
C.multiply(delta);
C.add(A);
The new method was more verbose but less work was hidden by C++ abstraction and the compiled binary would use fewer byte codes.
Post Reply