Retrieving World Shape Data (Solved)

Topics: Developer Forum
Oct 1, 2013 at 7:48 PM
Hello all, I have recently had trouble with drawing the bodies in my physics world because I cannot seem to get a list of shapes (or some other type of data that will suffice for finding the body's vertices). Normally I would just create a separate list of structs that contained the body, fixture and shape, and draw all the shapes in that list with the data from the shapes (combined with the body position and rotation information) contained in the structs I had created. But that doesn't work too well when I go to add breakable bodies in the world or want to use the cutting tools.
So, I was wondering if there was a way that you can get the vertices data from a fixture that exists in the world.

Or if there is another way to draw shapes, I would much appreciate being let in on the technique.

Please don't just tell me to "check the samples" or leave some other useless annotation that doesn't help. I have checked the forums and the samples many times and do not understand how the drawing system works because the code is poorly commented and over complicated (actually it's over simplified. but simplified things become quite complex when you're a novice programmer like myself who doesn't yet understand all the methods and classes provided by the XNA libraries).
Developer
Oct 2, 2013 at 9:48 AM
Hey,
So, I was wondering if there was a way that you can get the vertices data from a fixture that exists in the world.
I know you don't want to hear it... I'm gonna say it anyway: The debug view does exactly that. Each frame it loops over all bodies and fixtures and gets the shape data and renders it. The debug view itself is not a lot of code and the primitive buffer used in the debug view is taken form the XNA samples (more or less). You can find it here:
http://xbox.create.msdn.com/en-US/education/catalog/sample/shape_rendering
Shape rendering basics are explained in detail here:
http://msdn.microsoft.com/en-us/library/bb196414(v=xnagamestudio.40).aspx
Please don't just tell me to "check the samples" or leave some other useless annotation that doesn't help. I have checked the forums and the samples many times and do not understand how the drawing system works because the code is poorly commented and over complicated (actually it's over simplified. but simplified things become quite complex when you're a novice programmer like myself who doesn't yet understand all the methods and classes provided by the XNA libraries).
Apart from the texture generation (which you don't have to understand in order to see what is going on) most samples just use the spritebatch. It doesn't get any more basic than that if you want to render stuff with XNA. So may I suggest you just try one simpler project first to learn the basics of XNA before diving head first in something as complex as farseer. Most of the samples framework code is based on the scene graph and 2D rendering XNA samples which are very well documented. Anyone who had a look at those (hint: you really should have a look at those) should be able to find his way around the samples.
How the screen management works:
http://xbox.create.msdn.com/en-US/education/catalog/sample/game_state_management
2D rendering related resources:
http://xbox.create.msdn.com/en-US/education/catalog/?contenttype=0&devarea=5&platform=20&sort=1
Oct 3, 2013 at 5:57 AM
facepalm I've been developing with XNA for over a year and I didn't even know that debug view was a thing. This will help me a great deal in my future endeavors. Thank you much sir.

And yes, I know how to use the spritebatch haha. I just never really mess around with graphics stuff. Thanks for your advice but I have made many games with XNA before. actually I just did LudumDare this summer and ranked number 41 overall! you should check my stuff out if you're interested.
http://www.ludumdare.com/compo/ludum-dare-27/?action=preview&uid=23578

also, quick question; you being a developer of Farseer, are you a game developer as well?
Oct 7, 2013 at 8:15 PM
Edited Oct 7, 2013 at 8:18 PM
Alas I have figured it out, in fact, the debug view was not the solution, the debug view contains a bunch of pre-built ways for the shapes to be drawn. What I was looking for was a way to get the shape data of all the shapes that existed in the world, so I could create my own way to draw the shapes.
The solution was extremely simple as I had presumed it would be.
            World Main = new World(new Vector2(0, 9.8f));

            foreach (Body bod in Main.BodyList)
            {
                foreach (Fixture fix in bod.FixtureList)
                {
                    PolygonShape poly = (PolygonShape)fix.Shape;
                    //retrieves shape data and stores it in 'poly'
                }
            }
thank you for your help though, Elsch!