コード例 #1
0
        public void Reset(int bodyCapacity, int contactCapacity, int jointCapacity, IContactListener listener)
        {
            _bodyCapacity    = bodyCapacity;
            _contactCapacity = contactCapacity;
            _jointCapacity   = jointCapacity;
            _bodyCount       = 0;
            _jointCount      = 0;

            _listener = listener;

            if (_bodies == null || _bodies.Length < bodyCapacity)
            {
                _bodies = new Body[bodyCapacity];
            }

            if (_contacts == null || _contacts.Length < contactCapacity)
            {
                _contacts = new Contact[contactCapacity * 2];
            }

            if (_joints == null || _joints.Length < jointCapacity)
            {
                _joints = new Joint[jointCapacity * 2];
            }
        }
コード例 #2
0
ファイル: Island.cs プロジェクト: n1ckd0r/Box2D.XNA
        public void Reset(int bodyCapacity, int contactCapacity, int jointCapacity, IContactListener listener)
        {
            _bodyCapacity = bodyCapacity;
	        _contactCapacity = contactCapacity;
	        _jointCapacity	 = jointCapacity;
	        _bodyCount = 0;
	        _jointCount = 0;

	        _listener = listener;

            if (_bodies == null || _bodies.Length < bodyCapacity)
            {
                _bodies = new Body[bodyCapacity];
            }

            if (_contacts == null || _contacts.Length < contactCapacity)
            {
                _contacts = new Contact[contactCapacity * 2];
            }

            if (_joints == null || _joints.Length < jointCapacity)
            {
                _joints = new Joint[jointCapacity * 2];
            }
        }
コード例 #3
0
 public ContactManager(World argPool)
 {
     ContactList     = null;
     ContactCount    = 0;
     ContactFilter   = new ContactFilter();
     ContactListener = null;
     BroadPhase      = new BroadPhase();
     pool            = argPool;
 }
コード例 #4
0
 public ContactManager(World argPool)
 {
     ContactList = null;
     ContactCount = 0;
     ContactFilter = new ContactFilter();
     ContactListener = null;
     BroadPhase = new BroadPhase();
     pool = argPool;
 }
コード例 #5
0
ファイル: ContactManager.cs プロジェクト: Deusald/SharpBox2D
        public void Dispose()
        {
            if (Interlocked.Exchange(ref _disposed, DisposedTrue) == DisposedTrue)
            {
                return;
            }

            BroadPhase = null;
            ContactList?.Clear();
            ContactList = null;

            ContactFilter   = null;
            ContactListener = null;
        }
コード例 #6
0
ファイル: Island.cs プロジェクト: prepare/gerich_box2dnet
        public void Init(int bodyCapacity, int contactCapacity, int jointCapacity, IContactListener listener)
        {
            // Console.WriteLine("Initializing Island");
            BodyCapacity    = bodyCapacity;
            ContactCapacity = contactCapacity;
            JointCapacity   = jointCapacity;
            BodyCount       = 0;
            ContactCount    = 0;
            JointCount      = 0;

            Listener = listener;

            if (Bodies == null || BodyCapacity > Bodies.Length)
            {
                Bodies = new Body[BodyCapacity];
            }
            if (Joints == null || JointCapacity > Joints.Length)
            {
                Joints = new Joint[JointCapacity];
            }
            if (Contacts == null || ContactCapacity > Contacts.Length)
            {
                Contacts = new Contact[ContactCapacity];
            }

            // dynamic array
            if (Velocities == null || BodyCapacity > Velocities.Length)
            {
                Velocity[] old = Velocities ?? new Velocity[0];
                Velocities = new Velocity[BodyCapacity];
                Array.Copy(old, 0, Velocities, 0, old.Length);
                for (int i = old.Length; i < Velocities.Length; i++)
                {
                    Velocities[i] = new Velocity();
                }
            }

            // dynamic array
            if (Positions == null || BodyCapacity > Positions.Length)
            {
                Position[] old = Positions ?? new Position[0];
                Positions = new Position[BodyCapacity];
                Array.Copy(old, 0, Positions, 0, old.Length);
                for (int i = old.Length; i < Positions.Length; i++)
                {
                    Positions[i] = new Position();
                }
            }
        }
