Breakable body + Texture.

Topics: Developer Forum, User Forum
Apr 15, 2011 at 1:39 PM

Hi everyone.

Im currently developing a platformer game.
The character in the game can be different classes, therefor have different attacks and magic.
When i load the game all the attacks load and then i create a polygon using the Texture to polygon method in your documentation.
But what i want to do is to create a breakable body (is random pieces available?) from the texture. And when the attack is used i draw the
skills texture on the breakable body, and when the body breaks (hit an enemy or floor/wall i want the pieces to shatter and the texture to be
drawn on the different pieces (i attached a pixture to explain better).




So... Is this possible? I've read some threads about and couldn't quite figure out how to do it. Seen someone mention triangulation but i do not quite understand it,
care to explain ? :).

Coordinator
Apr 16, 2011 at 10:13 PM

Are you talking about the drawing of textures or breakable bodies (physics)?

To get breakable bodies, you could take a look at the samples. As for the textures, we are only a physics engine and don't have anything to do with drawing. We provide a couple of samples (with drawing obviously), but none of them currently support drawing of breakable bodies.

Apr 17, 2011 at 10:06 AM

Ok.
I've searched the discussion for other threads about breakable bodies. And i found one where Robert Dodd posted the following:

"If you are using sprites you will have to make each image by hand, which might be difficult.

An easier way is to create a vertexbuffer for each shape and render it as a triangle list. That way it will fit the shape exactly, and the same code will work for every shape. Heres what you'd have to do:

  1. Triangulate vertices
  2. Building vertex array with triangle coordinates
  3. Create VertexBuffer

You can also have a look at the DebugViewXNA, because it does the same thing (except without a vertexbuffer, it just renders straight from the vertex array, but a vertexbuffer is faster)"

Do you mind explaining the three steps above?. I load in a texture with the method from your documentation page.

Coordinator
Apr 17, 2011 at 2:20 PM

I can explain the first step. The two others are related to drawing and outside the scope of the engine.

Farseer Physics Engine 3.3 comes with a couple of triangulation algorithms, they are mostly designed to decompose concave polygons - this means that the algorithms first create a bunch of triangles, then combine them into convex polygons.

I would suggest you play around with the EarClipDecomposer class. Just use the triangulation method, not the convex decomposition ones.

For the other two questions, I would suggest you ask on the App Hub forums.

Apr 17, 2011 at 4:51 PM
Edited Apr 17, 2011 at 4:51 PM

Thank you Genbox, you have been very helpful :D keep the good work up!

Apr 18, 2011 at 8:26 AM

@Genbox: What exactly is the difference between the different triangulators Farseer supports? I thought the CDT decomposer is supposed to be better than earclip (as it handles holes and more arbitrary shapes)?

Martijn

Coordinator
Apr 18, 2011 at 3:05 PM

They are completely different algorithms and they each have their own behavior. Some of them support holes and some of them handle collinear points. Earclip does the most checking and is the most safe one to use. The CDT algorithm comes from the Poly2Tri project, and it does handle holes, but the C# port have some bugs related to collinear points that makes it crash a lot.

The triangulation algorithms are not designed to be used at run-time - they should only be used as a tool to generate objects and level at design time.

Apr 18, 2011 at 7:08 PM

So its not a good idea to create a breakable body during runtime (when using a spell in my game) with the Triangulation method in the EarclipDecomposer class?

Coordinator
Apr 18, 2011 at 7:14 PM

It is possible, but I do not recommend it. If you need breakable bodies, I would recommend you design a few of them at design time and "reply" them at runtime.

Example:

1. (At design time) use the triangulation algorithm on a vertices list and save the result.

2. (At run time) when you need a breakable body, create fixtures from the vertices result and attach them to the body.

Apr 18, 2011 at 7:18 PM

Ok . So in the game im developing im loading in all the different skills at the start, so when im loading the skills i should also create a list of vertices for every skill. and then just create a breakable body from the list made at the start up.

Coordinator
Apr 18, 2011 at 7:31 PM

You should create the triangulated data outside the game. Just like if you had a game editor.

Apr 18, 2011 at 7:34 PM
Edited Apr 18, 2011 at 11:26 PM

Edit: Hmmm. Considering the game having over 100 spells that could be alot of time.
Would it be to much to load it in at startup like i said before with the ThreadPool.QueueUserWorkItem(LoadMethodHere); ?

Because theres a 8 second long intro screen in the beginning wich should give it the time needed to load all.

Apr 19, 2011 at 7:20 AM
Genbox wrote:

They are completely different algorithms and they each have their own behavior. Some of them support holes and some of them handle collinear points. Earclip does the most checking and is the most safe one to use. The CDT algorithm comes from the Poly2Tri project, and it does handle holes, but the C# port have some bugs related to collinear points that makes it crash a lot.

The triangulation algorithms are not designed to be used at run-time - they should only be used as a tool to generate objects and level at design time.

So a worms style type of game where you'd need to alter/triangulize the tiles on the fly would be out of the question for the time being?

And on a side note; do you happen to know what the most stable/robust triangulizer is? Triangle or the GLU tesselator? Maybe I have a stab at porting any of those if the current ones won't suffice...

Developer
Apr 19, 2011 at 9:47 AM

For a worms style of game have a look at the MSTerrain testcase in our testbed. You might have to adjust the MSTerrain class though to fit your needs. It's just a prototype at the moment. As far as i know the marching squares stuff works fine and if you come up with some concrete questions Matt (who wrote it) can probably help you out.

Regarding the triangulizers: I'd say Triangle is the as good as it gets in terms of speed and robustness. Porting Triangle (which I tried myself a while ago) is not the problem. Porting the adaptive precision floating-point arithmetic library it uses however is a pain in the a...

If you want to give it a shot that would be great... I have to admit I just gave up on it because the arithmetic stuff would have taken up a lot of time i'd rather spent on other things ;)

Also take into account that Triangle is not completely open source (as far as I know anyway)... so you probably would have to ask the author before porting and using it anywhere else.

Apr 19, 2011 at 10:28 AM

I just found there's a managed c# port for the glutesselator available in agg-sharp: http://agg-sharp.svn.sourceforge.net/viewvc/agg-sharp/Tesselate/

I believe it's license is also less restrictive than that of Triangle...