コード例 #1
0
        public void reset()
        {
            foreach (RigidBodyObject rbo in _physics_world.rigid_body_objects)
            {
                rbo.body.ClearForces();
                rbo.body.AngularVelocity = Vector3.Zero;
                rbo.body.LinearVelocity  = Vector3.Zero;

                rbo.body.WorldTransform             = rbo.original_transformation;
                rbo.body.MotionState.WorldTransform = rbo.original_transformation;
                rbo.body.Activate();
            }


            OverlappingPairCache       pair_cache = _physics_world.world.Broadphase.OverlappingPairCache;
            AlignedBroadphasePairArray pair_array = pair_cache.OverlappingPairArray;

            for (int i = 0; i < pair_array.Count; i++)
            {
                pair_cache.CleanOverlappingPair(pair_array[i], _physics_world.world.Dispatcher);
            }

            _solver.Reset();
            _physics_world.world.ClearForces();
            _broadphase.ResetPool(_dispatcher);

            _physics_world.paused = false;
        }
コード例 #2
0
        public void GhostObjectPairsTest()
        {
            var world = _context.DiscreteDynamicsWorld;

            world.StepSimulation(1.0f / 60.0f);

            AlignedManifoldArray       manifoldArray = new AlignedManifoldArray();
            AlignedBroadphasePairArray pairArray     = _ghostObject.OverlappingPairCache.OverlappingPairArray;

            foreach (BroadphasePair pair in pairArray)
            {
                //unless we manually perform collision detection on this pair, the contacts are in the dynamics world paircache:
                BroadphasePair collisionPair = world.PairCache.FindPair(pair.Proxy0, pair.Proxy1);
                if (collisionPair == null)
                {
                    continue;
                }

                manifoldArray.Clear();

                if (collisionPair.Algorithm != null)
                {
                    collisionPair.Algorithm.GetAllContactManifolds(manifoldArray);
                }

                for (int j = 0; j < manifoldArray.Count; j++)
                {
                    PersistentManifold manifold = manifoldArray[j];
                    float directionSign         = manifold.Body0 == _ghostObject ? -1.0f : 1.0f;
                    for (int p = 0; p < manifold.NumContacts; p++)
                    {
                        ManifoldPoint pt = manifold.GetContactPoint(p);
                        if (pt.Distance < 0.0f)
                        {
                            Vector3 ptA       = pt.PositionWorldOnA;
                            Vector3 ptB       = pt.PositionWorldOnB;
                            Vector3 normalOnB = pt.NormalWorldOnB;
                        }
                    }
                }
            }

            manifoldArray.Dispose();
        }
コード例 #3
0
        static void TestGhostObjectPairs(PairCachingGhostObject ghostObject)
        {
            AlignedManifoldArray       manifoldArray = new AlignedManifoldArray();
            AlignedBroadphasePairArray pairArray     = ghostObject.OverlappingPairCache.OverlappingPairArray;
            int numPairs = pairArray.Count;

            for (int i = 0; i < numPairs; i++)
            {
                manifoldArray.Clear();

                BroadphasePair pair = pairArray[i];

                //unless we manually perform collision detection on this pair, the contacts are in the dynamics world paircache:
                BroadphasePair collisionPair = world.PairCache.FindPair(pair.Proxy0, pair.Proxy1);
                if (collisionPair == null)
                {
                    continue;
                }

                if (collisionPair.Algorithm != null)
                {
                    collisionPair.Algorithm.GetAllContactManifolds(manifoldArray);
                }

                for (int j = 0; j < manifoldArray.Count; j++)
                {
                    PersistentManifold manifold = manifoldArray[j];
                    float directionSign         = manifold.Body0 == ghostObject ? -1.0f : 1.0f;
                    for (int p = 0; p < manifold.NumContacts; p++)
                    {
                        ManifoldPoint pt = manifold.GetContactPoint(p);
                        if (pt.Distance < 0.0f)
                        {
                            Vector3 ptA       = pt.PositionWorldOnA;
                            Vector3 ptB       = pt.PositionWorldOnB;
                            Vector3 normalOnB = pt.NormalWorldOnB;
                            /// work here
                        }
                    }
                }
            }
        }