コード例 #7
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="Island" /> class
        /// </summary>
        /// <param name="bodyCapacity">The body capacity</param>
        /// <param name="contactCapacity">The contact capacity</param>
        /// <param name="jointCapacity">The joint capacity</param>
        /// <param name="listener">The listener</param>
        public Island(int bodyCapacity, int contactCapacity, int jointCapacity, IContactListener listener)
        {
            this.bodyCapacity = bodyCapacity;
            ContactCapacity   = contactCapacity;
            JointCapacity     = jointCapacity;
            //__bodyCount = 0;
            //_contactCount = 0;
            //_jointCount = 0;

            Listener = listener;

            Bodies   = new Body[bodyCapacity];
            Contacts = new Contact[contactCapacity];
            Joints   = new Joint[jointCapacity];

            Velocities = new Velocity[this.bodyCapacity];
            Positions  = new Position[this.bodyCapacity];
        }
コード例 #8
0
        public Island(int bodyCapacity, int contactCapacity, int jointCapacity, IContactListener listener)
        {
            _bodyCapacity    = bodyCapacity;
            _contactCapacity = contactCapacity;
            _jointCapacity   = jointCapacity;
            //__bodyCount = 0;
            //_contactCount = 0;
            //_jointCount = 0;

            _listener = listener;

            _bodies   = new Body[bodyCapacity];
            _contacts = new Contact[contactCapacity];
            _joints   = new Joint[jointCapacity];

            _velocities = new Velocity[_bodyCapacity];
            _positions  = new Position[_bodyCapacity];
        }
コード例 #9
0
ファイル: Island.cs プロジェクト: qq362946/Box2DSharp
        public Island(
            int bodyCapacity,
            int contactCapacity,
            int jointCapacity,
            IContactListener contactListener)
        {
            BodyCount    = 0;
            ContactCount = 0;
            JointCount   = 0;

            ContactListener = contactListener;

            Bodies   = new Body[bodyCapacity];
            Contacts = new Contact[contactCapacity];
            Joints   = new Joint[jointCapacity];

            Velocities = new Velocity[bodyCapacity];
            Positions  = new Position[bodyCapacity];
        }
コード例 #10
0
        public Island(
            int bodyCapacity,
            int contactCapacity,
            int jointCapacity,
            IContactListener contactListener)
        {
            BodyCount    = 0;
            ContactCount = 0;
            JointCount   = 0;

            ContactListener = contactListener;

            Bodies = ArrayPool <Body> .Shared.Rent(bodyCapacity);

            Contacts = ArrayPool <Contact> .Shared.Rent(contactCapacity);

            Joints = ArrayPool <Joint> .Shared.Rent(jointCapacity);

            Positions = ArrayPool <Position> .Shared.Rent(bodyCapacity);  //new Position[bodyCapacity];

            Velocities = ArrayPool <Velocity> .Shared.Rent(bodyCapacity); // new Velocity[bodyCapacity];
        }
コード例 #11
0
        public void Setup(
            int bodyCapacity,
            int contactCapacity,
            int jointCapacity,
            IContactListener contactListener)
        {
            BodyCount    = 0;
            ContactCount = 0;
            JointCount   = 0;

            ContactListener = contactListener;

            Bodies = ArrayPool <Body> .Shared.Rent(bodyCapacity);

            Contacts = ArrayPool <Contact> .Shared.Rent(contactCapacity);

            Joints = ArrayPool <Joint> .Shared.Rent(jointCapacity);

            Positions = ArrayPool <Position> .Shared.Rent(bodyCapacity);

            Velocities = ArrayPool <Velocity> .Shared.Rent(bodyCapacity);
        }
