Exemplo n.º 1
0
        //----------------------------------------------------------------------------------------------

        public override void ClientResetScene()
        {
            //#ifdef SHOW_NUM_DEEP_PENETRATIONS
            gNumDeepPenetrationChecks = 0;
            gNumGjkChecks             = 0;
            //#endif //SHOW_NUM_DEEP_PENETRATIONS

            gNumClampedCcdMotions = 0;
            int numObjects = 0;

            foreach (DiscreteDynamicsWorld world in m_worlds)
            {
                // Prefer a better place for this...
                world.SetDebugDrawer(m_debugDraw);
                numObjects = world.GetNumCollisionObjects();

                IList <CollisionObject> copyArray = world.GetCollisionObjectArray();

                for (int i = 0; i < numObjects; i++)
                {
                    CollisionObject colObj = copyArray[i];
                    RigidBody       body   = RigidBody.Upcast(colObj);
                    if (body != null)
                    {
                        if (body.GetMotionState() != null)
                        {
                            DefaultMotionState myMotionState = (DefaultMotionState)body.GetMotionState();
                            myMotionState.m_graphicsWorldTrans = myMotionState.m_startWorldTrans;
                            body.SetCenterOfMassTransform(ref myMotionState.m_graphicsWorldTrans);
                            colObj.SetInterpolationWorldTransform(ref myMotionState.m_startWorldTrans);
                            if (colObj.GetActivationState() != ActivationState.DISABLE_DEACTIVATION)
                            {
                                colObj.ForceActivationState(ActivationState.ACTIVE_TAG);
                                colObj.Activate();
                                colObj.SetDeactivationTime(0);
                            }
                            //colObj.setActivationState(WANTS_DEACTIVATION);
                        }
                        //removed cached contact points (this is not necessary if all objects have been removed from the dynamics world)
                        world.GetBroadphase().GetOverlappingPairCache().CleanProxyFromPairs(colObj.GetBroadphaseHandle(), world.GetDispatcher());

                        if (!body.IsStaticObject())
                        {
                            IndexedVector3 zero = IndexedVector3.Zero;
                            body.SetLinearVelocity(ref zero);
                            body.SetAngularVelocity(ref zero);
                        }
                    }
                }
                ///reset some internal cached data in the broadphase
                world.GetBroadphase().ResetPool(world.GetDispatcher());
                world.GetConstraintSolver().Reset();
            }
        }