A shape is used for collision detection. You can create a shape however you like. Shapes used for simulation in World are created automatically when a Fixture is created. Shapes may encapsulate a one or more child shapes.
 public FarseerObject(FarseerWorld world, Shape shape, BodyType BodyType = BodyType.Dynamic)
 {            
     body = new Body(world.World);
     body.BodyType = BodyType;
     body.CreateFixture(shape);
     body.Enabled = false;            
 }
Exemplo n.º 2
0
		/// <summary>
		/// tests for an overlap of shapeA and shapeB. Returns false if both Shapes are chains or if they are not overlapping.
		/// </summary>
		/// <returns><c>true</c>, if overlap was tested, <c>false</c> otherwise.</returns>
		/// <param name="shapeA">Shape a.</param>
		/// <param name="shapeB">Shape b.</param>
		/// <param name="transformA">Transform a.</param>
		/// <param name="transformB">Transform b.</param>
		public static bool testOverlap( Shape shapeA, Shape shapeB, ref FSTransform transformA, ref FSTransform transformB )
		{
			if( shapeA.childCount == 1 && shapeB.childCount == 1 )
				return Collision.testOverlap( shapeA, 0, shapeB, 0, ref transformA, ref transformB );

			if( shapeA.childCount > 1 )
			{
				for( var i = 0; i < shapeA.childCount; i++ )
				{
					if( Collision.testOverlap( shapeA, i, shapeB, 0, ref transformA, ref transformB ) )
						return true;
				}
			}

			if( shapeB.childCount > 1 )
			{
				for( var i = 0; i < shapeB.childCount; i++ )
				{
					if( Collision.testOverlap( shapeA, 0, shapeB, i, ref transformA, ref transformB ) )
						return true;
				}
			}

			return false;
		}
Exemplo n.º 3
0
		public void DrawLineShape(Shape shape, Color color)
		{
			if (!_hasBegun)
				throw new InvalidOperationException("Begin must be called before DrawLineShape can be called.");

			if (shape.ShapeType != ShapeType.Edge && shape.ShapeType != ShapeType.Chain)
				throw new NotSupportedException("The specified shapeType is not supported by LineBatch.");

			if (shape.ShapeType == ShapeType.Edge)
			{
				if (_lineVertsCount >= _lineVertices.Length)
					Flush();

				EdgeShape edge = (EdgeShape)shape;
				_lineVertices[_lineVertsCount].Position = new Vector3(edge.Vertex1, 0f);
				_lineVertices[_lineVertsCount + 1].Position = new Vector3(edge.Vertex2, 0f);
				_lineVertices[_lineVertsCount].Color = _lineVertices[_lineVertsCount + 1].Color = color;
				_lineVertsCount += 2;
			}
			else if (shape.ShapeType == ShapeType.Chain)
			{
				ChainShape chain = (ChainShape)shape;
				for (int i = 0; i < chain.Vertices.Count; ++i)
				{
					if (_lineVertsCount >= _lineVertices.Length)
						Flush();

					_lineVertices[_lineVertsCount].Position = new Vector3(chain.Vertices[i], 0f);
					_lineVertices[_lineVertsCount + 1].Position = new Vector3(chain.Vertices.NextVertex(i), 0f);
					_lineVertices[_lineVertsCount].Color = _lineVertices[_lineVertsCount + 1].Color = color;
					_lineVertsCount += 2;
				}
			}
		}
