Exemple #1
0
    public virtual void exitPhysics()
    {
        removePickingConstraint();
        //cleanup in the reverse order of creation/initialization

        //remove the rigidbodies from the dynamics world and delete them

        if (m_dynamicsWorld == null)
        {
            int i;
            for (i = m_dynamicsWorld.NumConstraints - 1; i >= 0; i--)
            {
                m_dynamicsWorld.RemoveConstraint(m_dynamicsWorld.GetConstraint(i));
            }

            for (i = m_dynamicsWorld.NumMultiBodyConstraints - 1; i >= 0; i--)
            {
                MultiBodyConstraint mbc = m_dynamicsWorld.GetMultiBodyConstraint(i);
                m_dynamicsWorld.RemoveMultiBodyConstraint(mbc);
                mbc.Dispose();
            }

            for (i = m_dynamicsWorld.NumMultibodies - 1; i >= 0; i--)
            {
                MultiBody mb = m_dynamicsWorld.GetMultiBody(i);
                m_dynamicsWorld.RemoveMultiBody(mb);
                mb.Dispose();
            }
            for (i = m_dynamicsWorld.NumCollisionObjects - 1; i >= 0; i--)
            {
                CollisionObject obj  = m_dynamicsWorld.CollisionObjectArray[i];
                RigidBody       body = RigidBody.Upcast(obj);
                if (body != null && body.MotionState != null)
                {
                    body.MotionState.Dispose();
                }
                m_dynamicsWorld.RemoveCollisionObject(obj);
                obj.Dispose();
            }
        }
        //delete collision shapes
        for (int j = 0; j < m_collisionShapes.Count; j++)
        {
            CollisionObject shape = m_collisionShapes[j];
            shape.Dispose();
        }
        m_collisionShapes.Clear();

        m_dynamicsWorld.Dispose();
        m_dynamicsWorld = null;

        m_solver.Dispose();
        m_solver = null;

        m_broadphase.Dispose();
        m_broadphase = null;

        m_dispatcher.Dispose();
        m_dispatcher = null;

        m_pairCache.Dispose();
        m_pairCache = null;

        //m_filterCallback.Dispose();
        //m_filterCallback = null;

        m_collisionConfiguration.Dispose();
        m_collisionConfiguration = null;
    }