示例#1
0
 public GearJointDef()
 {
     this.Type = JointType.GearJoint;
     this.Joint1 = null;
     this.Joint2 = null;
     this.Ratio = 1f;
 }
示例#2
0
文件: World.cs 项目: litdev1/LitDev
 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);
 }
示例#3
0
 // Message responders
 void DestroyJoint(Joint joint)
 {
     if (_world != null && joint != null)
     {
         _world.DestroyJoint(joint);
     }
 }
示例#4
0
 public void DestroyJoint(Joint joint)
 {
     if (joint == null)
     {
         return;
     }
     world.DestroyJoint(joint);
 }
示例#5
0
文件: Joint.cs 项目: litdev1/LitDev
 protected Joint(JointDef def)
 {
     this._type = def.Type;
     this._prev = null;
     this._next = null;
     this._body1 = def.Body1;
     this._body2 = def.Body2;
     this._collideConnected = def.CollideConnected;
     this._islandFlag = false;
     this._userData = def.UserData;
 }
示例#6
0
 public override void SayGoodbye(Joint joint)
 {
     if (test._mouseJoint == joint)
     {
         test._mouseJoint = null;
     }
     else
     {
         test.JointDestroyed(joint);
     }
 }
示例#7
0
        /// <summary>
        /// Construct a world object.
        /// </summary>
        /// <param name="gravity">The world gravity vector.</param>
        /// <param name="doSleep">Improve performance by not simulating inactive bodies.</param>
        public World(Vec2 gravity, bool doSleep)
        {
            _destructionListener = null;
            _debugDraw = null;

            _bodyList = null;
            _jointList = null;

            _bodyCount = 0;
            _jointCount = 0;

            _warmStarting = true;
            _continuousPhysics = true;

            _allowSleep = doSleep;
            _gravity = gravity;

            _flags = 0;

            _inv_dt0 = 0.0f;

            _contactManager = new ContactManager();
        }
 public GearJointDef()
 {
     Type = JointType.GearJoint;
     Joint1 = null;
     Joint2 = null;
     Ratio = 1.0f;
 }
 public void Add(Joint joint)
 {
     Box2DXDebug.Assert(_jointCount < _jointCapacity);
     _joints[_jointCount++] = joint;
 }
示例#10
0
文件: World.cs 项目: litdev1/LitDev
 private void DrawJoint(Joint joint)
 {
     Body body = joint.GetBody1();
     Body body2 = joint.GetBody2();
     XForm xForm = body.GetXForm();
     XForm xForm2 = body2.GetXForm();
     Vec2 position = xForm.Position;
     Vec2 position2 = xForm2.Position;
     Vec2 anchor = joint.Anchor1;
     Vec2 anchor2 = joint.Anchor2;
     Color color = new Color(0.5f, 0.8f, 0.8f);
     switch (joint.GetType())
     {
         case JointType.DistanceJoint:
         {
             this._debugDraw.DrawSegment(anchor, anchor2, color);
             break;
         }
         case JointType.PulleyJoint:
         {
             PulleyJoint pulleyJoint = (PulleyJoint)joint;
             Vec2 groundAnchor = pulleyJoint.GroundAnchor1;
             Vec2 groundAnchor2 = pulleyJoint.GroundAnchor2;
             this._debugDraw.DrawSegment(groundAnchor, anchor, color);
             this._debugDraw.DrawSegment(groundAnchor2, anchor2, color);
             this._debugDraw.DrawSegment(groundAnchor, groundAnchor2, color);
             break;
         }
         case JointType.MouseJoint:
         {
             break;
         }
         default:
         {
             this._debugDraw.DrawSegment(position, anchor, color);
             this._debugDraw.DrawSegment(anchor, anchor2, color);
             this._debugDraw.DrawSegment(position2, anchor2, color);
             break;
         }
     }
 }
