Page 1 of 1

btCompoundShape of convex hulls not rendering in BasicExample

Posted: Fri Sep 10, 2021 4:32 pm
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);

Re: btCompoundShape of convex hulls not rendering in BasicExample

Posted: Fri Sep 10, 2021 9:27 pm
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?

Re: btCompoundShape of convex hulls not rendering in BasicExample

Posted: Fri Sep 10, 2021 10:12 pm
by zb10948
Thank you, it gets displayed now. I wasn't aware I need to call setIdentity() to load the defaults.

Re: btCompoundShape of convex hulls not rendering in BasicExample

Posted: Sat Sep 11, 2021 7:05 pm
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.