private void ConstructPhysicsSimulator(Vector2 gravity)
        {
            GeomList        = new GenericList <Geom>(32);
            _geomAddList    = new List <Geom>(32);
            _geomRemoveList = new List <Geom>(32);

            BodyList        = new GenericList <Body>(32);
            _bodyAddList    = new List <Body>(32);
            _bodyRemoveList = new List <Body>(32);

            ControllerList        = new GenericList <Controller>(8);
            _controllerAddList    = new List <Controller>(8);
            _controllerRemoveList = new List <Controller>(8);

            JointList        = new GenericList <Joint>(32);
            _jointAddList    = new List <Joint>(32);
            _jointRemoveList = new List <Joint>(32);

            SpringList        = new GenericList <Spring>(32);
            _springAddList    = new List <Spring>(32);
            _springRemoveList = new List <Spring>(32);

            _broadPhaseCollider = new SelectiveSweepCollider(this);

            Gravity = gravity;

            //Create arbiter list with default capacity of 128
            ArbiterList = new ArbiterList(128);

            //Poolsize of 128, will grow as needed.
            arbiterPool = new Pool <Arbiter>(128);
        }
        /// <summary>
        /// Processes the disposed controllers, joints, springs, bodies and cleans up the arbiter list.
        /// </summary>
        private void ProcessDisposedItems()
        {
            //Allow each controller to validate itself. this is where a controller can Dispose of itself if need be.
            for (int i = 0; i < ControllerList.Count; i++)
            {
                ControllerList[i].Validate();
            }

            //Allow each joint to validate itself. this is where a joint can Dispose of itself if need be.
            for (int i = 0; i < JointList.Count; i++)
            {
                JointList[i].Validate();
            }

            //Allow each spring to validate itself. this is where a spring can Dispose of itself if need be.
            for (int i = 0; i < SpringList.Count; i++)
            {
                SpringList[i].Validate();
            }

            _tempCount = GeomList.RemoveDisposed();

            if (_tempCount > 0)
            {
                _broadPhaseCollider.ProcessDisposedGeoms();
            }

            BodyList.RemoveDisposed();
            ControllerList.RemoveDisposed();
            SpringList.RemoveDisposed();
            JointList.RemoveDisposed();

            //Clean up the arbiterlist
            ArbiterList.CleanArbiterList(arbiterPool);
        }
        private void ConstructPhysicsSimulator(Vector2 gravity)
        {
            geomList       = new GeomList();
            geomAddList    = new List <Geom>();
            geomRemoveList = new List <Geom>();

            bodyList       = new BodyList();
            bodyAddList    = new List <Body>();
            bodyRemoveList = new List <Body>();

            controllerList       = new ControllerList();
            controllerAddList    = new List <Controller>();
            controllerRemoveList = new List <Controller>();

            jointList       = new JointList();
            jointAddList    = new List <Joint>();
            jointRemoveList = new List <Joint>();

            _broadPhaseCollider = new SelectiveSweepCollider(this);

            arbiterList = new ArbiterList();
            _gravity    = gravity;

            arbiterPool = new Pool <Arbiter>(_arbiterPoolSize);

            #region Added by Daniel Pramel 08/17/08

            _inactivityController = new InactivityController(this);

            _scaling = new Scaling(0.001f, 0.01f);

            #endregion
        }
