Exemple #1
0
 public World(AABB worldAABB, Vec2 gravity, bool doSleep)
 {
     this._destructionListener = null;
     this._boundaryListener = null;
     this._contactFilter = WorldCallback.DefaultFilter;
     this._contactListener = null;
     this._debugDraw = null;
     this._bodyList = null;
     this._contactList = null;
     this._jointList = null;
     this._bodyCount = 0;
     this._contactCount = 0;
     this._jointCount = 0;
     this._warmStarting = true;
     this._continuousPhysics = true;
     this._allowSleep = doSleep;
     this._gravity = gravity;
     this._lock = false;
     this._inv_dt0 = 0f;
     this._contactManager = new ContactManager();
     this._contactManager._world = this;
     this._broadPhase = new BroadPhase(worldAABB, this._contactManager);
     BodyDef def = new BodyDef();
     this._groundBody = this.CreateBody(def);
 }
        public ContactManager()
        {
            _broadPhase = new BroadPhase();
            _defaultFilter = new ContactFilter();
            _defaultListener = new ContactListener();

            _contactList = null;
            _contactCount = 0;
            _contactFilter = _defaultFilter;
            _contactListener = _defaultListener;
        }
Exemple #3
0
        internal bool Synchronize(BroadPhase broadPhase, XForm transform1, XForm transform2)
        {
            if (_proxyId == PairManager.NullProxy)
            {
                return(false);
            }

            // Compute an AABB that covers the swept shape (may miss some rotation effect).
            AABB aabb;

            ComputeSweptAABB(out aabb, transform1, transform2);

            if (broadPhase.InRange(aabb))
            {
                broadPhase.MoveProxy(_proxyId, aabb);
                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemple #4
0
        internal void CreateProxy(BroadPhase broadPhase, XForm transform)
        {
            Box2DXDebug.Assert(_proxyId == PairManager.NullProxy);

            AABB aabb;

            ComputeAABB(out aabb, transform);

            bool inRange = broadPhase.InRange(aabb);

            // You are creating a shape outside the world box.
            Box2DXDebug.Assert(inRange);

            if (inRange)
            {
                _proxyId = broadPhase.CreateProxy(aabb, this);
            }
            else
            {
                _proxyId = PairManager.NullProxy;
            }
        }
Exemple #5
0
        internal bool Synchronize(BroadPhase broadPhase, XForm transform1, XForm transform2)
        {
            bool result;

            if (this._proxyId == PairManager.NullProxy)
            {
                result = false;
            }
            else
            {
                AABB aabb;
                this.ComputeSweptAABB(out aabb, transform1, transform2);
                if (broadPhase.InRange(aabb))
                {
                    broadPhase.MoveProxy((int)this._proxyId, aabb);
                    result = true;
                }
                else
                {
                    result = false;
                }
            }
            return(result);
        }
Exemple #6
0
        internal void RefilterProxy(BroadPhase broadPhase, XForm transform)
        {
            if (_proxyId == PairManager.NullProxy)
            {
                return;
            }

            broadPhase.DestroyProxy(_proxyId);

            AABB aabb;

            ComputeAABB(out aabb, transform);

            bool inRange = broadPhase.InRange(aabb);

            if (inRange)
            {
                _proxyId = broadPhase.CreateProxy(aabb, this);
            }
            else
            {
                _proxyId = PairManager.NullProxy;
            }
        }
Exemple #7
0
        public void Destroy(BroadPhase broadPhase)
        {
            // Remove proxy from the broad-phase.
            if (ProxyId != BroadPhase.NullProxy)
            {
                broadPhase.DestroyProxy(ProxyId);
                ProxyId = BroadPhase.NullProxy;
            }

            // Free the child shape.
            switch (Shape.Type)
            {
                case ShapeType.CircleShape:
                    {
                        //CircleShape s = (CircleShape)Shape;
                        //s->~b2CircleShape();
                        //allocator->Free(s, sizeof(b2CircleShape));
                    }
                    break;

                case ShapeType.PolygonShape:
                    {
                        //b2PolygonShape* s = (b2PolygonShape*)m_shape;
                        //s->~b2PolygonShape();
                        //allocator->Free(s, sizeof(b2PolygonShape));
                    }
                    break;
                default:
                    Box2DXDebug.Assert(false);
                    break;
            }

            Shape = null;
        }
Exemple #8
0
 internal bool Synchronize(BroadPhase broadPhase, XForm transform1, XForm transform2)
 {
     bool result;
     if (this._proxyId == PairManager.NullProxy)
     {
         result = false;
     }
     else
     {
         AABB aabb;
         this.ComputeSweptAABB(out aabb, transform1, transform2);
         if (broadPhase.InRange(aabb))
         {
             broadPhase.MoveProxy((int)this._proxyId, aabb);
             result = true;
         }
         else
         {
             result = false;
         }
     }
     return result;
 }
Exemple #9
0
 internal void DestroyProxy(BroadPhase broadPhase)
 {
     if (this._proxyId != PairManager.NullProxy)
     {
         broadPhase.DestroyProxy((int)this._proxyId);
         this._proxyId = PairManager.NullProxy;
     }
 }
Exemple #10
0
		public BroadPhaseTest()
		{
			BroadPhase.IsValidate = true;

			//srand(888);

			AABB worldAABB = new AABB();
			worldAABB.LowerBound.Set(-5.0f * k_extent, -5.0f * k_extent);
			worldAABB.UpperBound.Set(5.0f * k_extent, 5.0f * k_extent);

			_overlapCount = 0;
			_overlapCountExact = 0;
			_callback._test = this;

			_broadPhase = new BroadPhase(worldAABB, _callback);

			for (int i = 0; i < k_actorCount; i++)
				_overlaps[i] = new bool[k_actorCount];
			for (int i = 0; i < k_actorCount; i++)
				for (int j = 0; j < k_actorCount; j++)
					_overlaps[i][j] = false;

			for (int i = 0; i < k_actorCount; i++)
				_actors[i] = new Actor();

			for (int i = 0; i < k_actorCount; ++i)
			{
				bool s = false;
				if (i == 91)
					s = true;
				Actor actor = _actors[i];
				GetRandomAABB(ref actor.aabb);
				//actor->aabb.minVertex.Set(0.0f, 0.0f);
				//actor->aabb.maxVertex.Set(k_width, k_width);
				actor.proxyId = _broadPhase.CreateProxy(actor.aabb, actor);
				actor.overlapCount = 0;
				_broadPhase.Validate();
			}

			_automated = true;
			_stepCount = 0;
		}
Exemple #11
0
        public void Create(BroadPhase broadPhase, Body body, XForm xf, FixtureDef def)
        {
            UserData = def.UserData;
            Friction = def.Friction;
            Restitution = def.Restitution;
            Density = def.Density;

            _body = body;
            _next = null;

            Filter = def.Filter;

            _isSensor = def.IsSensor;

            _type = def.Type;

            // Allocate and initialize the child shape.
            switch (_type)
            {
                case ShapeType.CircleShape:
                    {
                        CircleShape circle = new CircleShape();
                        CircleDef circleDef = (CircleDef)def;
                        circle._position = circleDef.LocalPosition;
                        circle._radius = circleDef.Radius;
                        _shape = circle;
                    }
                    break;

                case ShapeType.PolygonShape:
                    {
                        PolygonShape polygon = new PolygonShape();
                        PolygonDef polygonDef = (PolygonDef)def;
                        polygon.Set(polygonDef.Vertices, polygonDef.VertexCount);
                        _shape = polygon;
                    }
                    break;

                case ShapeType.EdgeShape:
                    {
                        EdgeShape edge = new EdgeShape();
                        EdgeDef edgeDef = (EdgeDef)def;
                        edge.Set(edgeDef.Vertex1, edgeDef.Vertex2);
                        _shape = edge;
                    }
                    break;

                default:
                    Box2DXDebug.Assert(false);
                    break;
            }

            // Create proxy in the broad-phase.
            AABB aabb;
            _shape.ComputeAABB(out aabb, xf);

            bool inRange = broadPhase.InRange(aabb);

            // You are creating a shape outside the world box.
            Box2DXDebug.Assert(inRange);

            if (inRange)
            {
                _proxyId = broadPhase.CreateProxy(aabb, this);
            }
            else
            {
                _proxyId = PairManager.NullProxy;
            }
        }
Exemple #12
0
 protected virtual void Dispose(bool disposing)
 {
     if (disposing)
     {
         // free managed resources
         this.DestroyBody(this._groundBody);
         if (this._broadPhase is IDisposable)
         {
             (this._broadPhase as IDisposable).Dispose();
         }
         this._broadPhase = null;
     }
     // free native resources if there are any.
 }
		public void Initialize(BroadPhase broadPhase, PairCallback callback)
		{
			_broadPhase = broadPhase;
			_callback = callback;
		}
Exemple #14
0
		internal void DestroyProxy(BroadPhase broadPhase)
		{
			if (_proxyId != PairManager.NullProxy)
			{
				broadPhase.DestroyProxy(_proxyId);
				_proxyId = PairManager.NullProxy;
			}
		}
Exemple #15
0
		internal void CreateProxy(BroadPhase broadPhase, XForm transform)
		{
			Box2DXDebug.Assert(_proxyId == PairManager.NullProxy);

			AABB aabb;
			ComputeAABB(out aabb, transform);

			bool inRange = broadPhase.InRange(aabb);

			// You are creating a shape outside the world box.
			Box2DXDebug.Assert(inRange);

			if (inRange)
			{
				_proxyId = broadPhase.CreateProxy(aabb, this);
			}
			else
			{
				_proxyId = PairManager.NullProxy;
			}
		}
Exemple #16
0
        public void Synchronize(BroadPhase broadPhase, Transform transform1, Transform transform2)
        {
            if (ProxyId == BroadPhase.NullProxy)
            {
                return;
            }

            // Compute an AABB that covers the swept shape (may miss some rotation effect).
            AABB aabb1, aabb2;
            Shape.ComputeAABB(out aabb1, ref transform1);
            Shape.ComputeAABB(out aabb2, ref transform2);

            Aabb.Combine(aabb1, aabb2);

            Vec2 displacement = transform2.Position - transform1.Position;

            broadPhase.MoveProxy(ProxyId, Aabb, displacement);
        }
Exemple #17
0
        // We need separation create/destroy functions from the constructor/destructor because
        // the destructor cannot access the allocator or broad-phase (no destructor arguments allowed by C++).
        public void Create(BroadPhase broadPhase, Body body, Transform xf, FixtureDef def)
        {
            UserData = def.UserData;
            Friction = def.Friction;
            Restitution = def.Restitution;

            Body = body;
            _next = null;

            Filter = def.Filter;

            IsSensor = def.IsSensor;

            Shape = def.Shape.Clone();

            Shape.ComputeMass(out _massData, def.Density);

            // Create proxy in the broad-phase.
            Shape.ComputeAABB(out Aabb, ref xf);

            ProxyId = broadPhase.CreateProxy(Aabb, this);
        }
Exemple #18
0
        public void Destroy(BroadPhase broadPhase)
        {
            // Remove proxy from the broad-phase.
            if (_proxyId != PairManager.NullProxy)
            {
                broadPhase.DestroyProxy(_proxyId);
                _proxyId = PairManager.NullProxy;
            }

            // Free the child shape.
            _shape.Dispose();
            _shape = null;
        }
Exemple #19
0
		protected override void Dispose(bool state)
		{
			if (state)
			{
				BroadPhase.IsValidate = false;
				_broadPhase = null;
			}
		}
Exemple #20
0
        internal void RefilterProxy(BroadPhase broadPhase, XForm transform)
        {
            if (_proxyId == PairManager.NullProxy)
            {
                return;
            }

            broadPhase.DestroyProxy(_proxyId);

            AABB aabb;
            _shape.ComputeAABB(out aabb, transform);

            bool inRange = broadPhase.InRange(aabb);

            if (inRange)
            {
                _proxyId = broadPhase.CreateProxy(aabb, this);
            }
            else
            {
                _proxyId = PairManager.NullProxy;
            }
        }
Exemple #21
0
 internal void CreateProxy(BroadPhase broadPhase, XForm transform)
 {
     Box2DXDebug.Assert(this._proxyId == PairManager.NullProxy);
     AABB aabb;
     this.ComputeAABB(out aabb, transform);
     bool flag = broadPhase.InRange(aabb);
     Box2DXDebug.Assert(flag);
     if (flag)
     {
         this._proxyId = broadPhase.CreateProxy(aabb, this);
     }
     else
     {
         this._proxyId = PairManager.NullProxy;
     }
 }
Exemple #22
0
        internal bool Synchronize(BroadPhase broadPhase, XForm transform1, XForm transform2)
        {
            if (_proxyId == PairManager.NullProxy)
            {
                return false;
            }

            // Compute an AABB that covers the swept shape (may miss some rotation effect).
            AABB aabb1, aabb2;
            _shape.ComputeAABB(out aabb1, transform1);
            _shape.ComputeAABB(out aabb2, transform2);

            AABB aabb = new AABB();
            aabb.Combine(aabb1, aabb2);

            if (broadPhase.InRange(aabb))
            {
                broadPhase.MoveProxy(_proxyId, aabb);
                return true;
            }
            else
            {
                return false;
            }
        }
Exemple #23
0
 internal void RefilterProxy(BroadPhase broadPhase, XForm transform)
 {
     if (this._proxyId != PairManager.NullProxy)
     {
         broadPhase.DestroyProxy((int)this._proxyId);
         AABB aabb;
         this.ComputeAABB(out aabb, transform);
         bool flag = broadPhase.InRange(aabb);
         if (flag)
         {
             this._proxyId = broadPhase.CreateProxy(aabb, this);
         }
         else
         {
             this._proxyId = PairManager.NullProxy;
         }
     }
 }
Exemple #24
0
		/// <summary>
		/// Destruct the world. All physics entities are destroyed.
		/// </summary>
		public void Dispose()
		{
			DestroyBody(_groundBody);
			if (_broadPhase is IDisposable)
				(_broadPhase as IDisposable).Dispose();
			_broadPhase = null;
		}
Exemple #25
0
 public void Initialize(BroadPhase broadPhase, PairCallback callback)
 {
     this._broadPhase = broadPhase;
     this._callback   = callback;
 }
Exemple #26
0
		/// <summary>
		/// Construct a world object.
		/// </summary>
		/// <param name="worldAABB">A bounding box that completely encompasses all your shapes.</param>
		/// <param name="gravity">The world gravity vector.</param>
		/// <param name="doSleep">Improve performance by not simulating inactive bodies.</param>
		public World(AABB worldAABB, Vec2 gravity, bool doSleep)
		{
			_destructionListener = null;
			_boundaryListener = null;
			_contactFilter = WorldCallback.DefaultFilter;
			_contactListener = null;
			_debugDraw = null;

			_bodyList = null;
			_contactList = null;
			_jointList = null;

			_bodyCount = 0;
			_contactCount = 0;
			_jointCount = 0;

			_warmStarting = true;
			_continuousPhysics = true;

			_allowSleep = doSleep;
			_gravity = gravity;

			_lock = false;

			_inv_dt0 = 0.0f;

			_contactManager = new ContactManager();
			_contactManager._world = this;
			_broadPhase = new BroadPhase(worldAABB, _contactManager);

			BodyDef bd = new BodyDef();
			_groundBody = CreateBody(bd);
		}