"gridCellSize" question

Topics: User Forum
Sep 21, 2008 at 9:33 PM
Hello,$0I've been using Farseer for a few weeks now and getting along fine. I have a simple question regarding "gridCellSize".$0$0$0$0$0Looking through the source I see that when creating some geometry we set the grid cell size for each geometry. This is then used to construct a Grid object which is used during Collide to detect intersections.$0$0$0$0$0So. What does "gridCellSize" do? I've plugged in a few values and they affect the frame rate greatly but it would be great if someone could give me some explanation as to what this value is used for and why it will affect the frame rate so much.$0$0$0$0$0Many thanks!$0$0
Coordinator
Sep 21, 2008 at 9:56 PM

Hi.

Good to hear that you are getting along fine :)

As you said, the grid is used to check for intersections. The grid takes some time to compute and the smaller the gridsize the more time it takes. The grid is computed in the constructor if the Geom class, so you might want to create your Geoms beforehand and cache them for later use.

If you use the GeomFactory, you can pass 0 to the gridcellsize parameter. The factory will then calculate the cellsize based on the AABB (Axis Aligned Bounding Box... The bounderies of the element). If you have a geom with sharp points, you might want to put in an even smaller value to gridcellsize than default, or you will get trouble with the collisions.

You can BTW adjust the default gridcellsize in the GeomFactory by using the GeomFactory.GridCellSizeAABBFactor property.

So all in all, you will need to make as large a grid cell as possible (for performance) without hurting collision detection. You best bet for starters is passing in 0 to the geom factory and let it calculate the right cell size.

Sep 22, 2008 at 9:21 AM
Great! Thanks for the info, this gives me some direction for tweaking my simulation. : )

Out of interest what method does the "Grid" object use for intersection? We obvioulsy have our vertex data within Geom that could be used to calc intersections but instead we are using the Grid (with its 2D array). Is this like a kind of rasterisation of the Geom data? Meaning that you are doing a kind of per "pixel" (obviously not pixels though...) intersection test.

If I am close that last sentance would probably of made sense otherwise I'm just rambling. : )