This project has moved and is read-only. For the latest updates, please go here.

Get a list of terrain bodies to draw from MSTerrain

Mar 31, 2011 at 9:17 AM

Last few days I have been Messing around a bit with the new "MSTerrain" class using the testbed example and its working wonderfully :)
But now that I want to move away from the Debug view im trying to figure out how i best get the list of bodies that makes up the terrain as it looks at any given point in time.

Im creating the terrain just as in the sample and using ApplyTexture to add some data to it.

            World = new World(new Vector2(0, -10));
            _terrain = new MSTerrain(World, new AABB(new Vector2(0, 0), 80, 80))
                               PointsPerUnit = 10,
                               CellSize = 5,
                               SubCellSize = 50,
                               Decomposer = Decomposer.Bayazit,
                               Iterations = 3,
Now I want to get the list of objects that make up the terrain so I can draw them using my own methods.
Ive noticed that World.BodyList exists but that will give me all bodies and not just the ones in the terrain, right?

Apr 1, 2011 at 2:42 PM
Edited Apr 1, 2011 at 2:45 PM

I've been playing around with the MSTerrain class and while its a good example of how to use the Marching Squares and Destructible terrain concept  I disliked the way it was structured and the way the scaling worked. So I wrote my own version using that as a basis.  You can use the BodyMap field from the terrain object to get a 2d array of lists of bodies. (which is a mouth full) 

To iterate over that 2d array though, you need access to its dimensions, so you can either calculate them yourself or make the xnum and ynum fields public so you can access them.


In my version I just made one body at creation and converted the BodyMap to be a FixtureMap since in my game, I am more concerned with those.  I'm not certain why there are so many bodies in the terrain object. 

Apr 4, 2011 at 3:21 AM

MSTerrain was mostly designed as an example for others to follow. The reason Bodies are created instead of Fixtures was that originally some of the bodies that were going to be deleted were going to be changed into dynamic bodies to act as debris. I didn't have time to fully test or refine the MSTerrain class due to my own personal time constraints. I do hope it serves as a good tutorial until I am able to finish it.

Apr 4, 2011 at 6:35 PM

I found it useful matt. :D

I wanted to clarify that I didn't like the way it was structured for what I planned on doing with it.  It was good for its intended use.