Exemplo n.º 4
0
        /// <summary>
        /// Initialize the proxy using the given shape. The shape
        /// must remain in scope while the proxy is in use.
        /// </summary>
        /// <param name="shape">The shape.</param>
        /// <param name="index">The index.</param>
        public void Set(Shape shape, int index)
        {
            switch (shape.ShapeType)
            {
                case ShapeType.Circle:
                    {
                        CircleShape circle = (CircleShape) shape;
                        Vertices = new Vertices(1);
                        Vertices.Add(circle.Position);
                        Radius = circle.Radius;
                    }
                    break;

                case ShapeType.Polygon:
                    {
                        PolygonShape polygon = (PolygonShape) shape;
                        Vertices = polygon.Vertices;
                        Radius = polygon.Radius;
                    }
                    break;

                case ShapeType.Loop:
                    {
                        LoopShape loop = (LoopShape) shape;
                        Debug.Assert(0 <= index && index < loop.Vertices.Count);

                        Buffer[0] = loop.Vertices[index];
                        if (index + 1 < loop.Vertices.Count)
                        {
                            Buffer[1] = loop.Vertices[index + 1];
                        }
                        else
                        {
                            Buffer[1] = loop.Vertices[0];
                        }

                        Vertices = new Vertices(2);
                        Vertices.Add(Buffer[0]);
                        Vertices.Add(Buffer[1]);
                        Radius = loop.Radius;
                    }
                    break;

                case ShapeType.Edge:
                    {
                        EdgeShape edge = (EdgeShape) shape;
                        Vertices = new Vertices(2);
                        Vertices.Add(edge.Vertex1);
                        Vertices.Add(edge.Vertex2);
                        Radius = edge.Radius;
                    }
                    break;

                default:
                    Debug.Assert(false);
                    break;
            }
        }
Exemplo n.º 5
0
 public DynamicBody(GameWorld World, Shape Shape, Vector2 Position, string TexName)
     : base(World)
 {
     Body BodyDec;
     BodyDec = new Body(World.PhysicalWorld);
     BodyDec.BodyType = BodyType.Dynamic;
     BodyFixture = BodyDec.CreateFixture(Shape);
     BodyFixture.Body.Position = Position;
     Texture = GeneralManager.Textures[TexName];
 }
Exemplo n.º 6
0
 /// <summary>
 /// Gets the size from shape.
 /// </summary>
 /// <param name="shape">The shape.</param>
 /// <returns></returns>
 public static Vector2 GetSizeFromShape( Shape shape )
 {
     switch ( shape.ShapeType ) {
         case ShapeType.Circle:
             return new Vector2( shape.Radius );
         case ShapeType.Polygon:
             return GetSizeFromVertices( ( (PolygonShape)shape ).Vertices );
         default:
             return Vector2.Zero;
     }
 }
Exemplo n.º 7
0
		public Texture2D TextureFromShape(Shape shape, MaterialType type, Color color, float materialScale)
		{
			switch (shape.ShapeType)
			{
				case ShapeType.Circle:
				return CircleTexture(shape.Radius, type, color, materialScale);
				case ShapeType.Polygon:
				return TextureFromVertices(((PolygonShape)shape).Vertices, type, color, materialScale);
				default:
				throw new NotSupportedException("The specified shape type is not supported.");
			}
		}
Exemplo n.º 8
0
		// GJK using Voronoi regions (Christer Ericson) and Barycentric coordinates.

		/// <summary>
		/// Initialize the proxy using the given shape. The shape
		/// must remain in scope while the proxy is in use.
		/// </summary>
		/// <param name="shape">The shape.</param>
		/// <param name="index">The index.</param>
		public void set( Shape shape, int index )
		{
			switch( shape.shapeType )
			{
				case ShapeType.Circle:
					{
						var circle = (CircleShape)shape;
						vertices.Clear();
						vertices.Add( circle.position );
						radius = circle.radius;
					}
					break;

				case ShapeType.Polygon:
					{
						var polygon = (PolygonShape)shape;
						vertices.Clear();
						for( int i = 0; i < polygon.vertices.Count; i++ )
						{
							vertices.Add( polygon.vertices[i] );
						}
						radius = polygon.radius;
					}
					break;

				case ShapeType.Chain:
					{
						var chain = (ChainShape)shape;
						Debug.Assert( 0 <= index && index < chain.vertices.Count );
						vertices.Clear();
						vertices.Add( chain.vertices[index] );
						vertices.Add( index + 1 < chain.vertices.Count ? chain.vertices[index + 1] : chain.vertices[0] );

						radius = chain.radius;
					}
					break;

				case ShapeType.Edge:
					{
						var edge = (EdgeShape)shape;
						vertices.Clear();
						vertices.Add( edge.vertex1 );
						vertices.Add( edge.vertex2 );
						radius = edge.radius;
					}
					break;

				default:
					Debug.Assert( false );
					break;
			}
		}
