Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: SolidShaper + Box2D + SFML  (Read 20552 times)

0 Members and 2 Guests are viewing this topic.

Astrof

  • Full Member
  • ***
  • Posts: 135
    • View Profile
Re: SolidShaper + Box2D + SFML
« Reply #15 on: April 05, 2012, 11:27:25 pm »
Well, the difference between triangulation and triangle strips here is, in triangulation, you break them into many triangles, 3 triangles mean 3 shapes, however, triangle strip is considered a single shape, since it's basically just a list of points which are "converted" into triangles when being drawn (in SolidShaper).

After loading triangle strips, what you get is a list of points, then, you can decide to convert it into a list of triangles to be added to Box2D as shapes, or if you're just drawing it, you can just convert them in your draw functions.
However, if it's a triangulated polygon, it will be loaded as a list of triangles instead, the original information of it being from the same shape is lost the moment you triangulate it.

Also, once you triangulate a polygon, the triangles no longer share any vertices, since they are already separate shapes. Meaning that, triangulation is an irreversible process, even if I introduce a grouping system, and you can move the triangulated polygon, they will still not share any vertices.

Quote from: box2d Tutorial
Triangle strips are useful for creating “concave” shapes for collision detection/physics engines that cannot detect intersection/collision of concave shapes.

So again (sorry for beating a dead horse) shouldn't triangle strips help to create concave shapes (in box2d)? Is there not a triangulation method to turn things into triangle strips? I don't want separate shapes connected to a body (wouldn't that be inefficient?). 

I found this link http://stackoverflow.com/questions/8980379/polygon-triangulation-into-triangle-strips-for-opengl-es
it mentions splitting into triangles and feeding it into something back into triangle strips. 

Ideally I'd like to have one library/method to create and use shapes for collision and drawing. 

zorexx

  • Full Member
  • ***
  • Posts: 109
    • View Profile
    • zorexx@site
Re: SolidShaper + Box2D + SFML
« Reply #16 on: April 06, 2012, 04:24:58 am »
Yes, triangle strips does help create concave shapes.
However, you have to realize that not all concave polygons can be drawn with triangle strips (without overlapping).

In the link you provided, it says:
Quote
this algorithm works ok but the problem is it returns simple triangles which you can't draw with GL_TRIANGLE_STRIP, you need to use GL_TRIANGLES which isn't very efficient on a large number of vertices.

You said you don't want separate shapes connected to a body, however, that is not possible with concave shapes.
Same goes to triangle strips, what triangle strip does is simply break a list of points down into a list of triangles, meaning that if it's 3 triangles, 3 triangles (meaning 3 polygon shapes) will be added to box2d's body.
It isn't inefficient, however, too much of that may of course, slow things down. However, you shouldn't let that bother you, since that's how things are done anyway.

So what I'm saying is, whether you use triangle strips in SolidShaper, or do triangulation in your game engine, the result is the same, you'll still end up having multiple shapes in one body (which is really totally fine).

Ideally I'd like to have one library/method to create and use shapes for collision and drawing. 

I will try to implement triangulation in SSFile, since it's still manageable if I do it there, but since I can't estimate when it will be done, and since you said you're already using Thor in your project, why don't you try (or temporarily use) the triangulation function there until I've implemented it in SSFile?

Astrof

  • Full Member
  • ***
  • Posts: 135
    • View Profile
Re: SolidShaper + Box2D + SFML
« Reply #17 on: April 06, 2012, 08:03:09 am »
Thanks! If it's too much work/not useful you don't have to; I was just wondering if it existed/if it was possible.

If not a triangulation method a simple grouping method would work too (where one would outline a sprite using shapes and then just group them all together).  Thanks for all your work!

zorexx

  • Full Member
  • ***
  • Posts: 109
    • View Profile
    • zorexx@site
Re: SolidShaper + Box2D + SFML
« Reply #18 on: April 06, 2012, 08:29:17 am »
Implementing grouping in SolidShaper will be much more complex than triangulation in SSFile, since it requires changing how shapes are managed in SolidShaper, as well as the file specification as well, so I'd like to avoid that if possible.

However, how SolidShaper is designed to work isn't by putting all the shapes used in your game in 1 file and have different objects use different shape.

You should use SolidShaper to create 1 file for 1 object (characters, etc). This way, you're already grouping shapes as a single object. You also don't have to reload all the shapes if you just want one object, and it's easier to manage as well.

You can, however, put all the static objects in 1 file, like the terrain and other fixed objects.

In other word, if you have a character sprite, just load it as a reference in SolidShaper, outline it with shapes, and save it as a file (i.e. sprite.ssf), then there you go, the collision map for that sprite is done.

You can also achieve concave polygons if you can snap the vertices to the grid, since the only difference between that and triangulation is that, by using polygons, you'll have to manually make sure the vertices are at the same position, so that there isn't any holes (sometimes this doesn't even matter), while with triangulation or triangle strips, this is done automatically.
« Last Edit: April 06, 2012, 08:30:57 am by zorexx »

N1ghtly

  • Jr. Member
  • **
  • Posts: 96
    • View Profile
Re: SolidShaper + Box2D + SFML
« Reply #19 on: April 09, 2012, 03:08:21 pm »
That's pretty damn amazing!
Good work, keep it up!

zorexx

  • Full Member
  • ***
  • Posts: 109
    • View Profile
    • zorexx@site
Re: SolidShaper + Box2D + SFML
« Reply #20 on: April 09, 2012, 03:19:11 pm »
That's pretty damn amazing!
Good work, keep it up!

Thanks for the feedback!

 

anything