accesing the children of a compound shape

Rob_Theed
Posts: 7
Joined: Thu Jul 29, 2010 10:16 am
Location: Taunton UK

accesing the children of a compound shape

Post by Rob_Theed »

Hi there, this is just a simple question about syntax which I cannot seem to work out from any of the demos, or from the API, if anyone can help me I would be most grateful.

I have a rigidbody which is constructed using a compound collision shape, then later in the program I need to access the children of the compoundshape but I only have to pointer to the rigidbody. I can get the the collisionshape from the rigidbody using ->getCollisionShape(), but I don't know how to access the child shapes from this, using ->getChildShape(index) doesn't work, but I don't know how to go about this. Is there a solution or will I need to keep hold of the pointer to the original compoundshape. Here is my code at the moment, many thanks.

Code: Select all

mycompoundshape= new btCompoundShape;
mycompoundshape->addChildShape( transform , collisionshape );


btRigidBody::btRigidBodyConstructionInfo rbInfo(mass, motionState,mycompoundshape,localInertia);
rigidbody = new btRigidBody(rbInfo);

// lots of code here

//

if (rigidbody->getCollisionShape()->isCompound()==true) {
                     for(int i=0 ; i<rigidbody->getCollisionShape()->getNumChildShapes();i++){      // this does not work
                                    rigidbody->getCollisionShape->getChildShape(i);                                 // or this
                     }
}

Rob
mi076
Posts: 144
Joined: Fri Aug 01, 2008 6:36 am
Location: Bonn, Germany

Re: accesing the children of a compound shape

Post by mi076 »

Code: Select all

if (rigidbody->getCollisionShape()->isCompound())
{
btCompoundShape * compound = (btCompoundShape *)rigidbody->getCollisionShape();
    for(int i=0 ; i < compound->getNumChildShapes(); i++)
    {
    btCollisionShape * child = compound->getChildShape(i);
    }
}
Rob_Theed
Posts: 7
Joined: Thu Jul 29, 2010 10:16 am
Location: Taunton UK

Re: accesing the children of a compound shape

Post by Rob_Theed »

Awesome thank you so much, that had me in a right pickle. :D

I think my general C++ could do with some work.