Exemplo n.º 9
0
        /// <summary>
        /// Initialize the proxy using the given shape. The shape
        /// must remain in scope while the proxy is in use.
        /// </summary>
        /// <param name="shape">The shape.</param>
        /// <param name="index">The index.</param>
        public void Set(Shape shape, int index)
        {
            switch (shape.ShapeType)
            {
                case ShapeType.Circle:
                    {
                        CircleShape circle = (CircleShape)shape;
                        Vertices.Clear();
                        Vertices.Add(circle.Position);
                        Radius = circle.Radius;
                    }
                    break;

                case ShapeType.Polygon:
                    {
                        PolygonShape polygon = (PolygonShape)shape;
                        Vertices.Clear();
                        for (int i = 0; i < polygon.Vertices.Count; i++)
                        {
                            Vertices.Add(polygon.Vertices[i]);
                        }
                        Radius = polygon.Radius;
                    }
                    break;

                case ShapeType.Loop:
                    {
                        LoopShape loop = (LoopShape)shape;
                        Debug.Assert(0 <= index && index < loop.Vertices.Count);
                        Vertices.Clear();
                        Vertices.Add(loop.Vertices[index]);
                        Vertices.Add(index + 1 < loop.Vertices.Count ? loop.Vertices[index + 1] : loop.Vertices[0]);

                        Radius = loop.Radius;
                    }
                    break;

                case ShapeType.Edge:
                    {
                        EdgeShape edge = (EdgeShape)shape;
                        Vertices.Clear();
                        Vertices.Add(edge.Vertex1);
                        Vertices.Add(edge.Vertex2);
                        Radius = edge.Radius;
                    }
                    break;

                default:
                    Debug.Assert(false);
                    break;
            }
        }
Exemplo n.º 10
0
        public Collectible(GameScreen gameScreen, Shape shape, World world, Camera2D camera)
            : base(gameScreen.ScreenManager.Game)
        {
            this.gameScreen = gameScreen;

            this.world = world;
            body = new Body(world);
            body.CreateFixture(shape);
            body.CollisionCategories = Category.Cat3;
            body.CollidesWith = Category.Cat2;
            body.BodyType = BodyType.Kinematic;

            body.OnCollision += body_OnCollision;

            shootParticles = false;
            collected = false;

            this.camera = camera;
        }
Exemplo n.º 11
0
        private void SerializeShape(Shape shape)
        {
            _writer.WriteStartElement("Shape");
            _writer.WriteAttributeString("Type", shape.ShapeType.ToString());

            switch (shape.ShapeType)
            {
                case ShapeType.Circle:
                    {
                        CircleShape circle = (CircleShape)shape;

                        _writer.WriteElementString("Radius", circle.Radius.ToString());

                        WriteElement("Position", circle.Position);
                    }
                    break;
                case ShapeType.Polygon:
                    {
                        PolygonShape poly = (PolygonShape)shape;

                        _writer.WriteStartElement("Vertices");
                        foreach (Vector2 v in poly.Vertices)
                            WriteElement("Vertex", v);
                        _writer.WriteEndElement();

                        WriteElement("Centroid", poly.MassData.Centroid);
                    }
                    break;
                case ShapeType.Edge:
                    {
                        EdgeShape poly = (EdgeShape)shape;
                        WriteElement("Vertex1", poly.Vertex1);
                        WriteElement("Vertex2", poly.Vertex2);
                    }
                    break;
                default:
                    throw new Exception();
            }

            _writer.WriteEndElement();
        }
