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

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

0 Members and 1 Guest are viewing this topic.

zorexx

  • Full Member
  • ***
  • Posts: 109
    • View Profile
    • zorexx@site
SolidShaper + Box2D + SFML
« on: March 20, 2012, 06:19:00 pm »
So, I wrote an application a while ago (SolidShaper: http://www.zorexxlkl.com/solidshaper), and I'm currently working on a sample for it which uses SFML and Box2D.

Basically it's an application that allows you to create shapes for use in collision detection/physics engines. In other words, with this application, you can create shapes directly for your physics engine without using some workarounds like loading from svg files.

This sample demonstrates loading shape from an ssf file into Box2D bodies and displaying it with SFML shapes.
Properties for bodies and shapes can be set from SolidShaper directly, including density, friction, color, etc.

Here's a video of it in action:
http://youtu.be/MKFExir0X-Q

Source code available here:
http://www.zorexxlkl.com/files/downloads/SSFBox2DTest-1.0.1.zip
« Last Edit: April 03, 2012, 05:00:32 am by zorexx »

julen26

  • Jr. Member
  • **
  • Posts: 89
    • View Profile
    • http://julen26.blogspot.com
[WIP] SolidShaper + Box2D + SFML
« Reply #1 on: March 20, 2012, 08:34:57 pm »
Nice! I was thinking to do something like this merged to my generic map editor. But this could be my solution.

I've detected some interface errors, but it's Ok. I like the idea of making maps with collision shapes.

Good luck!

By the way, wich libary do you use for the GUI?

zorexx

  • Full Member
  • ***
  • Posts: 109
    • View Profile
    • zorexx@site
[WIP] SolidShaper + Box2D + SFML
« Reply #2 on: March 21, 2012, 02:29:15 am »
Thanks. Hope you'll like it.

May I know what interface errors you're talking about?

SolidShaper is written in C# .NET with WinForms.

julen26

  • Jr. Member
  • **
  • Posts: 89
    • View Profile
    • http://julen26.blogspot.com
[WIP] SolidShaper + Box2D + SFML
« Reply #3 on: March 21, 2012, 03:58:54 pm »
Yes for example:

 - Create a polygon and then select it.
 - Then select "Extend" radio button and see how the new point moves with mouse.
 - Then come back to the menu and select another radio button.
 - Then clic anywhere.

I get something like this.
https://legacy.sfmluploads.org/cache/pics/231_ss.png

It's difficult to get these errors, but could happen.
Cheers.

zorexx

  • Full Member
  • ***
  • Posts: 109
    • View Profile
    • zorexx@site
[WIP] SolidShaper + Box2D + SFML
« Reply #4 on: March 21, 2012, 04:55:20 pm »
Ahh, thanks for reporting.

Fixed it, will be available in the next version.

If you spot any other errors/problems (even minor ones), please let me know, thanks!  :D

zorexx

  • Full Member
  • ***
  • Posts: 109
    • View Profile
    • zorexx@site
Re: SolidShaper + Box2D + SFML
« Reply #5 on: March 25, 2012, 07:30:05 am »
Completed the sample.
Here's the latest video:
http://youtu.be/MKFExir0X-Q

and the source code:
http://www.zorexxlkl.com/files/downloads/SSFBox2DTest-1.0.0.zip

Be warned though, the code isn't very tidy, if you want to use the codes, you'll probably have to modify it to suit your needs.

Astrof

  • Full Member
  • ***
  • Posts: 135
    • View Profile
Re: SolidShaper + Box2D + SFML
« Reply #6 on: March 26, 2012, 07:13:24 pm »
This is cool! I haven't gotten a chance to test it yet (having some Visual Studio trouble as I haven't messed with it in about a year) but I was wondering, could I potentially use this to create/draw shapes for my game? One of my game ideas revolves around all the sprites to use shapes for drawing/collision and the only reason I haven't gotten to actually doing it is I thought it would be easier to have some kind of map editor to draw and save the shapes but I've been lazy and never got around to it. 

zorexx

  • Full Member
  • ***
  • Posts: 109
    • View Profile
    • zorexx@site
Re: SolidShaper + Box2D + SFML
« Reply #7 on: March 27, 2012, 04:26:37 am »
could I potentially use this to create/draw shapes for my game?

Sure! That's what it's made for.
Good luck on your game!  ;)

Bigz

  • Full Member
  • ***
  • Posts: 154
    • View Profile
    • Bigz.fr
Re: SolidShaper + Box2D + SFML
« Reply #8 on: March 27, 2012, 02:10:48 pm »
Interesting project ! I'll try it when I'll get time for.

I did something a bit similar, based on SVG files, but it's mostly a parser than something more sophisticated as you did. I posted it on the french part of the forum, (here -> http://www.sfml-dev.org/old-forum-fr/viewtopic.php?t=4178 ) but maybe I should also post it here.

zorexx

  • Full Member
  • ***
  • Posts: 109
    • View Profile
    • zorexx@site
Re: SolidShaper + Box2D + SFML
« Reply #9 on: March 27, 2012, 02:49:09 pm »
Cool, too bad I don't understand French.

Hope you'll like it (and find it useful).  :)

zorexx

  • Full Member
  • ***
  • Posts: 109
    • View Profile
    • zorexx@site
