Space between two colliding bodies

Oct 10, 2013 at 4:27 PM
I've modified the simpleDemo1 code, and I've added another rectangle:
using System.Text;
using FarseerPhysics.Dynamics;
using FarseerPhysics.Factories;
using FarseerPhysics.Samples.Demos.Prefabs;
using FarseerPhysics.Samples.DrawingSystem;
using FarseerPhysics.Samples.ScreenSystem;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace FarseerPhysics.Samples.Demos
{
    internal class SimpleDemo1 : PhysicsGameScreen, IDemoScreen
    {
        private Border _border;
        private Body _rectangle;
        private Sprite _rectangleSprite;
        private Body _rectangle2;
        private Sprite _rectangleSprite2;

        #region IDemoScreen Members

        public string GetTitle()
        {
            return "Body with a single fixture";
        }

        public string GetDetails()
        {
            StringBuilder sb = new StringBuilder();
            sb.AppendLine("This demo shows a single body with one attached fixture and shape.");
            sb.AppendLine("A fixture binds a shape to a body and adds material");
            sb.AppendLine("properties such as density, friction, and restitution.");
            sb.AppendLine(string.Empty);
            sb.AppendLine("GamePad:");
            sb.AppendLine("  - Rotate object: left and right triggers");
            sb.AppendLine("  - Move object: right thumbstick");
            sb.AppendLine("  - Move cursor: left thumbstick");
            sb.AppendLine("  - Grab object (beneath cursor): A button");
            sb.AppendLine("  - Drag grabbed object: left thumbstick");
            sb.AppendLine("  - Exit to menu: Back button");
            sb.AppendLine(string.Empty);
            sb.AppendLine("Keyboard:");
            sb.AppendLine("  - Rotate Object: left and right arrows");
            sb.AppendLine("  - Move Object: A,S,D,W");
            sb.AppendLine("  - Exit to menu: Escape");
            sb.AppendLine(string.Empty);
            sb.AppendLine("Mouse / Touchscreen");
            sb.AppendLine("  - Grab object (beneath cursor): Left click");
            sb.AppendLine("  - Drag grabbed object: move mouse / finger");
            return sb.ToString();
        }

        #endregion

        public override void LoadContent()
        {
            base.LoadContent();

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

            _border = new Border(World, ScreenManager, Camera);
            _rectangleSprite.Texture = FarseerPhysicsGame.c.Load<Texture2D>("Blu");

            _rectangleSprite.Origin = new Vector2(_rectangleSprite.Texture.Width / 2, _rectangleSprite.Texture.Height / 2);

            _rectangle = BodyFactory.CreateRectangle(World, ConvertUnits.ToSimUnits(_rectangleSprite.Texture.Width), ConvertUnits.ToSimUnits(_rectangleSprite.Texture.Height), 1f);
            _rectangle.BodyType = BodyType.Dynamic;
            _rectangle.FixedRotation = true;

            //SetUserAgent(_rectangle, 100f, 100f);

            // create sprite based on body

            _rectangleSprite2.Texture = FarseerPhysicsGame.c.Load<Texture2D>("Verde");

            _rectangleSprite2.Origin = new Vector2(_rectangleSprite2.Texture.Width / 2, _rectangleSprite2.Texture.Height / 2);

            _rectangle2 = BodyFactory.CreateRectangle(World, ConvertUnits.ToSimUnits( _rectangleSprite2.Texture.Width), ConvertUnits.ToSimUnits(_rectangleSprite2.Texture.Height), 1f);
            _rectangle2.BodyType = BodyType.Dynamic;

            //SetUserAgent(_rectangle, 100f, 100f);

            // create sprite based on body
        }

        public override void Draw(GameTime gameTime)
        {
            ScreenManager.SpriteBatch.Begin(0, null, null, null, null, null, Camera.View);
            ScreenManager.SpriteBatch.Draw(_rectangleSprite.Texture, new Rectangle((int)ConvertUnits.ToDisplayUnits(_rectangle.Position.X), (int)ConvertUnits.ToDisplayUnits(_rectangle.Position.Y), (int)_rectangleSprite.Texture.Width, (int)_rectangleSprite.Texture.Height), null, Color.White, _rectangle.Rotation, _rectangleSprite.Origin, SpriteEffects.None, 0f);
            ScreenManager.SpriteBatch.Draw(_rectangleSprite2.Texture, new Rectangle((int)ConvertUnits.ToDisplayUnits(_rectangle2.Position.X), (int)ConvertUnits.ToDisplayUnits(_rectangle2.Position.Y), (int)_rectangleSprite2.Texture.Width, (int)_rectangleSprite2.Texture.Height), null, Color.White, _rectangle2.Rotation, _rectangleSprite2.Origin, SpriteEffects.None, 0f);
            
            ScreenManager.SpriteBatch.End();
            _border.Draw();
            base.Draw(gameTime);
        }
    }
}
In the main game method I've changed the representation from 24 pixel per meter to 100 pixel per meter (to have a simple conversion).

ISSUE

My two bodies don't collide themselves and with the border in a precise way. There's always at least 1 empty pixel beetween them.

Image

Link of the enlarged image

I've tried everything and I don't know why it happens.
Thanks in advance.