Exemplo n.º 12
0
 public void DrawLineShape( SpriteBatch batch, Shape shape, Color color, float width )
 {
     if ( shape.ShapeType != ShapeType.Edge &&
          shape.ShapeType != ShapeType.Loop ) {
         throw new NotSupportedException ( "The specified shapeType is not supported by LineBatch." );
     }
     switch ( shape.ShapeType ) {
         case ShapeType.Edge : {
             var edge = (EdgeShape) shape;
             DrawLine ( batch, width, color, edge.Vertex1, edge.Vertex2 );
         }
             break;
         case ShapeType.Polygon : {
             var chain = (LoopShape) shape;
             for ( int i = 0; i < chain.Vertices.Count; ++i ) {
                 DrawLine ( batch, width, color, chain.Vertices [i], chain.Vertices.NextVertex ( i ) );
             }
         }
             break;
     }
 }
Exemplo n.º 13
0
 public static List<Body> EvenlyDistributeShapesAlongPath(World world, Path path, Shape shape, BodyType type,
                                                          int copies)
 {
     return EvenlyDistributeShapesAlongPath(world, path, shape, type, copies, null);
 }
Exemplo n.º 14
0
        /// <summary>
        /// Duplicates the given Body along the given path for approximatly the given copies.
        /// </summary>
        /// <param name="world">The world.</param>
        /// <param name="path">The path.</param>
        /// <param name="shape">The shape.</param>
        /// <param name="type">The type.</param>
        /// <param name="copies">The copies.</param>
        /// <param name="userData">The user data.</param>
        /// <returns></returns>
        public static List<Body> EvenlyDistributeShapesAlongPath(World world, Path path, Shape shape, BodyType type,
                                                                 int copies, DebugMaterial userData)
        {
            List<Shape> shapes = new List<Shape>(1);
            shapes.Add(shape);

            return EvenlyDistributeShapesAlongPath(world, path, shapes, type, copies, userData);
        }
Exemplo n.º 15
0
        public Texture2D TextureFromShape(Shape shape, string textureRef, Color color, float materialScale)
        {
            Texture2D shapeTexture = null;
            if (this.IsInitialized && shape != null)
            {
                switch (shape.ShapeType)
                {
                    case ShapeType.Circle:
                        shapeTexture = this.CircleTexture(shape.Radius, textureRef, color, materialScale);
                        break;

                    case ShapeType.Polygon:
                        shapeTexture = this.TextureFromVertices(((PolygonShape)shape).Vertices, textureRef, color, materialScale);
                        break;

                    case ShapeType.Chain:
                        ChainShape chain = shape as ChainShape;
                        if (chain != null)
                        {
                            shapeTexture = this.TextureFromVertices(AssetCreator.CreateChainVertices(chain), textureRef, color, materialScale);
                        }

                        break;
                }
            }

            return shapeTexture;
        }
Exemplo n.º 16
0
        private int FindShapeIndex(Shape shape)
        {
            for (int i = 0; i < _serializedShapes.Count; ++i)
            {
                if (_serializedShapes[i].CompareTo(shape))
                    return i;
            }

            return -1;
        }
Exemplo n.º 17
0
 public void DrawLineShape(Shape shape)
 {
     DrawLineShape(shape, Color.Black);
 }
Exemplo n.º 18
0
        public Fixture(Body body, Shape shape, object userData)
        {
            if (Settings.UseFPECollisionCategories)
                _collisionCategories = Category.All;
            else
                _collisionCategories = Category.Cat1;

            _collidesWith = Category.All;
            _collisionGroup = 0;

            //Fixture defaults
            Friction = 0.2f;
            Restitution = 0;

            IsSensor = false;

            Body = body;
            UserData = userData;

            if (Settings.ConserveMemory)
                Shape = shape;
            else
                Shape = shape.Clone();

            RegisterFixture();
        }
Exemplo n.º 19
0
 public Fixture CreateFixture(Shape shape, Category collisionCategories)
 {
     return new Fixture(this, shape, collisionCategories);
 }