コード例 #12
0
ファイル: Island.cs プロジェクト: gerich-home/box2dnet
        public void Init(int bodyCapacity, int contactCapacity, int jointCapacity, IContactListener listener)
        {
            // Console.WriteLine("Initializing Island");
            BodyCapacity = bodyCapacity;
            ContactCapacity = contactCapacity;
            JointCapacity = jointCapacity;
            BodyCount = 0;
            ContactCount = 0;
            JointCount = 0;

            Listener = listener;

            if (Bodies == null || BodyCapacity > Bodies.Length)
            {
                Bodies = new Body[BodyCapacity];
            }
            if (Joints == null || JointCapacity > Joints.Length)
            {
                Joints = new Joint[JointCapacity];
            }
            if (Contacts == null || ContactCapacity > Contacts.Length)
            {
                Contacts = new Contact[ContactCapacity];
            }

            // dynamic array
            if (Velocities == null || BodyCapacity > Velocities.Length)
            {
                Velocity[] old = Velocities ?? new Velocity[0];
                Velocities = new Velocity[BodyCapacity];
                Array.Copy(old, 0, Velocities, 0, old.Length);
                for (int i = old.Length; i < Velocities.Length; i++)
                {
                    Velocities[i] = new Velocity();
                }
            }

            // dynamic array
            if (Positions == null || BodyCapacity > Positions.Length)
            {
                Position[] old = Positions ?? new Position[0];
                Positions = new Position[BodyCapacity];
                Array.Copy(old, 0, Positions, 0, old.Length);
                for (int i = old.Length; i < Positions.Length; i++)
                {
                    Positions[i] = new Position();
                }
            }
        }
コード例 #13
0
        public void Update(IContactListener listener)
        {
            oldManifold.Set(Manifold);

            // Re-enable this contact.
            Flags |= ContactFlags.Enabled;

            bool touching;
            bool wasTouching = (Flags & ContactFlags.Touching) == ContactFlags.Touching;

            bool sensorA = FixtureA.Sensor;
            bool sensorB = FixtureB.Sensor;
            bool sensor  = sensorA || sensorB;

            Body      bodyA = FixtureA.Body;
            Body      bodyB = FixtureB.Body;
            Transform xfA   = bodyA.GetTransform();
            Transform xfB   = bodyB.GetTransform();

            // log.debug("TransformA: "+xfA);
            // log.debug("TransformB: "+xfB);

            if (sensor)
            {
                Shape shapeA = FixtureA.Shape;
                Shape shapeB = FixtureB.Shape;
                touching = Pool.GetCollision().TestOverlap(shapeA, ChildIndexA, shapeB, ChildIndexB, xfA, xfB);

                // Sensors don't generate manifolds.
                Manifold.PointCount = 0;
            }
            else
            {
                Evaluate(Manifold, xfA, xfB);
                touching = Manifold.PointCount > 0;

                // Match old contact ids to new contact ids and copy the
                // stored impulses to warm start the solver.
                for (int i = 0; i < Manifold.PointCount; ++i)
                {
                    ManifoldPoint mp2 = Manifold.Points[i];
                    mp2.NormalImpulse  = 0.0f;
                    mp2.TangentImpulse = 0.0f;
                    ContactID id2 = mp2.Id;

                    for (int j = 0; j < oldManifold.PointCount; ++j)
                    {
                        ManifoldPoint mp1 = oldManifold.Points[j];

                        if (mp1.Id.IsEqual(id2))
                        {
                            mp2.NormalImpulse  = mp1.NormalImpulse;
                            mp2.TangentImpulse = mp1.TangentImpulse;
                            break;
                        }
                    }
                }

                if (touching != wasTouching)
                {
                    bodyA.Awake = true;
                    bodyB.Awake = true;
                }
            }

            if (touching)
            {
                Flags |= ContactFlags.Touching;
            }
            else
            {
                Flags &= ~ContactFlags.Touching;
            }

            if (listener == null)
            {
                return;
            }

            if (!wasTouching && touching)
            {
                listener.BeginContact(this);
            }

            if (wasTouching && !touching)
            {
                listener.EndContact(this);
            }

            if (!sensor && touching)
            {
                listener.PreSolve(this, oldManifold);
            }
        }
