How do i completely clean bullet?

johnsonalpha
Posts: 73
Joined: Fri May 01, 2015 8:23 pm

How do i completely clean bullet?

Post by johnsonalpha »

How can i delete all joints,collision shapes, rigidbodies and everything in this scene? I need to do a complete clean.

Code: Select all

broadphase = new btDbvtBroadphase();
collisionConfiguration = new btDefaultCollisionConfiguration();
dispatcher = new btCollisionDispatcher(collisionConfiguration);
solver = new btSequentialImpulseConstraintSolver;
dynamicsWorld = new btDiscreteDynamicsWorld(dispatcher, broadphase, solver, collisionConfiguration);

dynamicsWorld->setGravity(btVector3(0, btgravity, 0));

 groundShape = new btStaticPlaneShape(btVector3(0, 1, 0), 1);
btDefaultMotionState* groundMotionState = new btDefaultMotionState(btTransform(btQuaternion(0, 0, 0, 1), btVector3(0, -1, 0)));
btRigidBody::btRigidBodyConstructionInfo
groundRigidBodyCI(0, groundMotionState, groundShape, btVector3(0, groundplaneheight, 0));
groundRigidBody = new btRigidBody(groundRigidBodyCI);
dynamicsWorld->addRigidBody(groundRigidBody);

Basroil
Posts: 463
Joined: Fri Nov 30, 2012 4:50 am

Re: How do i completely clean bullet?

Post by Basroil »

I suggest you take a look at the example code in the demo files. Adding an deleting is pretty straightforward if you understand C++ and object scopes, no tricks or hacks to worry about.
johnsonalpha
Posts: 73
Joined: Fri May 01, 2015 8:23 pm

Re: How do i completely clean bullet?

Post by johnsonalpha »

Basroil wrote:I suggest you take a look at the example code in the demo files. Adding an deleting is pretty straightforward if you understand C++ and object scopes, no tricks or hacks to worry about.
I've look at it but i dont have a m_collisionShapes.size as you can see and i don't now a alternative

Code: Select all

//delete collision shapes
for (int j=0;j<m_collisionShapes.size();j++)
{
    btCollisionShape* shape = m_collisionShapes[j];
    delete shape;
}
xexuxjy
Posts: 225
Joined: Wed Jan 07, 2009 11:43 am
Location: London

Re: How do i completely clean bullet?

Post by xexuxjy »

What the demos do is to keep a list(s) of all the shapes,bodies, constraints etc that you create and just go through and tidy those up at the end.
you'd have to do that (or similar ) in your own code
johnsonalpha
Posts: 73
Joined: Fri May 01, 2015 8:23 pm

Re: How do i completely clean bullet?

Post by johnsonalpha »

So everytime i make a collision shape add it to an array?
xexuxjy
Posts: 225
Joined: Wed Jan 07, 2009 11:43 am
Location: London

Re: How do i completely clean bullet?

Post by xexuxjy »

Yes that's one option, or you could extend btDiscreteDynamicsWorld and update with a 'cleanup' method, though if you do that you'd have to be very careful with any objects that had been created before that point as they would no longer be valid