示例#11
0
        protected Joint(JointDef def)
        {
            _type = def.Type;
            _prev = null;
            _next = null;
            _bodyA = def.Body1;
            _bodyB = def.Body2;
            _collideConnected = def.CollideConnected;
            _islandFlag = false;
            _userData = def.UserData;

            _edgeA.Joint = null;
            _edgeA.Other = null;
            _edgeA.Prev = null;
            _edgeA.Next = null;

            _edgeB.Joint = null;
            _edgeB.Other = null;
            _edgeB.Prev = null;
            _edgeB.Next = null;
        }
示例#12
0
文件: Joint.cs 项目: ajmaya/box2dx
		internal static void Destroy(Joint joint)
		{
			joint = null;
		}
示例#13
0
文件: World.cs 项目: colgreen/box2dx
		/// <summary>
		/// Create a joint to constrain bodies together. No reference to the definition
		/// is retained. This may cause the connected bodies to cease colliding.
		/// @warning This function is locked during callbacks.
		/// </summary>
		/// <param name="def"></param>
		/// <returns></returns>
		public Joint CreateJoint(JointDef def)
		{
			Box2DXDebug.Assert(_lock == false);

			Joint j = Joint.Create(def);

			// Connect to the world list.
			j._prev = null;
			j._next = _jointList;
			if (_jointList != null)
			{
				_jointList._prev = j;
			}
			_jointList = j;
			++_jointCount;

			// Connect to the bodies' doubly linked lists.
			j._node1.Joint = j;
			j._node1.Other = j._body2;
			j._node1.Prev = null;
			j._node1.Next = j._body1._jointList;
			if (j._body1._jointList != null)
				j._body1._jointList.Prev = j._node1;
			j._body1._jointList = j._node1;

			j._node2.Joint = j;
			j._node2.Other = j._body1;
			j._node2.Prev = null;
			j._node2.Next = j._body2._jointList;
			if (j._body2._jointList != null)
				j._body2._jointList.Prev = j._node2;
			j._body2._jointList = j._node2;

			// If the joint prevents collisions, then reset collision filtering.
			if (def.CollideConnected == false)
			{
				// Reset the proxies on the body with the minimum number of shapes.
				Body b = def.Body1._shapeCount < def.Body2._shapeCount ? def.Body1 : def.Body2;
				for (Shape s = b._shapeList; s != null; s = s._next)
				{
					s.RefilterProxy(_broadPhase, b.GetXForm());
				}
			}

			return j;
		}
示例#14
0
 internal static void Destroy(Joint joint)
 {
     joint = null;
 }
示例#15
0
        /// <summary>
        /// Destroy a joint. This may cause the connected bodies to begin colliding.
        /// @warning This function is locked during callbacks.
        /// </summary>
        /// <param name="j"></param>
        public void DestroyJoint(Joint j)
        {
            Box2DXDebug.Assert(IsLocked() == false);
            if (IsLocked())
            {
                return;
            }

            bool collideConnected = j._collideConnected;

            // Remove from the doubly linked list.
            if (j._prev != null)
            {
                j._prev._next = j._next;
            }

            if (j._next != null)
            {
                j._next._prev = j._prev;
            }

            if (j == _jointList)
            {
                _jointList = j._next;
            }

            // Disconnect from island graph.
            Body bodyA = j._bodyA;
            Body bodyB = j._bodyB;

            // Wake up connected bodies.
            bodyA.WakeUp();
            bodyB.WakeUp();

            // Remove from body 1.
            if (j._edgeA.Prev != null)
            {
                j._edgeA.Prev.Next = j._edgeA.Next;
            }

            if (j._edgeA.Next != null)
            {
                j._edgeA.Next.Prev = j._edgeA.Prev;
            }

            if (j._edgeA == bodyA._jointList)
            {
                bodyA._jointList = j._edgeA.Next;
            }

            j._edgeA.Prev = null;
            j._edgeA.Next = null;

            // Remove from body 2
            if (j._edgeB.Prev != null)
            {
                j._edgeB.Prev.Next = j._edgeB.Next;
            }

            if (j._edgeB.Next != null)
            {
                j._edgeB.Next.Prev = j._edgeB.Prev;
            }

            if (j._edgeB == bodyB._jointList)
            {
                bodyB._jointList = j._edgeB.Next;
            }

            j._edgeB.Prev = null;
            j._edgeB.Next = null;

            Joint.Destroy(j);

            Box2DXDebug.Assert(_jointCount > 0);
            --_jointCount;

            // If the joint prevents collisions, then flag any contacts for filtering.
            if (collideConnected == false)
            {
                ContactEdge edge = bodyB.GetContactList();
                while (edge != null)
                {
                    if (edge.Other == bodyA)
                    {
                        // Flag the contact for filtering at the next time step (where either
                        // body is awake).
                        edge.Contact.FlagForFiltering();
                    }

                    edge = edge.Next;
                }
            }
        }