コード例 #14
0
ファイル: Contact.cs プロジェクト: DPlayer234/cs-heartbeat
        // Update the contact manifold and touching status.
        // Note: do not assume the fixture AABBs are overlapping or are valid.
        internal void Update(IContactListener listener)
        {
            Manifold oldManifold = _manifold;

            // Re-enable this contact.
            _flags |= ContactFlags.Enabled;

            bool touching    = false;
            bool wasTouching = (_flags & ContactFlags.Touching) == ContactFlags.Touching;

            bool sensorA = _fixtureA.IsSensor();
            bool sensorB = _fixtureB.IsSensor();
            bool sensor  = sensorA || sensorB;

            Body      bodyA = _fixtureA.GetBody();
            Body      bodyB = _fixtureB.GetBody();
            Transform xfA; bodyA.GetTransform(out xfA);
            Transform xfB; bodyB.GetTransform(out xfB);

            // Is this contact a sensor?
            if (sensor)
            {
                Shape shapeA = _fixtureA.GetShape();
                Shape shapeB = _fixtureB.GetShape();
                touching = AABB.TestOverlap(shapeA, _indexA, shapeB, _indexB, ref xfA, ref xfB);

                // Sensors don't generate manifolds.
                _manifold._pointCount = 0;
            }
            else
            {
                Evaluate(ref _manifold, ref xfA, ref xfB);
                touching = _manifold._pointCount > 0;

                // Match old contact ids to new contact ids and copy the
                // stored impulses to warm start the solver.
                for (int i = 0; i < _manifold._pointCount; ++i)
                {
                    ManifoldPoint mp2 = _manifold._points[i];
                    mp2.NormalImpulse  = 0.0f;
                    mp2.TangentImpulse = 0.0f;
                    ContactID id2   = mp2.Id;
                    bool      found = false;

                    for (int j = 0; j < oldManifold._pointCount; ++j)
                    {
                        ManifoldPoint mp1 = oldManifold._points[j];

                        if (mp1.Id.Key == id2.Key)
                        {
                            mp2.NormalImpulse  = mp1.NormalImpulse;
                            mp2.TangentImpulse = mp1.TangentImpulse;
                            found = true;
                            break;
                        }
                    }
                    if (found == false)
                    {
                        mp2.NormalImpulse  = 0.0f;
                        mp2.TangentImpulse = 0.0f;
                    }

                    _manifold._points[i] = mp2;
                }

                if (touching != wasTouching)
                {
                    bodyA.SetAwake(true);
                    bodyB.SetAwake(true);
                }
            }

            if (touching)
            {
                _flags |= ContactFlags.Touching;
            }
            else
            {
                _flags &= ~ContactFlags.Touching;
            }

            if (wasTouching == false && touching == true && null != listener)
            {
                listener.BeginContact(this);
            }

            if (wasTouching == true && touching == false && null != listener)
            {
                listener.EndContact(this);
            }

            if (sensor == false && null != listener)
            {
                listener.PreSolve(this, ref oldManifold);
            }
        }
