Resetting scene

sara
Posts: 39
Joined: Thu Mar 24, 2011 3:50 pm

Resetting scene

Post by sara »

I'm trying to reset a scene without deleting the whole scene and creating it again. The problem is that the simulation is different every time I reset it.

What I've done is this:

Code: Select all

for(;it!=bodies.end();++it)
    {
        btRigidBody *bb = (btRigidBody*)(*it)->physicsBody;
        //m_dynamicsWorld->removeRigidBody(bb);
        btTransform transform;
        transform.setIdentity();
        transform.setRotation(btQuaternion((*it)->orientation.x(),(*it)->orientation.y(),(*it)->orientation.z(),(*it)->orientation.w()));
        transform.setOrigin(btVector3(btScalar((*it)->position(0)),btScalar((*it)->position(1)),btScalar((*it)->position(2))));

        btMotionState * motion = bb->getMotionState();
        motion->setWorldTransform(transform);
        bb->setMotionState(motion);
        bb->clearForces();
        btVector3 z(0,0,0);
        bb->setAngularVelocity(z);
        bb->setLinearVelocity(z);
        bb->activate(true);

    }

    m_solver->reset();
    m_dynamicsWorld->clearForces();
    m_broadphase->resetPool(m_dispatcher);
    m_clock.reset();
hikethru08
Posts: 4
Joined: Tue May 29, 2012 1:51 pm

Re: Resetting scene

Post by hikethru08 »

I am trying to do the same thing you are, more or less.
I see you call reset on the solver and on the broad phase which I have not tried, so I'm going to try out some those calls in my own code and see if my results improve.

In my code, I am trying to figure out which behaviors are explained by the problem described in the link below, and which other behaviors are a result of me leaving out important steps of the reset process.

http://www.bulletphysics.org/Bullet/php ... tic#p27147

Please post back if you have found a solution/explanation.

Thanks,
Brian
User avatar
jarno
Posts: 57
Joined: Tue Mar 16, 2010 1:42 am

Re: Resetting scene

Post by jarno »

As well as resetting the broadphase pool, I also clean out the overlapping pair cache:

Code: Select all

btOverlappingPairCache* pair_cache = m_dynamics_world->getBroadphase()->getOverlappingPairCache();
btBroadphasePairArray& pair_array = pair_cache->getOverlappingPairArray();
for(int i = 0; i < pair_array.size(); i++)
    pair_cache->cleanOverlappingPair(pair_array[i], m_dynamics_world->getDispatcher());
If you are using softbodies with the SDF based rigid versus softbody collision method, then also reset that:

Code: Select all

softbody_worldinfo.m_sparsesdf.Reset();
---JvdL---
sara
Posts: 39
Joined: Thu Mar 24, 2011 3:50 pm

Re: Resetting scene

Post by sara »

Wow, after so many days I wasn't expecting any answers.

Thanks! I'll try it out tonight, and post the result.