示例#16
0
        /// <summary>
        /// Create a joint to constrain bodies together. No reference to the definition
        /// is retained. This may cause the connected bodies to cease colliding.
        /// @warning This function is locked during callbacks.
        /// </summary>
        /// <param name="def"></param>
        /// <returns></returns>
        public Joint CreateJoint(JointDef def)
        {
            Box2DXDebug.Assert(IsLocked() == false);
            if (IsLocked())
            {
                return null;
            }

            Joint j = Joint.Create(def);

            // Connect to the world list.
            j._prev = null;
            j._next = _jointList;
            if (_jointList != null)
            {
                _jointList._prev = j;
            }
            _jointList = j;
            ++_jointCount;

            // Connect to the bodies' doubly linked lists.
            j._edgeA.Joint = j;
            j._edgeA.Other = j._bodyB;
            j._edgeA.Prev = null;
            j._edgeA.Next = j._bodyA._jointList;
            if (j._bodyA._jointList != null)
                j._bodyA._jointList.Prev = j._edgeA;
            j._bodyA._jointList = j._edgeA;

            j._edgeB.Joint = j;
            j._edgeB.Other = j._bodyA;
            j._edgeB.Prev = null;
            j._edgeB.Next = j._bodyB._jointList;
            if (j._bodyB._jointList != null)
                j._bodyB._jointList.Prev = j._edgeB;
            j._bodyB._jointList = j._edgeB;

            Body bodyA = def.Body1;
            Body bodyB = def.Body2;

            bool staticA = bodyA.IsStatic();
            bool staticB = bodyB.IsStatic();

            // If the joint prevents collisions, then flag any contacts for filtering.
            if (def.CollideConnected == false && (staticA == false || staticB == false))
            {
                // Ensure we iterate over contacts on a dynamic body (usually have less contacts
                // than a static body). Ideally we will have a contact count on both bodies.
                if (staticB)
                {
                    Math.Swap(ref bodyA, ref bodyB);
                }

                ContactEdge edge = bodyB.GetContactList();
                while (edge != null)
                {
                    if (edge.Other == bodyA)
                    {
                        // Flag the contact for filtering at the next time step (where either
                        // body is awake).
                        edge.Contact.FlagForFiltering();
                    }

                    edge = edge.Next;
                }
            }

            // Note: creating a joint doesn't wake the bodies.

            return j;
        }
示例#17
0
文件: Web.cs 项目: colgreen/box2dx
		public override void JointDestroyed(Joint joint)
		{
			for (int i = 0; i < 8; ++i)
			{
				if (_joints[i] == joint)
				{
					_joints[i] = null;
					break;
				}
			}
		}
示例#18
0
文件: World.cs 项目: colgreen/box2dx
		/// <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);
		}