Exemplo n.º 20
0
        public override void LoadContent()
        {
            base.LoadContent();

            World.Gravity = new Vector2(0, 9.82f);

            _border = new Border(World, Lines, Framework.GraphicsDevice);

            // Bridge
            // We make a path using 2 points.
            Path bridgePath = new Path();
            bridgePath.Add(new Vector2(-15, 5));
            bridgePath.Add(new Vector2(15, 5));
            bridgePath.Closed = false;

            Vertices box = PolygonTools.CreateRectangle(0.125f, 0.5f);
            PolygonShape shape = new PolygonShape(box, 20);

            _bridgeBodies = PathManager.EvenlyDistributeShapesAlongPath(World, bridgePath, shape, BodyType.Dynamic, 29);

            // Attach the first and last fixtures to the world
            Body anchor = new Body(World, Vector2.Zero);
            anchor.BodyType = BodyType.Static;
            World.AddJoint(new RevoluteJoint(_bridgeBodies[0], anchor, _bridgeBodies[0].Position - new Vector2(0.5f, 0f), true));
            World.AddJoint(new RevoluteJoint(_bridgeBodies[_bridgeBodies.Count - 1], anchor, _bridgeBodies[_bridgeBodies.Count - 1].Position + new Vector2(0.5f, 0f), true));

            PathManager.AttachBodiesWithRevoluteJoint(World, _bridgeBodies, new Vector2(0f, -0.5f), new Vector2(0f, 0.5f), false, true);

            // Soft body
            // We make a rectangular path.
            Path rectanglePath = new Path();
            rectanglePath.Add(new Vector2(-6, -11));
            rectanglePath.Add(new Vector2(-6, 1));
            rectanglePath.Add(new Vector2(6, 1));
            rectanglePath.Add(new Vector2(6, -11));
            rectanglePath.Closed = true;

            // Creating two shapes. A circle to form the circle and a rectangle to stabilize the soft body.
            Shape[] shapes = new Shape[2];
            shapes[0] = new PolygonShape(PolygonTools.CreateRectangle(0.5f, 0.5f, new Vector2(-0.1f, 0f), 0f), 1f);
            shapes[1] = new CircleShape(0.5f, 1f);

            // We distribute the shapes in the rectangular path.
            _softBodies = PathManager.EvenlyDistributeShapesAlongPath(World, rectanglePath, shapes, BodyType.Dynamic, 30);

            // Attach the bodies together with revolute joints. The rectangular form will converge to a circular form.
            PathManager.AttachBodiesWithRevoluteJoint(World, _softBodies, new Vector2(0f, -0.5f), new Vector2(0f, 0.5f), true, true);

            // GFX
            _bridgeBox = new Sprite(ContentWrapper.TextureFromShape(shape, ContentWrapper.Orange, ContentWrapper.Brown));
            _softBodyBox = new Sprite(ContentWrapper.TextureFromShape(shapes[0], ContentWrapper.Green, ContentWrapper.Black));
            _softBodyBox.Origin += new Vector2(ConvertUnits.ToDisplayUnits(0.1f), 0f);
            _softBodyCircle = new Sprite(ContentWrapper.TextureFromShape(shapes[1], ContentWrapper.Lime, ContentWrapper.Grey));
        }
Exemplo n.º 21
0
        private void MakeLivingFixture()
        {
            if (_fsFixture != null)
            {
                _fsBody.DestroyFixture(_fsFixture);
            }

            _fsShape = new CircleShape(0.7f, 1.0f);
            _fsFixture = _fsBody.CreateFixture(_fsShape, this);
            _fsFixture.Restitution = 0.2f;
            _fsFixture.OnCollision += BehaviorCollided;
        }