コード例 #15
0
ファイル: Contact.cs プロジェクト: n1ckd0r/Box2D.XNA
        // Update the contact manifold and touching status.
        // Note: do not assume the fixture AABBs are overlapping or are valid.
	    internal void Update(IContactListener listener)
        {
            Manifold oldManifold = _manifold;

            // Re-enable this contact.
            _flags |= ContactFlags.Enabled;

            bool touching = false;
            bool wasTouching = (_flags & ContactFlags.Touching) == ContactFlags.Touching;

            bool sensorA = _fixtureA.IsSensor();
            bool sensorB = _fixtureB.IsSensor();
            bool sensor = sensorA || sensorB;

	        Body bodyA = _fixtureA.GetBody();
	        Body bodyB = _fixtureB.GetBody();
	        Transform xfA; bodyA.GetTransform(out xfA);
	        Transform xfB; bodyB.GetTransform(out xfB);

	        // Is this contact a sensor?
	        if (sensor)
	        {
		        Shape shapeA = _fixtureA.GetShape();
		        Shape shapeB = _fixtureB.GetShape();
		        touching = AABB.TestOverlap(shapeA, _indexA, shapeB, _indexB, ref xfA, ref xfB);

		        // Sensors don't generate manifolds.
		        _manifold._pointCount = 0;
	        }
	        else
	        {
		        Evaluate(ref _manifold, ref xfA, ref xfB);
		        touching = _manifold._pointCount > 0;

		        // Match old contact ids to new contact ids and copy the
		        // stored impulses to warm start the solver.
		        for (int i = 0; i < _manifold._pointCount; ++i)
		        {
			        ManifoldPoint mp2 = _manifold._points[i];
			        mp2.NormalImpulse = 0.0f;
			        mp2.TangentImpulse = 0.0f;
			        ContactID id2 = mp2.Id;
                    bool found = false;

			        for (int j = 0; j < oldManifold._pointCount; ++j)
			        {
				        ManifoldPoint mp1 = oldManifold._points[j];

				        if (mp1.Id.Key == id2.Key)
				        {
					        mp2.NormalImpulse = mp1.NormalImpulse;
					        mp2.TangentImpulse = mp1.TangentImpulse;
                            found = true;
					        break;
				        }
			        }
                    if (found == false)
                    {
                        mp2.NormalImpulse = 0.0f;
                        mp2.TangentImpulse = 0.0f;
                    }

                    _manifold._points[i] = mp2;
		        }

		        if (touching != wasTouching)
		        {
			        bodyA.SetAwake(true);
			        bodyB.SetAwake(true);
		        }
	        }

	        if (touching)
	        {
		        _flags |= ContactFlags.Touching;
	        }
	        else
	        {
		        _flags &= ~ContactFlags.Touching;
	        }

	        if (wasTouching == false && touching == true && null != listener)
	        {
		        listener.BeginContact(this);
	        }

	        if (wasTouching == true && touching == false && null != listener)
	        {
		        listener.EndContact(this);
	        }

	        if (sensor == false && null != listener)
	        {
		        listener.PreSolve(this, ref oldManifold);
	        }
        }
コード例 #16
0
        public void Update(IContactListener listener)
        {
            Manifold oldManifold = _manifold.Clone();

            Evaluate();

            Body bodyA = _fixtureA.Body;
            Body bodyB = _fixtureB.Body;

            int oldCount = oldManifold.PointCount;
            int newCount = _manifold.PointCount;

            if (newCount == 0 && oldCount > 0)
            {
                bodyA.WakeUp();
                bodyB.WakeUp();
            }

            // Slow contacts don't generate TOI events.
            if (bodyA.IsStatic() || bodyA.IsBullet() || bodyB.IsStatic() || bodyB.IsBullet())
            {
                _flags &= ~CollisionFlags.Slow;
            }
            else
            {
                _flags |= CollisionFlags.Slow;
            }

            // Match old contact ids to new contact ids and copy the
            // stored impulses to warm start the solver.
            for (int i = 0; i < _manifold.PointCount; ++i)
            {
                ManifoldPoint mp2 = _manifold.Points[i];
                mp2.NormalImpulse  = 0.0f;
                mp2.TangentImpulse = 0.0f;
                ContactID id2 = mp2.ID;

                for (int j = 0; j < oldManifold.PointCount; ++j)
                {
                    ManifoldPoint mp1 = oldManifold.Points[j];

                    if (mp1.ID.Key == id2.Key)
                    {
                        mp2.NormalImpulse  = mp1.NormalImpulse;
                        mp2.TangentImpulse = mp1.TangentImpulse;
                        break;
                    }
                }
            }

            if (oldCount == 0 && newCount > 0)
            {
                _flags |= CollisionFlags.Touch;
                if (listener != null)
                {
                    listener.BeginContact(this);
                }
            }

            if (oldCount > 0 && newCount == 0)
            {
                _flags &= ~CollisionFlags.Touch;
                if (listener != null)
                {
                    listener.EndContact(this);
                }
            }

            if ((_flags & CollisionFlags.NonSolid) == 0)
            {
                if (listener != null)
                {
                    listener.PreSolve(this, oldManifold);
                }

                // The user may have disabled contact.
                if (_manifold.PointCount == 0)
                {
                    _flags &= ~CollisionFlags.Touch;
                }
            }
        }