Exemple #4
0
 private void PhysicsConstructor(Vector2 gravity)
 {
     _rigidBodyList = new RigidBodyList();
     _arbiterList   = new ArbiterList();
     _springList    = new SpringList();
     _jointList     = new JointList();
     _gravity       = gravity;
 }
 /// <summary>
 /// Does the narrow phase collision detection.
 /// The narrow phase checks collisionpairs found in the broad phase in detail.
 /// This phase creates contacts between geometries and then applies impulse to them.
 /// </summary>
 private void DoNarrowPhaseCollision()
 {
     for (int i = 0; i < ArbiterList.Count; i++)
     {
         ArbiterList[i].Collide();
     }
     ArbiterList.RemoveContactCountEqualsZero(arbiterPool);
 }
        public void Clear(int newGeomCount, ArbiterList arbiterList)
        {
            if (_geomCount >= newGeomCount)
            {
                Array.Clear(_bitmap, 0, _bitmap.Length);
            }
            else
            {
                _geomCount = newGeomCount;
                _bitmap = new bool[CalculateSize(newGeomCount)];
            }

            if (arbiterList != null)
            {
                foreach (Arbiter arbiter in arbiterList)
                {
                    TestAndSet(arbiter.GeometryA, arbiter.GeometryB);
                }
            }
        }
        public void Clear(int newGeomCount, ArbiterList arbiterList)
        {
            if (_geomCount >= newGeomCount)
            {
                Array.Clear(_bitmap, 0, _bitmap.Length);
            }
            else
            {
                _geomCount = newGeomCount;
                _bitmap    = new bool[CalculateSize(newGeomCount)];
            }

            if (arbiterList != null)
            {
                foreach (Arbiter arbiter in arbiterList)
                {
                    TestAndSet(arbiter.GeometryA, arbiter.GeometryB);
                }
            }
        }
        private void ConstructPhysicsSimulator(Vector2 gravity)
        {
            geomList = new GenericList<Geom>();
            geomAddList = new List<Geom>();
            geomRemoveList = new List<Geom>();

            bodyList = new GenericList<Body>();
            bodyAddList = new List<Body>();
            bodyRemoveList = new List<Body>();

            controllerList = new GenericList<Controller>();
            controllerAddList = new List<Controller>();
            controllerRemoveList = new List<Controller>();

            jointList = new GenericList<Joint>();
            jointAddList = new List<Joint>();
            jointRemoveList = new List<Joint>();

            springList = new GenericList<Spring>();
            springAddList = new List<Spring>();
            springRemoveList = new List<Spring>();

            _broadPhaseCollider = new SelectiveSweepCollider(this);

            arbiterList = new ArbiterList();
            Gravity = gravity;

            //Poolsize of 10, will grow as needed.
            arbiterPool = new Pool<Arbiter>(100);
        }
        private void ConstructPhysicsSimulator(Vector2 gravity)
        {
            GeomList = new GenericList<Geom>(32);
            _geomAddList = new List<Geom>(32);
            _geomRemoveList = new List<Geom>(32);

            BodyList = new GenericList<Body>(32);
            _bodyAddList = new List<Body>(32);
            _bodyRemoveList = new List<Body>(32);

            ControllerList = new GenericList<Controller>(8);
            _controllerAddList = new List<Controller>(8);
            _controllerRemoveList = new List<Controller>(8);

            JointList = new GenericList<Joint>(32);
            _jointAddList = new List<Joint>(32);
            _jointRemoveList = new List<Joint>(32);

            SpringList = new GenericList<Spring>(32);
            _springAddList = new List<Spring>(32);
            _springRemoveList = new List<Spring>(32);

            _broadPhaseCollider = new SelectiveSweepCollider(this);

            Gravity = gravity;

            //Create arbiter list with default capacity of 128
            ArbiterList = new ArbiterList(128);

            //Poolsize of 128, will grow as needed.
            arbiterPool = new Pool<Arbiter>(128);
        }
 public GeomPairBitmap(int geomCount, ArbiterList arbiterList)
 {
     Clear(geomCount, arbiterList);
 }
        private void ConstructPhysicsSimulator(Vector2 gravity)
        {
            geomList = new GeomList();
            geomAddList = new List<Geom>();
            geomRemoveList = new List<Geom>();

            bodyList = new BodyList();
            bodyAddList = new List<Body>();
            bodyRemoveList = new List<Body>();

            controllerList = new ControllerList();
            controllerAddList = new List<Controller>();
            controllerRemoveList = new List<Controller>();

            jointList = new JointList();
            jointAddList = new List<Joint>();
            jointRemoveList = new List<Joint>();

            springList = new SpringList();
            springAddList = new List<Spring>();
            springRemoveList = new List<Spring>();

            _broadPhaseCollider = new SelectiveSweepCollider(this);

            arbiterList = new ArbiterList();
            _gravity = gravity;

            arbiterPool = new Pool<Arbiter>(_arbiterPoolSize);

            #region Added by Daniel Pramel 08/17/08

            _inactivityController = new InactivityController(this);

            _scaling = new Scaling(0.001f, 0.01f);

            #endregion
        }
        /// <summary>
        /// Processes the removed geometries (and their arbiters), bodies, controllers, joints and springs.
        /// </summary>
        private void ProcessRemovedItems()
        {
            //Remove any new geometries
            _tempCount = _geomRemoveList.Count;
            for (int i = 0; i < _tempCount; i++)
            {
                _geomRemoveList[i].InSimulation = false;
                GeomList.Remove(_geomRemoveList[i]);

                //Remove any arbiters associated with the geometries being removed
                for (int j = ArbiterList.Count; j > 0; j--)
                {
                    if (ArbiterList[j - 1].GeometryA == _geomRemoveList[i] ||
                        ArbiterList[j - 1].GeometryB == _geomRemoveList[i])
                    {
                        //TODO: Should we create a RemoveComplete method and remove all Contacts associated
                        //with the arbiter?
                        arbiterPool.Insert(ArbiterList[j - 1]);
                        ArbiterList.Remove(ArbiterList[j - 1]);
                    }
                }
            }

            if (_geomRemoveList.Count > 0)
            {
                _broadPhaseCollider.ProcessRemovedGeoms();
            }

            _geomRemoveList.Clear();

            //Remove any new bodies
            _tempCount = _bodyRemoveList.Count;
            for (int i = 0; i < _tempCount; i++)
            {
                BodyList.Remove(_bodyRemoveList[i]);
            }
            _bodyRemoveList.Clear();

            //Remove any new controllers
            _tempCount = _controllerRemoveList.Count;
            for (int i = 0; i < _tempCount; i++)
            {
                ControllerList.Remove(_controllerRemoveList[i]);
            }
            _controllerRemoveList.Clear();

            //Remove any new joints
            int jointRemoveCount = _jointRemoveList.Count;

            for (int i = 0; i < jointRemoveCount; i++)
            {
                JointList.Remove(_jointRemoveList[i]);
            }
            _jointRemoveList.Clear();

            //Remove any new springs
            _tempCount = _springRemoveList.Count;
            for (int i = 0; i < _tempCount; i++)
            {
                SpringList.Remove(_springRemoveList[i]);
            }
            _springRemoveList.Clear();
        }
        /// <summary>
        /// Updates the physics simulator with the specified time change.
        /// </summary>
        /// <param name="dt">The delta time.</param>
        /// <param name="dtReal">The real delta time.</param>
        public void Update(float dt, float dtReal)
        {
#if (XNA)
            if (EnableDiagnostics)
            {
                _sw.Start();
            }
#endif

            ProcessAddedItems();
            ProcessRemovedItems();
            ProcessDisposedItems();

            ArbiterList.PrepareForBroadphaseCollision(GeomList);

#if (XNA)
            if (EnableDiagnostics)
            {
                CleanUpTime = _sw.ElapsedTicks;
            }
#endif

            //If there is no change in time, no need to calculate anything.
            if (dt == 0 || !Enabled)
            {
                return;
            }

            DoBroadPhaseCollision();
#if (XNA)
            if (EnableDiagnostics)
            {
                BroadPhaseCollisionTime = _sw.ElapsedTicks - CleanUpTime;
            }
#endif
            DoNarrowPhaseCollision();
#if (XNA)
            if (EnableDiagnostics)
            {
                NarrowPhaseCollisionTime = _sw.ElapsedTicks - BroadPhaseCollisionTime - CleanUpTime;
            }
#endif
            ApplyForces(dt, dtReal);
#if (XNA)
            if (EnableDiagnostics)
            {
                ApplyForcesTime = _sw.ElapsedTicks - NarrowPhaseCollisionTime - BroadPhaseCollisionTime - CleanUpTime;
            }
#endif
            ApplyImpulses(dt);

#if (XNA)
            if (EnableDiagnostics)
            {
                ApplyImpulsesTime = _sw.ElapsedTicks - ApplyForcesTime - NarrowPhaseCollisionTime - BroadPhaseCollisionTime - CleanUpTime;
            }
#endif
            UpdatePositions(dt);
#if (XNA)
            if (EnableDiagnostics)
            {
                UpdatePositionsTime = _sw.ElapsedTicks - ApplyImpulsesTime - ApplyForcesTime - NarrowPhaseCollisionTime - BroadPhaseCollisionTime - CleanUpTime;
            }
#endif
#if (XNA)
            if (EnableDiagnostics)
            {
                _sw.Stop();
                UpdateTime = _sw.ElapsedTicks;

                CleanUpTime              = 1000 * CleanUpTime / Stopwatch.Frequency;
                BroadPhaseCollisionTime  = 1000 * BroadPhaseCollisionTime / Stopwatch.Frequency;
                NarrowPhaseCollisionTime = 1000 * NarrowPhaseCollisionTime / Stopwatch.Frequency;
                ApplyForcesTime          = 1000 * ApplyForcesTime / Stopwatch.Frequency;
                ApplyImpulsesTime        = 1000 * ApplyImpulsesTime / Stopwatch.Frequency;
                UpdatePositionsTime      = 1000 * UpdatePositionsTime / Stopwatch.Frequency;
                UpdateTime = 1000 * UpdateTime / Stopwatch.Frequency;
                _sw.Reset();
            }
#endif
        }
 private void PhysicsConstructor(Vector2 gravity)
 {
     _rigidBodyList = new RigidBodyList();
     _arbiterList = new ArbiterList();
     _springList = new SpringList();
     _jointList = new JointList();
     _gravity = gravity;
 }
 public GeomPairBitmap(int geomCount, ArbiterList arbiterList)
 {
     Clear(geomCount, arbiterList);
 }