Exemplo n.º 22
0
 /// <summary>
 /// Creates a fixture and attach it to this body.
 /// If the density is non-zero, this function automatically updates the mass of the body.
 /// Contacts are not created until the next time step.
 /// Warning: This function is locked during callbacks.
 /// </summary>
 /// <param name="shape">The shape.</param>
 /// <param name="userData">Application specific data</param>
 /// <returns></returns>
 public Fixture CreateFixture(Shape shape, object userData)
 {
     return CreateFixture(shape, userData, DefaultCollisionCategories);
 }
Exemplo n.º 23
0
 public Fixture CreateFixture(Shape shape, object userData, Category collisionCategories)
 {
     return new Fixture(this, shape, userData, collisionCategories);
 }
Exemplo n.º 24
0
 /// <summary>
 /// Creates a fixture with the supplied shape.
 /// Note: Default density is 1
 /// </summary>
 /// <param name="shape">The shape</param>
 /// <returns></returns>
 public Fixture CreateFixture(Shape shape)
 {
     return CreateFixture(shape, 1);
 }
Exemplo n.º 25
0
        /// <summary>
        /// Creates a fixture and attach it to this body.
        /// If the density is non-zero, this function automatically updates the mass of the body.
        /// Contacts are not created until the next time step.
        /// Warning: This function is locked during callbacks.
        /// </summary>
        /// <param name="shape">The shape.</param>
        /// <param name="density">The density.</param>
        /// <returns></returns>
        public Fixture CreateFixture(Shape shape, float density)
        {
            Debug.Assert(World.IsLocked == false);
            if (World.IsLocked)
            {
                return null;
            }

            Fixture fixture = new Fixture(this, shape, density);

            if ((Flags & BodyFlags.Active) == BodyFlags.Active)
            {
                BroadPhase broadPhase = World.ContactManager.BroadPhase;
                fixture.CreateProxies(broadPhase, ref Xf);
            }

            FixtureList.Add(fixture);
            fixture.Body = this;

            // Adjust mass properties if needed.
            if (fixture.Density > 0.0f)
            {
                ResetMassData();
            }

            // Let the world know we have a new fixture. This will cause new contacts
            // to be created at the beginning of the next time step.
            World.Flags |= WorldFlags.NewFixture;

            if (World.FixtureAdded != null)
            {
                World.FixtureAdded(fixture);
            }

            return fixture;
        }
Exemplo n.º 26
0
        public static bool TestOverlap(Shape shapeA, int indexA,
                                       Shape shapeB, int indexB,
                                       ref Transform xfA, ref Transform xfB)
        {
            _input.ProxyA.Set(shapeA, indexA);
            _input.ProxyB.Set(shapeB, indexB);
            _input.TransformA = xfA;
            _input.TransformB = xfB;
            _input.UseRadii = true;

            SimplexCache cache;
            DistanceOutput output;
            Distance.ComputeDistance(out output, out cache, _input);

            return output.Distance < 10.0f * Settings.Epsilon;
        }
Exemplo n.º 27
0
 /// <summary>
 /// Creates a fixture and attach it to this body.
 /// If the density is non-zero, this function automatically updates the mass of the body.
 /// Contacts are not created until the next time step.
 /// Warning: This function is locked during callbacks.
 /// </summary>
 /// <param name="shape">The shape.</param>
 /// <returns></returns>
 public Fixture CreateFixture(Shape shape)
 {
     return new Fixture(this, shape);
 }
Exemplo n.º 28
0
 /// <summary>
 /// Creates a fixture and attach it to this body.
 /// If the density is non-zero, this function automatically updates the mass of the body.
 /// Contacts are not created until the next time step.
 /// Warning: This function is locked during callbacks.
 /// </summary>
 /// <param name="shape">The shape.</param>
 /// <returns></returns>
 public Fixture CreateFixture(Shape shape)
 {
     return CreateFixture(shape, DefaultCollisionCategories);
 }