示例#19
0
文件: World.cs 项目: colgreen/box2dx
		private void DrawJoint(Joint joint)
		{
			Body b1 = joint.GetBody1();
			Body b2 = joint.GetBody2();
			XForm xf1 = b1.GetXForm();
			XForm xf2 = b2.GetXForm();
			Vec2 x1 = xf1.Position;
			Vec2 x2 = xf2.Position;
			Vec2 p1 = joint.Anchor1;
			Vec2 p2 = joint.Anchor2;

			Color color = new Color(0.5f, 0.8f, 0.8f);

			switch (joint.GetType())
			{
				case JointType.DistanceJoint:
					_debugDraw.DrawSegment(p1, p2, color);
					break;

				case JointType.PulleyJoint:
					{
						PulleyJoint pulley = (PulleyJoint)joint;
						Vec2 s1 = pulley.GroundAnchor1;
						Vec2 s2 = pulley.GroundAnchor2;
						_debugDraw.DrawSegment(s1, p1, color);
						_debugDraw.DrawSegment(s2, p2, color);
						_debugDraw.DrawSegment(s1, s2, color);
					}
					break;

				case JointType.MouseJoint:
					// don't draw this
					break;

				default:
					_debugDraw.DrawSegment(x1, p1, color);
					_debugDraw.DrawSegment(p1, p2, color);
					_debugDraw.DrawSegment(x2, p2, color);
					break;
			}
		}
示例#20
0
文件: Joint.cs 项目: ajmaya/box2dx
		protected Joint(JointDef def)
		{
			_type = def.Type;
			_prev = null;
			_next = null;
			_body1 = def.Body1;
			_body2 = def.Body2;
			_collideConnected = def.CollideConnected;
			_islandFlag = false;
			_userData = def.UserData;
		}
示例#21
0
文件: World.cs 项目: colgreen/box2dx
		/// <summary>
		/// Destroy a joint. This may cause the connected bodies to begin colliding.
		/// @warning This function is locked during callbacks.
		/// </summary>
		/// <param name="j"></param>
		public void DestroyJoint(Joint j)
		{
			Box2DXDebug.Assert(_lock == false);

			bool collideConnected = j._collideConnected;

			// Remove from the doubly linked list.
			if (j._prev != null)
			{
				j._prev._next = j._next;
			}

			if (j._next != null)
			{
				j._next._prev = j._prev;
			}

			if (j == _jointList)
			{
				_jointList = j._next;
			}

			// Disconnect from island graph.
			Body body1 = j._body1;
			Body body2 = j._body2;

			// Wake up connected bodies.
			body1.WakeUp();
			body2.WakeUp();

			// Remove from body 1.
			if (j._node1.Prev != null)
			{
				j._node1.Prev.Next = j._node1.Next;
			}

			if (j._node1.Next != null)
			{
				j._node1.Next.Prev = j._node1.Prev;
			}

			if (j._node1 == body1._jointList)
			{
				body1._jointList = j._node1.Next;
			}

			j._node1.Prev = null;
			j._node1.Next = null;

			// Remove from body 2
			if (j._node2.Prev != null)
			{
				j._node2.Prev.Next = j._node2.Next;
			}

			if (j._node2.Next != null)
			{
				j._node2.Next.Prev = j._node2.Prev;
			}

			if (j._node2 == body2._jointList)
			{
				body2._jointList = j._node2.Next;
			}

			j._node2.Prev = null;
			j._node2.Next = null;

			Joint.Destroy(j);

			Box2DXDebug.Assert(_jointCount > 0);
			--_jointCount;

			// If the joint prevents collisions, then reset collision filtering.
			if (collideConnected == false)
			{
				// Reset the proxies on the body with the minimum number of shapes.
				Body b = body1._shapeCount < body2._shapeCount ? body1 : body2;
				for (Shape s = b._shapeList; s != null; s = s._next)
				{
					s.RefilterProxy(_broadPhase, b.GetXForm());
				}
			}
		}
示例#22
0
 private void Events_MouseButtonDown(object sender, MouseButtonEventArgs e)
 {
     foreach (var worldObject in worldObjects)
     {
         var vec3 = Helper.Foo(e.X, e.Y);
         if (worldObject.HitTest(vec3.X, vec3.Y))
         {
             MouseJointDef mouseJointDef = new MouseJointDef();
             mouseJointDef.Body1 = ((Box)worldObject).Body;
             this.mouseJoint = this.world.CreateJoint(mouseJointDef);
         }
     }
 }