Re: SolidShaper + Box2D + SFML
« Reply #10 on: March 30, 2012, 02:30:22 pm »
Just a minor update on SSFile:

SSFile for Java and Python are released.

Downloads available on the project page: http://www.zorexxlkl.com/solidshaper

Edit:
SolidShaper 1.0.1 released.
This release contains several minor bugfixes and improvements.
« Last Edit: March 30, 2012, 05:06:00 pm by zorexx »

Astrof

  • Full Member
  • ***
  • Posts: 135
    • View Profile
Re: SolidShaper + Box2D + SFML
« Reply #11 on: April 05, 2012, 04:18:14 am »
I've been messing with Solid Shaper and have a couple questions:
First: When I'm drawing a shape, what happens when things overlap?

Second: Can I request a feature? Would it be possible to make a function that takes a set of points and draws a triangle strip? I tried to outline one of my sprites and it has a lot of concave sections.  Basically the function would take a list of points in the order they were drawn and figures out a triangle shape pattern.  I'm not sure how complicated that would be but it would be a perfect feature to outline sprites (the current way I have to draw it just right to get a proper outline). 

zorexx

  • Full Member
  • ***
  • Posts: 109
    • View Profile
    • zorexx@site
Re: SolidShaper + Box2D + SFML
« Reply #12 on: April 05, 2012, 07:10:04 am »
First: When I'm drawing a shape, what happens when things overlap?

The last shape drawn or selected will be at the top, use right click to select if you want to select anything below that, this will first select the topmost, then the one below that, and so on.

Second: Can I request a feature? Would it be possible to make a function that takes a set of points and draws a triangle strip? I tried to outline one of my sprites and it has a lot of concave sections.  Basically the function would take a list of points in the order they were drawn and figures out a triangle shape pattern.  I'm not sure how complicated that would be but it would be a perfect feature to outline sprites (the current way I have to draw it just right to get a proper outline). 

That's called triangulation.
It's possible to break polygons into triangles with triangulation, but not into triangle strip.
Since SolidShaper does not have any object-like feature to group shapes together, if I included a triangulation feature, it will break it down to triangles, but then you cannot move them as a set anymore, you'll end up moving each triangle individually.
With that in mind, I would suggest you implement the triangulation in your game itself instead.
I'm pretty sure Nexus's Thor library can do that, you may want to take a look at that:
http://en.sfml-dev.org/forums/index.php?topic=7329.0

On the other hand, if I do find a good way to implement triangulation (probably by introducing a grouping feature or so), I will definitely implement it.  ;)

Astrof

  • Full Member
  • ***
  • Posts: 135
    • View Profile
Re: SolidShaper + Box2D + SFML
« Reply #13 on: April 05, 2012, 07:40:50 am »
First: When I'm drawing a shape, what happens when things overlap?

The last shape drawn or selected will be at the top, use right click to select if you want to select anything below that, this will first select the topmost, then the one below that, and so on.

Ah sorry I wasn't specific; I meant while drawing using triangle strip and parts of it overlap how does that draw a shape? 

That's called triangulation.
It's possible to break polygons into triangles with triangulation, but not into triangle strip.
Since SolidShaper does not have any object-like feature to group shapes together, if I included a triangulation feature, it will break it down to triangles, but then you cannot move them as a set anymore, you'll end up moving each triangle individually.
With that in mind, I would suggest you implement the triangulation in your game itself instead.
I'm pretty sure Nexus's Thor library can do that, you may want to take a look at that:
http://en.sfml-dev.org/forums/index.php?topic=7329.0

On the other hand, if I do find a good way to implement triangulation (probably by introducing a grouping feature or so), I will definitely implement it.  ;)

I'm actually planning on using Thor for particles, etc. but haven't thought about it for triangulation.  I was more looking for an easy fix for my shape drawing/collision problem (most games I try to do die when I get to the physics part or messing with box2d). 


And I'm a bit confused about the triangle strip/triangulation thing.  When drawing with triangle strip doesn't it break everything into triangles anyway (or that's what it looks like)? Aren't triangle strips just connected triangles? I can eventually outline my sprite using the triangle strip if I do it just right but it takes a while.  Maybe it's just wishful thinking but I think there should be a way to split it up into a strip since everything still does share vertices.  Or maybe have everything share a body and have the shapes grouped?

zorexx

  • Full Member
  • ***
  • Posts: 109
    • View Profile
    • zorexx@site
Re: SolidShaper + Box2D + SFML
« Reply #14 on: April 05, 2012, 08:03:45 am »
Ah sorry I wasn't specific; I meant while drawing using triangle strip and parts of it overlap how does that draw a shape? 

Triangle strips are pretty much just, well, triangles, so if there's parts overlapped, it's actually just triangles overlapped, like how other shapes overlap, how it's handled will have to depend on your game.
In Box2D, if you set it as a static body, there should be no problems with overlapping shape (since static shapes won't collide with each other).

And I'm a bit confused about the triangle strip/triangulation thing.  When drawing with triangle strip doesn't it break everything into triangles anyway (or that's what it looks like)? Aren't triangle strips just connected triangles? I can eventually outline my sprite using the triangle strip if I do it just right but it takes a while.  Maybe it's just wishful thinking but I think there should be a way to split it up into a strip since everything still does share vertices.  Or maybe have everything share a body and have the shapes grouped?

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.