Exemplo n.º 29
0
 /// <summary>
 /// Creates a fixture and attach it to this body.
 /// If the density is non-zero, this function automatically updates the mass of the body.
 /// Contacts are not created until the next time step.
 /// Warning: This function is locked during callbacks.
 /// </summary>
 /// <param name="shape">The shape.</param>
 /// <param name="userData">Application specific data</param>
 /// <returns></returns>
 public Fixture CreateFixture(Shape shape, object userData)
 {
     return new Fixture(this, shape, userData);
 }
Exemplo n.º 30
0
        internal void BindToEntity(Entity _entity)
        {
            this._Entity = _entity;

            //try
            //{
            FarseerPhysics.Collision.Shapes.Shape s = this.Shape._ToShape(new Vector(0, 0), this.Scale, _density: this.Density);
            this._Fixture = _entity._Body.CreateFixture(s, this);
            //this._Fixture.Friction = (float)this.Friction;
            //this._Fixture = FixtureFactory.AttachPolygon(this.Shape.ToVertices(), 1, this.Entity.Body);

            this._Fixture.IsSensor = this.IsSensor;

            this._Fixture.OnCollision += (Fixture _me, Fixture _you, Contact _contact) =>
            {
                Collider me  = (Collider)_me.UserData;
                Collider you = (Collider)_you.UserData;

                if ((me.Entity.CollidesWith == null) || me.Entity.CollidesWith.Contains(you.Entity.CollisionGroup) ||
                    (you.Entity.CollidesWith == null) || you.Entity.CollidesWith.Contains(me.Entity.CollisionGroup))
                //if (me.Entity.CollidesWith.Contains(you.Entity.CollisionGroups) || you.Entity.CollidesWith.Contains(me.Entity.CollisionGroups))
                {
                    bool b = (this.OnCollision == null) ? true : this.OnCollision(me, you);

                    if (b)
                    {
                        if (!you.IsSensor)
                        {
                            this.SolidColliders.Add(you);
                        }
                        this.ContactColliders.Add(you);

                        if (!me.IsSensor && you.IsSensor && you.Entity.GroundSensor == you /* && you.Entity.CarriedBy == null*/)
                        {
                            me.Entity.StartCarrying(you.Entity);
                        }
                    }

                    return(b);
                }
                else
                {
                    return(false);
                }
            };

            this._Fixture.OnSeparation += (Fixture _me, Fixture _you) =>
            {
                Collider me  = (Collider)_me.UserData;
                Collider you = (Collider)_you.UserData;

                if ((me.Entity.CollidesWith == null) || me.Entity.CollidesWith.Contains(you.Entity.CollisionGroup) ||
                    ((you.Entity.CollidesWith == null) || you.Entity.CollidesWith.Contains(me.Entity.CollisionGroup)))
                //if (me.Entity.CollidesWith.Contains(you.Entity.CollisionGroups) || you.Entity.CollidesWith.Contains(me.Entity.CollisionGroups))
                {
                    //this.ContactColliders.Remove(you);
                    if (!you.IsSensor)
                    {
                        this.SolidColliders.Remove(you);
                    }
                    this.ContactColliders.Remove(you);

                    this.OnSeparation?.Invoke(me, you);

                    if (!me.IsSensor && you.IsSensor && you.Entity.GroundSensor == you)
                    {
                        me.Entity.StopCarrying(you.Entity);
                    }
                }
            };
            //if (this.OnCollision != null)
            //	this._Fixture.OnCollision += (Fixture _me, Fixture _you, Contact _contact) => this.OnCollision((Collider)_me.UserData, (Collider)_you.UserData);

            //this._Fixture.OnSeparation += (Fixture _me, Fixture _you) => { /*this._TouchNumber--; */this.ContactColliders.Remove((Collider)_you.UserData); };
            //if (this.OnSeparation != null)
            //	this._Fixture.OnSeparation += (Fixture _me, Fixture _you) => this.OnSeparation((Collider)_me.UserData, (Collider)_you.UserData);
            //}
            //catch { }
        }
Exemplo n.º 31
0
 public Fixture(Body body, Shape shape)
     : this(body, shape, null)
 {
 }