Shape collision geom seems too large

Jul 4, 2009 at 7:29 PM

Hello

I've only been working with Farseer for a week or so now and don't know it inside out so I need some help please. My problem is that the collision geometry on my created shapes (using the brushes in the DrawingHelpSystem from the demos) the geometries seem to be too large for the created shape. As far as I know i'm not manually increasing the size, even if that is possible. Heres an image that shows the problem. The shapes are at rest so theres no movement. http://img294.imageshack.us/img294/6687/geoms.jpg

Can anyone tell me why this is happening and/or how to fix it?

Thanks in advance.

Coordinator
Jul 4, 2009 at 8:58 PM

You need to make sure that the size you give the geometry is the same you give to the DrawingHelper. You are not using any kind of scaling?

Jul 4, 2009 at 9:08 PM

As far as I know I am giving them the same size, and no not using scaling, here is the code if it helps.

public void New(int width, int height, Colour colour)
        {
            if (_nextIndex < _maxIndex)
            {
                _colours[_nextIndex] = _setColours.GetColour(colour);
                _rectangleBrush[_nextIndex] = new RectangleBrush(width, height, 2, _colours[_nextIndex],
                    Color.Black);
                _rectangleBrush[_nextIndex].Load(_graphics.GraphicsDevice);

                _bodies[_nextIndex] = BodyFactory.Instance.CreateRectangleBody(_physicsSimulator,
                    _rectangleBrush[_nextIndex].Width, _rectangleBrush[_nextIndex].Height,
                    CalculateMass(width, height));
                _bodies[_nextIndex].Position = new Vector2(_graphics.PreferredBackBufferWidth / 2,
                    _graphics.PreferredBackBufferHeight / 2);
                _bodies[_nextIndex].RotationalDragCoefficient = 0.5f;

                _geoms[_nextIndex] = GeomFactory.Instance.CreateRectangleGeom(_physicsSimulator,
                    _bodies[_nextIndex], _rectangleBrush[_nextIndex].Width, _rectangleBrush[_nextIndex].Height);
                _geoms[_nextIndex].FrictionCoefficient = 2.5f;
                _geoms[_nextIndex].RestitutionCoefficient = 0.5f;

                ++_nextIndex;
            }
        }
Coordinator
Jul 4, 2009 at 9:11 PM
Edited Jul 4, 2009 at 9:11 PM

I do not see anything wrong - unless the RectangleBrush returns the wrong width and hight. Try giving the geometry the values from the arguments instead of from the properties on the brush.

Jul 4, 2009 at 9:17 PM

No that didn't work. I checked the values from the brush and they were the same, but I did it anyway. Any other ideas?

Jul 4, 2009 at 9:19 PM

I've just noticed with the PhysicsSimulatorView turned on, the little circle sensor things around each shape is slightly offset from the shape and is shown outside the borders. I reckon this is the problem, but I do not know how to solve it.

Coordinator
Jul 4, 2009 at 9:50 PM

Do you mean the polygons?

Have a look at known issue number 3 here.

Sensors are geometries that can't collide with other geometries like normal. They only detect collisions but do not react to them. If you mean the black points that make up your shape, then it is easily fixed using another origin.

Offsets should not be a problem with circles tho. Only with polygons since their area distribution can be uneven.

Jul 4, 2009 at 9:55 PM
Edited Jul 4, 2009 at 10:21 PM

No not with polygons (well maybe, can't remember). Its with my rectangles and circles.

Coordinator
Jul 4, 2009 at 10:19 PM

Can you take a screenshot of your game with the debug view (PhysicsSimulatorView) enabled?

Jul 4, 2009 at 10:27 PM

Here it is: http://img217.imageshack.us/img217/5484/geomprob.jpg

Coordinator
Jul 5, 2009 at 12:08 AM

To me the geometry seems to be fine, but the border on the texture looks odd.

You create your RectangleBrush like this:

new RectangleBrush(width, height, 2, _colours[_nextIndex], Color.Black);
But the rectangle brush from the samples only have 4 arguments. Have you created a border thickness yourself? If that is the case, you need to make sure that the arguments sent to DrawingHelper.CreateRectangleTexture() are the right ones.

Jul 5, 2009 at 12:25 AM

I had forgotten I had added that. Well I did as you suggested and check the values being sent which turned out to be correct. So I decided to remove the code I had added to see if that made any difference. Well it did a bit, as the gap between the shapes got a little smaller but the sensor things around the shapes still appear more outside than in.

I have to go now, so I'll get back to this tomorrow. Thank you for time so far.