示例#23
0
文件: Test.cs 项目: ajmaya/box2dx
		// Let derived tests know that a joint was destroyed.
		public virtual void JointDestroyed(Joint joint) { ; }
示例#24
0
文件: World.cs 项目: litdev1/LitDev
 public Joint CreateJoint(JointDef def)
 {
     Box2DXDebug.Assert(!this._lock);
     Joint joint = Joint.Create(def);
     joint._prev = null;
     joint._next = this._jointList;
     if (this._jointList != null)
     {
         this._jointList._prev = joint;
     }
     this._jointList = joint;
     this._jointCount++;
     joint._node1.Joint = joint;
     joint._node1.Other = joint._body2;
     joint._node1.Prev = null;
     joint._node1.Next = joint._body1._jointList;
     if (joint._body1._jointList != null)
     {
         joint._body1._jointList.Prev = joint._node1;
     }
     joint._body1._jointList = joint._node1;
     joint._node2.Joint = joint;
     joint._node2.Other = joint._body1;
     joint._node2.Prev = null;
     joint._node2.Next = joint._body2._jointList;
     if (joint._body2._jointList != null)
     {
         joint._body2._jointList.Prev = joint._node2;
     }
     joint._body2._jointList = joint._node2;
     if (!def.CollideConnected)
     {
         Body body = (def.Body1._shapeCount < def.Body2._shapeCount) ? def.Body1 : def.Body2;
         for (Shape shape = body._shapeList; shape != null; shape = shape._next)
         {
             shape.RefilterProxy(this._broadPhase, body.GetXForm());
         }
     }
     return joint;
 }
示例#25
0
文件: Joint.cs 项目: litdev1/LitDev
 internal static void Destroy(Joint joint)
 {
 }
示例#26
0
文件: World.cs 项目: litdev1/LitDev
 public void DestroyJoint(Joint j)
 {
     Box2DXDebug.Assert(!this._lock);
     bool collideConnected = j._collideConnected;
     if (j._prev != null)
     {
         j._prev._next = j._next;
     }
     if (j._next != null)
     {
         j._next._prev = j._prev;
     }
     if (j == this._jointList)
     {
         this._jointList = j._next;
     }
     Body body = j._body1;
     Body body2 = j._body2;
     body.WakeUp();
     body2.WakeUp();
     if (j._node1.Prev != null)
     {
         j._node1.Prev.Next = j._node1.Next;
     }
     if (j._node1.Next != null)
     {
         j._node1.Next.Prev = j._node1.Prev;
     }
     if (j._node1 == body._jointList)
     {
         body._jointList = j._node1.Next;
     }
     j._node1.Prev = null;
     j._node1.Next = null;
     if (j._node2.Prev != null)
     {
         j._node2.Prev.Next = j._node2.Next;
     }
     if (j._node2.Next != null)
     {
         j._node2.Next.Prev = j._node2.Prev;
     }
     if (j._node2 == body2._jointList)
     {
         body2._jointList = j._node2.Next;
     }
     j._node2.Prev = null;
     j._node2.Next = null;
     Joint.Destroy(j);
     Box2DXDebug.Assert(this._jointCount > 0);
     this._jointCount--;
     if (!collideConnected)
     {
         Body body3 = (body._shapeCount < body2._shapeCount) ? body : body2;
         for (Shape shape = body3._shapeList; shape != null; shape = shape._next)
         {
             shape.RefilterProxy(this._broadPhase, body3.GetXForm());
         }
     }
 }
 /// <summary>
 /// Called when any joint is about to be destroyed due
 /// to the destruction of one of its attached bodies.
 /// </summary>
 public abstract void SayGoodbye(Joint joint);
示例#28
0
文件: Island.cs 项目: litdev1/LitDev
 public void Add(Joint joint)
 {
     Box2DXDebug.Assert(this._jointCount < this._jointCapacity);
     this._joints[this._jointCount++] = joint;
 }