コード例 #17
0
ファイル: Contact.cs プロジェクト: gerich-home/box2dnet
        public void Update(IContactListener listener)
        {
            oldManifold.Set(Manifold);

            // Re-enable this contact.
            Flags |= ContactFlags.Enabled;

            bool touching;
            bool wasTouching = (Flags & ContactFlags.Touching) == ContactFlags.Touching;

            bool sensorA = FixtureA.Sensor;
            bool sensorB = FixtureB.Sensor;
            bool sensor = sensorA || sensorB;

            Body bodyA = FixtureA.Body;
            Body bodyB = FixtureB.Body;
            Transform xfA = bodyA.GetTransform();
            Transform xfB = bodyB.GetTransform();
            // log.debug("TransformA: "+xfA);
            // log.debug("TransformB: "+xfB);

            if (sensor)
            {
                Shape shapeA = FixtureA.Shape;
                Shape shapeB = FixtureB.Shape;
                touching = Pool.GetCollision().TestOverlap(shapeA, ChildIndexA, shapeB, ChildIndexB, xfA, xfB);

                // Sensors don't generate manifolds.
                Manifold.PointCount = 0;
            }
            else
            {
                Evaluate(Manifold, xfA, xfB);
                touching = Manifold.PointCount > 0;

                // Match old contact ids to new contact ids and copy the
                // stored impulses to warm start the solver.
                for (int i = 0; i < Manifold.PointCount; ++i)
                {
                    ManifoldPoint mp2 = Manifold.Points[i];
                    mp2.NormalImpulse = 0.0f;
                    mp2.TangentImpulse = 0.0f;
                    ContactID id2 = mp2.Id;

                    for (int j = 0; j < oldManifold.PointCount; ++j)
                    {
                        ManifoldPoint mp1 = oldManifold.Points[j];

                        if (mp1.Id.IsEqual(id2))
                        {
                            mp2.NormalImpulse = mp1.NormalImpulse;
                            mp2.TangentImpulse = mp1.TangentImpulse;
                            break;
                        }
                    }
                }

                if (touching != wasTouching)
                {
                    bodyA.Awake = true;
                    bodyB.Awake = true;
                }
            }

            if (touching)
            {
                Flags |= ContactFlags.Touching;
            }
            else
            {
                Flags &= ~ContactFlags.Touching;
            }

            if (listener == null)
            {
                return;
            }

            if (!wasTouching && touching)
            {
                listener.BeginContact(this);
            }

            if (wasTouching && !touching)
            {
                listener.EndContact(this);
            }

            if (!sensor && touching)
            {
                listener.PreSolve(this, oldManifold);
            }
        }
コード例 #18
0
 public void SetContactListener(IContactListener contactListener)
 {
     _world?.SetContactListener(contactListener);
 }